Skip to content

[Clang-REPL] Fix crash during __run_exit_handlers with dynamic libraries. #117475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
20 changes: 20 additions & 0 deletions clang/test/Interpreter/crash.cpp
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This invokes the system linker. From the build system's point of view, it's almost never correct to invoke the system linker without the environment variables $LDFLAGS and $LIBS. In this case, you expect to make the shared library to link against the default libs.

I am thinking of changing this line to read

// RUN: %clang++ -shared %t/vec.o -o %t/vec.so $LDFLAGS $LIBS

Not particularly satisfied with this approach though.

I also think that your vec.o and vec.so are both empty after my previous fix. This suggests that the two steps here may not even be needed at all for the sake of testing this fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should use this yaml-to-so tool to build the library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should use this yaml-to-so tool to build the library.

Can you point me to the tool? A naive search returned nothing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no quick solution, I would propose to revert the testing portion of this patch. This has been blocking CI on our end for a couple of days. No other tests in llvm repo invokes system linker like this one.

Copy link
Contributor

@vgvassilev vgvassilev Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tools is called yaml2obj. Alternatively we can upload the binary file which is my least favorite but still should get you going...

//
// RUN: cat %t/Test.cpp | LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH clang-repl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does clang-repl respond to #include <vector> if the path to the library is not provided on the command line? IIUC, this will continue to search for a systemwide installation of the C++ standard library. If that's the case, this continues to be wrong.


//--- vec.cpp
#include <vector>

//--- Test.cpp
%lib vec.so
#include <vector>
std::vector<int> v;
%quit
Loading