17#define DEBUG_TYPE "orc"
26 Desc += (TT.getArchName() +
" slice of universal binary").str();
31template <
typename HeaderType>
33 bool SwapEndianness,
const Triple &TT,
38 memcpy(&Hdr,
Data.data(),
sizeof(HeaderType));
44 return make_error<StringError>(
objDesc(Obj, TT, ObjIsSlice) +
45 " is not a MachO relocatable object",
49 if (ObjArch != TT.getArch())
50 return make_error<StringError>(
52 ", cannot be loaded into " + TT.str() +
" process",
63 return make_error<StringError>(
65 " is not a valid MachO relocatable object file (truncated header)",
74 return checkMachORelocatableObject<MachO::mach_header>(
78 return checkMachORelocatableObject<MachO::mach_header_64>(
81 return make_error<StringError>(
83 " is not a valid MachO relocatable object (bad magic value)",
93 return std::move(Err);
94 return std::move(Obj);
99 std::optional<StringRef> IdentifierOverride) {
102 "TT must specify MachO or Unknown object format");
104 if (!IdentifierOverride)
105 IdentifierOverride = Path;
117 return make_error<StringError>(
118 StringRef(
"Could not load MachO object at path ") + Path,
125 return CheckedObj.takeError();
126 return std::make_pair(std::move(*CheckedObj),
132 *IdentifierOverride);
134 return make_error<StringError>(
135 Path +
" does not contain a relocatable object file compatible with " +
143 std::unique_ptr<MemoryBuffer> UBBuf,
151 return UniversalBin.takeError();
155 return SliceRange.takeError();
160 return make_error<StringError>(
161 "Could not load " + TT.getArchName() +
162 " slice of MachO universal binary at path " + UBPath,
174 return CheckedObj.takeError();
175 return std::make_pair(std::move(*CheckedObj),
187 return "a mach-o relocatable object file";
189 return "a mach-o relocatable object file or archive";
196 return make_error<StringError>(TT.getArchName() +
" slice of " + UBPath +
197 " does not contain " + FT(),
205 for (
const auto &Obj : UB.
objects()) {
206 auto ObjTT = Obj.getTriple();
207 if (ObjTT.getArch() == TT.getArch() &&
208 ObjTT.getSubArch() == TT.getSubArch() &&
210 ObjTT.getVendor() == TT.getVendor())) {
212 return std::make_pair(Obj.getOffset(), Obj.getSize());
216 return make_error<StringError>(
Twine(
"Universal binary ") + UB.
getFileName() +
217 " does not contain a slice for " +
227 return UB.takeError();
246 if (
auto *MachOObj = dyn_cast<object::MachOObjectFile>(&**Obj)) {
248 for (
auto Sec : MachOObj->sections()) {
250 MachOObj->getSectionFinalSegmentName(Sec.getRawDataRefImpl());
251 if (
auto SecName = Sec.getName()) {
252 if (*SecName ==
"__objc_classlist" || *SecName ==
"__objc_protolist" ||
253 *SecName ==
"__objc_clsrolist" || *SecName ==
"__objc_catlist" ||
254 *SecName ==
"__objc_catlist2" || *SecName ==
"__objc_nlcatlist" ||
255 (SegName ==
"__TEXT" && (*SecName).starts_with(
"__swift") &&
256 *SecName !=
"__swift_modhash"))
259 return SecName.takeError();
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as 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 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)
Error operator()(MemoryBufferRef MemberBuf)
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
Error checkMachORelocatableObject(MemoryBufferRef Obj, const Triple &TT, bool ObjIsSlice)
Check that the given buffer contains a MachO object file compatible with the given triple.
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)
std::error_code closeFile(file_t &F)
Close the file object.
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.
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)
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.