[llvm] d8efed5 - [lli] Honor explicit emulated TLS option in ORC mode (#217554)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 13:51:27 PDT 2026
Author: Jiaxun Yang
Date: 2026-09-17T21:51:21+01:00
New Revision: d8efed58ca9e324915f80c77524855d40a65d0c7
URL: https://github.com/llvm/llvm-project/commit/d8efed58ca9e324915f80c77524855d40a65d0c7
DIFF: https://github.com/llvm/llvm-project/commit/d8efed58ca9e324915f80c77524855d40a65d0c7.diff
LOG: [lli] Honor explicit emulated TLS option in ORC mode (#217554)
JITTargetMachineBuilder enables emulated TLS by default, but lli's ORC
path did not forward the existing -emulated-tls option. Consequently,
explicitly passing -emulated-tls=false still produced emulated-TLS
accesses.
Forward an explicitly specified value into the ORC JIT target-machine
options. Leave the builder default unchanged when the command-line
option is omitted.
Extend the existing OrcLazy emulated-TLS test with the false case,
verifying that native lowering is selected instead of
__emutls_get_address.
Rename emulated-tls.ll to tls.ll, and add a TODO to replace the
error-based checks with successful TLS execution tests using the new ORC
runtime.
Added:
llvm/test/ExecutionEngine/OrcLazy/tls.ll
Modified:
llvm/include/llvm/ExecutionEngine/RuntimeDyld.h
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
llvm/tools/lli/lli.cpp
Removed:
llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h b/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h
index 57387f029b6cf..aec57b7795f4a 100644
--- a/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h
+++ b/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h
@@ -123,6 +123,7 @@ class RuntimeDyld {
/// Allocate a memory block of (at least) the given size to be used for
/// thread-local storage (TLS).
+ /// Return a null InitializationImage if allocation is unsupported or fails.
virtual TLSSection allocateTLSSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName);
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index 9f8c1dd87c76a..252506ef22853 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -864,6 +864,9 @@ RuntimeDyldImpl::emitSection(const ObjectFile &Obj,
if (IsTLS) {
auto TLSSection = MemMgr.allocateTLSSection(Allocate, Alignment.value(),
SectionID, Name);
+ if (!TLSSection.InitializationImage)
+ return make_error<RuntimeDyldError>(
+ "Unable to allocate TLS section memory");
Addr = TLSSection.InitializationImage;
LoadAddress = TLSSection.Offset;
} else if (IsCode) {
@@ -1299,7 +1302,7 @@ RuntimeDyld::MemoryManager::allocateTLSSection(uintptr_t Size,
unsigned Alignment,
unsigned SectionID,
StringRef SectionName) {
- report_fatal_error("allocation of TLS not implemented");
+ return {};
}
void RuntimeDyld::MemoryManager::anchor() {}
diff --git a/llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll b/llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll
deleted file mode 100644
index a70bc5f4ceb42..0000000000000
--- a/llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll
+++ /dev/null
@@ -1,26 +0,0 @@
-; LoongArch does not support emulated tls.
-; UNSUPPORTED: target=loongarch{{.*}}
-
-; RUN: not lli -no-process-syms -lljit-platform=Inactive -emulated-tls \
-; RUN: -jit-kind=orc-lazy %s 2>&1 | FileCheck %s
-;
-; Test that emulated-tls does not generate any unexpected errors.
-;
-; Unfortunately we cannot test successful execution of JIT'd code with
-; emulated-tls as this would require the JIT itself, in this case lli, to be
-; built with emulated-tls, which is not a common configuration. Instead we test
-; that the only error produced by the JIT for a thread-local with emulated-tls
-; enabled is a missing symbol error for __emutls_get_address. An unresolved
-; reference to this symbol (and only this symbol) implies (1) that the emulated
-; tls lowering was applied, and (2) that thread locals defined in the JIT'd code
-; were otherwise handled correctly.
-
-; CHECK: JIT session error: Symbols not found: [ {{[^,]*}}__emutls_get_address ]
-
- at x = thread_local global i32 42, align 4
-
-define i32 @main(i32 %argc, ptr %argv) {
-entry:
- %0 = load i32, ptr @x, align 4
- ret i32 %0
-}
diff --git a/llvm/test/ExecutionEngine/OrcLazy/tls.ll b/llvm/test/ExecutionEngine/OrcLazy/tls.ll
new file mode 100644
index 0000000000000..272a6ecdaee75
--- /dev/null
+++ b/llvm/test/ExecutionEngine/OrcLazy/tls.ll
@@ -0,0 +1,41 @@
+; LoongArch does not support emulated tls.
+; UNSUPPORTED: target=loongarch{{.*}}
+
+; RUN: not lli -no-process-syms -lljit-platform=Inactive -emulated-tls \
+; RUN: -jit-kind=orc-lazy %s 2>&1 | FileCheck %s --check-prefix=EMULATED
+; RUN: not lli -no-process-syms -lljit-platform=Inactive -emulated-tls=false \
+; RUN: -jit-kind=orc-lazy %s 2>&1 | FileCheck %s --check-prefix=NATIVE
+; RUN: %if system-linux %{ not lli -no-process-syms -lljit-platform=Inactive \
+; RUN: -emulated-tls=false -jit-kind=orc-lazy -jit-linker=rtdyld \
+; RUN: -code-model=small %s 2>&1 \
+; RUN: | FileCheck %s --check-prefix=RTDYLD %}
+;
+; Test that emulated and native TLS lowering produce the expected errors.
+; Use the small code model for RuntimeDyld: AArch64's large code model does not
+; support general-dynamic TLS lowering.
+;
+; TODO: Replace this test with positive tests of successful TLS execution using
+; the new ORC runtime once it supports them.
+;
+; Unfortunately we cannot test successful execution of JIT'd code with
+; emulated-tls as this would require the JIT itself, in this case lli, to be
+; built with emulated-tls, which is not a common configuration. Instead we test
+; that the only error produced by the JIT for a thread-local with emulated-tls
+; enabled is a missing symbol error for __emutls_get_address. An unresolved
+; reference to this symbol (and only this symbol) implies (1) that the emulated
+; tls lowering was applied, and (2) that thread locals defined in the JIT'd code
+; were otherwise handled correctly.
+
+; EMULATED: JIT session error: Symbols not found: [ {{[^,]*}}__emutls_get_address ]
+; NATIVE-NOT: __emutls_get_address
+; NATIVE: JIT session error:
+; NATIVE-NOT: __emutls_get_address
+; RTDYLD: JIT session error: Unable to allocate TLS section memory
+
+ at x = thread_local global i32 42, align 4
+
+define i32 @main(i32 %argc, ptr %argv) {
+entry:
+ %0 = load i32, ptr @x, align 4
+ ret i32 %0
+}
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index 9cafbcf104921..6bee74935a115 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -971,6 +971,10 @@ static int runOrcJIT(const char *ProgName) {
.setRelocationModel(codegen::getExplicitRelocModel())
.setCodeModel(codegen::getExplicitCodeModel());
+ if (auto EmulatedTLS = codegen::getExplicitEmulatedTLS())
+ Builder.getJITTargetMachineBuilder()->getOptions().EmulatedTLS =
+ *EmulatedTLS;
+
// Link process symbols unless NoProcessSymbols is set.
Builder.setLinkProcessSymbolsByDefault(!NoProcessSymbols);
More information about the llvm-commits
mailing list