Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Dec 2025 18:18:49 +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: 03d5ae50dc7f - stable/13 - libc: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V
Message-ID:  <69405109.2553c.2c5e2c77@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/13 has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=03d5ae50dc7f2c12427c937d374a679901eaf9dc

commit 03d5ae50dc7f2c12427c937d374a679901eaf9dc
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2025-05-06 22:14:50 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2025-12-15 17:56:36 +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 b6dab041bac3..c554deb0e5fc 100644
--- a/lib/libc/gen/dlfcn.c
+++ b/lib/libc/gen/dlfcn.c
@@ -226,7 +226,7 @@ dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused,
 		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;
 	mutex_lock(&dl_phdr_info_lock);
 	phdr_info.dlpi_tls_data = __tls_get_addr(&ti);
 	ret = callback(&phdr_info, sizeof(phdr_info), data);


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69405109.2553c.2c5e2c77>