diff --git a/llvm/include/llvm/Object/MachOUniversal.h b/llvm/include/llvm/Object/MachOUniversal.h --- a/llvm/include/llvm/Object/MachOUniversal.h +++ b/llvm/include/llvm/Object/MachOUniversal.h @@ -159,8 +159,14 @@ return V->isMachOUniversalBinary(); } - Expected> + Expected getObjectForArch(StringRef ArchName) const; + + Expected> + getMachOObjectForArch(StringRef ArchName) const; + + Expected> + getArchiveForArch(StringRef ArchName) const; }; } diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -401,7 +401,7 @@ return I->second.get(); Expected> ObjOrErr = - UB->getObjectForArch(ArchName); + UB->getMachOObjectForArch(ArchName); if (!ObjOrErr) { ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName), std::unique_ptr()); diff --git a/llvm/lib/Object/MachOUniversal.cpp b/llvm/lib/Object/MachOUniversal.cpp --- a/llvm/lib/Object/MachOUniversal.cpp +++ b/llvm/lib/Object/MachOUniversal.cpp @@ -210,19 +210,34 @@ Err = Error::success(); } -Expected> +Expected MachOUniversalBinary::getObjectForArch(StringRef ArchName) const { if (Triple(ArchName).getArch() == Triple::ArchType::UnknownArch) return make_error("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("fat file does not " "contain " + ArchName, object_error::arch_not_found); } + +Expected> +MachOUniversalBinary::getMachOObjectForArch(StringRef ArchName) const { + Expected O = getObjectForArch(ArchName); + if (!O) + return O.takeError(); + return O->getAsObjectFile(); +} + +Expected> +MachOUniversalBinary::getArchiveForArch(StringRef ArchName) const { + Expected O = getObjectForArch(ArchName); + if (!O) + return O.takeError(); + return O->getAsArchive(); +} diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp --- a/llvm/lib/Object/Object.cpp +++ b/llvm/lib/Object/Object.cpp @@ -138,7 +138,7 @@ char **ErrorMessage) { auto universal = cast(unwrap(BR)); Expected> ObjOrErr( - universal->getObjectForArch({Arch, ArchLen})); + universal->getMachOObjectForArch({Arch, ArchLen})); if (!ObjOrErr) { *ErrorMessage = strdup(toString(ObjOrErr.takeError()).c_str()); return nullptr; diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp --- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -682,7 +682,7 @@ if (auto *Universal = dyn_cast(Bin.get())) { // If we have a universal binary, try to look up the object for the // appropriate architecture. - auto ObjectFileOrErr = Universal->getObjectForArch(Arch); + auto ObjectFileOrErr = Universal->getMachOObjectForArch(Arch); if (!ObjectFileOrErr) return ObjectFileOrErr.takeError(); OF = std::move(ObjectFileOrErr.get()); diff --git a/llvm/tools/llvm-lipo/llvm-lipo.cpp b/llvm/tools/llvm-lipo/llvm-lipo.cpp --- a/llvm/tools/llvm-lipo/llvm-lipo.cpp +++ b/llvm/tools/llvm-lipo/llvm-lipo.cpp @@ -306,9 +306,8 @@ if (auto UO = dyn_cast(InputBinaries.front().getBinary())) { for (StringRef Arch : VerifyArchList) { - Expected> Obj = - UO->getObjectForArch(Arch); - if (!Obj) + auto ObjForArch = UO->getObjectForArch(Arch); + if (!ObjForArch) exit(EXIT_FAILURE); } } else if (auto O = @@ -399,7 +398,7 @@ auto *UO = cast(InputBinaries.front().getBinary()); Expected> Obj = - UO->getObjectForArch(ThinArchType); + UO->getMachOObjectForArch(ThinArchType); if (!Obj) reportError("fat input file " + UO->getFileName() + " does not contain the specified architecture " + ThinArchType + diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -7387,7 +7387,7 @@ Triple T = MachOObjectFile::getArchTriple(CPUType, CPUSubType, nullptr, &ArchFlag); Expected> MachDSYM = - UB->getObjectForArch(ArchFlag); + UB->getMachOObjectForArch(ArchFlag); if (!MachDSYM) { reportError(MachDSYM.takeError(), DSYMFile); return;