TLS for Android (and iOS)
zans.is.for.cans at yahoo.com
Tue Apr 1 07:46:12 PDT 2014
Dan Olson <zans.is.for.cans at yahoo.com> writes:
> "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:
>> 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:
> I had disabled initTLSRanges for iOS since dyld_enumerate_tlv_storage is
> a stub for x86 (see
I meant it is a stub for ARM.
> 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.
I did reenable and it works. I can tell because the std.datetime
unittest uses enough memory that it causes a GC. When I first rebuild
everything with TLS enabled and plugged in support from
threadLocalVariables.c (but without initTLSRanges enabled), the
std.datetime unittest started crashing. The datetime unittest tests
have a fair number of thread locals. Then I reenabled David's
initTLSRanges() for iOS, and std.datetime unittest went back to passing.
More information about the digitalmars-d-ldc