summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-readobj
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2016-05-02 20:28:12 +0000
committerKevin Enderby <enderby@apple.com>2016-05-02 20:28:12 +0000
commit7bd8d994978d6404a79b28e04a802d070c45ba16 (patch)
treeb827e6424c503f1ec157ad5dd700b9a0fee9bc06 /llvm/tools/llvm-readobj
parent34c549ea02081e48946750adbc928ae57ff67bd9 (diff)
downloadbcm5719-llvm-7bd8d994978d6404a79b28e04a802d070c45ba16.tar.gz
bcm5719-llvm-7bd8d994978d6404a79b28e04a802d070c45ba16.zip
Thread Expected<...> up from libObject’s getType() for symbols to allow llvm-objdump to produce a good error message.
Produce another specific error message for a malformed Mach-O file when a symbol’s section index is more than the number of sections. The existing test case in test/Object/macho-invalid.test for macho-invalid-section-index-getSectionRawName now reports the error with the message indicating that a symbol at a specific index has a bad section index and that bad section index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: "// TODO: Actually report errors helpfully" and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. llvm-svn: 268298
Diffstat (limited to 'llvm/tools/llvm-readobj')
-rw-r--r--llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp13
-rw-r--r--llvm/tools/llvm-readobj/MachODumper.cpp4
-rw-r--r--llvm/tools/llvm-readobj/Win64EHDumper.cpp4
3 files changed, 13 insertions, 8 deletions
diff --git a/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp b/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
index 8d00c90b3c1..9e14e69015d 100644
--- a/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
+++ b/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
@@ -198,9 +198,9 @@ Decoder::getSectionContaining(const COFFObjectFile &COFF, uint64_t VA) {
ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
uint64_t VA, bool FunctionOnly) {
for (const auto &Symbol : COFF.symbols()) {
- ErrorOr<SymbolRef::Type> Type = Symbol.getType();
- if (std::error_code EC = Type.getError())
- return EC;
+ Expected<SymbolRef::Type> Type = Symbol.getType();
+ if (!Type)
+ return errorToErrorCode(Type.takeError());
if (FunctionOnly && *Type != SymbolRef::ST_Function)
continue;
@@ -648,9 +648,12 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
- ErrorOr<section_iterator> SIOrErr = XDataRecord->getSection();
- if (!SIOrErr)
+ Expected<section_iterator> SIOrErr = XDataRecord->getSection();
+ if (!SIOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(SIOrErr.takeError());
return false;
+ }
section_iterator SI = *SIOrErr;
return dumpXDataRecord(COFF, *SI, FunctionAddress, Address);
diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index 2faf36842ed..cc57211b280 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -617,8 +617,8 @@ void MachODumper::printSymbol(const SymbolRef &Symbol) {
getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol);
StringRef SectionName = "";
- ErrorOr<section_iterator> SecIOrErr = Symbol.getSection();
- error(SecIOrErr.getError());
+ Expected<section_iterator> SecIOrErr = Symbol.getSection();
+ error(errorToErrorCode(SecIOrErr.takeError()));
section_iterator SecI = *SecIOrErr;
if (SecI != Obj->section_end())
error(SecI->getName(SectionName));
diff --git a/llvm/tools/llvm-readobj/Win64EHDumper.cpp b/llvm/tools/llvm-readobj/Win64EHDumper.cpp
index e6e8367f293..f797d4baa40 100644
--- a/llvm/tools/llvm-readobj/Win64EHDumper.cpp
+++ b/llvm/tools/llvm-readobj/Win64EHDumper.cpp
@@ -153,7 +153,9 @@ static std::error_code resolveRelocation(const Dumper::Context &Ctx,
return EC;
ResolvedAddress = *ResolvedAddressOrErr;
- ErrorOr<section_iterator> SI = Symbol.getSection();
+ Expected<section_iterator> SI = Symbol.getSection();
+ if (!SI)
+ return errorToErrorCode(SI.takeError());
ResolvedSection = Ctx.COFF.getCOFFSection(**SI);
return std::error_code();
}
OpenPOWER on IntegriCloud