27 std::string StringMsg =
"truncated or malformed fat file (" + Msg.
str() +
")";
28 return make_error<GenericBinaryError>(std::move(StringMsg),
44 : Parent(Parent), Index(Index) {
54 Header = getUniversalBinaryStruct<MachO::fat_arch>(HeaderPos);
58 Header64 = getUniversalBinaryStruct<MachO::fat_arch_64>(HeaderPos);
67 "called when Parent is a nullptr");
88 "called when Parent is a nullptr");
101 void MachOUniversalBinary::anchor() { }
106 std::unique_ptr<MachOUniversalBinary>
Ret(
109 return std::move(Err);
110 return std::move(Ret);
118 Err = make_error<GenericBinaryError>(
"File too small to be a Mach-O " 126 getUniversalBinaryStruct<MachO::fat_header>(Buf.
begin());
129 if (NumberOfObjects == 0) {
142 if (Buf.
size() < MinSize) {
145 " structs would extend past the end of the file");
148 for (
uint32_t i = 0; i < NumberOfObjects; i++) {
152 if (bigSize > Buf.
size()) {
156 ") extends past the end of the file");
159 #define MAXSECTALIGN 15 171 ") not aligned on it's alignment (2^" +
Twine(A.
getAlign()) +
")");
177 ") offset " +
Twine(A.
getOffset()) +
" overlaps universal headers");
181 for (
uint32_t i = 0; i < NumberOfObjects; i++) {
183 for (
uint32_t j = i + 1; j < NumberOfObjects; j++) {
188 Err =
malformedError(
"contains two of the same architecture (cputype " 215 if (
Triple(ArchName).getArch() == Triple::ArchType::UnknownArch)
216 return make_error<GenericBinaryError>(
"Unknown architecture " 222 if (Obj.getArchFlagName() == ArchName)
223 return Obj.getAsObjectFile();
224 return make_error<GenericBinaryError>(
"fat file does not " uint32_t getAlign() const
void swapStruct(fat_header &mh)
static T getUniversalBinaryStruct(const char *Ptr)
Expected< std::unique_ptr< Archive > > getAsArchive() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
uint32_t getMagic() const
uint32_t getOffset() const
StringRef getFileName() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
ObjectForArch(const MachOUniversalBinary *Parent, uint32_t Index)
static Error malformedError(Twine Msg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
uint32_t getNumberOfObjects() const
Tagged union holding either a T or a Error.
static const bool IsLittleEndianHost
Expected< std::unique_ptr< MachOObjectFile > > getAsObjectFile() const
MachOUniversalBinary(MemoryBufferRef Souce, Error &Err)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static Expected< std::unique_ptr< Archive > > create(MemoryBufferRef Source)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
size_t getBufferSize() const
uint32_t getCPUSubType() const
Triple - Helper class for working with autoconf configuration names.
static const char *const Magic
static Expected< std::unique_ptr< MachOUniversalBinary > > create(MemoryBufferRef Source)
iterator_range< object_iterator > objects() const
static ErrorSuccess success()
Create a success value.
Expected< std::unique_ptr< MachOObjectFile > > getObjectForArch(StringRef ArchName) const
static Expected< std::unique_ptr< MachOObjectFile > > createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0)
uint32_t getCPUType() const
Helper for Errors used as out-parameters.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
std::string str() const
Return the twine contents as a std::string.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
StringRef getData() const