* [PATCHv2] Fix static TLS exhaustion by TLS descriptors
@ 2014-06-03 17:50 Kyle McMartin
2014-11-21 5:17 ` Alexandre Oliva
0 siblings, 1 reply; 2+ messages in thread
From: Kyle McMartin @ 2014-06-03 17:50 UTC (permalink / raw)
To: libc-alpha
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 -mtls-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
2014-06-03 Kyle McMartin <kyle@redhat.com>
* sysdeps/aarch64/dl-machine.h (elf_machine_rela): Always
allocate dynamic TLS space for TLS descriptors.
* sysdeps/x86_64/dl-machine.h (elf_machine_rela): Ditto.
* sysdeps/arm/dl-machine.h (elf_machine_rel): Ditto.
* sysdeps/i386/dl-machine.h (elf_machine_rel): Ditto.
--- a/sysdeps/aarch64/dl-machine.h
+++ b/sysdeps/aarch64/dl-machine.h
@@ -295,7 +295,7 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
# ifndef SHARED
CHECK_STATIC_TLS (map, sym_map);
# else
- if (!TRY_STATIC_TLS (map, sym_map))
+ if (1)
{
td->arg = _dl_make_tlsdesc_dynamic
(sym_map, sym->st_value + reloc->r_addend);
diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
index 899b256..f55a991 100644
--- a/sysdeps/arm/dl-machine.h
+++ b/sysdeps/arm/dl-machine.h
@@ -458,7 +458,7 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
# ifndef SHARED
CHECK_STATIC_TLS (map, sym_map);
# else
- if (!TRY_STATIC_TLS (map, sym_map))
+ if (1)
{
td->argument.pointer
= _dl_make_tlsdesc_dynamic (sym_map, value);
diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
index 368bee2..b6b5802 100644
--- a/sysdeps/i386/dl-machine.h
+++ b/sysdeps/i386/dl-machine.h
@@ -394,7 +394,7 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
# ifndef SHARED
CHECK_STATIC_TLS (map, sym_map);
# else
- if (!TRY_STATIC_TLS (map, sym_map))
+ if (1)
{
td->arg = _dl_make_tlsdesc_dynamic
(sym_map, sym->st_value + (ElfW(Word))td->arg);
diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
index 8df04a9..4ec4340 100644
--- a/sysdeps/x86_64/dl-machine.h
+++ b/sysdeps/x86_64/dl-machine.h
@@ -359,7 +359,7 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
# ifndef SHARED
CHECK_STATIC_TLS (map, sym_map);
# else
- if (!TRY_STATIC_TLS (map, sym_map))
+ if (1)
{
td->arg = _dl_make_tlsdesc_dynamic
(sym_map, sym->st_value + reloc->r_addend);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCHv2] Fix static TLS exhaustion by TLS descriptors
2014-06-03 17:50 [PATCHv2] Fix static TLS exhaustion by TLS descriptors Kyle McMartin
@ 2014-11-21 5:17 ` Alexandre Oliva
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2014-11-21 5:17 UTC (permalink / raw)
To: Kyle McMartin; +Cc: libc-alpha
Hi, Kyle,
On Jun 3, 2014, 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 approach severely worsens performance of TLS Descriptors.
If what you're running into is the DTV limit for Static TLS, rather than
Static TLS space proper, please consider using in its stead the final
version (still under review) of the patch I posted this week, with
Subject: “[BZ#17090/17620/17621]: fix DTV race, assert, and DTV_SURPLUS
Static TLS limit”. It should allow TPREL relocs regardless of how many
TLS modules you've loaded before, static or dynamic, except in the
unlikely case of actually filling up the Static TLS segment.
Please let me know if you have any problems with it.
--
Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-21 5:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-03 17:50 [PATCHv2] Fix static TLS exhaustion by TLS descriptors Kyle McMartin
2014-11-21 5:17 ` Alexandre Oliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).