mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-24 04:09:45 +00:00
Change llvm-objdump, llvm-nm and llvm-size when reporting an object file error
when the object is from a slice of a Mach-O Universal Binary use something like "foo.o (for architecture i386)" as part of the error message when expected. Also fixed places in these tools that were ignoring object file errors from MachOUniversalBinary::getAsObjectFile() when the code moved on to see if the slice was an archive. To do this MachOUniversalBinary::getAsObjectFile() and MachOUniversalBinary::getObjectForArch() were changed from returning ErrorOr<...> to Expected<...> then that was threaded up to its users. Converting these interfaces to Expected<> from ErrorOr<> does involve touching a number of places. To contain the changes for now the use of errorToErrorCode() is still used in two places yet to be fully converted. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271332 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
37735dbc09
commit
e9ddf3a4a7
@ -63,7 +63,7 @@ public:
|
||||
return T.getArchName();
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<MachOObjectFile>> getAsObjectFile() const;
|
||||
Expected<std::unique_ptr<MachOObjectFile>> getAsObjectFile() const;
|
||||
|
||||
ErrorOr<std::unique_ptr<Archive>> getAsArchive() const;
|
||||
};
|
||||
@ -110,7 +110,7 @@ public:
|
||||
return V->isMachOUniversalBinary();
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<MachOObjectFile>>
|
||||
Expected<std::unique_ptr<MachOObjectFile>>
|
||||
getObjectForArch(StringRef ArchName) const;
|
||||
};
|
||||
|
||||
|
@ -319,9 +319,10 @@ LLVMSymbolizer::getOrCreateObject(const std::string &Path,
|
||||
return EC;
|
||||
return I->second->get();
|
||||
}
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
|
||||
UB->getObjectForArch(ArchName);
|
||||
if (auto EC = ObjOrErr.getError()) {
|
||||
if (!ObjOrErr) {
|
||||
auto EC = errorToErrorCode(ObjOrErr.takeError());
|
||||
ObjectForUBPathAndArch.insert(
|
||||
std::make_pair(std::make_pair(Path, ArchName), EC));
|
||||
return EC;
|
||||
|
@ -67,16 +67,16 @@ MachOUniversalBinary::ObjectForArch::ObjectForArch(
|
||||
}
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<MachOObjectFile>>
|
||||
Expected<std::unique_ptr<MachOObjectFile>>
|
||||
MachOUniversalBinary::ObjectForArch::getAsObjectFile() const {
|
||||
if (!Parent)
|
||||
return object_error::parse_failed;
|
||||
return errorCodeToError(object_error::parse_failed);
|
||||
|
||||
StringRef ParentData = Parent->getData();
|
||||
StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
|
||||
StringRef ObjectName = Parent->getFileName();
|
||||
MemoryBufferRef ObjBuffer(ObjectData, ObjectName);
|
||||
return expectedToErrorOr(ObjectFile::createMachOObjectFile(ObjBuffer));
|
||||
return ObjectFile::createMachOObjectFile(ObjBuffer);
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<Archive>>
|
||||
@ -123,14 +123,14 @@ MachOUniversalBinary::MachOUniversalBinary(MemoryBufferRef Source,
|
||||
ec = std::error_code();
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<MachOObjectFile>>
|
||||
Expected<std::unique_ptr<MachOObjectFile>>
|
||||
MachOUniversalBinary::getObjectForArch(StringRef ArchName) const {
|
||||
if (Triple(ArchName).getArch() == Triple::ArchType::UnknownArch)
|
||||
return object_error::arch_not_found;
|
||||
return errorCodeToError(object_error::arch_not_found);
|
||||
|
||||
for (object_iterator I = begin_objects(), E = end_objects(); I != E; ++I) {
|
||||
if (I->getArchTypeName() == ArchName)
|
||||
return I->getAsObjectFile();
|
||||
}
|
||||
return object_error::arch_not_found;
|
||||
return errorCodeToError(object_error::arch_not_found);
|
||||
}
|
||||
|
@ -597,8 +597,8 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,
|
||||
// If we have a universal binary, try to look up the object for the
|
||||
// appropriate architecture.
|
||||
auto ObjectFileOrErr = Universal->getObjectForArch(Arch);
|
||||
if (auto EC = ObjectFileOrErr.getError())
|
||||
return errorCodeToError(EC);
|
||||
if (!ObjectFileOrErr)
|
||||
return ObjectFileOrErr.takeError();
|
||||
OF = std::move(ObjectFileOrErr.get());
|
||||
} else if (isa<object::ObjectFile>(Bin.get())) {
|
||||
// For any other object file, upcast and take ownership.
|
||||
|
BIN
test/Object/Inputs/macho-universal-archive-bad1.x86_64.i386
Normal file
BIN
test/Object/Inputs/macho-universal-archive-bad1.x86_64.i386
Normal file
Binary file not shown.
BIN
test/Object/Inputs/macho-universal-archive-bad2.x86_64.i386
Normal file
BIN
test/Object/Inputs/macho-universal-archive-bad2.x86_64.i386
Normal file
Binary file not shown.
BIN
test/Object/Inputs/macho-universal-bad1.x86_64.i386
Normal file
BIN
test/Object/Inputs/macho-universal-bad1.x86_64.i386
Normal file
Binary file not shown.
BIN
test/Object/Inputs/macho-universal-bad2.x86_64.i386
Normal file
BIN
test/Object/Inputs/macho-universal-bad2.x86_64.i386
Normal file
Binary file not shown.
@ -60,6 +60,13 @@ RUN: not llvm-objdump -t %p/Inputs/macho-bad-archive1.a 2>&1 \
|
||||
RUN: | FileCheck -check-prefix NAME-PAST-EOF-ARCHIVE %s
|
||||
NAME-PAST-EOF-ARCHIVE: macho-bad-archive1.a(macho-invalid-symbol-name-past-eof) truncated or malformed object (bad string index: 4261412866 for symbol at index 0)
|
||||
|
||||
RUN: not llvm-objdump -macho -arch all -t %p/Inputs/macho-universal-bad1.x86_64.i386 2>&1 \
|
||||
RUN: | FileCheck -check-prefix NAME-PAST-EOF-FAT %s
|
||||
NAME-PAST-EOF-FAT: macho-universal-bad1.x86_64.i386 (for architecture x86_64) truncated or malformed object (bad string index: 4261412866 for symbol at index 0)
|
||||
RUN: not llvm-objdump -macho -arch all -t %p/Inputs/macho-universal-archive-bad1.x86_64.i386 2>&1 \
|
||||
RUN: | FileCheck -check-prefix NAME-PAST-EOF-FAT-ARCHIVE %s
|
||||
NAME-PAST-EOF-FAT-ARCHIVE: macho-universal-archive-bad1.x86_64.i386(macho-invalid-symbol-name-past-eof) (for architecture x86_64) truncated or malformed object (bad string index: 4261412866 for symbol at index 0)
|
||||
|
||||
RUN: llvm-nm %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
|
||||
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC %s
|
||||
INVALID-SECTION-IDX-SYMBOL-SEC: 0000000100000000 S __mh_execute_header
|
||||
@ -81,3 +88,9 @@ INCOMPLETE-SEGMENT-LOADC: truncated or malformed object (load commands extend pa
|
||||
|
||||
RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-bad-archive2.a 2>&1 | FileCheck -check-prefix INCOMPLETE-SEGMENT-LOADC-ARCHIVE %s
|
||||
INCOMPLETE-SEGMENT-LOADC-ARCHIVE: macho-bad-archive2.a(macho64-invalid-incomplete-segment-load-command) truncated or malformed object (load commands extend past the end of the file)
|
||||
|
||||
RUN: not llvm-objdump -macho -private-headers -arch all %p/Inputs/macho-universal-bad2.x86_64.i386 2>&1 | FileCheck -check-prefix INCOMPLETE-SEGMENT-LOADC-FAT %s
|
||||
INCOMPLETE-SEGMENT-LOADC-FAT: macho-universal-bad2.x86_64.i386 (for architecture x86_64) truncated or malformed object (load commands extend past the end of the file)
|
||||
|
||||
RUN: not llvm-objdump -macho -private-headers -arch all %p/Inputs/macho-universal-archive-bad2.x86_64.i386 2>&1 | FileCheck -check-prefix INCOMPLETE-SEGMENT-LOADC-FAT-ARCHIVE %s
|
||||
INCOMPLETE-SEGMENT-LOADC-FAT-ARCHIVE: macho-universal-archive-bad2.x86_64.i386(macho64-invalid-incomplete-segment-load-command) (for architecture x86_64) truncated or malformed object (load commands extend past the end of the file)
|
||||
|
@ -105,7 +105,7 @@ static void DumpInput(StringRef Filename) {
|
||||
else if (auto *Fat = dyn_cast<MachOUniversalBinary>(BinOrErr->get()))
|
||||
for (auto &ObjForArch : Fat->objects()) {
|
||||
auto MachOOrErr = ObjForArch.getAsObjectFile();
|
||||
error(Filename, MachOOrErr.getError());
|
||||
error(Filename, errorToErrorCode(MachOOrErr.takeError()));
|
||||
DumpObjectFile(**MachOOrErr,
|
||||
Filename + " (" + ObjForArch.getArchTypeName() + ")");
|
||||
}
|
||||
|
@ -193,7 +193,8 @@ static bool error(std::error_code EC, Twine Path = Twine()) {
|
||||
// This version of error() prints the archive name and member name, for example:
|
||||
// "libx.a(foo.o)" after the ToolName before the error message. It sets
|
||||
// HadError but returns allowing the code to move on to other archive members.
|
||||
static void error(llvm::Error E, StringRef FileName, const Archive::Child &C) {
|
||||
static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,
|
||||
StringRef ArchitectureName = StringRef()) {
|
||||
HadError = true;
|
||||
errs() << ToolName << ": " << FileName;
|
||||
|
||||
@ -206,6 +207,28 @@ static void error(llvm::Error E, StringRef FileName, const Archive::Child &C) {
|
||||
else
|
||||
errs() << "(" << NameOrErr.get() << ")";
|
||||
|
||||
if (!ArchitectureName.empty())
|
||||
errs() << " (for architecture " << ArchitectureName << ") ";
|
||||
|
||||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(std::move(E), OS, "");
|
||||
OS.flush();
|
||||
errs() << " " << Buf << "\n";
|
||||
}
|
||||
|
||||
// This version of error() prints the file name and which architecture slice it
|
||||
// is from, for example: "foo.o (for architecture i386)" after the ToolName
|
||||
// before the error message. It sets HadError but returns allowing the code to
|
||||
// move on to other architecture slices.
|
||||
static void error(llvm::Error E, StringRef FileName,
|
||||
StringRef ArchitectureName = StringRef()) {
|
||||
HadError = true;
|
||||
errs() << ToolName << ": " << FileName;
|
||||
|
||||
if (!ArchitectureName.empty())
|
||||
errs() << " (for architecture " << ArchitectureName << ") ";
|
||||
|
||||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(std::move(E), OS, "");
|
||||
@ -1123,7 +1146,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
I != E; ++I) {
|
||||
if (ArchFlags[i] == I->getArchTypeName()) {
|
||||
ArchFound = true;
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
|
||||
I->getAsObjectFile();
|
||||
std::string ArchiveName;
|
||||
std::string ArchitectureName;
|
||||
@ -1141,6 +1164,11 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
}
|
||||
dumpSymbolNamesFromObject(Obj, false, ArchiveName,
|
||||
ArchitectureName);
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ObjOrErr.takeError())) {
|
||||
error(std::move(E), Filename, ArchFlags.size() > 1 ?
|
||||
StringRef(I->getArchTypeName()) : StringRef());
|
||||
continue;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
|
||||
I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &A = *AOrErr;
|
||||
@ -1154,8 +1182,10 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
C.getAsBinary(&Context);
|
||||
if (!ChildOrErr) {
|
||||
if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ChildOrErr.takeError()))
|
||||
error(std::move(E), Filename, C);
|
||||
ChildOrErr.takeError())) {
|
||||
error(std::move(E), Filename, C, ArchFlags.size() > 1 ?
|
||||
StringRef(I->getArchTypeName()) : StringRef());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (SymbolicFile *O =
|
||||
@ -1196,12 +1226,16 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
E = UB->end_objects();
|
||||
I != E; ++I) {
|
||||
if (HostArchName == I->getArchTypeName()) {
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
std::string ArchiveName;
|
||||
ArchiveName.clear();
|
||||
if (ObjOrErr) {
|
||||
ObjectFile &Obj = *ObjOrErr.get();
|
||||
dumpSymbolNamesFromObject(Obj, false);
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ObjOrErr.takeError())) {
|
||||
error(std::move(E), Filename);
|
||||
return;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
|
||||
I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &A = *AOrErr;
|
||||
@ -1241,7 +1275,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
|
||||
E = UB->end_objects();
|
||||
I != E; ++I) {
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
std::string ArchiveName;
|
||||
std::string ArchitectureName;
|
||||
ArchiveName.clear();
|
||||
@ -1260,6 +1294,11 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
outs() << ":\n";
|
||||
}
|
||||
dumpSymbolNamesFromObject(Obj, false, ArchiveName, ArchitectureName);
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ObjOrErr.takeError())) {
|
||||
error(std::move(E), Filename, moreThanOneArch ?
|
||||
StringRef(I->getArchTypeName()) : StringRef());
|
||||
continue;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr = I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &A = *AOrErr;
|
||||
for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
|
||||
@ -1267,11 +1306,13 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
if (error(AI->getError()))
|
||||
return;
|
||||
auto &C = AI->get();
|
||||
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context);
|
||||
Expected<std::unique_ptr<Binary>> ChildOrErr =
|
||||
C.getAsBinary(&Context);
|
||||
if (!ChildOrErr) {
|
||||
if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ChildOrErr.takeError()))
|
||||
error(std::move(E), Filename, C);
|
||||
error(std::move(E), Filename, C, moreThanOneArch ?
|
||||
StringRef(ArchitectureName) : StringRef());
|
||||
continue;
|
||||
}
|
||||
if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {
|
||||
|
@ -1266,7 +1266,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
||||
PrintDylibs(MachOOF, true);
|
||||
if (SymbolTable) {
|
||||
StringRef ArchiveName = ArchiveMemberName == StringRef() ? "" : Filename;
|
||||
PrintSymbolTable(MachOOF, ArchiveName);
|
||||
PrintSymbolTable(MachOOF, ArchiveName, ArchitectureName);
|
||||
}
|
||||
if (UnwindInfo)
|
||||
printMachOUnwindInfo(MachOOF);
|
||||
@ -1604,7 +1604,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
|
||||
I != E; ++I) {
|
||||
if (ArchFlags[i] == I->getArchTypeName()) {
|
||||
ArchFound = true;
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
|
||||
I->getAsObjectFile();
|
||||
std::string ArchitectureName = "";
|
||||
if (ArchFlags.size() > 1)
|
||||
@ -1613,6 +1613,11 @@ void llvm::ParseInputMachO(StringRef Filename) {
|
||||
ObjectFile &O = *ObjOrErr.get();
|
||||
if (MachOObjectFile *MachOOF = dyn_cast<MachOObjectFile>(&O))
|
||||
ProcessMachO(Filename, MachOOF, "", ArchitectureName);
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ObjOrErr.takeError())) {
|
||||
report_error(Filename, StringRef(), std::move(E),
|
||||
ArchitectureName);
|
||||
continue;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
|
||||
I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &A = *AOrErr;
|
||||
@ -1631,7 +1636,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
|
||||
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
|
||||
if (!ChildOrErr) {
|
||||
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
|
||||
report_error(Filename, C, std::move(E));
|
||||
report_error(Filename, C, std::move(E), ArchitectureName);
|
||||
continue;
|
||||
}
|
||||
if (MachOObjectFile *O =
|
||||
@ -1657,13 +1662,17 @@ void llvm::ParseInputMachO(StringRef Filename) {
|
||||
I != E; ++I) {
|
||||
if (MachOObjectFile::getHostArch().getArchName() ==
|
||||
I->getArchTypeName()) {
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
std::string ArchiveName;
|
||||
ArchiveName.clear();
|
||||
if (ObjOrErr) {
|
||||
ObjectFile &O = *ObjOrErr.get();
|
||||
if (MachOObjectFile *MachOOF = dyn_cast<MachOObjectFile>(&O))
|
||||
ProcessMachO(Filename, MachOOF);
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ObjOrErr.takeError())) {
|
||||
report_error(Filename, std::move(E));
|
||||
continue;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
|
||||
I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &A = *AOrErr;
|
||||
@ -1697,7 +1706,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
|
||||
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
|
||||
E = UB->end_objects();
|
||||
I != E; ++I) {
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
Expected<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
std::string ArchitectureName = "";
|
||||
if (moreThanOneArch)
|
||||
ArchitectureName = I->getArchTypeName();
|
||||
@ -1705,6 +1714,10 @@ void llvm::ParseInputMachO(StringRef Filename) {
|
||||
ObjectFile &Obj = *ObjOrErr.get();
|
||||
if (MachOObjectFile *MachOOF = dyn_cast<MachOObjectFile>(&Obj))
|
||||
ProcessMachO(Filename, MachOOF, "", ArchitectureName);
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ObjOrErr.takeError())) {
|
||||
report_error(StringRef(), Filename, std::move(E), ArchitectureName);
|
||||
continue;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr = I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &A = *AOrErr;
|
||||
outs() << "Archive : " << Filename;
|
||||
@ -1721,7 +1734,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
|
||||
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
|
||||
if (!ChildOrErr) {
|
||||
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
|
||||
report_error(Filename, C, std::move(E));
|
||||
report_error(Filename, C, std::move(E), ArchitectureName);
|
||||
continue;
|
||||
}
|
||||
if (MachOObjectFile *O =
|
||||
|
@ -284,13 +284,16 @@ LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
|
||||
|
||||
LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef ArchiveName,
|
||||
StringRef FileName,
|
||||
llvm::Error E) {
|
||||
llvm::Error E,
|
||||
StringRef ArchitectureName) {
|
||||
assert(E);
|
||||
errs() << ToolName << ": ";
|
||||
if (ArchiveName != "")
|
||||
errs() << ArchiveName << "(" << FileName << ")";
|
||||
else
|
||||
errs() << FileName;
|
||||
if (!ArchitectureName.empty())
|
||||
errs() << " (for architecture " << ArchitectureName << ")";
|
||||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(std::move(E), OS, "");
|
||||
@ -301,15 +304,17 @@ LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef ArchiveName,
|
||||
|
||||
LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef ArchiveName,
|
||||
const object::Archive::Child &C,
|
||||
llvm::Error E) {
|
||||
llvm::Error E,
|
||||
StringRef ArchitectureName) {
|
||||
ErrorOr<StringRef> NameOrErr = C.getName();
|
||||
// TODO: if we have a error getting the name then it would be nice to print
|
||||
// the index of which archive member this is and or its offset in the
|
||||
// archive instead of "???" as the name.
|
||||
if (NameOrErr.getError())
|
||||
llvm::report_error(ArchiveName, "???", std::move(E));
|
||||
llvm::report_error(ArchiveName, "???", std::move(E), ArchitectureName);
|
||||
else
|
||||
llvm::report_error(ArchiveName, NameOrErr.get(), std::move(E));
|
||||
llvm::report_error(ArchiveName, NameOrErr.get(), std::move(E),
|
||||
ArchitectureName);
|
||||
}
|
||||
|
||||
static const Target *getTarget(const ObjectFile *Obj = nullptr) {
|
||||
@ -1377,7 +1382,8 @@ void llvm::PrintSectionContents(const ObjectFile *Obj) {
|
||||
}
|
||||
}
|
||||
|
||||
void llvm::PrintSymbolTable(const ObjectFile *o, StringRef ArchiveName) {
|
||||
void llvm::PrintSymbolTable(const ObjectFile *o, StringRef ArchiveName,
|
||||
StringRef ArchitectureName) {
|
||||
outs() << "SYMBOL TABLE:\n";
|
||||
|
||||
if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o)) {
|
||||
@ -1402,7 +1408,8 @@ void llvm::PrintSymbolTable(const ObjectFile *o, StringRef ArchiveName) {
|
||||
} else {
|
||||
Expected<StringRef> NameOrErr = Symbol.getName();
|
||||
if (!NameOrErr)
|
||||
report_error(ArchiveName, o->getFileName(), NameOrErr.takeError());
|
||||
report_error(ArchiveName, o->getFileName(), NameOrErr.takeError(),
|
||||
ArchitectureName);
|
||||
Name = *NameOrErr;
|
||||
}
|
||||
|
||||
|
@ -86,15 +86,20 @@ void printRawClangAST(const object::ObjectFile *o);
|
||||
void PrintRelocations(const object::ObjectFile *o);
|
||||
void PrintSectionHeaders(const object::ObjectFile *o);
|
||||
void PrintSectionContents(const object::ObjectFile *o);
|
||||
void PrintSymbolTable(const object::ObjectFile *o, StringRef ArchiveName);
|
||||
void PrintSymbolTable(const object::ObjectFile *o, StringRef ArchiveName,
|
||||
StringRef ArchitectureName = StringRef());
|
||||
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, std::error_code EC);
|
||||
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, llvm::Error E);
|
||||
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef FileName,
|
||||
StringRef ArchiveName,
|
||||
llvm::Error E);
|
||||
llvm::Error E,
|
||||
StringRef ArchitectureName
|
||||
= StringRef());
|
||||
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef ArchiveName,
|
||||
const object::Archive::Child &C,
|
||||
llvm::Error E);
|
||||
llvm::Error E,
|
||||
StringRef ArchitectureName
|
||||
= StringRef());
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
|
@ -442,13 +442,18 @@ static void dumpArchive(const Archive *Arc) {
|
||||
/// @brief Dumps each object file in \a MachO Universal Binary;
|
||||
static void dumpMachOUniversalBinary(const MachOUniversalBinary *UBinary) {
|
||||
for (const MachOUniversalBinary::ObjectForArch &Obj : UBinary->objects()) {
|
||||
ErrorOr<std::unique_ptr<MachOObjectFile>> ObjOrErr = Obj.getAsObjectFile();
|
||||
Expected<std::unique_ptr<MachOObjectFile>> ObjOrErr = Obj.getAsObjectFile();
|
||||
if (ObjOrErr)
|
||||
dumpObject(&*ObjOrErr.get());
|
||||
else if (auto E = isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) {
|
||||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(ObjOrErr.takeError(), OS, "");
|
||||
OS.flush();
|
||||
reportError(UBinary->getFileName(), Buf);
|
||||
}
|
||||
else if (ErrorOr<std::unique_ptr<Archive>> AOrErr = Obj.getAsArchive())
|
||||
dumpArchive(&*AOrErr.get());
|
||||
else
|
||||
reportError(UBinary->getFileName(), ObjOrErr.getError().message());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,8 @@ static bool error(std::error_code ec) {
|
||||
// This version of error() prints the archive name and member name, for example:
|
||||
// "libx.a(foo.o)" after the ToolName before the error message. It sets
|
||||
// HadError but returns allowing the code to move on to other archive members.
|
||||
static void error(llvm::Error E, StringRef FileName, const Archive::Child &C) {
|
||||
static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,
|
||||
StringRef ArchitectureName = StringRef()) {
|
||||
HadError = true;
|
||||
errs() << ToolName << ": " << FileName;
|
||||
|
||||
@ -115,6 +116,27 @@ static void error(llvm::Error E, StringRef FileName, const Archive::Child &C) {
|
||||
else
|
||||
errs() << "(" << NameOrErr.get() << ")";
|
||||
|
||||
if (!ArchitectureName.empty())
|
||||
errs() << " (for architecture " << ArchitectureName << ") ";
|
||||
|
||||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(std::move(E), OS, "");
|
||||
OS.flush();
|
||||
errs() << " " << Buf << "\n";
|
||||
}
|
||||
|
||||
// This version of error() prints the file name and which architecture slice it // is from, for example: "foo.o (for architecture i386)" after the ToolName
|
||||
// before the error message. It sets HadError but returns allowing the code to
|
||||
// move on to other architecture slices.
|
||||
static void error(llvm::Error E, StringRef FileName,
|
||||
StringRef ArchitectureName = StringRef()) {
|
||||
HadError = true;
|
||||
errs() << ToolName << ": " << FileName;
|
||||
|
||||
if (!ArchitectureName.empty())
|
||||
errs() << " (for architecture " << ArchitectureName << ") ";
|
||||
|
||||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(std::move(E), OS, "");
|
||||
@ -539,7 +561,7 @@ static void printFileSectionSizes(StringRef file) {
|
||||
I != E; ++I) {
|
||||
if (ArchFlags[i] == I->getArchTypeName()) {
|
||||
ArchFound = true;
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
|
||||
Expected<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
|
||||
if (UO) {
|
||||
if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
|
||||
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
|
||||
@ -558,6 +580,11 @@ static void printFileSectionSizes(StringRef file) {
|
||||
outs() << "\n";
|
||||
}
|
||||
}
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(
|
||||
UO.takeError())) {
|
||||
error(std::move(E), file, ArchFlags.size() > 1 ?
|
||||
StringRef(I->getArchTypeName()) : StringRef());
|
||||
return;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
|
||||
I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &UA = *AOrErr;
|
||||
@ -571,8 +598,11 @@ static void printFileSectionSizes(StringRef file) {
|
||||
Expected<std::unique_ptr<Binary>> ChildOrErr =
|
||||
i->get().getAsBinary();
|
||||
if (!ChildOrErr) {
|
||||
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
|
||||
error(std::move(E), a->getFileName(), i->get());
|
||||
if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ChildOrErr.takeError()))
|
||||
error(std::move(E), UA->getFileName(), i->get(),
|
||||
ArchFlags.size() > 1 ?
|
||||
StringRef(I->getArchTypeName()) : StringRef());
|
||||
continue;
|
||||
}
|
||||
if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
|
||||
@ -619,7 +649,7 @@ static void printFileSectionSizes(StringRef file) {
|
||||
E = UB->end_objects();
|
||||
I != E; ++I) {
|
||||
if (HostArchName == I->getArchTypeName()) {
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
|
||||
Expected<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
|
||||
if (UO) {
|
||||
if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
|
||||
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
|
||||
@ -638,6 +668,9 @@ static void printFileSectionSizes(StringRef file) {
|
||||
outs() << "\n";
|
||||
}
|
||||
}
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(UO.takeError())) {
|
||||
error(std::move(E), file);
|
||||
return;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
|
||||
I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &UA = *AOrErr;
|
||||
@ -651,8 +684,9 @@ static void printFileSectionSizes(StringRef file) {
|
||||
Expected<std::unique_ptr<Binary>> ChildOrErr =
|
||||
i->get().getAsBinary();
|
||||
if (!ChildOrErr) {
|
||||
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
|
||||
error(std::move(E), a->getFileName(), i->get());
|
||||
if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ChildOrErr.takeError()))
|
||||
error(std::move(E), UA->getFileName(), i->get());
|
||||
continue;
|
||||
}
|
||||
if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
|
||||
@ -686,7 +720,7 @@ static void printFileSectionSizes(StringRef file) {
|
||||
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
|
||||
E = UB->end_objects();
|
||||
I != E; ++I) {
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
|
||||
Expected<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
|
||||
if (UO) {
|
||||
if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
|
||||
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
|
||||
@ -706,6 +740,10 @@ static void printFileSectionSizes(StringRef file) {
|
||||
outs() << "\n";
|
||||
}
|
||||
}
|
||||
} else if (auto E = isNotObjectErrorInvalidFileType(UO.takeError())) {
|
||||
error(std::move(E), file, MoreThanOneArch ?
|
||||
StringRef(I->getArchTypeName()) : StringRef());
|
||||
return;
|
||||
} else if (ErrorOr<std::unique_ptr<Archive>> AOrErr =
|
||||
I->getAsArchive()) {
|
||||
std::unique_ptr<Archive> &UA = *AOrErr;
|
||||
@ -717,8 +755,10 @@ static void printFileSectionSizes(StringRef file) {
|
||||
exit(1);
|
||||
Expected<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary();
|
||||
if (!ChildOrErr) {
|
||||
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
|
||||
error(std::move(E), UA->getFileName(), i->get());
|
||||
if (auto E = isNotObjectErrorInvalidFileType(
|
||||
ChildOrErr.takeError()))
|
||||
error(std::move(E), UA->getFileName(), i->get(), MoreThanOneArch ?
|
||||
StringRef(I->getArchTypeName()) : StringRef());
|
||||
continue;
|
||||
}
|
||||
if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
|
||||
|
Loading…
Reference in New Issue
Block a user