diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-12-03 13:33:44 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-12-03 13:48:55 +0100 |
commit | 1d9cbb96082e646de7515a1667efa041ffb79958 (patch) | |
tree | b52e641f97c37dfed401538a038a4ae058ea87ce /sysdeps/i386 | |
parent | 7c331116971d38e57703af4097ed13ab6bef91d0 (diff) | |
download | glibc-1d9cbb96082e646de7515a1667efa041ffb79958.zip glibc-1d9cbb96082e646de7515a1667efa041ffb79958.tar.gz glibc-1d9cbb96082e646de7515a1667efa041ffb79958.tar.bz2 |
x86: Fix THREAD_SELF definition to avoid ld.so crash (bug 27004)
The previous definition of THREAD_SELF did not tell the compiler
that %fs (or %gs) usage is invalid for the !DL_LOOKUP_GSCOPE_LOCK
case in _dl_lookup_symbol_x. As a result, ld.so could try to use the
TCB before it was initialized.
As the comment in tls.h explains, asm volatile is undesirable here.
Using the __seg_fs (or __seg_gs) namespace does not interfere with
optimization, and expresses that THREAD_SELF is potentially trapping.
Diffstat (limited to 'sysdeps/i386')
-rw-r--r-- | sysdeps/i386/nptl/tls.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h index b74347b..ab98c24 100644 --- a/sysdeps/i386/nptl/tls.h +++ b/sysdeps/i386/nptl/tls.h @@ -234,11 +234,16 @@ tls_fill_user_desc (union user_desc_init *desc, assignments like pthread_descr self = thread_self(); do not get optimized away. */ -# define THREAD_SELF \ +# if __GNUC_PREREQ (6, 0) +# define THREAD_SELF \ + (*(struct pthread *__seg_gs *) offsetof (struct pthread, header.self)) +# else +# define THREAD_SELF \ ({ struct pthread *__self; \ asm ("movl %%gs:%c1,%0" : "=r" (__self) \ : "i" (offsetof (struct pthread, header.self))); \ __self;}) +# endif /* Magic for libthread_db to know how to do THREAD_SELF. */ # define DB_THREAD_SELF \ |