diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Object/MachOUniversal.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Object/MachOUniversal.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/contrib/llvm-project/llvm/lib/Object/MachOUniversal.cpp b/contrib/llvm-project/llvm/lib/Object/MachOUniversal.cpp index b3f0993412c6..a178ecde949e 100644 --- a/contrib/llvm-project/llvm/lib/Object/MachOUniversal.cpp +++ b/contrib/llvm-project/llvm/lib/Object/MachOUniversal.cpp @@ -155,15 +155,16 @@ MachOUniversalBinary::MachOUniversalBinary(MemoryBufferRef Source, Error &Err) ") extends past the end of the file"); return; } -#define MAXSECTALIGN 15 /* 2**15 or 0x8000 */ - if (A.getAlign() > MAXSECTALIGN) { - Err = malformedError("align (2^" + Twine(A.getAlign()) + ") too large " - "for cputype (" + Twine(A.getCPUType()) + ") cpusubtype (" + - Twine(A.getCPUSubType() & ~MachO::CPU_SUBTYPE_MASK) + - ") (maximum 2^" + Twine(MAXSECTALIGN) + ")"); + + if (A.getAlign() > MaxSectionAlignment) { + Err = malformedError("align (2^" + Twine(A.getAlign()) + + ") too large for cputype (" + Twine(A.getCPUType()) + + ") cpusubtype (" + + Twine(A.getCPUSubType() & ~MachO::CPU_SUBTYPE_MASK) + + ") (maximum 2^" + Twine(MaxSectionAlignment) + ")"); return; } - if(A.getOffset() % (1 << A.getAlign()) != 0){ + if(A.getOffset() % (1ull << A.getAlign()) != 0){ Err = malformedError("offset: " + Twine(A.getOffset()) + " for cputype (" + Twine(A.getCPUType()) + ") cpusubtype (" + Twine(A.getCPUSubType() & ~MachO::CPU_SUBTYPE_MASK) + @@ -209,19 +210,34 @@ MachOUniversalBinary::MachOUniversalBinary(MemoryBufferRef Source, Error &Err) Err = Error::success(); } -Expected<std::unique_ptr<MachOObjectFile>> +Expected<MachOUniversalBinary::ObjectForArch> MachOUniversalBinary::getObjectForArch(StringRef ArchName) const { if (Triple(ArchName).getArch() == Triple::ArchType::UnknownArch) return make_error<GenericBinaryError>("Unknown architecture " "named: " + ArchName, object_error::arch_not_found); - - for (auto &Obj : objects()) + for (const auto &Obj : objects()) if (Obj.getArchFlagName() == ArchName) - return Obj.getAsObjectFile(); + return Obj; return make_error<GenericBinaryError>("fat file does not " "contain " + ArchName, object_error::arch_not_found); } + +Expected<std::unique_ptr<MachOObjectFile>> +MachOUniversalBinary::getMachOObjectForArch(StringRef ArchName) const { + Expected<ObjectForArch> O = getObjectForArch(ArchName); + if (!O) + return O.takeError(); + return O->getAsObjectFile(); +} + +Expected<std::unique_ptr<Archive>> +MachOUniversalBinary::getArchiveForArch(StringRef ArchName) const { + Expected<ObjectForArch> O = getObjectForArch(ArchName); + if (!O) + return O.takeError(); + return O->getAsArchive(); +} |