Date: Mon, 15 Dec 2025 17:00:24 +0000 From: Jessica Clarke <jrtc27@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 79b0a953ada4 - stable/14 - rtld-elf: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V Message-ID: <69403ea8.e873.327df7d5@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=79b0a953ada4c516c43f163c51d3f083da666d59 commit 79b0a953ada4c516c43f163c51d3f083da666d59 Author: Jessica Clarke <jrtc27@FreeBSD.org> AuthorDate: 2025-05-06 22:14:51 +0000 Commit: Jessica Clarke <jrtc27@FreeBSD.org> CommitDate: 2025-12-15 16:58:44 +0000 rtld-elf: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V The implementation of dl_iterate_phdr abuses tls_get_addr_slow to get to the start of the TLS block, inlining the implementation of __tls_get_addr as if the tls_index's ti_offset were 0 (historically it called __tls_get_addr itself but changed due to locking issues). 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, but it's __tls_get_addr's responsibility to compensate for that. By using an offset of zero here, tls_get_addr_slow will return a pointer to the start of the TLS block itself, so by adding TLS_DTV_OFFSET we will point TLS_DTV_OFFSET past the module's TLS block. Fix this by removing the extra bias (the alternative would be to pass -TLS_DTV_OFFSET and keep the addition, which would more closely follow what __tls_get_addr does, but this is more direct). (Note this also applies to MIPS on stable/13) Reviewed by: kib Fixes: d36d68161517 ("rtld dl_iterate_phdr(): dlpi_tls_data is wrong") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50184 (cherry picked from commit c02aaba1b4549c1c3b1481f7c935f6cc80b98e8d) --- libexec/rtld-elf/rtld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 00e805c5c4c9..a44a5e303dcc 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -4269,7 +4269,7 @@ rtld_fill_dl_phdr_info(const Obj_Entry *obj, struct dl_phdr_info *phdr_info) phdr_info->dlpi_tls_modid = obj->tlsindex; dtvp = &_tcb_get()->tcb_dtv; phdr_info->dlpi_tls_data = (char *)tls_get_addr_slow(dtvp, - obj->tlsindex, 0, true) + TLS_DTV_OFFSET; + obj->tlsindex, 0, true); phdr_info->dlpi_adds = obj_loads; phdr_info->dlpi_subs = obj_loads - obj_count; }help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69403ea8.e873.327df7d5>
