[clang] 30ad53b - [Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (#117475)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 9 23:57:34 PST 2024
Author: SahilPatidar
Date: 2024-12-10T09:57:31+02:00
New Revision: 30ad53b92cec0cff9679d559edcc5b933312ba0c
URL: https://github.com/llvm/llvm-project/commit/30ad53b92cec0cff9679d559edcc5b933312ba0c
DIFF: https://github.com/llvm/llvm-project/commit/30ad53b92cec0cff9679d559edcc5b933312ba0c.diff
LOG: [Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (#117475)
Apply the fix suggested by Lang Hames to address a crash in Clang-REPL
that occurs during the execution of `__run_exit_handlers` when using
dynamic libraries.
Added:
clang/test/Interpreter/crash.cpp
Modified:
clang/lib/Interpreter/Interpreter.cpp
Removed:
################################################################################
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index fa4c1439c92612..6cd60a9bcf4f38 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -719,7 +719,9 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
if (auto DLSG = llvm::orc::DynamicLibrarySearchGenerator::Load(
name, DL.getGlobalPrefix()))
- EE->getMainJITDylib().addGenerator(std::move(*DLSG));
+ // FIXME: Eventually we should put each library in its own JITDylib and
+ // turn off process symbols by default.
+ EE->getProcessSymbolsJITDylib()->addGenerator(std::move(*DLSG));
else
return DLSG.takeError();
diff --git a/clang/test/Interpreter/crash.cpp b/clang/test/Interpreter/crash.cpp
new file mode 100644
index 00000000000000..1ab24b0febfa15
--- /dev/null
+++ b/clang/test/Interpreter/crash.cpp
@@ -0,0 +1,20 @@
+// REQUIRES: host-supports-jit, x86_64-linux
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+//
+// RUN: split-file %s %t
+//
+// RUN: %clang++ -std=c++20 -fPIC -c %t/vec.cpp -o %t/vec.o
+// RUN: %clang++ -shared %t/vec.o -o %t/vec.so
+//
+// RUN: cat %t/Test.cpp | LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH clang-repl
+
+//--- vec.cpp
+#include <vector>
+
+//--- Test.cpp
+%lib vec.so
+#include <vector>
+std::vector<int> v;
+%quit
More information about the cfe-commits
mailing list