Pass libCling handle at construction time, resolve from it:
OrcV2 uses specific DyLibs to resolve symbols from, we need a dedicated resolver for libCling because its symbols cannot be found from the process. Remove now unused "ExposeHiddenSharedLibrarySymbols".
This commit is contained in:
parent
0362d3fcda
commit
d8c5c2a206
@ -199,14 +199,6 @@ namespace cling {
|
|||||||
return getSymbolLocation(reinterpret_cast<void*>(func));
|
return getSymbolLocation(reinterpret_cast<void*>(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///\brief Explicitly tell the execution engine to use symbols from
|
|
||||||
/// a shared library that would otherwise not be used for symbol
|
|
||||||
/// resolution, e.g. because it was dlopened with RTLD_LOCAL.
|
|
||||||
///\param [in] handle - the system specific shared library handle.
|
|
||||||
///
|
|
||||||
static void ExposeHiddenSharedLibrarySymbols(void* handle);
|
|
||||||
|
|
||||||
static std::string normalizePath(llvm::StringRef path);
|
static std::string normalizePath(llvm::StringRef path);
|
||||||
|
|
||||||
/// Returns true if file is a shared library.
|
/// Returns true if file is a shared library.
|
||||||
|
@ -344,7 +344,8 @@ namespace cling {
|
|||||||
/// constructors. parentInterp might be nullptr.
|
/// constructors. parentInterp might be nullptr.
|
||||||
///
|
///
|
||||||
Interpreter(int argc, const char* const* argv, const char* llvmdir,
|
Interpreter(int argc, const char* const* argv, const char* llvmdir,
|
||||||
const ModuleFileExtensions& moduleExtensions, bool noRuntime,
|
const ModuleFileExtensions& moduleExtensions,
|
||||||
|
void *extraLibHandle, bool noRuntime,
|
||||||
const Interpreter* parentInterp);
|
const Interpreter* parentInterp);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -353,13 +354,14 @@ namespace cling {
|
|||||||
///\param[in] argc - no. of args.
|
///\param[in] argc - no. of args.
|
||||||
///\param[in] argv - arguments passed when driver is invoked.
|
///\param[in] argv - arguments passed when driver is invoked.
|
||||||
///\param[in] llvmdir - ???
|
///\param[in] llvmdir - ???
|
||||||
|
///\param[in] extraLibHandle - resolve symbols also from this dylib
|
||||||
///\param[in] noRuntime - flag to control the presence of runtime universe
|
///\param[in] noRuntime - flag to control the presence of runtime universe
|
||||||
///
|
///
|
||||||
Interpreter(int argc, const char* const* argv, const char* llvmdir = 0,
|
Interpreter(int argc, const char* const* argv, const char* llvmdir = 0,
|
||||||
const ModuleFileExtensions& moduleExtensions = {},
|
const ModuleFileExtensions& moduleExtensions = {},
|
||||||
bool noRuntime = false)
|
void *extraLibHandle = nullptr, bool noRuntime = false)
|
||||||
: Interpreter(argc, argv, llvmdir, moduleExtensions, noRuntime,
|
: Interpreter(argc, argv, llvmdir, moduleExtensions, extraLibHandle,
|
||||||
nullptr) {}
|
noRuntime, nullptr) {}
|
||||||
|
|
||||||
///\brief Constructor for child Interpreter.
|
///\brief Constructor for child Interpreter.
|
||||||
/// If the parent Interpreter has a replacement DiagnosticConsumer, it is
|
/// If the parent Interpreter has a replacement DiagnosticConsumer, it is
|
||||||
@ -368,12 +370,13 @@ namespace cling {
|
|||||||
///\param[in] argc - no. of args.
|
///\param[in] argc - no. of args.
|
||||||
///\param[in] argv - arguments passed when driver is invoked.
|
///\param[in] argv - arguments passed when driver is invoked.
|
||||||
///\param[in] llvmdir - ???
|
///\param[in] llvmdir - ???
|
||||||
|
///\param[in] extraLibHandle - resolve symbols also from this dylib
|
||||||
///\param[in] noRuntime - flag to control the presence of runtime universe
|
///\param[in] noRuntime - flag to control the presence of runtime universe
|
||||||
///
|
///
|
||||||
Interpreter(const Interpreter& parentInterpreter, int argc,
|
Interpreter(const Interpreter& parentInterpreter, int argc,
|
||||||
const char* const* argv, const char* llvmdir = 0,
|
const char* const* argv, const char* llvmdir = 0,
|
||||||
const ModuleFileExtensions& moduleExtensions = {},
|
const ModuleFileExtensions& moduleExtensions = {},
|
||||||
bool noRuntime = true);
|
void *extraLibHandle = nullptr, bool noRuntime = true);
|
||||||
|
|
||||||
virtual ~Interpreter();
|
virtual ~Interpreter();
|
||||||
|
|
||||||
|
@ -444,10 +444,6 @@ namespace cling {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicLibraryManager::ExposeHiddenSharedLibrarySymbols(void* handle) {
|
|
||||||
llvm::sys::DynamicLibrary::addPermanentLibrary(const_cast<void*>(handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DynamicLibraryManager::isSharedLibrary(llvm::StringRef libFullPath,
|
bool DynamicLibraryManager::isSharedLibrary(llvm::StringRef libFullPath,
|
||||||
bool* exists /*=0*/) {
|
bool* exists /*=0*/) {
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
@ -109,7 +109,7 @@ CreateHostTargetMachine(const clang::CompilerInstance& CI) {
|
|||||||
|
|
||||||
IncrementalExecutor::IncrementalExecutor(clang::DiagnosticsEngine& /*diags*/,
|
IncrementalExecutor::IncrementalExecutor(clang::DiagnosticsEngine& /*diags*/,
|
||||||
const clang::CompilerInstance& CI,
|
const clang::CompilerInstance& CI,
|
||||||
bool Verbose):
|
void *ExtraLibHandle, bool Verbose):
|
||||||
m_Callbacks(nullptr), m_externalIncrementalExecutor(nullptr)
|
m_Callbacks(nullptr), m_externalIncrementalExecutor(nullptr)
|
||||||
#if 0
|
#if 0
|
||||||
: m_Diags(diags)
|
: m_Diags(diags)
|
||||||
@ -125,7 +125,7 @@ IncrementalExecutor::IncrementalExecutor(clang::DiagnosticsEngine& /*diags*/,
|
|||||||
llvm::Error Err = llvm::Error::success();
|
llvm::Error Err = llvm::Error::success();
|
||||||
auto EPC = llvm::cantFail(llvm::orc::SelfExecutorProcessControl::Create());
|
auto EPC = llvm::cantFail(llvm::orc::SelfExecutorProcessControl::Create());
|
||||||
m_JIT.reset(new IncrementalJIT(*this, std::move(TM), std::move(EPC), Err,
|
m_JIT.reset(new IncrementalJIT(*this, std::move(TM), std::move(EPC), Err,
|
||||||
Verbose));
|
ExtraLibHandle, Verbose));
|
||||||
if (Err) {
|
if (Err) {
|
||||||
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "Fatal: ");
|
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "Fatal: ");
|
||||||
llvm_unreachable("Propagate this error and exit gracefully");
|
llvm_unreachable("Propagate this error and exit gracefully");
|
||||||
|
@ -154,7 +154,8 @@ namespace cling {
|
|||||||
|
|
||||||
IncrementalExecutor(clang::DiagnosticsEngine& diags,
|
IncrementalExecutor(clang::DiagnosticsEngine& diags,
|
||||||
const clang::CompilerInstance& CI,
|
const clang::CompilerInstance& CI,
|
||||||
bool Verbose);
|
void *ExtraLibHandle = nullptr,
|
||||||
|
bool Verbose = false);
|
||||||
|
|
||||||
~IncrementalExecutor();
|
~IncrementalExecutor();
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ namespace cling {
|
|||||||
IncrementalJIT::IncrementalJIT(
|
IncrementalJIT::IncrementalJIT(
|
||||||
IncrementalExecutor& Executor, std::unique_ptr<TargetMachine> TM,
|
IncrementalExecutor& Executor, std::unique_ptr<TargetMachine> TM,
|
||||||
std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC, Error& Err,
|
std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC, Error& Err,
|
||||||
bool Verbose)
|
void *ExtraLibHandle, bool Verbose)
|
||||||
: SkipHostProcessLookup(false),
|
: SkipHostProcessLookup(false),
|
||||||
TM(std::move(TM)),
|
TM(std::move(TM)),
|
||||||
SingleThreadedContext(std::make_unique<LLVMContext>()) {
|
SingleThreadedContext(std::make_unique<LLVMContext>()) {
|
||||||
@ -81,6 +81,14 @@ IncrementalJIT::IncrementalJIT(
|
|||||||
}
|
}
|
||||||
Jit->getMainJITDylib().addGenerator(std::move(*HostProcessLookup));
|
Jit->getMainJITDylib().addGenerator(std::move(*HostProcessLookup));
|
||||||
|
|
||||||
|
// This must come after process resolution, to consistently resolve global
|
||||||
|
// symbols (e.g. std::cout) to the same address.
|
||||||
|
auto LibLookup = std::make_unique<DynamicLibrarySearchGenerator>(
|
||||||
|
llvm::sys::DynamicLibrary(ExtraLibHandle), LinkerPrefix,
|
||||||
|
[&](const SymbolStringPtr &Sym) {
|
||||||
|
return !m_ForbidDlSymbols.contains(*Sym); });
|
||||||
|
Jit->getMainJITDylib().addGenerator(std::move(LibLookup));
|
||||||
|
|
||||||
// This replaces llvm::orc::ExecutionSession::logErrorsToStdErr:
|
// This replaces llvm::orc::ExecutionSession::logErrorsToStdErr:
|
||||||
auto&& ErrorReporter = [&Executor, LinkerPrefix, Verbose](Error Err) {
|
auto&& ErrorReporter = [&Executor, LinkerPrefix, Verbose](Error Err) {
|
||||||
Err = handleErrors(std::move(Err),
|
Err = handleErrors(std::move(Err),
|
||||||
|
@ -54,7 +54,7 @@ public:
|
|||||||
IncrementalJIT(IncrementalExecutor& Executor,
|
IncrementalJIT(IncrementalExecutor& Executor,
|
||||||
std::unique_ptr<llvm::TargetMachine> TM,
|
std::unique_ptr<llvm::TargetMachine> TM,
|
||||||
std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC,
|
std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC,
|
||||||
llvm::Error &Err, bool Verbose = false);
|
llvm::Error &Err, void *ExtraLibHandle, bool Verbose);
|
||||||
|
|
||||||
/// Register a DefinitionGenerator to dynamically provide symbols for
|
/// Register a DefinitionGenerator to dynamically provide symbols for
|
||||||
/// generated code that are not already available within the process.
|
/// generated code that are not already available within the process.
|
||||||
|
@ -200,7 +200,8 @@ namespace cling {
|
|||||||
Interpreter::Interpreter(int argc, const char* const *argv,
|
Interpreter::Interpreter(int argc, const char* const *argv,
|
||||||
const char* llvmdir /*= 0*/,
|
const char* llvmdir /*= 0*/,
|
||||||
const ModuleFileExtensions& moduleExtensions,
|
const ModuleFileExtensions& moduleExtensions,
|
||||||
bool noRuntime, const Interpreter* parentInterp) :
|
void *extraLibHandle, bool noRuntime,
|
||||||
|
const Interpreter* parentInterp) :
|
||||||
m_Opts(argc, argv),
|
m_Opts(argc, argv),
|
||||||
m_UniqueCounter(parentInterp ? parentInterp->m_UniqueCounter + 1 : 0),
|
m_UniqueCounter(parentInterp ? parentInterp->m_UniqueCounter + 1 : 0),
|
||||||
m_PrintDebug(false), m_DynamicLookupDeclared(false),
|
m_PrintDebug(false), m_DynamicLookupDeclared(false),
|
||||||
@ -258,7 +259,7 @@ namespace cling {
|
|||||||
|
|
||||||
if (!isInSyntaxOnlyMode()) {
|
if (!isInSyntaxOnlyMode()) {
|
||||||
m_Executor.reset(new IncrementalExecutor(SemaRef.Diags, *getCI(),
|
m_Executor.reset(new IncrementalExecutor(SemaRef.Diags, *getCI(),
|
||||||
m_Opts.Verbose()));
|
extraLibHandle, m_Opts.Verbose()));
|
||||||
|
|
||||||
if (!m_Executor)
|
if (!m_Executor)
|
||||||
return;
|
return;
|
||||||
@ -350,8 +351,8 @@ namespace cling {
|
|||||||
const char* const *argv,
|
const char* const *argv,
|
||||||
const char* llvmdir /*= 0*/,
|
const char* llvmdir /*= 0*/,
|
||||||
const ModuleFileExtensions& moduleExtensions/*={}*/,
|
const ModuleFileExtensions& moduleExtensions/*={}*/,
|
||||||
bool noRuntime /*= true*/) :
|
void *ExtraLibHandle, bool noRuntime /*= true*/) :
|
||||||
Interpreter(argc, argv, llvmdir, moduleExtensions, noRuntime,
|
Interpreter(argc, argv, llvmdir, moduleExtensions, ExtraLibHandle, noRuntime,
|
||||||
&parentInterpreter) {
|
&parentInterpreter) {
|
||||||
// Do the "setup" of the connection between this interpreter and
|
// Do the "setup" of the connection between this interpreter and
|
||||||
// its parent interpreter.
|
// its parent interpreter.
|
||||||
@ -1769,7 +1770,8 @@ namespace cling {
|
|||||||
std::string llvmdir
|
std::string llvmdir
|
||||||
= getCI()->getHeaderSearchOpts().ResourceDir + "/../../../";
|
= getCI()->getHeaderSearchOpts().ResourceDir + "/../../../";
|
||||||
cling::Interpreter fwdGen(1, &dummy, llvmdir.c_str(),
|
cling::Interpreter fwdGen(1, &dummy, llvmdir.c_str(),
|
||||||
/*moduleExtensions*/ {}, /*noRuntime=*/true);
|
/*moduleExtensions*/ {},
|
||||||
|
/*ExtraLibHandle*/ nullptr, /*noRuntime=*/true);
|
||||||
|
|
||||||
// Copy the same header search options to the new instance.
|
// Copy the same header search options to the new instance.
|
||||||
Preprocessor& fwdGenPP = fwdGen.getCI()->getPreprocessor();
|
Preprocessor& fwdGenPP = fwdGen.getCI()->getPreprocessor();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user