TLS for Android (and iOS)

Dan Olson zans.is.for.cans at yahoo.com
Mon Mar 31 08:31:00 PDT 2014


"David Nadlinger" <code at klickverbot.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:
>>
>> https://github.com/D-Programming-Language/druntime/blob/master/src/rt/sections_osx.d
>
> 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
> https://github.com/ldc-developers/druntime/blob/a08f158618eb5d06c42bd4746b782312e937f6b3/src/rt/sections_ldc.d#L296. _d_dyld_getTLSRange
> uses an undocumented dyld API function (dyld_enumerate_tlv_storage) to
> get the actual TLS  memory range on the current thread:
> https://github.com/ldc-developers/druntime/blob/a08f158618eb5d06c42bd4746b782312e937f6b3/src/ldc/osx_tls.c.
>
> David

I had disabled initTLSRanges for iOS since dyld_enumerate_tlv_storage is
a stub for x86 (see
http://www.opensource.apple.com/source/dyld/dyld-210.2.3/src/threadLocalVariables.c).

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.
-- 
Dan


More information about the digitalmars-d-ldc mailing list