Skip to content

Commit

Permalink
Add libjulia-internal to ORCJIT symbol resolution (#48712)
Browse files Browse the repository at this point in the history
We need to make sure that libjulia-internal is loaded and placed first in the
DynamicLibrary search order so that calls to runtime intrinsics are resolved
to the correct library when multiple libjulia-*'s have been loaded (e.g. when
we `ccall` into a PackageCompiler.jl-created shared library).
  • Loading branch information
topolarity authored Feb 28, 2023
1 parent d6a77b6 commit fd45943
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,13 +1288,29 @@ JuliaOJIT::JuliaOJIT()
});
#endif

std::string ErrorStr;

// Make sure that libjulia-internal is loaded and placed first in the
// DynamicLibrary order so that calls to runtime intrinsics are resolved
// to the correct library when multiple libjulia-*'s have been loaded
// (e.g. when we `ccall` into a PackageCompiler.jl-created shared library)
sys::DynamicLibrary libjulia_internal_dylib = sys::DynamicLibrary::addPermanentLibrary(
jl_libjulia_internal_handle, &ErrorStr);
if(!ErrorStr.empty())
report_fatal_error(llvm::Twine("FATAL: unable to dlopen libjulia-internal\n") + ErrorStr);

// Make sure SectionMemoryManager::getSymbolAddressInProcess can resolve
// symbols in the program as well. The nullptr argument to the function
// tells DynamicLibrary to load the program, not a library.
std::string ErrorStr;
if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr, &ErrorStr))
report_fatal_error(llvm::Twine("FATAL: unable to dlopen self\n") + ErrorStr);

GlobalJD.addGenerator(
std::make_unique<orc::DynamicLibrarySearchGenerator>(
libjulia_internal_dylib,
DL.getGlobalPrefix(),
orc::DynamicLibrarySearchGenerator::SymbolPredicate()));

GlobalJD.addGenerator(
cantFail(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
DL.getGlobalPrefix())));
Expand Down

0 comments on commit fd45943

Please sign in to comment.