[llvm] c352a2b - [lli] Add option -lljit-platform=Inactive to disable platform support explicitly

Stefan Gränitz via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 30 00:30:15 PDT 2021


Author: Stefan Gränitz
Date: 2021-03-30T09:29:45+02:00
New Revision: c352a2b8290b0a088ac3442aca89380248f02381

URL: https://github.com/llvm/llvm-project/commit/c352a2b8290b0a088ac3442aca89380248f02381
DIFF: https://github.com/llvm/llvm-project/commit/c352a2b8290b0a088ac3442aca89380248f02381.diff

LOG: [lli] Add option -lljit-platform=Inactive to disable platform support explicitly

This option tells LLJIT to disable platform support explicitly: JITDylibs aren't scanned for special init/deinit symbols and no runtime API interposes are injected.
It's useful in two cases: for platforms that don't have such requirements and platforms for which we have no explicit support yet and that don't work well with the generic IR platform.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D99416

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
    llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
    llvm/test/ExecutionEngine/MCJIT/cross-module-sm-pic-a.ll
    llvm/test/ExecutionEngine/MCJIT/multi-module-sm-pic-a.ll
    llvm/test/ExecutionEngine/MCJIT/test-global-init-nonzero-sm-pic.ll
    llvm/test/ExecutionEngine/MCJIT/test-ptr-reloc-sm-pic.ll
    llvm/tools/lli/lli.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index ff0aa02385230..6eb3d0c3f96d8 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -456,6 +456,12 @@ void setUpGenericLLVMIRPlatform(LLJIT &J);
 /// 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
index 8e5aa865cc3aa..9e2177e1eaea0 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -124,7 +124,6 @@ class GlobalCtorDtorScraper {
 /// 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 @@ class MachOPlatformSupport : public LLJIT::PlatformSupport {
   std::map<std::thread::id, std::unique_ptr<std::string>> 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 @@ Error setUpMachOPlatform(LLJIT &J) {
   return Error::success();
 }
 
+Error setUpInactivePlatform(LLJIT &J) {
+  LLVM_DEBUG(
+      { dbgs() << "Explicitly deactivated platform support for LLJIT\n"; });
+  J.setPlatformSupport(std::make_unique<InactivePlatformSupport>());
+  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
index 04331990db338..e9b14fc717552 100644
--- 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
index 7e5710dbf9c98..cba64c488265f 100644
--- 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
index e54135fc7cbc4..4eac7177b6567 100644
--- 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
index eea6fde2e2caf..d471e877427c2 100644
--- 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
index 782bc745e4a94..4ddae61ee49f1 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -228,7 +228,7 @@ namespace {
       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<LLJITPlatform>
       Platform("lljit-platform", cl::desc("Platform to use with LLJIT"),
@@ -238,7 +238,9 @@ namespace {
                           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 @@ int runOrcJIT(const char *ProgName) {
       Builder.setPlatformSetUp(orc::setUpMachOPlatform);
       ExitOnErr(orc::enableObjCRegistration("libobjc.dylib"));
       break;
+    case LLJITPlatform::Inactive:
+      Builder.setPlatformSetUp(orc::setUpInactivePlatform);
+      break;
     default:
       llvm_unreachable("Unrecognized platform value");
     }


        


More information about the llvm-commits mailing list