TLS for Android (and iOS)
Dan Olson
zans.is.for.cans at yahoo.com
Sun Mar 30 08:24:53 PDT 2014
"Joakim" <joakim at airpost.net> writes:
> Have you experimented with seeing which of that TLV stuff from OS X
> that iOS actually supports? The iOS dyld could be pretty different.
> We don't know since they don't release the source for the iOS core
> like they do for OS X, ie is tlv_get_addr even available in the iOS
> dyld and does it execute other possible TLS relocations? Only way to
> find out is to try it, or somehow inspect their iOS binaries. ;) Their
> source does show an ARM assembly implementation of tlv_get_address but
> it's commented out:
> http://www.opensource.apple.com/source/dyld/dyld-210.2.3/src/threadLocalHelpers.s
I did try it in an iOS app. The function _tlv_bootstrap is unresolved
when I link in Xcode using the current iPhoneSDK. That is why I had to
provide a stub. Pretty sure tlv functions are not available.
> I wonder if it'd be easier to pack your own Mach-O sections rather
> than figuring out how to access all their sections and reimplementing
> their TLV functions, assuming they're not available. You might even
> be able to do it as an llvm patch since the relevant lib/MC/ files
> where llvm packs the TLS data into Mach-O sections seem pretty
> straightforward.
I think we can use their sections and it did not take long to figure
out. Here is what an example link map has for one of my test apps:
0x0004E22C 0x00000084 __DATA __thread_vars
0x0004E2B0 0x0000000C __DATA __thread_data
0x0004E2BC 0x00000024 __DATA __thread_bss
The _thread_vars section has a TVLDescriptors for each thread local. It
is used for caching the pthread_get/set key and has the variable offset
into the thread local chunk of memory that can be initialized by copying
_thread_data and _thread_bss (or just zerofill it).
> I've never submitted anything to llvm, so not really based on anything
> than speculation, but I doubt they would accept such a patch, doesn't
> mean we can't use it though. ;)
Another thing, Apple might consider the tlv functions and thread local
sections a reserved API.
A long way off from submitting anything to App Store. With the way
things change, tlv may show up in a near future sdk, then this just
becomes a bridge.
--
Dan
More information about the digitalmars-d-ldc
mailing list