Implementing native TLS on OS X in DMD

Jacob Carlborg via digitalmars-d-ldc digitalmars-d-ldc at
Thu Jan 7 23:37:16 PST 2016

This might be a bit odd to ask this question in the LDC newsgroup, but 
since LDC already supports native TLS on OS X I was hoping to get some 
help here.

I've implemented native TLS on OS X in DMD to the best of my knowledge. 
The data in the sections look correct, the assembly look correct, I've 
updated druntime to use the same code, in this regard, as LDC does. 
Everything seems to work correctly in the simple cases I've tried.

But, I have an issue when the garbage collector is run. In particular 
when running the DMD test suite. The failing test is this one [1]. I get 
a segmentation fault (in the debugger, range error) here [2], after 
executing the outer loop once. I highly suspect that it's the garbage 
collector that collects "_chars" [3] (or its content) too early, since 
the destructor of SomeClass [4] is executed. If I make "_chars" 
__gshared it doesn't crash. If I remove the call to the GC [5], it 
doesn't crash.

I've been trying to debug this but I don't have much knowledge in this 
area. What I have found out is that "_chars" is included in the range 
returned by _d_dyld_getTLSRange [6]. I've been trying to debug the GC, 
and it looks like "_chars" is marked twice, before crashing. Or at least 
a range where "_chars" is included.

One thing that worries me though is the range returned by 
_d_dyld_getTLSRange for LDC is a quite a lot larger (around 3500) than 
for DMD (around 650). But I noticed that LDC has a couple of additional 
TLS symbols that DMD doesn't have. If I recall correctly, they looked 
like they were related to exception handling.

Any ideas what can be wrong or suggestions how to further debug this?







/Jacob Carlborg

More information about the digitalmars-d-ldc mailing list