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. JITDylibs 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/test/ExecutionEngine/MCJIT/cross-module-sm-pic-a.ll b/llvm/test/ExecutionEngine/MCJIT/cross-module-sm-pic-a.ll --- a/llvm/test/ExecutionEngine/MCJIT/cross-module-sm-pic-a.ll +++ b/llvm/test/ExecutionEngine/MCJIT/cross-module-sm-pic-a.ll @@ -1,4 +1,5 @@ -; RUN: %lli -extra-module=%p/Inputs/cross-module-b.ll -relocation-model=pic -code-model=small %s > /dev/null +; RUN: %lli -jit-kind=mcjit -extra-module=%p/Inputs/cross-module-b.ll -relocation-model=pic -code-model=small %s > /dev/null +; RUN: %lli -jit-kind=orc -lljit-platform=Inactive -extra-module=%p/Inputs/cross-module-b.ll -relocation-model=pic -code-model=small %s > /dev/null ; XFAIL: mips-, mipsel-, i686, i386 declare i32 @FB() diff --git a/llvm/test/ExecutionEngine/MCJIT/multi-module-sm-pic-a.ll b/llvm/test/ExecutionEngine/MCJIT/multi-module-sm-pic-a.ll --- a/llvm/test/ExecutionEngine/MCJIT/multi-module-sm-pic-a.ll +++ b/llvm/test/ExecutionEngine/MCJIT/multi-module-sm-pic-a.ll @@ -1,4 +1,5 @@ -; RUN: %lli -extra-module=%p/Inputs/multi-module-b.ll -extra-module=%p/Inputs/multi-module-c.ll -relocation-model=pic -code-model=small %s > /dev/null +; RUN: %lli -jit-kind=mcjit -extra-module=%p/Inputs/multi-module-b.ll -extra-module=%p/Inputs/multi-module-c.ll -relocation-model=pic -code-model=small %s > /dev/null +; RUN: %lli -jit-kind=orc -lljit-platform=Inactive -extra-module=%p/Inputs/multi-module-b.ll -extra-module=%p/Inputs/multi-module-c.ll -relocation-model=pic -code-model=small %s > /dev/null ; XFAIL: mips-, mipsel-, i686, i386 declare i32 @FB() diff --git a/llvm/test/ExecutionEngine/MCJIT/test-global-init-nonzero-sm-pic.ll b/llvm/test/ExecutionEngine/MCJIT/test-global-init-nonzero-sm-pic.ll --- a/llvm/test/ExecutionEngine/MCJIT/test-global-init-nonzero-sm-pic.ll +++ b/llvm/test/ExecutionEngine/MCJIT/test-global-init-nonzero-sm-pic.ll @@ -1,4 +1,5 @@ -; RUN: %lli -relocation-model=pic -code-model=small %s > /dev/null +; RUN: %lli -jit-kind=mcjit -relocation-model=pic -code-model=small %s > /dev/null +; RUN: %lli -jit-kind=orc -lljit-platform=Inactive -relocation-model=pic -code-model=small %s > /dev/null ; XFAIL: mips-, mipsel-, aarch64, arm, i686, i386 @count = global i32 1, align 4 diff --git a/llvm/test/ExecutionEngine/MCJIT/test-ptr-reloc-sm-pic.ll b/llvm/test/ExecutionEngine/MCJIT/test-ptr-reloc-sm-pic.ll --- a/llvm/test/ExecutionEngine/MCJIT/test-ptr-reloc-sm-pic.ll +++ b/llvm/test/ExecutionEngine/MCJIT/test-ptr-reloc-sm-pic.ll @@ -1,4 +1,5 @@ -; RUN: %lli -O0 -relocation-model=pic -code-model=small %s +; RUN: %lli -jit-kind=mcjit -O0 -relocation-model=pic -code-model=small %s +; RUN: %lli -jit-kind=orc -lljit-platform=Inactive -O0 -relocation-model=pic -code-model=small %s ; XFAIL: mips-, mipsel-, aarch64, arm, i686, i386 @.str = private unnamed_addr constant [6 x i8] c"data1\00", align 1 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 { @@ -925,6 +927,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"); }