This is an archive of the discontinued LLVM Phabricator instance.

[RuntimeDyld] Initial limited TLS support
Needs ReviewPublic

Authored by loladiro on Apr 2 2015, 7:10 PM.

Details

Reviewers
lhames
Summary

This patch adds limited support for thread-local-storage relocations to MCJIT. The approach is to add a separate "TLS symbol resolver" that is orthogonal to the usual symbol resolver, for resolving TLS symbols. The reason to use a separate resolver rather than making this part of the symbol resolver is twofold. First, a TLS lookup will in general require more information than a regular symbol lookup (e.g. a module/offset id, rather than an address) and second, it may be sensible to use different TLSSymbolResolvers for the same symbol resolver, e.g. depending on the host platform, or C library, etc., so it would be preferable for the user to specify independently of the Symbol Resolver.

This patch only deals with references to thread local variables declared outside the JIT, i.e. it does not add support for declaring variables thread local and setting up the correct data structures (doing so would also require significant collaboration from the OS dynamic linker, which is not present in current systems). Even so, the exact implementation still depends on deeply on the system details and the ABI. Hopefully the TLSSymbolResolver interface should allow the user to write their own implementation if their system ABI differs.

The majority of this patch is targeted at ELF, which has several special relocations for TLS support. MachO uses a different scheme that uses more GOT space (three words rather than two), but gets away without a special relocation for TLS symbols. No attempt at supporting COFF was made at this point, but hopefully the interface is sufficiently general that COFF support can be added easily in the future.

Also note that this depends on my GOT changes in D8813 and D8814.

Diff Detail

Repository
rL LLVM

Event Timeline

loladiro updated this revision to Diff 23199.Apr 2 2015, 7:10 PM
loladiro retitled this revision from to [RuntimeDyld] Initial limited TLS support.
loladiro updated this object.
loladiro edited the test plan for this revision. (Show Details)
loladiro added a reviewer: lhames.
loladiro set the repository for this revision to rL LLVM.
loladiro added a subscriber: Unknown Object (MLST).
loladiro planned changes to this revision.Apr 3 2015, 2:00 AM

I found small issue in here. Please review the patches this depends on first and I'll update soon.

loladiro updated this revision to Diff 23564.Apr 9 2015, 9:30 PM

Fixed a few bugs that came up in stress testing, also added support for GOTTPOFF relocations. Still planning a few more cleanup changes, but should be mostly reviewable now.

vtjnash added inline comments.
lib/ExecutionEngine/RuntimeDyld/TLSSymbolResolverELF.cpp
49

this Value is only correct if MemoryManager hasn't cached the address from a different thread. Since the function is using pthread_self for direct interaction with the host system anyways, maybe it should just call dlsym also?

emaste added a subscriber: emaste.Oct 12 2015, 1:57 PM