[Gc] RE: Registering TLS as roots
mike at navi.cx
Wed Oct 20 04:48:34 PDT 2004
Ben Hutchings wrote:
> > I know how to find TLS on Windows NT on x86 (it's in the TEB structure
> > defined in <winternl.h> and that can be found through fs:[18h]) and I
> > can probably look up details of other TLS implementations but this
> > sort of platform-specific hackery doesn't seem like the best solution.
> > Does anybody have any suggestions for how to include TLS in the root
> > set or how to keep extra copies of such pointers elsewhere (and only
> > so long as they are also in TLS)?
> The solution I came up with was to add a TLS interface to the GC as an
> alternative to the native TLS interfaces. It's a cross between the
> Win32 and pthreads interfaces:
TLS on Linux uses one of several mechanisms. The older LinuxThreads
implementation associates TLS data (I think) by using offsets relative
to the stack. I don't know much about LinuxThreads.
Newer NPTL systems can use either pthread TLS explicitly, or the new ELF
TLS mechanism which allows you to mark variables with __thread.
These ELF TLS variables are stored in a new ELF section .tbss, which
AFAIK has the same layout as the standard BSS section does. So, you
could extend the collector to scan the .tbss section as a root section
in the same way that I guess it does for the BSS normally. As long as
you stick to ELF TLS that would work. Of course, *all* these mechanisms,
including poking the TEB on Win32, are relying on implementation details
though due to the way ELFTLS is a formal spec and relies on data in the
binaries it's the least likely to change (imho).
It might be worth working with the glibc team to design an interface
that allows you to retrieve all TLS slots so they can be added to GC
root sets. I'm not sure what they'd think of such a proposal but it's
worth a shot.
More information about the Gc