[clang] 7ebfcbd - Allow for custom code model in clang::Interpreter (#156977)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 12 08:34:19 PDT 2025
Author: Jeaye Wilkerson
Date: 2025-09-12T18:34:14+03:00
New Revision: 7ebfcbd0ec525810d3874b5826ac1cb53f14c6e4
URL: https://github.com/llvm/llvm-project/commit/7ebfcbd0ec525810d3874b5826ac1cb53f14c6e4
DIFF: https://github.com/llvm/llvm-project/commit/7ebfcbd0ec525810d3874b5826ac1cb53f14c6e4.diff
LOG: Allow for custom code model in clang::Interpreter (#156977)
This is necessary when using ASan, since the larger code size will lead
to errors such as:
```
JIT session error: In graph clojure_core-clojure.core$clojure_core_cpp_cast_24538-24543-jitted-objectbuffer, section .eh_frame: relocation target 0x7bffe374b000 (DW.ref.__gxx_personality_v0) is out of range of Delta32 fixup at address 0x7bffe374b000 (<anonymous block> @ 0x7fffebf48158 + 0x13)
```
Previously, `clang::Interpreter` would hard-code the usage of a small
code model. With this change, we default to small, but allow for custom
values. This related to #102858 and #135401.
There is no change to default behavior here.
@lhames for review.
Added:
Modified:
clang/include/clang/Interpreter/Interpreter.h
clang/lib/Interpreter/Interpreter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h
index 61af7bf762d5e..fcc270a17001e 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -135,11 +135,13 @@ class Interpreter {
std::string OrcRuntimePath = "";
/// PID of the out-of-process JIT executor.
uint32_t ExecutorPID = 0;
+ /// An optional code model to provide to the JITTargetMachineBuilder
+ std::optional<llvm::CodeModel::Model> CM = std::nullopt;
JITConfig()
: IsOutOfProcess(false), OOPExecutor(""), OOPExecutorConnect(""),
UseSharedMemory(false), SlabAllocateSize(0), OrcRuntimePath(""),
- ExecutorPID(0) {}
+ ExecutorPID(0), CM(std::nullopt) {}
};
protected:
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 043e0c1e5754e..84f1c363b5f6f 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -647,6 +647,8 @@ llvm::Error Interpreter::CreateExecutor(JITConfig Config) {
auto JTMB = createJITTargetMachineBuilder(TT);
if (!JTMB)
return JTMB.takeError();
+ if (Config.CM)
+ JTMB->setCodeModel(Config.CM);
auto JB = IncrementalExecutor::createDefaultJITBuilder(std::move(*JTMB));
if (!JB)
return JB.takeError();
More information about the cfe-commits
mailing list