TLS for Android (and iOS)

Dan Olson at
Mon Mar 31 08:31:00 PDT 2014

"David Nadlinger" <code at> writes:

> On 31 Mar 2014, at 8:25, Jacob Carlborg wrote:
>> You'll just need to add a call to druntime in one of the functions
>> in the dyld TLS code. Have a look at:
> More specifically, for the DMD TLS emulation implementation, this is
> done in the initTLSRanges() function, which forwards to
> getTLSBlock(). IIRC, initTLSRanges() is only called for new
> threads. For the main thread, the TLS ranges is included in the GC
> ranges detected in initSections().
> For LDC on OS X, which makes use of the 10.7+ system-level TLS
> implementation, the place where this is handled is
> _d_dyld_getTLSRange
> uses an undocumented dyld API function (dyld_enumerate_tlv_storage) to
> get the actual TLS  memory range on the current thread:
> David

I had disabled initTLSRanges for iOS since dyld_enumerate_tlv_storage is
a stub for x86 (see

Now that I have tweaked threadLocalVariables.c,
dyld_enumerate_tlv_storage should now work on iOS. I will have to
reenble initTLSRanges and see what happens.

More information about the digitalmars-d-ldc mailing list