diff options
author | Kevin Enderby <enderby@apple.com> | 2016-05-02 20:28:12 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-05-02 20:28:12 +0000 |
commit | a486dcaf360f13deb0a5c485a2b4a4e4652392e8 (patch) | |
tree | 023b46c9a2c7fcc414f1dceff6a92ef46a210c69 /tools/llvm-nm | |
parent | 6b3315d64b0b05c136590496ac27470a53afe127 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268298 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-nm')
-rw-r--r-- | tools/llvm-nm/llvm-nm.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 05ebc44ff83..4c0d7535ec2 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -373,9 +373,10 @@ static void darwinPrintSymbol(SymbolicFile &Obj, SymbolListT::iterator I, outs() << "(?,?) "; break; } - ErrorOr<section_iterator> SecOrErr = + Expected<section_iterator> SecOrErr = MachO->getSymbolSection(I->Sym.getRawDataRefImpl()); - if (SecOrErr.getError()) { + if (!SecOrErr) { + consumeError(SecOrErr.takeError()); outs() << "(?,?) "; break; } @@ -697,9 +698,11 @@ static char getSymbolNMTypeChar(ELFObjectFileBase &Obj, // OK, this is ELF elf_symbol_iterator SymI(I); - ErrorOr<elf_section_iterator> SecIOrErr = SymI->getSection(); - if (error(SecIOrErr.getError())) + Expected<elf_section_iterator> SecIOrErr = SymI->getSection(); + if (!SecIOrErr) { + consumeError(SecIOrErr.takeError()); return '?'; + } elf_section_iterator SecI = *SecIOrErr; if (SecI != Obj.section_end()) { @@ -759,9 +762,11 @@ static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) { uint32_t Characteristics = 0; if (!COFF::isReservedSectionNumber(Symb.getSectionNumber())) { - ErrorOr<section_iterator> SecIOrErr = SymI->getSection(); - if (error(SecIOrErr.getError())) + Expected<section_iterator> SecIOrErr = SymI->getSection(); + if (!SecIOrErr) { + consumeError(SecIOrErr.takeError()); return '?'; + } section_iterator SecI = *SecIOrErr; const coff_section *Section = Obj.getCOFFSection(*SecI); Characteristics = Section->Characteristics; @@ -802,9 +807,11 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) { case MachO::N_INDR: return 'i'; case MachO::N_SECT: { - ErrorOr<section_iterator> SecOrErr = Obj.getSymbolSection(Symb); - if (SecOrErr.getError()) + Expected<section_iterator> SecOrErr = Obj.getSymbolSection(Symb); + if (!SecOrErr) { + consumeError(SecOrErr.takeError()); return 's'; + } section_iterator Sec = *SecOrErr; DataRefImpl Ref = Sec->getRawDataRefImpl(); StringRef SectionName; |