diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h --- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h @@ -456,6 +456,12 @@ /// your JITDylib names do not shadow any real library paths). Error setUpMachOPlatform(LLJIT &J); +/// Configure the LLJIT instance to disable platform support explicitly. This is +/// useful in two cases: for platforms that don't have such requirements and for +/// platforms, that we have no explicit support yet and that don't work well +/// with the generic IR platform. +Error setUpInactivePlatform(LLJIT &J); + } // End namespace orc } // End namespace llvm diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -124,7 +124,6 @@ /// some runtime API, including __cxa_atexit, dlopen, and dlclose. class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport { public: - // GenericLLVMIRPlatform &P) : P(P) { GenericLLVMIRPlatformSupport(LLJIT &J) : J(J), InitFunctionPrefix(J.mangle("__orc_init_func.")) { @@ -894,6 +893,28 @@ std::map> dlErrorMsgs; }; +/// Inactive Platform Support +/// +/// Explicitly disables platform support. JITDylib are not scanned for special +/// init/deinit symbols. No runtime API interposes are injected. +class InactivePlatformSupport : public LLJIT::PlatformSupport { +public: + InactivePlatformSupport() = default; + + Error initialize(JITDylib &JD) override { + LLVM_DEBUG(dbgs() << "InactivePlatformSupport: no initializers running for " + << JD.getName() << "\n"); + return Error::success(); + } + + Error deinitialize(JITDylib &JD) override { + LLVM_DEBUG( + dbgs() << "InactivePlatformSupport: no deinitializers running for " + << JD.getName() << "\n"); + return Error::success(); + } +}; + } // end anonymous namespace namespace llvm { @@ -1165,6 +1186,13 @@ return Error::success(); } +Error setUpInactivePlatform(LLJIT &J) { + LLVM_DEBUG( + { dbgs() << "Explicitly deactivated platform support for LLJIT\n"; }); + J.setPlatformSupport(std::make_unique()); + return Error::success(); +} + Error LLLazyJITBuilderState::prepareForConstruction() { if (auto Err = LLJITBuilderState::prepareForConstruction()) return Err; diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -228,7 +228,7 @@ cl::desc("Do not resolve lli process symbols in JIT'd code"), cl::init(false)); - enum class LLJITPlatform { DetectHost, GenericIR, MachO }; + enum class LLJITPlatform { Inactive, DetectHost, GenericIR, MachO }; cl::opt Platform("lljit-platform", cl::desc("Platform to use with LLJIT"), @@ -238,7 +238,9 @@ clEnumValN(LLJITPlatform::GenericIR, "GenericIR", "Use LLJITGenericIRPlatform"), clEnumValN(LLJITPlatform::MachO, "MachO", - "Use LLJITMachOPlatform")), + "Use LLJITMachOPlatform"), + clEnumValN(LLJITPlatform::Inactive, "Inactive", + "Disable platform support explicitly")), cl::Hidden); enum class DumpKind { @@ -924,6 +926,9 @@ Builder.setPlatformSetUp(orc::setUpMachOPlatform); ExitOnErr(orc::enableObjCRegistration("libobjc.dylib")); break; + case LLJITPlatform::Inactive: + Builder.setPlatformSetUp(orc::setUpInactivePlatform); + break; default: llvm_unreachable("Unrecognized platform value"); }