[llvm] 17f0afe - [ORC] Merge GetDylibInterface.h APIs into MachO.h. (#168462)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 17 16:51:12 PST 2025


Author: Lang Hames
Date: 2025-11-18T11:51:08+11:00
New Revision: 17f0afe40ae899d500089156b80b403e63fba71e

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

LOG: [ORC] Merge GetDylibInterface.h APIs into MachO.h. (#168462)

These APIs are MachO specific, and the interfaces are about to be
extended to support more MachO-specific behavior. For now it makes sense
to group them with other MachO specific APIs in MachO.h.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/MachO.h
    llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
    llvm/lib/ExecutionEngine/Orc/MachO.cpp
    llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Removed: 
    llvm/include/llvm/ExecutionEngine/Orc/GetDylibInterface.h
    llvm/lib/ExecutionEngine/Orc/GetDylibInterface.cpp


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/GetDylibInterface.h b/llvm/include/llvm/ExecutionEngine/Orc/GetDylibInterface.h
deleted file mode 100644
index 077d88d1758a0..0000000000000
--- a/llvm/include/llvm/ExecutionEngine/Orc/GetDylibInterface.h
+++ /dev/null
@@ -1,41 +0,0 @@
-//===---- GetDylibInterface.h - Get interface for real dylib ----*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Get symbol interface from a real dynamic library or TAPI file. These
-// interfaces can be used to simulate weak linking (ld64 -weak-lx /
-// -weak_library) against a library that is absent at runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_EXECUTIONENGINE_ORC_GETDYLIBINTERFACE_H
-#define LLVM_EXECUTIONENGINE_ORC_GETDYLIBINTERFACE_H
-
-#include "llvm/ExecutionEngine/Orc/Core.h"
-#include "llvm/Support/Compiler.h"
-
-namespace llvm::orc {
-
-/// Returns a SymbolNameSet containing the exported symbols defined in the
-/// given dylib.
-LLVM_ABI Expected<SymbolNameSet>
-getDylibInterfaceFromDylib(ExecutionSession &ES, Twine Path);
-
-/// Returns a SymbolNameSet containing the exported symbols defined in the
-/// relevant slice of the TapiUniversal file.
-LLVM_ABI Expected<SymbolNameSet>
-getDylibInterfaceFromTapiFile(ExecutionSession &ES, Twine Path);
-
-/// Returns a SymbolNameSet containing the exported symbols defined in the
-/// relevant slice of the given file, which may be either a dylib or a tapi
-/// file.
-LLVM_ABI Expected<SymbolNameSet> getDylibInterface(ExecutionSession &ES,
-                                                   Twine Path);
-
-} // namespace llvm::orc
-
-#endif // LLVM_EXECUTIONENGINE_ORC_GETDYLIBINTERFACE_H

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/MachO.h b/llvm/include/llvm/ExecutionEngine/Orc/MachO.h
index a0342d8d75bc2..049595c330f5c 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachO.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachO.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_EXECUTIONENGINE_ORC_MACHO_H
 #define LLVM_EXECUTIONENGINE_ORC_MACHO_H
 
+#include "llvm/ExecutionEngine/Orc/CoreContainers.h"
 #include "llvm/ExecutionEngine/Orc/LoadLinkableFile.h"
 #include "llvm/Object/Archive.h"
 #include "llvm/Support/Compiler.h"
@@ -31,6 +32,7 @@ class MachOUniversalBinary;
 
 namespace orc {
 
+class ExecutionSession;
 class JITDylib;
 class ObjectLayer;
 
@@ -93,6 +95,22 @@ class ForceLoadMachOArchiveMembers {
   bool ObjCOnly;
 };
 
+/// Returns a SymbolNameSet containing the exported symbols defined in the
+/// given dylib.
+LLVM_ABI Expected<SymbolNameSet>
+getDylibInterfaceFromDylib(ExecutionSession &ES, Twine Path);
+
+/// Returns a SymbolNameSet containing the exported symbols defined in the
+/// relevant slice of the TapiUniversal file.
+LLVM_ABI Expected<SymbolNameSet>
+getDylibInterfaceFromTapiFile(ExecutionSession &ES, Twine Path);
+
+/// Returns a SymbolNameSet containing the exported symbols defined in the
+/// relevant slice of the given file, which may be either a dylib or a tapi
+/// file.
+LLVM_ABI Expected<SymbolNameSet> getDylibInterface(ExecutionSession &ES,
+                                                   Twine Path);
+
 } // namespace orc
 } // namespace llvm
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
index f34392538a7cb..db16a3005f6c1 100644
--- a/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
@@ -26,7 +26,6 @@ add_llvm_component_library(LLVMOrcJIT
   ExecutionUtils.cpp
   ExecutorResolutionGenerator.cpp
   ObjectFileInterface.cpp
-  GetDylibInterface.cpp
   IndirectionUtils.cpp
   InProcessMemoryAccess.cpp
   IRCompileLayer.cpp

diff  --git a/llvm/lib/ExecutionEngine/Orc/GetDylibInterface.cpp b/llvm/lib/ExecutionEngine/Orc/GetDylibInterface.cpp
deleted file mode 100644
index 9ccb211931a5b..0000000000000
--- a/llvm/lib/ExecutionEngine/Orc/GetDylibInterface.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-//===-------- GetDylibInterface.cpp - Get interface for real dylib --------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ExecutionEngine/Orc/GetDylibInterface.h"
-
-#include "llvm/BinaryFormat/Magic.h"
-#include "llvm/Object/MachO.h"
-#include "llvm/Object/MachOUniversal.h"
-#include "llvm/Object/TapiUniversal.h"
-
-#define DEBUG_TYPE "orc"
-
-namespace llvm::orc {
-
-Expected<SymbolNameSet> getDylibInterfaceFromDylib(ExecutionSession &ES,
-                                                   Twine Path) {
-  auto CPUType = MachO::getCPUType(ES.getTargetTriple());
-  if (!CPUType)
-    return CPUType.takeError();
-
-  auto CPUSubType = MachO::getCPUSubType(ES.getTargetTriple());
-  if (!CPUSubType)
-    return CPUSubType.takeError();
-
-  auto Buf = MemoryBuffer::getFile(Path);
-  if (!Buf)
-    return createFileError(Path, Buf.getError());
-
-  auto BinFile = object::createBinary((*Buf)->getMemBufferRef());
-  if (!BinFile)
-    return BinFile.takeError();
-
-  std::unique_ptr<object::MachOObjectFile> MachOFile;
-  if (isa<object::MachOObjectFile>(**BinFile))
-    MachOFile.reset(dyn_cast<object::MachOObjectFile>(BinFile->release()));
-  else if (auto *MachOUni =
-               dyn_cast<object::MachOUniversalBinary>(BinFile->get())) {
-    for (auto &O : MachOUni->objects()) {
-      if (O.getCPUType() == *CPUType &&
-          (O.getCPUSubType() & ~MachO::CPU_SUBTYPE_MASK) == *CPUSubType) {
-        if (auto Obj = O.getAsObjectFile())
-          MachOFile = std::move(*Obj);
-        else
-          return Obj.takeError();
-        break;
-      }
-    }
-    if (!MachOFile)
-      return make_error<StringError>("MachO universal binary at " + Path +
-                                         " does not contain a slice for " +
-                                         ES.getTargetTriple().str(),
-                                     inconvertibleErrorCode());
-  } else
-    return make_error<StringError>("File at " + Path + " is not a MachO",
-                                   inconvertibleErrorCode());
-
-  if (MachOFile->getHeader().filetype != MachO::MH_DYLIB)
-    return make_error<StringError>("MachO at " + Path + " is not a dylib",
-                                   inconvertibleErrorCode());
-
-  SymbolNameSet Symbols;
-  for (auto &Sym : MachOFile->symbols()) {
-    if (auto Name = Sym.getName())
-      Symbols.insert(ES.intern(*Name));
-    else
-      return Name.takeError();
-  }
-
-  return std::move(Symbols);
-}
-
-Expected<SymbolNameSet> getDylibInterfaceFromTapiFile(ExecutionSession &ES,
-                                                      Twine Path) {
-  SymbolNameSet Symbols;
-
-  auto TapiFileBuffer = MemoryBuffer::getFile(Path);
-  if (!TapiFileBuffer)
-    return createFileError(Path, TapiFileBuffer.getError());
-
-  auto Tapi =
-      object::TapiUniversal::create((*TapiFileBuffer)->getMemBufferRef());
-  if (!Tapi)
-    return Tapi.takeError();
-
-  auto CPUType = MachO::getCPUType(ES.getTargetTriple());
-  if (!CPUType)
-    return CPUType.takeError();
-
-  auto CPUSubType = MachO::getCPUSubType(ES.getTargetTriple());
-  if (!CPUSubType)
-    return CPUSubType.takeError();
-
-  auto &IF = (*Tapi)->getInterfaceFile();
-  auto Interface =
-      IF.extract(MachO::getArchitectureFromCpuType(*CPUType, *CPUSubType));
-  if (!Interface)
-    return Interface.takeError();
-
-  for (auto *Sym : (*Interface)->exports())
-    Symbols.insert(ES.intern(Sym->getName()));
-
-  return Symbols;
-}
-
-Expected<SymbolNameSet> getDylibInterface(ExecutionSession &ES, Twine Path) {
-  file_magic Magic;
-  if (auto EC = identify_magic(Path, Magic))
-    return createFileError(Path, EC);
-
-  switch (Magic) {
-  case file_magic::macho_universal_binary:
-  case file_magic::macho_dynamically_linked_shared_lib:
-    return getDylibInterfaceFromDylib(ES, Path);
-  case file_magic::tapi_file:
-    return getDylibInterfaceFromTapiFile(ES, Path);
-  default:
-    return make_error<StringError>("Cannot get interface for " + Path +
-                                       " unrecognized file type",
-                                   inconvertibleErrorCode());
-  }
-}
-
-} // namespace llvm::orc

diff  --git a/llvm/lib/ExecutionEngine/Orc/MachO.cpp b/llvm/lib/ExecutionEngine/Orc/MachO.cpp
index 89721d16930c0..14d1c843bf6e4 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachO.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachO.cpp
@@ -10,9 +10,11 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/BinaryFormat/MachO.h"
+#include "llvm/BinaryFormat/Magic.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 #include "llvm/ExecutionEngine/Orc/Layer.h"
 #include "llvm/Object/MachOUniversal.h"
+#include "llvm/Object/TapiUniversal.h"
 #include "llvm/Support/FileSystem.h"
 
 #define DEBUG_TYPE "orc"
@@ -280,5 +282,113 @@ Expected<bool> ForceLoadMachOArchiveMembers::operator()(
   return true;
 }
 
+Expected<SymbolNameSet> getDylibInterfaceFromDylib(ExecutionSession &ES,
+                                                   Twine Path) {
+  auto CPUType = MachO::getCPUType(ES.getTargetTriple());
+  if (!CPUType)
+    return CPUType.takeError();
+
+  auto CPUSubType = MachO::getCPUSubType(ES.getTargetTriple());
+  if (!CPUSubType)
+    return CPUSubType.takeError();
+
+  auto Buf = MemoryBuffer::getFile(Path);
+  if (!Buf)
+    return createFileError(Path, Buf.getError());
+
+  auto BinFile = object::createBinary((*Buf)->getMemBufferRef());
+  if (!BinFile)
+    return BinFile.takeError();
+
+  std::unique_ptr<object::MachOObjectFile> MachOFile;
+  if (isa<object::MachOObjectFile>(**BinFile))
+    MachOFile.reset(dyn_cast<object::MachOObjectFile>(BinFile->release()));
+  else if (auto *MachOUni =
+               dyn_cast<object::MachOUniversalBinary>(BinFile->get())) {
+    for (auto &O : MachOUni->objects()) {
+      if (O.getCPUType() == *CPUType &&
+          (O.getCPUSubType() & ~MachO::CPU_SUBTYPE_MASK) == *CPUSubType) {
+        if (auto Obj = O.getAsObjectFile())
+          MachOFile = std::move(*Obj);
+        else
+          return Obj.takeError();
+        break;
+      }
+    }
+    if (!MachOFile)
+      return make_error<StringError>("MachO universal binary at " + Path +
+                                         " does not contain a slice for " +
+                                         ES.getTargetTriple().str(),
+                                     inconvertibleErrorCode());
+  } else
+    return make_error<StringError>("File at " + Path + " is not a MachO",
+                                   inconvertibleErrorCode());
+
+  if (MachOFile->getHeader().filetype != MachO::MH_DYLIB)
+    return make_error<StringError>("MachO at " + Path + " is not a dylib",
+                                   inconvertibleErrorCode());
+
+  SymbolNameSet Symbols;
+  for (auto &Sym : MachOFile->symbols()) {
+    if (auto Name = Sym.getName())
+      Symbols.insert(ES.intern(*Name));
+    else
+      return Name.takeError();
+  }
+
+  return std::move(Symbols);
+}
+
+Expected<SymbolNameSet> getDylibInterfaceFromTapiFile(ExecutionSession &ES,
+                                                      Twine Path) {
+  SymbolNameSet Symbols;
+
+  auto TapiFileBuffer = MemoryBuffer::getFile(Path);
+  if (!TapiFileBuffer)
+    return createFileError(Path, TapiFileBuffer.getError());
+
+  auto Tapi =
+      object::TapiUniversal::create((*TapiFileBuffer)->getMemBufferRef());
+  if (!Tapi)
+    return Tapi.takeError();
+
+  auto CPUType = MachO::getCPUType(ES.getTargetTriple());
+  if (!CPUType)
+    return CPUType.takeError();
+
+  auto CPUSubType = MachO::getCPUSubType(ES.getTargetTriple());
+  if (!CPUSubType)
+    return CPUSubType.takeError();
+
+  auto &IF = (*Tapi)->getInterfaceFile();
+  auto Interface =
+      IF.extract(MachO::getArchitectureFromCpuType(*CPUType, *CPUSubType));
+  if (!Interface)
+    return Interface.takeError();
+
+  for (auto *Sym : (*Interface)->exports())
+    Symbols.insert(ES.intern(Sym->getName()));
+
+  return Symbols;
+}
+
+Expected<SymbolNameSet> getDylibInterface(ExecutionSession &ES, Twine Path) {
+  file_magic Magic;
+  if (auto EC = identify_magic(Path, Magic))
+    return createFileError(Path, EC);
+
+  switch (Magic) {
+  case file_magic::macho_universal_binary:
+  case file_magic::macho_dynamically_linked_shared_lib:
+    return getDylibInterfaceFromDylib(ES, Path);
+  case file_magic::tapi_file:
+    return getDylibInterfaceFromTapiFile(ES, Path);
+  default:
+    return make_error<StringError>("Cannot get interface for " + Path +
+                                       " unrecognized file type",
+                                   inconvertibleErrorCode());
+  }
+}
+
 } // End namespace orc.
 } // End namespace llvm.

diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 50b4ac372b4e4..217e521b2e43e 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -27,7 +27,6 @@
 #include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
 #include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
-#include "llvm/ExecutionEngine/Orc/GetDylibInterface.h"
 #include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
 #include "llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h"
 #include "llvm/ExecutionEngine/Orc/JITLinkReentryTrampolines.h"


        


More information about the llvm-commits mailing list