opnsense-src/libexec/rtld-elf
Jessica Clarke ccfb1c50e4 Revert "rtld: fix allocate_module_tls() variant I fallback to static allocation"
This was applying a NetBSD fix to FreeBSD. However, the original code
was correct for FreeBSD. NetBSD's obj->tlsoffset is relative to the end
of the TCB, not the TCB itself, whilst ours is relative to the TCB[1]
itself. For example, our allocate_tls uses (char *)tcb + obj->tlsoffset
for the memcpy and memset calls.

Without this reverted, for dynamically loaded shared objects, Initial
Exec accesses to TLS variables on variant I architectures (non-x86) use
the correct address, whilst General Dynamic and dlsym(3) use the
incorrect address (TLS_TCB_SIZE past the start). Note that, on arm64,
LLVM only supports TLSDESC (including LLD) and TLSDESC will use the
static resolver if the variable ends up allocated to the static TLS
block, even in the presence of dlopen(3), so only dlsym(3) shows the
discrepancy there.

Whilst here, add a comment to explain this difference to try and avoid
the same mistake being made in future.

[1] In the case of variant II, it's the amount to subtract, so still
    positive

This reverts commit e9a38ed2fa.

Reviewed by:	kib (prior version)
Fixes:		e9a38ed2fa ("rtld: fix allocate_module_tls() variant I fallback to static allocation")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D50565
2025-05-28 21:24:52 +01:00
..
aarch64 tls: Introduce struct dtv and struct dtv_slot 2025-05-07 20:20:26 +01:00
amd64 amd64: switch to amd64_set_tlsbase to set tls base 2025-05-28 14:11:23 +03:00
arm tls: Introduce struct dtv and struct dtv_slot 2025-05-07 20:20:26 +01:00
i386 tls: Introduce struct dtv and struct dtv_slot 2025-05-07 20:20:26 +01:00
powerpc tls: Introduce struct dtv and struct dtv_slot 2025-05-07 20:20:26 +01:00
powerpc64 tls: Introduce struct dtv and struct dtv_slot 2025-05-07 20:20:26 +01:00
riscv rtld-elf/riscv: Don't allocate static TLS for dynamic TLS relocations 2025-05-28 21:22:15 +01:00
rtld-libc rtld: get syscall implementations from libsys 2025-05-24 00:37:17 +01:00
tests Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
debug.c Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
debug.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
libmap.c Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:23 -06:00
libmap.conf Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libmap.h Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:23 -06:00
Makefile Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
Makefile.depend Update Makefile.depend files 2024-10-14 10:26:17 -07:00
map_object.c rtld-elf: Fix executable's TLS module index for direct exec 2025-05-06 23:14:51 +01:00
rtld.1 rtld.1: cross-reference rtld_get_var.3 2024-11-07 07:15:30 +02:00
rtld.c Revert "rtld: fix allocate_module_tls() variant I fallback to static allocation" 2025-05-28 21:24:52 +01:00
rtld.h tls: Introduce struct dtv and struct dtv_slot 2025-05-07 20:20:26 +01:00
rtld_lock.c rtld: add lockstate_wlocked() 2025-05-02 21:08:09 +03:00
rtld_lock.h rtld: add lockstate_wlocked() 2025-05-02 21:08:09 +03:00
rtld_malloc.c libexec: Remove ancient SCCS tags. 2023-11-26 22:23:28 -07:00
rtld_malloc.h Remove "All Rights Reserved" from FreeBSD Foundation copyrights 2024-07-30 12:16:36 -04:00
rtld_paths.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld_printf.c rtld: Catch up to 07d90ee0a6 in subr_prf.c: Fix '+' conversion handling 2024-09-22 10:52:11 -06:00
rtld_printf.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld_tls.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld_utrace.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
Symbol.map rtld: implement _dl_iterate_phdr_locked 2024-11-13 19:33:59 -06:00
xmalloc.c rtld: switch from malloc_aligned() to __crt_aligned_alloc() 2023-08-21 17:16:42 +03:00