14#define DEBUG_TYPE "orc"
23 Desc += (TT.getArchName() +
" slice of universal binary").str();
28template <
typename HeaderType>
31 bool SwapEndianness,
const Triple &TT,
36 memcpy(&Hdr,
Data.data(),
sizeof(HeaderType));
42 return make_error<StringError>(
objDesc(*Obj, TT, ObjIsSlice) +
43 " is not a MachO relocatable object",
47 if (ObjArch != TT.getArch())
48 return make_error<StringError>(
50 ", cannot be loaded into " + TT.str() +
" process",
53 return std::move(Obj);
62 return make_error<StringError>(
64 " is not a valid MachO relocatable object file (truncated header)",
73 return checkMachORelocatableObject<MachO::mach_header>(
77 return checkMachORelocatableObject<MachO::mach_header_64>(
80 return make_error<StringError>(
82 " is not a valid MachO relocatable object (bad magic value)",
91 "TT must specify MachO or Unknown object format");
104 return make_error<StringError>(
105 Path +
" does not contain a relocatable object file compatible with " +
113 StringRef UBPath, std::unique_ptr<MemoryBuffer> UBBuf,
const Triple &TT) {
118 return UniversalBin.takeError();
122 return SliceRange.takeError();
125 UBPath, SliceRange->second, SliceRange->first,
false));
136 for (
const auto &Obj : UB.
objects()) {
137 auto ObjTT = Obj.getTriple();
138 if (ObjTT.getArch() == TT.getArch() &&
139 ObjTT.getSubArch() == TT.getSubArch() &&
141 ObjTT.getVendor() == TT.getVendor())) {
143 return std::make_pair(Obj.getOffset(), Obj.getSize());
147 return make_error<StringError>(
Twine(
"Universal binary ") + UB.
getFileName() +
148 " does not contain a slice for " +
158 return UB.takeError();
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Tagged union holding either a T or a Error.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Map a subrange of the specified file as a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
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
Expected< std::unique_ptr< MemoryBuffer > > checkMachORelocatableObject(std::unique_ptr< MemoryBuffer > Obj, const Triple &TT, bool ObjIsSlice)
Check that the given buffer contains a MachO object file compatible with the given triple.
static std::string objDesc(MemoryBuffer &Obj, const Triple &TT, bool ObjIsSlice)
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.
Expected< std::unique_ptr< MemoryBuffer > > loadMachORelocatableObjectFromUniversalBinary(StringRef UBPath, std::unique_ptr< MemoryBuffer > UBBuf, const Triple &TT)
Load a compatible relocatable object (if available) from a MachO universal binary.
Expected< std::unique_ptr< MemoryBuffer > > loadMachORelocatableObject(StringRef Path, const Triple &TT)
Load a relocatable object compatible with TT from Path.
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.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Expected< T > errorOrToExpected(ErrorOr< T > &&EO)
Convert an ErrorOr<T> to an Expected<T>.
Description of the encoding of one expression Op.
@ macho_universal_binary
Mach-O universal binary.
@ macho_object
Mach-O Object file.