Add emulated TLS support
Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls.
This commit is contained in:
parent
8a7b2035f8
commit
e5b76892cc
17 changed files with 71 additions and 28 deletions
|
@ -410,7 +410,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
|||
const char *SplitDwarfFile,
|
||||
const char *OutputObjFile,
|
||||
const char *DebugInfoCompression,
|
||||
bool ForceEmulatedTls,
|
||||
bool UseEmulatedTls,
|
||||
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen) {
|
||||
|
||||
auto OptLevel = fromRust(RustOptLevel);
|
||||
|
@ -456,13 +456,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
|||
Options.UseInitArray = UseInitArray;
|
||||
|
||||
#if LLVM_VERSION_LT(17, 0)
|
||||
if (ForceEmulatedTls) {
|
||||
Options.ExplicitEmulatedTLS = true;
|
||||
Options.EmulatedTLS = true;
|
||||
}
|
||||
#else
|
||||
Options.EmulatedTLS = ForceEmulatedTls || Trip.hasDefaultEmulatedTLS();
|
||||
Options.ExplicitEmulatedTLS = true;
|
||||
#endif
|
||||
Options.EmulatedTLS = UseEmulatedTls;
|
||||
|
||||
if (TrapUnreachable) {
|
||||
// Tell LLVM to codegen `unreachable` into an explicit trap instruction.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue