[llvm] 89e7304 - [llvm-jitlink] Add -platform for explicit platform selection (#228703)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 14:17:09 PDT 2026


Author: Lang Hames
Date: 2026-10-04T08:17:02+11:00
New Revision: 89e73043002530e7df3da13e423258f6766f23bf

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

LOG: [llvm-jitlink] Add -platform for explicit platform selection (#228703)

The -platform option can be passed to llvm-jitlink to select the ORC
Platform class to be used for the session. Values are:

  - none: Do not use a Platform
  - native: Auto-detect the executor platform
  - macho: Use MachOPlatform
  - elfnix: Use ELFNixPlatorm
  - coff: Use COFFPlatform

If no -platform argument is given then the default depends on whether an
-orc-runtime option was used. If -orc-runtime was used then the default
is "native". If -orc-runtime was not used then the default is "none".

There should be no functional change from this patch. The intent is to
allow the platform to be explicitly specified (previously it was always
implicitly auto-detected, equivalent to the "native" value), and to
allow new platform variants to be easily added and tested.

There is no testcase for this patch since all available platform options
depend on the ORC runtime, which LLVM tests cannot depend on. Upcoming
ORC runtime tests will exercise this option.

Added: 
    

Modified: 
    llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 1a24e49476611..d6b0d0e59666e 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -328,6 +328,19 @@ static cl::opt<std::string> OutOfProcessConnect(
     "oop-connect", cl::desc("How to connect to the out-of-process executor"),
     cl::cat(JITLinkCategory));
 
+enum class PlatformKind { None, Native, MachO, ELFNix, COFF };
+
+static cl::opt<PlatformKind> UsePlatform(
+    "platform", cl::desc("Which ORC platform to use"),
+    cl::init(PlatformKind::None),
+    cl::values(clEnumValN(PlatformKind::None, "none", "no platform"),
+               clEnumValN(PlatformKind::Native, "native",
+                          "Native platform for the executor"),
+               clEnumValN(PlatformKind::MachO, "macho", "MachO platform"),
+               clEnumValN(PlatformKind::ELFNix, "elfnix", "ELFNix platform"),
+               clEnumValN(PlatformKind::COFF, "coff", "COFF platform")),
+    cl::cat(JITLinkCategory));
+
 static cl::opt<std::string>
     OrcRuntime("orc-runtime", cl::desc("Use ORC runtime from given path"),
                cl::init(""), cl::cat(JITLinkCategory));
@@ -1368,12 +1381,33 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
   }
 
   // Set up the platform.
-  if (!OrcRuntime.empty()) {
+  if (!OrcRuntime.empty() && UsePlatform != PlatformKind::None) {
+
     assert(ProcessSymsJD && "ProcessSymsJD should have been set");
     PlatformJD = &ES.createBareJITDylib("Platform");
     PlatformJD->addToLinkOrder(*ProcessSymsJD);
 
-    if (TT.isOSBinFormatMachO()) {
+    // If the '-platform' option PlatformKind::Native then detect the
+    // platform to use.
+    if (UsePlatform == PlatformKind::Native) {
+      if (TT.isOSBinFormatMachO())
+        UsePlatform = PlatformKind::MachO;
+      else if (TT.isOSBinFormatELF())
+        UsePlatform = PlatformKind::ELFNix;
+      else if (TT.isOSBinFormatCOFF())
+        UsePlatform = PlatformKind::COFF;
+      else {
+        Err = make_error<StringError>(
+            "-" + OrcRuntime.ArgStr + " specified, but format " +
+                Triple::getObjectFormatTypeName(TT.getObjectFormat()) +
+                " not supported",
+            inconvertibleErrorCode());
+        return;
+      }
+    }
+
+    switch (UsePlatform) {
+    case PlatformKind::MachO:
       if (auto P =
               MachOPlatform::Create(*ObjLayer, *PlatformJD, OrcRuntime.c_str()))
         ES.setPlatform(std::move(*P));
@@ -1381,7 +1415,8 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
         Err = P.takeError();
         return;
       }
-    } else if (TT.isOSBinFormatELF()) {
+      break;
+    case PlatformKind::ELFNix:
       if (auto P = ELFNixPlatform::Create(*ObjLayer, *PlatformJD,
                                           OrcRuntime.c_str()))
         ES.setPlatform(std::move(*P));
@@ -1389,7 +1424,8 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
         Err = P.takeError();
         return;
       }
-    } else if (TT.isOSBinFormatCOFF()) {
+      break;
+    case PlatformKind::COFF: {
       auto LoadDynLibrary = [&, this](JITDylib &JD,
                                       StringRef DLLName) -> Error {
         if (!DLLName.ends_with_insensitive(".dll"))
@@ -1406,13 +1442,10 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
         Err = P.takeError();
         return;
       }
-    } else {
-      Err = make_error<StringError>(
-          "-" + OrcRuntime.ArgStr + " specified, but format " +
-              Triple::getObjectFormatTypeName(TT.getObjectFormat()) +
-              " not supported",
-          inconvertibleErrorCode());
-      return;
+      break;
+    }
+    default:
+      llvm_unreachable("Invalid UsePlatform value");
     }
   } else if (TT.isOSBinFormatMachO()) {
     if (!NoExec) {
@@ -1922,6 +1955,12 @@ static Error sanitizeArguments(const Triple &TT, const char *ArgV0) {
     return make_error<StringError>("-orc-runtime requires process symbols",
                                    inconvertibleErrorCode());
 
+  // If no -platform option was specified then pick a default: If an ORC
+  // runtime path was given then use "native", otherwise use "none".
+  if (UsePlatform.getNumOccurrences() == 0)
+    UsePlatform =
+        OrcRuntime.empty() ? PlatformKind::None : PlatformKind::Native;
+
   // If -slab-allocate is passed, check that we're not trying to use it in
   // -oop-launch or -oop-connect mode.
   //


        


More information about the llvm-commits mailing list