Page MenuHomeFreeBSD

libc: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-V
ClosedPublic

Authored by jrtc27 on May 5 2025, 11:18 PM.
Tags
None
Referenced Files
F142131789: D50182.id155010.diff
Fri, Jan 16, 8:10 AM
Unknown Object (File)
Wed, Jan 7, 5:08 PM
Unknown Object (File)
Wed, Dec 31, 12:23 AM
Unknown Object (File)
Tue, Dec 30, 11:33 AM
Unknown Object (File)
Mon, Dec 29, 4:48 PM
Unknown Object (File)
Sat, Dec 20, 10:11 AM
Unknown Object (File)
Dec 16 2025, 7:09 PM
Unknown Object (File)
Dec 12 2025, 6:10 PM
Subscribers

Details

Summary

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)

Fixes: dbd2053026a6 ("libc dl_iterate_phdr(): dlpi_tls_data is wrong")
MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable