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] 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 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::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 =