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.