18#define DEBUG_TYPE "orc"
27 Desc += (TT.getArchName() +
" slice of universal binary").str();
32template <
typename HeaderType>
34 bool SwapEndianness,
const Triple &TT,
39 memcpy(&Hdr,
Data.data(),
sizeof(HeaderType));
45 return make_error<StringError>(
objDesc(Obj, TT, ObjIsSlice) +
46 " is not a MachO relocatable object",
50 if (ObjArch != TT.getArch())
51 return make_error<StringError>(
53 ", cannot be loaded into " + TT.str() +
" process",
64 return make_error<StringError>(
66 " is not a valid MachO relocatable object file (truncated header)",
75 return checkMachORelocatableObject<MachO::mach_header>(
79 return checkMachORelocatableObject<MachO::mach_header_64>(
82 return make_error<StringError>(
84 " is not a valid MachO relocatable object (bad magic value)",
94 return std::move(Err);
95 return std::move(Obj);
100 std::optional<StringRef> IdentifierOverride) {
103 "TT must specify MachO or Unknown object format");
105 if (!IdentifierOverride)
106 IdentifierOverride = Path;
118 return make_error<StringError>(
119 StringRef(
"Could not load MachO object at path ") + Path,
126 return CheckedObj.takeError();
127 return std::make_pair(std::move(*CheckedObj),
133 *IdentifierOverride);
135 return make_error<StringError>(
136 Path +
" does not contain a relocatable object file compatible with " +
144 std::unique_ptr<MemoryBuffer> UBBuf,
152 return UniversalBin.takeError();
156 return SliceRange.takeError();
161 return make_error<StringError>(
162 "Could not load " + TT.getArchName() +
163 " slice of MachO universal binary at path " + UBPath,
175 return CheckedObj.takeError();
176 return std::make_pair(std::move(*CheckedObj),
188 return "a mach-o relocatable object file";
190 return "a mach-o relocatable object file or archive";
197 return make_error<StringError>(TT.getArchName() +
" slice of " + UBPath +
198 " does not contain " + FT(),
206 for (
const auto &Obj : UB.
objects()) {
207 auto ObjTT = Obj.getTriple();
208 if (ObjTT.getArch() == TT.getArch() &&
209 ObjTT.getSubArch() == TT.getSubArch() &&
211 ObjTT.getVendor() == TT.getVendor())) {
213 return std::make_pair(Obj.getOffset(), Obj.getSize());
217 return make_error<StringError>(
Twine(
"Universal binary ") + UB.
getFileName() +
218 " does not contain a slice for " +
228 return UB.takeError();
236 auto LoadMember = [&]() {
244 if (
auto Err = L.
add(JD, LoadMember()))
258 if (
auto *MachOObj = dyn_cast<object::MachOObjectFile>(&**Obj)) {
260 for (
auto Sec : MachOObj->sections()) {
262 MachOObj->getSectionFinalSegmentName(Sec.getRawDataRefImpl());
263 if (
auto SecName = Sec.getName()) {
264 if (*SecName ==
"__objc_classlist" || *SecName ==
"__objc_protolist" ||
265 *SecName ==
"__objc_clsrolist" || *SecName ==
"__objc_catlist" ||
266 *SecName ==
"__objc_catlist2" || *SecName ==
"__objc_nlcatlist" ||
267 (SegName ==
"__TEXT" && (*SecName).starts_with(
"__swift") &&
268 *SecName !=
"__swift_modhash")) {
269 if (
auto Err = L.
add(JD, LoadMember()))
274 return SecName.takeError();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
StringRef getBufferIdentifier() const
StringRef getBuffer() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFileSlice(sys::fs::file_t FD, const Twine &Filename, uint64_t MapSize, int64_t Offset, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Given an already-open file descriptor, map some slice of it into a MemoryBuffer.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
static LLVM_ABI StringRef getArchTypeName(ArchType Kind)
Get the canonical name for the Kind architecture.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef getFileName() const
Triple::ArchType getArch() const override
static Expected< std::unique_ptr< MachOUniversalBinary > > create(MemoryBufferRef Source)
iterator_range< object_iterator > objects() const
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
LLVM_ABI Expected< bool > operator()(object::Archive &A, MemoryBufferRef MemberBuf, size_t Index)
virtual Error add(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > O, MaterializationUnit::Interface I)
Adds a MaterializationUnit for the object file in the given memory buffer to the JITDylib for the giv...
static std::unique_ptr< MemoryBuffer > createMemberBuffer(object::Archive &A, MemoryBufferRef BufRef, size_t Index)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI Expected< std::pair< std::unique_ptr< MemoryBuffer >, LinkableFileKind > > loadLinkableSliceFromMachOUniversalBinary(sys::fs::file_t FD, std::unique_ptr< MemoryBuffer > UBBuf, const Triple &TT, LoadArchives LA, StringRef UBPath, StringRef Identifier)
Load a compatible relocatable object (if available) from a MachO universal binary.
LLVM_ABI Error checkMachORelocatableObject(MemoryBufferRef Obj, const Triple &TT, bool ObjIsSlice)
Check that the given buffer contains a MachO object file compatible with the given triple.
LLVM_ABI Expected< std::pair< size_t, size_t > > getMachOSliceRangeForTriple(object::MachOUniversalBinary &UB, const Triple &TT)
Utility for identifying the file-slice compatible with TT in a universal binary.
static std::string objDesc(const MemoryBufferRef &Obj, const Triple &TT, bool ObjIsSlice)
Expected< std::pair< std::unique_ptr< MemoryBuffer >, LinkableFileKind > > loadMachORelocatableObject(StringRef Path, const Triple &TT, LoadArchives LA, std::optional< StringRef > IdentifierOverride)
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
LLVM_ABI Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
void consumeError(Error Err)
Consume a Error without doing anything.
Description of the encoding of one expression Op.
@ archive
ar style archive file
@ macho_universal_binary
Mach-O universal binary.
@ macho_object
Mach-O Object file.