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
Unknown Object (File)
Sat, Jun 20, 12:46 AM
Unknown Object (File)
Tue, Jun 16, 2:58 AM
Unknown Object (File)
May 3 2026, 11:54 AM
Unknown Object (File)
Apr 22 2026, 9:50 PM
Unknown Object (File)
Apr 21 2026, 5:42 PM
Unknown Object (File)
Apr 21 2026, 7:10 AM
Unknown Object (File)
Apr 19 2026, 4:53 AM
Unknown Object (File)
Apr 17 2026, 4:35 AM
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