[PATCH] D106783: [AIX][XCOFF][llvm-readobj] Replace unwrapOrError with reportUniqueWarning
Maryam via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 4 03:56:56 PDT 2021
MaryamBen updated this revision to Diff 364033.
MaryamBen marked an inline comment as done.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106783/new/
https://reviews.llvm.org/D106783
Files:
llvm/test/tools/llvm-readobj/XCOFF/relocations-invalid.test
llvm/tools/llvm-readobj/XCOFFDumper.cpp
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<StringRef> 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);
Index: llvm/test/tools/llvm-readobj/XCOFF/relocations-invalid.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-readobj/XCOFF/relocations-invalid.test
@@ -0,0 +1,39 @@
+## Check we report warnings when relocations are broken.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readobj --relocs --expand-relocs %t1 2>&1 | \
+# RUN: FileCheck %s -DFILE=%t1 --check-prefix=INVALID-REL
+
+# INVALID-REL: Relocations [
+# INVALID-REL-NEXT: warning: '[[FILE]]': The end of the file was unexpectedly encountered
+# INVALID-REL-NEXT: ]
+
+--- !XCOFF
+FileHeader:
+ MagicNumber: 0x1DF
+Sections:
+ - Name: .text
+ Flags: [ STYP_TEXT ]
+## Case 1: Incorrect offset to relocation entries.
+ FileOffsetToRelocations: 0x222
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readobj --relocs --expand-relocs %t2 2>&1 | \
+# RUN: FileCheck %s -DFILE=%t2 --check-prefix=INVALID-SYM
+
+# INVALID-SYM: Relocations [
+# INVALID-SYM-NEXT: Section (index: 1) .text {
+# INVALID-SYM-NEXT: warning: '[[FILE]]': Invalid symbol index
+# INVALID-SYM-NEXT: }
+# INVALID-SYM-NEXT: ]
+
+--- !XCOFF
+FileHeader:
+ MagicNumber: 0x1DF
+Sections:
+ - Name: .text
+ Flags: [ STYP_TEXT ]
+ Relocations:
+ - Address: 0x80
+## Case 2: There is no symbol with index 0x21.
+ Symbol: 0x21
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106783.364033.patch
Type: text/x-patch
Size: 2842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210804/3b18c86c/attachment.bin>
More information about the llvm-commits
mailing list