Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions llvm/include/llvm/ExecutionEngine/Orc/GetDylibInterface.h

This file was deleted.

18 changes: 18 additions & 0 deletions llvm/include/llvm/ExecutionEngine/Orc/MachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,6 +32,7 @@ class MachOUniversalBinary;

namespace orc {

class ExecutionSession;
class JITDylib;
class ObjectLayer;

Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ add_llvm_component_library(LLVMOrcJIT
ExecutionUtils.cpp
ExecutorResolutionGenerator.cpp
ObjectFileInterface.cpp
GetDylibInterface.cpp
IndirectionUtils.cpp
InProcessMemoryAccess.cpp
IRCompileLayer.cpp
Expand Down
128 changes: 0 additions & 128 deletions llvm/lib/ExecutionEngine/Orc/GetDylibInterface.cpp

This file was deleted.

110 changes: 110 additions & 0 deletions llvm/lib/ExecutionEngine/Orc/MachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
1 change: 0 additions & 1 deletion llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading