[PATCH] fix static TLS consumption by TLS descriptors

Florian Weimer fweimer@redhat.com
Fri Oct 30 20:50:07 GMT 2020


* Andrew Pinski via Libc-alpha:

> On Wed, May 14, 2014 at 1:33 PM Kyle McMartin <kmcmarti@redhat.com> wrote:
>>
>> AArch64 presently defaults to use TLS descriptors, as opposed to
>> traditional dynamic TLS relocations, and has hit a bug in the copy-pasta
>> used in elf_machine_rel{,a} for all TLS descriptor implementations. When
>> a program calls dlopen() with R_AARCH64_TLSDESC relocs, we're consuming
>> static TLS until it's exhausted (presumably as an optimisation.)
>> However, this means that once our static TLS space is consumed,
>> attempting to dlopen() any shared object which contain an
>> R_AARCH64_TPREL reloc will fail, since we've exhausted all the space.
>>
>> Instead, always use dynamic TLS for TLS descriptors, which lets us load
>> arbitrarily many proper dynamic TLS using shared objects, and allow the
>> static TLS fallback only in the non-SHARED case.
>>
>> This issue is reproducible on x86_64, by specifying -ftls-dialect=gnu2
>> when building with gcc. I've written a test for this:
>> https://github.com/jkkm/test-tls_desc.git
>> Tweak DIALECT to be appropriate, and run ./test-tls_desc.sh, ./main
>> and it should fail with:
>> % ./test-tls_desc.sh; ./main
>> ./tmp16.so: cannot allocate memory in static TLS block
>> ./test-tls_desc.sh: line 18: 10141 Aborted                 (core dumped) ./main
>
> This or a variant of this patch never went in it seems and VPP folks
> had run into this similar thing:

> https://jira.fd.io/browse/VPP-1284

There isn't really enough information in the JIRA ticket.  It could also
be the race fixed in:

commit b7cf203b5c17dd6d9878537d41e0c7cc3d270a67
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Sep 27 16:55:14 2017 +0100

    aarch64: Disable lazy symbol binding of TLSDESC

The allocation issue should be fixed in:

commit ffb17e7ba3a5ba9632cee97330b325072fbe41dd
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Jun 10 13:40:40 2020 +0100

    rtld: Avoid using up static TLS surplus for optimizations [BZ #25051]

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill



More information about the Libc-alpha mailing list