From: Georgii Rymar Date: Wed, 24 Jun 2020 13:51:42 +0000 (+0300) Subject: [llvm-readelf] - Report a warning instead of an error when dumping a broken section... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03b902752e377e18f0cb10742df249bc855e00ec;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test b/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test index cc05f13..84583d2 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] NULL 0000000000000000 000000 000000 00 0 0 0 +# GNU-NEXT: [ 1] STRTAB 0000000000000000 000040 000001 00 0 0 1 +# GNU-NEXT: [ 2] 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 482476f..eea5ed7 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 b424918..3f29c99 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -3825,10 +3825,13 @@ void GNUStyle::printSectionHeaders(const ELFO *Obj) { printField(F); OS << "\n"; - const ELFObjectFile *ElfObj = this->dumper()->getElfObject(); - StringRef SecStrTable = unwrapOrError( - ElfObj->getFileName(), - Obj->getSectionStringTable(Sections, this->dumper()->WarningHandler)); + StringRef SecStrTable; + if (Expected 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::printSectionHeaders(const ELFO *Obj) { Fields[1].Str = ""; else Fields[1].Str = std::string(unwrapOrError( - 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 =