TLS for Android

Joakim joakim at airpost.net
Sat Mar 8 10:16:57 PST 2014


On Saturday, 8 March 2014 at 14:25:43 UTC, David Nadlinger wrote:
> LLVM does support putting variables into custom sections, and 
> you can more or less get away with the DMD bracketing approach 
> (see e.g. the new ModuleInfo discovery functionality I 
> implemented for Linux, which is the same as DMD's druntime 
> uses).
You're talking about findDataSection and friends?

https://github.com/ldc-developers/druntime/blob/ldc/src/rt/sections_ldc.d#L115

> However, there is a catch: Due to what I can only imagine is a 
> bug, LLVM does not support emitting a symbol both into a custom 
> section and with weak linkage. Thus, you might be in for a 
> round of LLVM hacking either way, even though it will likely 
> involve much less when going the DMD route.
Hmm, I guess this is why you don't use the bracketing approach 
anywhere?  What will be much less when going the DMD route?

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

As for reimplementing the runtime linker, in a sense that's 
what's being done with dmd/druntime for OS X, where it implements 
it's own ___tls_get_addr using pthread_setspecific.  I'll have to 
do the same for Android, as bionic doesn't have a __tls_get_addr.


More information about the digitalmars-d-ldc mailing list