Index: llvm/test/tools/llvm-readobj/XCOFF/report_warning.yaml =================================================================== --- /dev/null +++ llvm/test/tools/llvm-readobj/XCOFF/report_warning.yaml @@ -0,0 +1,22 @@ +# RUN: yaml2obj %s -o %t +# RUN: llvm-readobj --relocs --expand-relocs %t 2>&1 | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section (index: 1) .text { +# CHECK-NEXT: {{.*}} warning: {{.*}} Invalid symbol index +# CHECK-NEXT: } +# CHECK-NEXT: ] + +--- !XCOFF +FileHeader: + MagicNumber: 0x1DF +Sections: + - Name: .text + Flags: [ STYP_TEXT ] + Relocations: + - Address: 0x80 + Symbol: 0x21 +Symbols: + - Name: .text + Section: .text + NumberOfAuxEntries: 1 Index: llvm/tools/llvm-readobj/XCOFFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/XCOFFDumper.cpp +++ llvm/tools/llvm-readobj/XCOFFDumper.cpp @@ -134,16 +134,27 @@ if (Sec.Flags != XCOFF::STYP_TEXT && Sec.Flags != XCOFF::STYP_DATA && Sec.Flags != XCOFF::STYP_TDATA && Sec.Flags != XCOFF::STYP_DWARF) continue; - auto Relocations = unwrapOrError(Obj.getFileName(), Obj.relocations(Sec)); + auto ErrOrRelocations = Obj.relocations(Sec); + if (Error E = ErrOrRelocations.takeError()) { + reportUniqueWarning(std::move(E)); + continue; + } + + auto Relocations = *ErrOrRelocations; if (Relocations.empty()) continue; W.startLine() << "Section (index: " << Index << ") " << Sec.getName() << " {\n"; for (auto Reloc : Relocations) { - StringRef SymbolName = unwrapOrError( - Obj.getFileName(), Obj.getSymbolNameByIndex(Reloc.SymbolIndex)); + Expected ErrOrSymbolName = + Obj.getSymbolNameByIndex(Reloc.SymbolIndex); + if (Error E = ErrOrSymbolName.takeError()) { + reportUniqueWarning(std::move(E)); + continue; + } + StringRef SymbolName = *ErrOrSymbolName; DictScope RelocScope(W, "Relocation"); W.printHex("Virtual Address", Reloc.VirtualAddress); W.printNumber("Symbol", SymbolName, Reloc.SymbolIndex);