diff options
author | Kevin Enderby <enderby@apple.com> | 2016-04-20 21:24:34 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-04-20 21:24:34 +0000 |
commit | 81e8b7d9496688476c6bb601cce2575c3f2811ed (patch) | |
tree | df826623cc6e8219f57929601c58be265328102f /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 64d4e2bc0d1e3eaec2f20a198b6362287031b931 (diff) | |
download | bcm5719-llvm-81e8b7d9496688476c6bb601cce2575c3f2811ed.tar.gz bcm5719-llvm-81e8b7d9496688476c6bb601cce2575c3f2811ed.zip |
Thread Expected<...> up from libObject’s getName() 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
string index is past the end of the string table. The existing test case in test/Object/macho-invalid.test
for macho-invalid-symbol-name-past-eof now reports the error with the message indicating
that a symbol at a specific index has a bad sting index and that bad string 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. There is some
code for this that could be factored into a routine but I would like to leave that for
the code owners post-commit to do as they want for handling an llvm::Error. An
example of how this could be done is shown in the diff in
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h which had a Check() routine
already for std::error_code so I added one like it for llvm::Error .
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.
Note there fixes needed to lld that goes along with this that I will commit right after this.
So expect lld not to built after this commit and before the next one.
llvm-svn: 266919
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 6eab69c1b2e..c99e4b0e205 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -494,9 +494,9 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj, return EC; Target = *SecName; } else { - ErrorOr<StringRef> SymName = symb->getName(StrTab); + Expected<StringRef> SymName = symb->getName(StrTab); if (!SymName) - return SymName.getError(); + return errorToErrorCode(SymName.takeError()); Target = *SymName; } switch (EF.getHeader()->e_machine) { @@ -586,9 +586,9 @@ static std::error_code getRelocationValueString(const COFFObjectFile *Obj, const RelocationRef &Rel, SmallVectorImpl<char> &Result) { symbol_iterator SymI = Rel.getSymbol(); - ErrorOr<StringRef> SymNameOrErr = SymI->getName(); - if (std::error_code EC = SymNameOrErr.getError()) - return EC; + Expected<StringRef> SymNameOrErr = SymI->getName(); + if (!SymNameOrErr) + return errorToErrorCode(SymNameOrErr.takeError()); StringRef SymName = *SymNameOrErr; Result.append(SymName.begin(), SymName.end()); return std::error_code(); @@ -613,9 +613,14 @@ static void printRelocationTargetName(const MachOObjectFile *O, report_fatal_error(ec.message()); if (*Addr != Val) continue; - ErrorOr<StringRef> Name = Symbol.getName(); - if (std::error_code EC = Name.getError()) - report_fatal_error(EC.message()); + Expected<StringRef> Name = Symbol.getName(); + if (!Name) { + std::string Buf; + raw_string_ostream OS(Buf); + logAllUnhandledErrors(Name.takeError(), OS, ""); + OS.flush(); + report_fatal_error(Buf); + } fmt << *Name; return; } @@ -646,8 +651,8 @@ static void printRelocationTargetName(const MachOObjectFile *O, if (isExtern) { symbol_iterator SI = O->symbol_begin(); advance(SI, Val); - ErrorOr<StringRef> SOrErr = SI->getName(); - error(SOrErr.getError()); + Expected<StringRef> SOrErr = SI->getName(); + error(errorToErrorCode(SOrErr.takeError())); S = *SOrErr; } else { section_iterator SI = O->section_begin(); @@ -952,8 +957,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { error(AddressOrErr.getError()); uint64_t Address = *AddressOrErr; - ErrorOr<StringRef> Name = Symbol.getName(); - error(Name.getError()); + Expected<StringRef> Name = Symbol.getName(); + error(errorToErrorCode(Name.takeError())); if (Name->empty()) continue; @@ -1358,8 +1363,9 @@ void llvm::PrintSymbolTable(const ObjectFile *o) { if (Type == SymbolRef::ST_Debug && Section != o->section_end()) { Section->getName(Name); } else { - ErrorOr<StringRef> NameOrErr = Symbol.getName(); - error(NameOrErr.getError()); + Expected<StringRef> NameOrErr = Symbol.getName(); + if (!NameOrErr) + report_error(o->getFileName(), NameOrErr.takeError()); Name = *NameOrErr; } |