Page MenuHomeFreeBSD

rtld-elf: Pass struct tcb * around rather than struct dtv **
ClosedPublic

Authored by jrtc27 on May 28 2025, 10:42 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jul 27, 12:01 AM
Unknown Object (File)
Fri, Jul 25, 11:59 PM
Unknown Object (File)
Fri, Jul 25, 10:20 AM
Unknown Object (File)
Thu, Jul 24, 6:36 AM
Unknown Object (File)
Tue, Jul 22, 3:10 AM
Unknown Object (File)
Tue, Jul 22, 2:10 AM
Unknown Object (File)
Sat, Jul 19, 5:31 PM
Unknown Object (File)
Fri, Jul 18, 10:34 PM
Subscribers

Details

Summary

When this code was first written we didn't have even a struct tcb, so to
make it MI a pointer to the DTV pointer in the TCB was passed around.
Now that we have a struct tcb we can simplify the code by instead
passing around a pointer to that, and the MI code can access the tcb_dtv
member wherever it happens to be in the layout. This reduces boilerplate
in all the various callers of tls_get_addr_common/slow and makes it
clearer that tls_get_addr_common/slow are operating on the TCB, rather
than obfuscating it slightly through the double pointer.

Whilst here, clarify the comments in aarch64's TLSDESC dynamic resolver,
which were using tp without clarifying what this was for (previously a
pointer to the DTV pointer, now a pointer to the TCB, which happen to be
the same thing for Variant I TLS, and in the case of AArch64 are what
TPIDR_EL0 point to directly, with no offset/bias).

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 64522
Build 61406: arc lint + arc unit

Event Timeline

libexec/rtld-elf/rtld.c
5391

tcp is always the current thread tcb. Why not remove the first arg from tls_get_addr_common() at all?

I am not so sure about tls_get_addr_slow() tcb arg, but it might be a reasonable thing to do as well.

libexec/rtld-elf/rtld.c
5391

_rtld_tlsdesc_dynamic already has the TCB to hand, so might as well pass it in here, for example. Also downstream for the new CHERI TLS ABI I'm working on there are some cases (for distributing static TLS) of calling some of these functions with another thread's TCB (and yes this gets exciting from a concurrency perspective, so I have some extra tricks to make that safe, or at least I think so)

This revision is now accepted and ready to land.May 29 2025, 3:44 PM