Skip to content

Commit

Permalink
Missing files.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Oct 9, 2024
1 parent 458c97c commit 1f4f705
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ set(HEYOKA_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/debug.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/aligned_buffer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/type_traits.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/get_dl_path.cpp"
# NOTE: this will be an empty file in case we are not
# building with support for real.
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/real_helpers.cpp"
Expand Down
6 changes: 3 additions & 3 deletions src/detail/get_dl_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <iostream>
#include <string>

#include <heyoka/config.hpp>
#include <heyoka/detail/get_dl_path.hpp>

#if __has_include(<dlfcn.h>)

#define HEYOKA_DETAIL_GET_DL_PATH_DLFCN
Expand All @@ -22,6 +19,9 @@

#endif

#include <heyoka/config.hpp>
#include <heyoka/detail/get_dl_path.hpp>

HEYOKA_BEGIN_NAMESPACE

namespace detail
Expand Down
52 changes: 51 additions & 1 deletion src/llvm_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

#endif

#include <heyoka/detail/get_dl_path.hpp>
#include <heyoka/detail/llvm_func_create.hpp>
#include <heyoka/detail/llvm_fwd.hpp>
#include <heyoka/detail/llvm_helpers.hpp>
Expand Down Expand Up @@ -720,6 +721,31 @@ struct llvm_state::jit {
// LCOV_EXCL_STOP
m_lljit->getMainJITDylib().addGenerator(std::move(*dlsg));

// NOTE: we also want to manually inject the symbols from the heyoka shared library
// into the JIT runtime.
//
// The reason for this is that if heyoka is loaded with dlopen() and the RTLD_LOCAL flag,
// then the JIT runtime will not be able to resolve symbols defined either in heyoka or
// in its dependencies. This will happen for instance in heyoka.py.
//
// With the following contraption, as far as I have understood, we are manually injecting all the
// symbols from heyoka (and, transitively, its dependencies) into the JIT runtime, and the symbols
// are thus made available to JIT code despite the use of RTLD_LOCAL.
//
// This approach was suggested by lhames on the LLVM discord.
if (const auto &dl_path = detail::get_dl_path(); !dl_path.empty()) {
auto new_dlsg = llvm::orc::DynamicLibrarySearchGenerator::Load(dl_path.c_str(),
m_lljit->getDataLayout().getGlobalPrefix());
if (new_dlsg) [[likely]] {
m_lljit->getMainJITDylib().addGenerator(std::move(*new_dlsg));
} else {
// LCOV_EXCL_START
throw std::invalid_argument(
"Could not create the dynamic library search generator for the heyoka library");
// LCOV_EXCL_STOP
}
}

// Keep a target machine around to fetch various
// properties of the host CPU.
auto tm = jtmb.createTargetMachine();
Expand All @@ -735,7 +761,7 @@ struct llvm_state::jit {

// NOTE: by default, errors in the execution session are printed
// to screen. A custom error reported can be specified, ideally
// we would like th throw here but I am not sure whether throwing
// we would like to throw here but I am not sure whether throwing
// here would disrupt LLVM's cleanup actions?
// https://llvm.org/doxygen/classllvm_1_1orc_1_1ExecutionSession.html

Expand Down Expand Up @@ -1802,6 +1828,30 @@ multi_jit::multi_jit(unsigned n_modules, unsigned opt_level, code_model c_model,
// LCOV_EXCL_STOP
m_lljit->getMainJITDylib().addGenerator(std::move(*dlsg));

// NOTE: we also want to manually inject the symbols from the heyoka shared library
// into the JIT runtime.
//
// The reason for this is that if heyoka is loaded with dlopen() and the RTLD_LOCAL flag,
// then the JIT runtime will not be able to resolve symbols defined either in heyoka or
// in its dependencies. This will happen for instance in heyoka.py.
//
// With the following contraption, as far as I have understood, we are manually injecting all the
// symbols from heyoka (and, transitively, its dependencies) into the JIT runtime, and the symbols
// are thus made available to JIT code despite the use of RTLD_LOCAL.
//
// This approach was suggested by lhames on the LLVM discord.
if (const auto &dl_path = detail::get_dl_path(); !dl_path.empty()) {
auto new_dlsg = llvm::orc::DynamicLibrarySearchGenerator::Load(dl_path.c_str(),
m_lljit->getDataLayout().getGlobalPrefix());
if (new_dlsg) [[likely]] {
m_lljit->getMainJITDylib().addGenerator(std::move(*new_dlsg));
} else {
// LCOV_EXCL_START
throw std::invalid_argument("Could not create the dynamic library search generator for the heyoka library");
// LCOV_EXCL_STOP
}
}

// Create the master context.
m_ctx = std::make_unique<llvm::orc::ThreadSafeContext>(std::make_unique<llvm::LLVMContext>());

Expand Down

0 comments on commit 1f4f705

Please sign in to comment.