5 Dec 2025 17:00:22 +0000 Message-Id: <69403ea6.de21.2b71f604@gitrepo.freebsd.org> The branch stable/14 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=11d41989cc62c8812c5f6140d1c1877575f09aad commit 11d41989cc62c8812c5f6140d1c1877575f09aad Author: Jessica Clarke AuthorDate: 2025-05-06 22:14:50 +0000 Commit: Jessica Clarke CommitDate: 2025-12-15 16:58:44 +0000 libc: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V The implementation of dl_iterate_phdr for statically-linked binaries abuses __tls_get_addr to get to the start of the TLS block. For most architectures, tls_index's ti_offset (relocated by DTPOFF/DTPREL for GOT entries) is just the offset within that module's TLS block. However, for PowerPC and RISC-V, which have a non-zero TLS_DTV_OFFSET and thus are designed assuming DTV entries are biased by that value, ti_offset normally has TLS_DTV_OFFSET pre-subtracted. By using an offset of zero here we end up getting a pointer TLS_DTV_OFFSET past what __tls_get_addr would return for the first TLS variable. Fix this by using -TLS_DTV_OFFSET to mirror what the General Dynamic GOT entry for the first TLS variable would be. (Note this also applies to MIPS on stable/13) Reviewed by: kib Fixes: dbd2053026a6 ("libc dl_iterate_phdr(): dlpi_tls_data is wrong") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50182 (cherry picked from commit 78b99f369f75f5df49b506ae750659b07ab34362) --- lib/libc/gen/dlfcn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c index bffee3952e0d..ae1c8d83df19 100644 --- a/lib/libc/gen/dlfcn.c +++ b/lib/libc/gen/dlfcn.c @@ -229,7 +229,7 @@ _dl_iterate_phdr_locked( return (1); _once(&dl_phdr_info_once, dl_init_phdr_info); ti.ti_module = 1; - ti.ti_offset = 0; + ti.ti_offset = -TLS_DTV_OFFSET; phdr_info.dlpi_tls_data = __tls_get_addr(&ti); ret = callback(&phdr_info, sizeof(phdr_info), data); return (ret);