forked from OSchip/llvm-project
[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
This commit is contained in:
parent
95a3550dc8
commit
03b902752e
|
@ -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
|
||||
|
|
|
@ -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:"
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in New Issue