TLS for Android

Joakim joakim at airpost.net
Sun Mar 9 03:11:53 PDT 2014


On Sunday, 9 March 2014 at 09:55:33 UTC, Jacob Carlborg wrote:
> On 2014-03-09 07:04, Joakim wrote:
>
>> I wondered earlier why you weren't just using Walter's packed 
>> TLS
>> approach and now I see why, ldc doesn't use it.  Looks like 
>> Apple hasn't
>> ported the TLV functions which ldc uses to iOS yet either, so 
>> you're out
>> of luck there too.  I guess you'll have to port Walter's 
>> approach to ldc
>> to get TLS working on iOS:
>
> I think it would be possible to implement the missing TLV 
> functions our self in druntime. Hopefully this would allow to 
> use the same TLS approach both on OS X and on iOS.

OK, I assumed OS support was necessary, maybe not.

On Saturday, 8 March 2014 at 18:16:58 UTC, Joakim wrote:
> On Saturday, 8 March 2014 at 14:25:43 UTC, David Nadlinger 
> wrote:
>> However, there is a third options which might be worth 
>> investigating, namely re-implementing at least parts of the 
>> necessary runtime linker features in druntime and continuing 
>> to use the same scheme as on GNU Linux/x86. This depends on 
>> %gs not being used in another way, etc. though.
> I tried to reuse the existing dl_iterate_phdr approach on 
> Android, but then I noticed that the dl_phdr_info struct 
> defined in bionic doesn't include the dlpi_tls_modid and 
> dlpi_tls_data members.  However, now that you mention it, maybe 
> those aren't strictly necessary, as long as I'm not worried 
> about shared libraries.  I'll look into it further.

Speaking of OS support, I just tried this and I was able to 
access the TLS initialization image using dl_phdr_info on 
Android/x86.  Those dlpi_tls_* members are not necessary, though 
I'm guessing dlpi_tls_modid would be for shared library support.  
Now I just have to figure out some way to have the TLS 
relocations access the initialization image, presumably the way 
Walter does it for dmd/OSX.


More information about the digitalmars-d-ldc mailing list