[clang] [Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (PR #117475)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 27 01:12:14 PST 2024
https://github.com/SahilPatidar updated https://github.com/llvm/llvm-project/pull/117475
>From 559a2d05e0a3518cf59cd828bcf41a6de10a4e76 Mon Sep 17 00:00:00 2001
From: SahilPatidar <patidarsahil2001 at gmail.com>
Date: Sun, 24 Nov 2024 15:19:50 +0530
Subject: [PATCH 1/3] [Clang-REPL] Fix crash during `__run_exit_handlers` with
dynamic libraries
---
clang/lib/Interpreter/Interpreter.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 5dc67f6375098f..71299f7176e2fe 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();
>From 86210eda27a32e7910780f954171e2c9186d48ac Mon Sep 17 00:00:00 2001
From: SahilPatidar <patidarsahil2001 at gmail.com>
Date: Wed, 27 Nov 2024 14:08:33 +0530
Subject: [PATCH 2/3] Add test to verify fix for crash
---
clang/test/Interpreter/crash.cpp | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 clang/test/Interpreter/crash.cpp
diff --git a/clang/test/Interpreter/crash.cpp b/clang/test/Interpreter/crash.cpp
new file mode 100644
index 00000000000000..1dda3e65f54582
--- /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.dylib
+#include <vector>
+std::vector<int> v;
+%quit
>From 89015b34f27cdb7fd9241f26d0c73afd8e32d789 Mon Sep 17 00:00:00 2001
From: SahilPatidar <patidarsahil2001 at gmail.com>
Date: Wed, 27 Nov 2024 14:40:54 +0530
Subject: [PATCH 3/3] Fix minor typo
---
clang/test/Interpreter/crash.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Interpreter/crash.cpp b/clang/test/Interpreter/crash.cpp
index 1dda3e65f54582..1ab24b0febfa15 100644
--- a/clang/test/Interpreter/crash.cpp
+++ b/clang/test/Interpreter/crash.cpp
@@ -14,7 +14,7 @@
#include <vector>
//--- Test.cpp
-%lib vec.dylib
+%lib vec.so
#include <vector>
std::vector<int> v;
%quit
More information about the cfe-commits
mailing list