glibc/sysdeps
Florian Weimer 018f0fc3b8 elf: Support recursive use of dynamic TLS in interposed malloc
It turns out that quite a few applications use bundled mallocs that
have been built to use global-dynamic TLS (instead of the recommended
initial-exec TLS).  The previous workaround from
commit afe42e935b ("elf: Avoid some
free (NULL) calls in _dl_update_slotinfo") does not fix all
encountered cases unfortunatelly.

This change avoids the TLS generation update for recursive use
of TLS from a malloc that was called during a TLS update.  This
is possible because an interposed malloc has a fixed module ID and
TLS slot.  (It cannot be unloaded.)  If an initially-loaded module ID
is encountered in __tls_get_addr and the dynamic linker is already
in the middle of a TLS update, use the outdated DTV, thus avoiding
another call into malloc.  It's still necessary to update the
DTV to the most recent generation, to get out of the slow path,
which is why the check for recursion is needed.

The bookkeeping is done using a global counter instead of per-thread
flag because TLS access in the dynamic linker is tricky.

All this will go away once the dynamic linker stops using malloc
for TLS, likely as part of a change that pre-allocates all TLS
during pthread_create/dlopen.

Fixes commit d2123d6827 ("elf: Fix slow
tls access after dlopen [BZ #19924]").

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
2024-07-01 19:02:11 +02:00
..
aarch64 Aarch64: Add new memset for Qualcomm's oryon-1 core 2024-06-30 13:47:17 +02:00
alpha elf: Remove HWCAP_IMPORTANT 2024-06-18 10:45:36 +02:00
arc Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
arm arm: Avoid UB in elf_machine_rel() 2024-06-26 12:45:43 +02:00
csky elf: Remove HWCAP_IMPORTANT 2024-06-18 10:45:36 +02:00
generic elf: Support recursive use of dynamic TLS in interposed malloc 2024-07-01 19:02:11 +02:00
gnu login: Use unsigned 32-bit types for seconds-since-epoch 2024-04-19 14:38:17 +02:00
hppa Update hppa libm-test-ulps 2024-06-23 13:51:25 -04:00
htl htl: Implement some support for TLS_DTV_AT_TP 2024-03-23 23:00:30 +01:00
hurd hurd: Move internal functions to internal header 2024-03-23 22:43:07 +01:00
i386 i386: Update ulps 2024-06-20 19:00:48 +02:00
ieee754 Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
loongarch LoongArch: Fix tst-gnu2-tls2 test case 2024-06-26 12:02:07 +08:00
m68k Implement C23 logp1 2024-06-17 13:47:09 +00:00
mach Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
microblaze Implement C23 logp1 2024-06-17 13:47:09 +00:00
mips Revert "MIPSr6/math: Use builtin fma and fmaf" 2024-06-25 01:02:58 +02:00
nios2 Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
nptl Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-04-02 15:28:36 -03:00
or1k Implement C23 logp1 2024-06-17 13:47:09 +00:00
posix posix: Sync tempname with gnulib 2024-04-10 14:53:39 -03:00
powerpc powerpc: Update ulps 2024-06-20 12:15:31 +02:00
pthread Add crt1-2.0.o for glibc 2.0 compatibility tests 2024-05-06 07:49:40 -07:00
riscv RISC-V: Update ulps 2024-06-20 23:46:32 +02:00
s390 s390x: Capture grep output in static PIE check 2024-06-20 14:34:06 +02:00
sh Implement C23 logp1 2024-06-17 13:47:09 +00:00
sparc sparc: Regenerate ULPs 2024-06-19 14:58:32 +02:00
unix posix: Fix pidfd_spawn/pidfd_spawnp leak if execve fails (BZ 31695) 2024-06-25 12:11:48 -03:00
wordsize-32 Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wordsize-64 Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
x86 x86: Set default non_temporal_threshold for Zhaoxin processors 2024-06-30 06:26:43 -07:00
x86_64 elf: Support recursive use of dynamic TLS in interposed malloc 2024-07-01 19:02:11 +02:00