[llvm] [lli] Honor explicit emulated TLS option in ORC mode (PR #217554)

Jiaxun Yang via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 01:32:34 PDT 2026


https://github.com/FlyGoat created https://github.com/llvm/llvm-project/pull/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.

Testing:
- llvm-lit -v llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll
- ninja lli

>From 27c6ffbc7717086a7670a2fd628e68e012f69e0a Mon Sep 17 00:00:00 2001
From: Jiaxun Yang <jiaxun.yang at flygoat.com>
Date: Thu, 20 Aug 2026 09:32:04 +0100
Subject: [PATCH] [lli] Honor explicit emulated TLS option in ORC mode

Forward an explicitly specified -emulated-tls value to the ORC JITTargetMachineBuilder. This preserves the builder default when the option is omitted while allowing callers to request native TLS lowering.
---
 llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll | 8 ++++++--
 llvm/tools/lli/lli.cpp                            | 4 ++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll b/llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll
index a70bc5f4ceb42..4c1b23201f9a0 100644
--- a/llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll
+++ b/llvm/test/ExecutionEngine/OrcLazy/emulated-tls.ll
@@ -2,7 +2,9 @@
 ; UNSUPPORTED: target=loongarch{{.*}}
 
 ; RUN: not lli -no-process-syms -lljit-platform=Inactive -emulated-tls \
-; RUN:   -jit-kind=orc-lazy %s 2>&1 | FileCheck %s
+; 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
 ;
 ; Test that emulated-tls does not generate any unexpected errors.
 ;
@@ -15,7 +17,9 @@
 ; 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 ]
+; EMULATED: JIT session error: Symbols not found: [ {{[^,]*}}__emutls_get_address ]
+; NATIVE-NOT: __emutls_get_address
+; NATIVE: JIT session error:
 
 @x = thread_local global i32 42, align 4
 
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index 0fcad0a09591a..63f7858ace5c6 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -961,6 +961,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