[llvm] 03b9027 - [llvm-readelf] - Report a warning instead of an error when dumping a broken section header.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 25 04:38:45 PDT 2020


Author: Georgii Rymar
Date: 2020-06-25T14:38:06+03:00
New Revision: 03b902752e377e18f0cb10742df249bc855e00ec

URL: https://github.com/llvm/llvm-project/commit/03b902752e377e18f0cb10742df249bc855e00ec
DIFF: https://github.com/llvm/llvm-project/commit/03b902752e377e18f0cb10742df249bc855e00ec.diff

LOG: [llvm-readelf] - Report a warning instead of an error when dumping a broken section header.

There is no reason to report an error in `printSectionHeaders()`, we can report
a warning and continue dumping. This is what the patch does.

Differential revision: https://reviews.llvm.org/D82462

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test
    llvm/test/tools/llvm-readobj/ELF/many-sections.s
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test b/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test
index cc05f13a322f..84583d2c3cd9 100644
--- a/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test
+++ b/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test
@@ -6,8 +6,15 @@
 # GNU:        Section header string table index: 255
 # GNU-NEXT:   There are 3 section headers, starting at offset 0x58:
 # GNU:      Section Headers:
-# GNU-NEXT:  [Nr] Name
-# GNU-NEXT:  error: '[[FILE]]': section header string table index 255 does not exist
+# GNU-NEXT:  [Nr] Name         Type   Address          Off    Size   ES Flg Lk Inf Al
+# GNU-NEXT: warning: '[[FILE]]': section header string table index 255 does not exist
+# GNU-NEXT:  [ 0] <no-strings> NULL   0000000000000000 000000 000000 00      0   0  0
+# GNU-NEXT:  [ 1] <no-strings> STRTAB 0000000000000000 000040 000001 00      0   0  1
+# GNU-NEXT:  [ 2] <no-strings> STRTAB 0000000000000000 000041 000013 00      0   0  1
+# GNU-NEXT: Key to Flags:
+# GNU:      Section to Segment mapping:
+# GNU-NEXT:   Segment Sections...
+# GNU-NEXT: error: '[[FILE]]': section header string table index 255 does not exist
 
 # LLVM:      ElfHeader {
 # LLVM:        StringTableSectionIndex: 255

diff  --git a/llvm/test/tools/llvm-readobj/ELF/many-sections.s b/llvm/test/tools/llvm-readobj/ELF/many-sections.s
index 482476feca5b..eea5ed7f95e4 100644
--- a/llvm/test/tools/llvm-readobj/ELF/many-sections.s
+++ b/llvm/test/tools/llvm-readobj/ELF/many-sections.s
@@ -34,7 +34,7 @@ Sections:
 
 # RUN: yaml2obj --docnum=2 %s -o %t2
 
-# RUN: not llvm-readelf --file-headers --sections %t2 2>&1 | \
+# RUN: llvm-readelf --file-headers --sections %t2 2>&1 | \
 # RUN:   FileCheck %s -DFILE=%t2 --check-prefix=GNU2
 # GNU2: Number of section headers:         0
 # GNU2: Section header string table index: 65535 (corrupt: out of range)
@@ -43,7 +43,8 @@ Sections:
 # GNU2-EMPTY:
 # GNU2-NEXT:  Section Headers:
 # GNU2-NEXT:   [Nr] Name Type Address Off Size ES Flg Lk Inf Al
-# GNU2-NEXT:   error: '[[FILE]]': e_shstrndx == SHN_XINDEX, but the section header table is empty
+# GNU2-NEXT:  warning: '[[FILE]]': e_shstrndx == SHN_XINDEX, but the section header table is empty
+# GNU2-NEXT:  Key to Flags:
 
 # RUN: llvm-readobj --file-headers --sections %t2 | \
 # RUN:   FileCheck %s --check-prefix=LLVM2 --implicit-check-not="warning:"

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index b424918a8d4b..3f29c99a5c54 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -3825,10 +3825,13 @@ void GNUStyle<ELFT>::printSectionHeaders(const ELFO *Obj) {
     printField(F);
   OS << "\n";
 
-  const ELFObjectFile<ELFT> *ElfObj = this->dumper()->getElfObject();
-  StringRef SecStrTable = unwrapOrError<StringRef>(
-      ElfObj->getFileName(),
-      Obj->getSectionStringTable(Sections, this->dumper()->WarningHandler));
+  StringRef SecStrTable;
+  if (Expected<StringRef> SecStrTableOrErr =
+          Obj->getSectionStringTable(Sections, this->dumper()->WarningHandler))
+    SecStrTable = *SecStrTableOrErr;
+  else
+    this->reportUniqueWarning(SecStrTableOrErr.takeError());
+
   size_t SectionIndex = 0;
   for (const Elf_Shdr &Sec : Sections) {
     Fields[0].Str = to_string(SectionIndex);
@@ -3836,7 +3839,7 @@ void GNUStyle<ELFT>::printSectionHeaders(const ELFO *Obj) {
       Fields[1].Str = "<no-strings>";
     else
       Fields[1].Str = std::string(unwrapOrError<StringRef>(
-          ElfObj->getFileName(), Obj->getSectionName(&Sec, SecStrTable)));
+          this->FileName, Obj->getSectionName(&Sec, SecStrTable)));
     Fields[2].Str =
         getSectionTypeString(Obj->getHeader()->e_machine, Sec.sh_type);
     Fields[3].Str =


        


More information about the llvm-commits mailing list