From 0378afc4b9c23b7a568073120d6f9def4fc79509 Mon Sep 17 00:00:00 2001 From: Georgii Rymar Date: Wed, 5 Feb 2020 16:53:27 +0300 Subject: [PATCH] [llvm-readobj] - Change the error to warning when a section name is unknown. We reported the error in this case. But it was asked (https://reviews.llvm.org/D73193#inline-665595) to convert it to a warning. This patch does it. Differential revision: https://reviews.llvm.org/D74047 --- llvm/test/Object/invalid.test | 4 +- .../llvm-readobj/ELF/invalid-shstrndx.test | 22 ++++++++- ...ctions-no-section-header-string-table.test | 49 ++++++++++++++++++- llvm/tools/llvm-readobj/ELFDumper.cpp | 10 ++-- 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/llvm/test/Object/invalid.test b/llvm/test/Object/invalid.test index c923937ac343..4d19b66238cc 100644 --- a/llvm/test/Object/invalid.test +++ b/llvm/test/Object/invalid.test @@ -353,9 +353,9 @@ Symbols: [] ## overflows the section name string table. # RUN: yaml2obj %s --docnum=17 -o %t17 -# RUN: not llvm-readobj --sections %t17 2>&1 | FileCheck -DFILE=%t17 --check-prefix=BROKEN-SECNAME %s +# RUN: llvm-readobj --sections %t17 2>&1 | FileCheck -DFILE=%t17 --check-prefix=BROKEN-SECNAME %s -## BROKEN-SECNAME: error: '[[FILE]]': a section [index 1] has an invalid sh_name (0x1) offset which goes past the end of the section name string table +## BROKEN-SECNAME: warning: '[[FILE]]': a section [index 2] has an invalid sh_name (0xb) offset which goes past the end of the section name string table --- !ELF FileHeader: diff --git a/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test b/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test index 270d558f6d9a..cc05f13a322f 100644 --- a/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test +++ b/llvm/test/tools/llvm-readobj/ELF/invalid-shstrndx.test @@ -1,6 +1,6 @@ # RUN: yaml2obj %s -o %t # RUN: not llvm-readelf --headers -S 2>&1 %t | FileCheck %s -DFILE=%t --check-prefix=GNU -# RUN: not llvm-readobj --headers -S 2>&1 %t | FileCheck %s -DFILE=%t --check-prefix=LLVM +# RUN: llvm-readobj --headers -S 2>&1 %t | FileCheck %s -DFILE=%t --check-prefix=LLVM # GNU: ELF Header: # GNU: Section header string table index: 255 @@ -13,7 +13,25 @@ # LLVM: StringTableSectionIndex: 255 # LLVM-NEXT: } # LLVM-NEXT: Sections [ -# LLVM-NEXT: error: '[[FILE]]': section header string table index 255 does not exist +# LLVM-NEXT: warning: '[[FILE]]': section header string table index 255 does not exist +# LLVM-NEXT: Section { +# LLVM-NEXT: Index: 0 +# LLVM-NEXT: Name: (0) +# LLVM-NEXT: Type: SHT_NULL (0x0) +# LLVM-NEXT: Flags [ (0x0) +# LLVM-NEXT: ] +# LLVM-NEXT: Address: 0x0 +# LLVM-NEXT: Offset: 0x0 +# LLVM-NEXT: Size: 0 +# LLVM-NEXT: Link: 0 +# LLVM-NEXT: Info: 0 +# LLVM-NEXT: AddressAlignment: 0 +# LLVM-NEXT: EntrySize: 0 +# LLVM-NEXT: } +# LLVM: Index: 1 +# LLVM-NEXT: Name: (11) +# LLVM: Index: 2 +# LLVM-NEXT: Name: (1) --- !ELF FileHeader: diff --git a/llvm/test/tools/llvm-readobj/ELF/sections-no-section-header-string-table.test b/llvm/test/tools/llvm-readobj/ELF/sections-no-section-header-string-table.test index 4f9cd1b9e424..e5442d26444b 100644 --- a/llvm/test/tools/llvm-readobj/ELF/sections-no-section-header-string-table.test +++ b/llvm/test/tools/llvm-readobj/ELF/sections-no-section-header-string-table.test @@ -3,7 +3,7 @@ # RUN: yaml2obj %s -o %t # RUN: llvm-readelf --sections %t \ # RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=GNU -# RUN: not llvm-readobj --sections %t 2>&1 \ +# RUN: llvm-readobj --sections %t 2>&1 \ # RUN: | FileCheck %s -DFILE=%t --check-prefix=LLVM # GNU:Section Headers: @@ -43,7 +43,52 @@ # LLVM-NEXT: AddressAlignment: 0 # LLVM-NEXT: EntrySize: 0 # LLVM-NEXT: } -# LLVM-NEXT: error: '[[FILE]]': a section [index 2] has an invalid sh_name (0x1) offset which goes past the end of the section name string table +# LLVM-NEXT: warning: '[[FILE]]': a section [index 2] has an invalid sh_name (0x1) offset which goes past the end of the section name string table +# LLVM-NEXT: Section { +# LLVM-NEXT: Index: 2 +# LLVM-NEXT: Name: (1) +# LLVM-NEXT: Type: SHT_PROGBITS (0x1) +# LLVM-NEXT: Flags [ (0x0) +# LLVM-NEXT: ] +# LLVM-NEXT: Address: 0x0 +# LLVM-NEXT: Offset: 0x40 +# LLVM-NEXT: Size: 0 +# LLVM-NEXT: Link: 0 +# LLVM-NEXT: Info: 0 +# LLVM-NEXT: AddressAlignment: 0 +# LLVM-NEXT: EntrySize: 0 +# LLVM-NEXT: } +# LLVM-NEXT: warning: '[[FILE]]': a section [index 3] has an invalid sh_name (0x15) offset which goes past the end of the section name string table +# LLVM-NEXT: Section { +# LLVM-NEXT: Index: 3 +# LLVM-NEXT: Name: (21) +# LLVM-NEXT: Type: SHT_STRTAB (0x3) +# LLVM-NEXT: Flags [ (0x0) +# LLVM-NEXT: ] +# LLVM-NEXT: Address: 0x0 +# LLVM-NEXT: Offset: 0x40 +# LLVM-NEXT: Size: 1 +# LLVM-NEXT: Link: 0 +# LLVM-NEXT: Info: 0 +# LLVM-NEXT: AddressAlignment: 1 +# LLVM-NEXT: EntrySize: 0 +# LLVM-NEXT: } +# LLVM-NEXT: warning: '[[FILE]]': a section [index 4] has an invalid sh_name (0xb) offset which goes past the end of the section name string table +# LLVM-NEXT: Section { +# LLVM-NEXT: Index: 4 +# LLVM-NEXT: Name: (11) +# LLVM-NEXT: Type: SHT_STRTAB (0x3) +# LLVM-NEXT: Flags [ (0x0) +# LLVM-NEXT: ] +# LLVM-NEXT: Address: 0x0 +# LLVM-NEXT: Offset: 0x41 +# LLVM-NEXT: Size: 29 +# LLVM-NEXT: Link: 0 +# LLVM-NEXT: Info: 0 +# LLVM-NEXT: AddressAlignment: 1 +# LLVM-NEXT: EntrySize: 0 +# LLVM-NEXT: } +# LLVM-NEXT: ] --- !ELF FileHeader: diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 5a5c4ca34259..4dd4e4129c24 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -5748,12 +5748,16 @@ void LLVMStyle::printSectionHeaders(const ELFO *Obj) { int SectionIndex = -1; ArrayRef Sections = unwrapOrError(this->FileName, Obj->sections()); - const ELFObjectFile *ElfObj = this->dumper()->getElfObject(); std::vector> FlagsList = getSectionFlagsForTarget(Obj->getHeader()->e_machine); for (const Elf_Shdr &Sec : Sections) { - StringRef Name = unwrapOrError( - ElfObj->getFileName(), Obj->getSectionName(&Sec, this->WarningHandler)); + StringRef Name = ""; + if (Expected SecNameOrErr = + Obj->getSectionName(&Sec, this->WarningHandler)) + Name = *SecNameOrErr; + else + this->reportUniqueWarning(SecNameOrErr.takeError()); + DictScope SectionD(W, "Section"); W.printNumber("Index", ++SectionIndex); W.printNumber("Name", Name, Sec.sh_name);