Skip to content

Commit 30ad53b

Browse files
authoredDec 10, 2024··
[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.
1 parent 3791323 commit 30ad53b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎clang/lib/Interpreter/Interpreter.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
719719

720720
if (auto DLSG = llvm::orc::DynamicLibrarySearchGenerator::Load(
721721
name, DL.getGlobalPrefix()))
722-
EE->getMainJITDylib().addGenerator(std::move(*DLSG));
722+
// FIXME: Eventually we should put each library in its own JITDylib and
723+
// turn off process symbols by default.
724+
EE->getProcessSymbolsJITDylib()->addGenerator(std::move(*DLSG));
723725
else
724726
return DLSG.takeError();
725727

‎clang/test/Interpreter/crash.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// REQUIRES: host-supports-jit, x86_64-linux
2+
3+
// RUN: rm -rf %t
4+
// RUN: mkdir -p %t
5+
//
6+
// RUN: split-file %s %t
7+
//
8+
// RUN: %clang++ -std=c++20 -fPIC -c %t/vec.cpp -o %t/vec.o
9+
// RUN: %clang++ -shared %t/vec.o -o %t/vec.so
10+
//
11+
// RUN: cat %t/Test.cpp | LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH clang-repl
12+
13+
//--- vec.cpp
14+
#include <vector>
15+
16+
//--- Test.cpp
17+
%lib vec.so
18+
#include <vector>
19+
std::vector<int> v;
20+
%quit

0 commit comments

Comments
 (0)
Please sign in to comment.