TLS for Android

Dan Olson at
Sat Mar 8 11:11:52 PST 2014

David Nadlinger <code at> writes:

> On 03/08/2014 01:55 AM, Joakim wrote:
>> Do you have any advice on how to pull this off with ldc?  Should I be
>> going the dmd route and packing the TLS myself?  Does llvm provide good
>> support for this?
>> Or is there some other llvm TLS shortcut I can use?  I tried to see if
>> llvm just has some thread-local implementation that automatically uses
>> pthread_setspecific, but didn't find anything.
> 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). 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.
> 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.
> David

While on the subject of TLS, that is probably the most needed language
feature to allow threading to work reliably on iOS.  So hoping the
solution will work on iOS too!

Another topic - I was looking at adding fiber_switchContext support for
arm in threadasm.S, and noticed GDC's version has an arm
implementation.  Is it ok to use portions of GDC source in LDC?

More information about the digitalmars-d-ldc mailing list