Getting tls symbols out of the compiler.

Iain Buclaw ibuclaw at ubuntu.com
Wed May 29 16:19:10 PDT 2013


OK, from today till the end of the week I'm going to be sitting 
down and thinking through this, as I'd really like the emitting 
of _tlsstart and _tlsend out of the compiler by hook or by crook.


Phase one - start:

We have rt/tls.S.  Have added this to the libdruntime builds, and 
I see no immediate problems running this through the testsuite  
(though - that is never really a good indicator of anything).  
Drawbacks, this is only available for linux at the moment. But 
that's fine if we keep this temporary for the week.


Phase two - plan:

The GC has a hook gc_addRoot used for the purpose of tracking GC 
allocated memory in C-land.  The idea I've got turning over in my 
head at the moment is that any thread local decls that are 
'new-able' (classes, pointers, d arrays) are added as a root upon 
'new' declaration,  this is safe-guarded by a thread-local static 
to prevent multiple calls to gc_addRoot.

eg:
---
var = new Object();
---
if (!var.guard)
{
   ++var.guard;
   gc_addRoot (&var);
}
var = _d_new_class (&Object_Class);
---

Then in the destruction of the thread (eg: atexit, or through a 
destructor called in .fini section)

---
if (var.guard)
   gc_removeRoot (&var);
---

Though this should not be required if we have a proper TLS GC in 
place.

Does this seem like a reasonable job?  Or have I completely lost 
the plot at half past 2 in the morning?  :o)

Regards
Iain.


More information about the D.gnu mailing list