diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2016-12-26 10:08:34 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2016-12-26 10:08:34 +0100 |
commit | 003a27e8195470f470f4d9384ca70d4e9fc8bd1b (patch) | |
tree | 9706d90e8c0806acaabde547fe8f1017329087b2 /csu/libc-tls.c | |
parent | 03baef1c9cfb396d76cae20a00aee657871e79c4 (diff) | |
download | glibc-003a27e8195470f470f4d9384ca70d4e9fc8bd1b.tar glibc-003a27e8195470f470f4d9384ca70d4e9fc8bd1b.tar.gz glibc-003a27e8195470f470f4d9384ca70d4e9fc8bd1b.tar.bz2 glibc-003a27e8195470f470f4d9384ca70d4e9fc8bd1b.zip |
Initialize the stack guard earlier when linking statically [BZ #7065]
The address of the stack canary is stored in a per-thread variable,
which means that we must ensure that the TLS area is intialized before
calling any -fstack-protector'ed functions. For dynamically linked
applications, we ensure this (in a later patch) by disabling
-fstack-protector for the whole dynamic linker, but for static
applications, the AT_ENTRY address is called directly by the kernel, so
we must deal with the problem differently.
In static appliations, __libc_setup_tls performs the TCB setup and TLS
initialization, so this commit arranges for it to be called early and
unconditionally. The call (and the stack guard initialization) is
before the DL_SYSDEP_OSCHECK hook, which if set will probably call
functions which are stack-protected (it does on Linux and NaCL too). We
also move apply_irel up, so that we can still safely call functions that
require ifuncs while in __libc_setup_tls (though if stack-protection is
enabled we still have to avoid calling functions that are not
stack-protected at this stage).
Diffstat (limited to 'csu/libc-tls.c')
-rw-r--r-- | csu/libc-tls.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/csu/libc-tls.c b/csu/libc-tls.c index 8f922341de..454f165457 100644 --- a/csu/libc-tls.c +++ b/csu/libc-tls.c @@ -102,14 +102,14 @@ init_static_tls (size_t memsz, size_t align) } void -__libc_setup_tls (size_t tcbsize, size_t tcbalign) +__libc_setup_tls (void) { void *tlsblock; size_t memsz = 0; size_t filesz = 0; void *initimage = NULL; size_t align = 0; - size_t max_align = tcbalign; + size_t max_align = TCB_ALIGNMENT; size_t tcb_offset; const ElfW(Phdr) *phdr; @@ -142,9 +142,9 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) _dl_allocate_tls_storage (in elf/dl-tls.c) does using __libc_memalign and dl_tls_static_align. */ tcb_offset = roundup (memsz + GL(dl_tls_static_size), max_align); - tlsblock = __sbrk (tcb_offset + tcbsize + max_align); + tlsblock = __sbrk (tcb_offset + TLS_INIT_TCB_SIZE + max_align); #elif TLS_DTV_AT_TP - tcb_offset = roundup (tcbsize, align ?: 1); + tcb_offset = roundup (TLS_INIT_TCB_SIZE, align ?: 1); tlsblock = __sbrk (tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size)); tlsblock += TLS_PRE_TCB_SIZE; @@ -215,12 +215,3 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) init_static_tls (memsz, MAX (TLS_TCB_ALIGN, max_align)); } - -/* This is the minimal initialization function used when libpthread is - not used. */ -void -__attribute__ ((weak)) -__pthread_initialize_minimal (void) -{ - __libc_setup_tls (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN); -} |