mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
[Object] Extend MachOUniversalBinary::getObjectForArch
Make the method MachOUniversalBinary::getObjectForArch return MachOUniversalBinary::ObjectForArch and add helper methods MachOUniversalBinary::getMachOObjectForArch, MachOUniversalBinary::getArchiveForArch for those who explicitly expect to get a MachOObjectFile or an Archive. Differential revision: https://reviews.llvm.org/D67700 Test plan: make check-all llvm-svn: 372278
This commit is contained in:
parent
af808a61d7
commit
7afab9f42f
@ -159,8 +159,14 @@ public:
|
||||
return V->isMachOUniversalBinary();
|
||||
}
|
||||
|
||||
Expected<std::unique_ptr<MachOObjectFile>>
|
||||
Expected<ObjectForArch>
|
||||
getObjectForArch(StringRef ArchName) const;
|
||||
|
||||
Expected<std::unique_ptr<MachOObjectFile>>
|
||||
getMachOObjectForArch(StringRef ArchName) const;
|
||||
|
||||
Expected<std::unique_ptr<Archive>>
|
||||
getArchiveForArch(StringRef ArchName) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ LLVMSymbolizer::getOrCreateObject(const std::string &Path,
|
||||
return I->second.get();
|
||||
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
|
||||
UB->getObjectForArch(ArchName);
|
||||
UB->getMachOObjectForArch(ArchName);
|
||||
if (!ObjOrErr) {
|
||||
ObjectForUBPathAndArch.emplace(std::make_pair(Path, ArchName),
|
||||
std::unique_ptr<ObjectFile>());
|
||||
|
@ -210,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();
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ LLVMBinaryRef LLVMMachOUniversalBinaryCopyObjectForArch(LLVMBinaryRef BR,
|
||||
char **ErrorMessage) {
|
||||
auto universal = cast<MachOUniversalBinary>(unwrap(BR));
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr(
|
||||
universal->getObjectForArch({Arch, ArchLen}));
|
||||
universal->getMachOObjectForArch({Arch, ArchLen}));
|
||||
if (!ObjOrErr) {
|
||||
*ErrorMessage = strdup(toString(ObjOrErr.takeError()).c_str());
|
||||
return nullptr;
|
||||
|
@ -682,7 +682,7 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch) {
|
||||
if (auto *Universal = dyn_cast<MachOUniversalBinary>(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());
|
||||
|
@ -306,9 +306,8 @@ static void verifyArch(ArrayRef<OwningBinary<Binary>> InputBinaries,
|
||||
if (auto UO =
|
||||
dyn_cast<MachOUniversalBinary>(InputBinaries.front().getBinary())) {
|
||||
for (StringRef Arch : VerifyArchList) {
|
||||
Expected<std::unique_ptr<MachOObjectFile>> Obj =
|
||||
UO->getObjectForArch(Arch);
|
||||
if (!Obj)
|
||||
auto ObjForArch = UO->getObjectForArch(Arch);
|
||||
if (!ObjForArch)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else if (auto O =
|
||||
@ -399,7 +398,7 @@ static void extractSlice(ArrayRef<OwningBinary<Binary>> InputBinaries,
|
||||
|
||||
auto *UO = cast<MachOUniversalBinary>(InputBinaries.front().getBinary());
|
||||
Expected<std::unique_ptr<MachOObjectFile>> Obj =
|
||||
UO->getObjectForArch(ThinArchType);
|
||||
UO->getMachOObjectForArch(ThinArchType);
|
||||
if (!Obj)
|
||||
reportError("fat input file " + UO->getFileName() +
|
||||
" does not contain the specified architecture " + ThinArchType +
|
||||
|
@ -7387,7 +7387,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
||||
Triple T = MachOObjectFile::getArchTriple(CPUType, CPUSubType, nullptr,
|
||||
&ArchFlag);
|
||||
Expected<std::unique_ptr<MachOObjectFile>> MachDSYM =
|
||||
UB->getObjectForArch(ArchFlag);
|
||||
UB->getMachOObjectForArch(ArchFlag);
|
||||
if (!MachDSYM) {
|
||||
reportError(MachDSYM.takeError(), DSYMFile);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user