This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] elf: Do not use memalign for TCB/TLS blocks allocation [BZ #17730]
- From: Florian Weimer <fweimer at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Tue, 21 Jun 2016 13:41:36 +0200
- Subject: Re: [PATCH] elf: Do not use memalign for TCB/TLS blocks allocation [BZ #17730]
- Authentication-results: sourceware.org; auth=none
- References: <20160621113822 dot 0A6F04016363B at oldenburg dot str dot redhat dot com>
On 06/21/2016 01:38 PM, Florian Weimer wrote:
Instead, call malloc and explicitly align the pointer.
There is no external location to store the original (unaligned)
pointer, and this commit increases the allocation size to store
the pointer at a fixed location relative to the TCB pointer.
The manual alignment means that some space goes unused which
was previously made available for subsequent allocations.
However, in the TLS_DTV_AT_TP case, the manual alignment code
avoids aligning the pre-TCB to the TLS block alignment. (Even
while using memalign, the allocation had some unused padding
in front.)
This concludes the removal of memalign calls from the TLS code,
and the new tst-tls3-malloc test verifies that only core malloc
routines are used.
2016-06-21 Florian Weimer <fweimer@redhat.com>
[BZ #17730]
Avoid using memalign for TCB allocations.
* elf/dl-tls.c (tcb_to_pointer_to_free_location): New.
(_dl_allocate_tls_storage): Use malloc and manual alignment.
Avoid alignment gap in the TLS_DTV_AT_TP case.
(_dl_deallocate_tls): Use tcb_to_pointer_to_free_location to
determine the pointer to free.
* nptl/tst-tls3-malloc.c: New test.
* nptl/Makefile (tests): Add it.
(tst-tls3-malloc): Link with libdl, libpthread.
(LDFLAGS-tst-tls3-malloc): Set.
(tst-tls3-malloc.out): Depend on DSO used in test.
I tested this series on aarch64, ppc64le and x86_64, which have:
sysdeps/aarch64/nptl/tls.h:# define TLS_DTV_AT_TP 1
sysdeps/aarch64/nptl/tls.h:# define TLS_TCB_AT_TP 0
sysdeps/powerpc/nptl/tls.h:# define TLS_DTV_AT_TP 1
sysdeps/powerpc/nptl/tls.h:# define TLS_TCB_AT_TP 0
sysdeps/x86_64/nptl/tls.h:# define TLS_TCB_AT_TP 1
sysdeps/x86_64/nptl/tls.h:# define TLS_DTV_AT_TP 0
So both cases are covered.
Thanks,
Florian