Index: llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test +++ llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test @@ -331,28 +331,30 @@ StName: [[NAME=]] ## Check the behavior for unnamed versioned section symbols. -## TODO: we should print proper symbol names instead of descriptions. # RUN: yaml2obj %s -DTYPE=STT_SECTION -DNAME=0 -DINDEX=SHN_ABS --docnum=6 -o %t6.sec.sym -# RUN: llvm-readobj -V --dyn-symbols %t6.sec.sym | FileCheck %s --check-prefix=VERSIONED-SEC-SYM-LLVM -# RUN: llvm-readelf -V --dyn-symbols %t6.sec.sym | FileCheck %s --check-prefix=VERSIONED-SEC-SYM-GNU +# RUN: llvm-readobj -V --dyn-symbols %t6.sec.sym 2>&1 | \ +# RUN: FileCheck %s -DFILE=%t6.sec.sym --check-prefix=VERSIONED-SEC-SYM-LLVM +# RUN: llvm-readelf -V --dyn-symbols %t6.sec.sym 2>&1 | \ +# RUN: FileCheck %s -DFILE=%t6.sec.sym --check-prefix=VERSIONED-SEC-SYM-GNU # VERSIONED-SEC-SYM-LLVM: DynamicSymbols [ # VERSIONED-SEC-SYM-LLVM: Name: (0) # VERSIONED-SEC-SYM-LLVM: Name: # VERSIONED-SEC-SYM-LLVM-SAME: foo (16) +# VERSIONED-SEC-SYM-LLVM: warning: '[[FILE]]': invalid section index: 65521 # VERSIONED-SEC-SYM-LLVM: Name: -# VERSIONED-SEC-SYM-LLVM-SAME: Absolute (0) -# VERSIONED-SEC-SYM-LLVM: Name: -# VERSIONED-SEC-SYM-LLVM-SAME: Undefined (0) +# VERSIONED-SEC-SYM-LLVM-SAME:
(0) +# VERSIONED-SEC-SYM-LLVM: Name: (0) # VERSIONED-SEC-SYM-LLVM: VersionSymbols [ # VERSIONED-SEC-SYM-LLVM: Name: foo -# VERSIONED-SEC-SYM-LLVM: Name: Absolute -# VERSIONED-SEC-SYM-LLVM: Name: Undefined +# VERSIONED-SEC-SYM-LLVM: Name:
+# VERSIONED-SEC-SYM-LLVM: Name: {{$}} # VERSIONED-SEC-SYM-GNU: Num: {{.*}} Ndx Name # VERSIONED-SEC-SYM-GNU: 1: {{.*}} UND foo -# VERSIONED-SEC-SYM-GNU-NEXT: 2: {{.*}} ABS Absolute -# VERSIONED-SEC-SYM-GNU-NEXT: 3: {{.*}} UND Undefined +# VERSIONED-SEC-SYM-GNU: warning: '[[FILE]]': invalid section index: 65521 +# VERSIONED-SEC-SYM-GNU-NEXT: 2: {{.*}} ABS
+# VERSIONED-SEC-SYM-GNU-NEXT: 3: {{.*}} UND {{$}} ## Case 8: Check what we print when: ## a) The dynamic symbol table does not exist. Index: llvm/test/tools/llvm-readobj/ELF/hash-symbols.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/hash-symbols.test +++ llvm/test/tools/llvm-readobj/ELF/hash-symbols.test @@ -117,22 +117,23 @@ - Section: .dynamic ## Check what we print for unnamed section symbols. -## TODO: we should print proper symbol names instead of descriptions. # RUN: yaml2obj --docnum=1 -DBITS=64 -DTYPE=STT_SECTION -DNAME=0 %s -o %t1-sec-syms.so -# RUN: llvm-readelf --hash-symbols %t1-sec-syms.so | FileCheck %s --check-prefix=UNNAMED-SEC-SYMS +# RUN: llvm-readelf --hash-symbols %t1-sec-syms.so 2>&1 | \ +# RUN: FileCheck %s -DFILE=%t1-sec-syms.so --check-prefix=UNNAMED-SEC-SYMS # UNNAMED-SEC-SYMS: Symbol table of .hash for image: # UNNAMED-SEC-SYMS-NEXT: Num {{.*}} Ndx Name -# UNNAMED-SEC-SYMS-NEXT: 1 {{.*}} UND Undefined +# UNNAMED-SEC-SYMS-NEXT: 1 {{.*}} UND {{$}} # UNNAMED-SEC-SYMS-NEXT: 5 {{.*}} 1 .hash -# UNNAMED-SEC-SYMS-NEXT: 3 {{.*}} ABS Absolute +# UNNAMED-SEC-SYMS-NEXT: warning: '[[FILE]]': invalid section index: 65521 +# UNNAMED-SEC-SYMS-NEXT: 3 {{.*}} ABS
# UNNAMED-SEC-SYMS-NEXT: 2 {{.*}} 1 .hash # UNNAMED-SEC-SYMS-NEXT: 4 {{.*}} 2 .gnu.hash # UNNAMED-SEC-SYMS-EMPTY: # UNNAMED-SEC-SYMS: Symbol table of .gnu.hash for image: # UNNAMED-SEC-SYMS-NEXT: Num {{.*}} Ndx Name # UNNAMED-SEC-SYMS-NEXT: 2 {{.*}} 1 .hash -# UNNAMED-SEC-SYMS-NEXT: 3 {{.*}} ABS Absolute +# UNNAMED-SEC-SYMS-NEXT: 3 {{.*}} ABS
# UNNAMED-SEC-SYMS-NEXT: 4 {{.*}} 2 .gnu.hash # UNNAMED-SEC-SYMS-NEXT: 5 {{.*}} 1 .hash Index: llvm/test/tools/llvm-readobj/ELF/mips-got.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/mips-got.test +++ llvm/test/tools/llvm-readobj/ELF/mips-got.test @@ -653,7 +653,6 @@ - Name: foo ## Check how we print global GOT entries when they are unnamed section symbols. -## TODO: we should print proper symbol names instead of descriptions. # RUN: yaml2obj --docnum=5 %s -o %t.err8.o # RUN: llvm-readobj -A %t.err8.o 2>&1 | FileCheck %s -DFILE=%t.err8.o --check-prefix=SEC-SYMS-LLVM # RUN: llvm-readelf -A %t.err8.o 2>&1 | FileCheck %s -DFILE=%t.err8.o --check-prefix=SEC-SYMS-GNU @@ -661,7 +660,8 @@ # SEC-SYMS-LLVM: Global entries [ # SEC-SYMS-LLVM-NEXT: Entry { # SEC-SYMS-LLVM: Section: Absolute (0xFFF1) -# SEC-SYMS-LLVM-NEXT: Name: Absolute (0) +# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': invalid section index: 65521 +# SEC-SYMS-LLVM-NEXT: Name:
(0) # SEC-SYMS-LLVM-NEXT: } # SEC-SYMS-LLVM-NEXT: Entry { # SEC-SYMS-LLVM: Section: .got (0x1) @@ -669,15 +669,18 @@ # SEC-SYMS-LLVM-NEXT: } # SEC-SYMS-LLVM-NEXT: Entry { # SEC-SYMS-LLVM: Section: Common (0xFFF2) -# SEC-SYMS-LLVM-NEXT: Name: Common (0) +# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': invalid section index: 65522 +# SEC-SYMS-LLVM-NEXT: Name:
(0) # SEC-SYMS-LLVM-NEXT: } # SEC-SYMS-LLVM-NEXT: ] # SEC-SYMS-GNU: Global entries: # SEC-SYMS-GNU-NEXT: {{.*}} Ndx Name -# SEC-SYMS-GNU-NEXT: {{.*}} ABS Absolute +# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': invalid section index: 65521 +# SEC-SYMS-GNU-NEXT: {{.*}} ABS
# SEC-SYMS-GNU-NEXT: {{.*}} 1 .got -# SEC-SYMS-GNU-NEXT: {{.*}} COM Common +# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': invalid section index: 65522 +# SEC-SYMS-GNU-NEXT: {{.*}} COM
--- !ELF FileHeader: Index: llvm/test/tools/llvm-readobj/ELF/mips-plt.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/mips-plt.test +++ llvm/test/tools/llvm-readobj/ELF/mips-plt.test @@ -142,16 +142,16 @@ # ERR7: error: '[[FILE]]': unable to get a string table for the SHT_DYNAMIC section with index 1: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM ## Check how we print PLT entries when they are unnamed section symbols. -## TODO: we should print proper symbol names instead of descriptions. -# RUN: yaml2obj --docnum=3 %s -o %t.3 -# RUN: llvm-readobj -A %t.3 2>&1 | FileCheck %s -DFILE=%t.err8.o --check-prefix=SEC-SYMS-LLVM -# RUN: llvm-readelf -A %t.3 2>&1 | FileCheck %s -DFILE=%t.err8.o --check-prefix=SEC-SYMS-GNU +# RUN: yaml2obj --docnum=3 %s -o %t3 +# RUN: llvm-readobj -A %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=SEC-SYMS-LLVM +# RUN: llvm-readelf -A %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=SEC-SYMS-GNU # SEC-SYMS-LLVM: PLT GOT { # SEC-SYMS-LLVM: Entries [ # SEC-SYMS-LLVM: Entry { # SEC-SYMS-LLVM: Section: Absolute (0xFFF1) -# SEC-SYMS-LLVM-NEXT: Name: Absolute (0) +# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': invalid section index: 65521 +# SEC-SYMS-LLVM-NEXT: Name:
(0) # SEC-SYMS-LLVM-NEXT: } # SEC-SYMS-LLVM-NEXT: Entry { # SEC-SYMS-LLVM: Section: .got.plt (0x2) @@ -159,7 +159,8 @@ # SEC-SYMS-LLVM-NEXT: } # SEC-SYMS-LLVM-NEXT: Entry { # SEC-SYMS-LLVM: Section: Common (0xFFF2) -# SEC-SYMS-LLVM-NEXT: Name: Common (0) +# SEC-SYMS-LLVM-NEXT: warning: '[[FILE]]': invalid section index: 65522 +# SEC-SYMS-LLVM-NEXT: Name:
(0) # SEC-SYMS-LLVM-NEXT: } # SEC-SYMS-LLVM-NEXT: ] # SEC-SYMS-LLVM-NEXT: } @@ -167,9 +168,11 @@ # SEC-SYMS-GNU: PLT GOT: # SEC-SYMS-GNU: Entries: # SEC-SYMS-GNU-NEXT: Address {{.*}} Ndx Name -# SEC-SYMS-GNU-NEXT: 0000000000002010 {{.*}} ABS Absolute +# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': invalid section index: 65521 +# SEC-SYMS-GNU-NEXT: 0000000000002010 {{.*}} ABS
# SEC-SYMS-GNU-NEXT: 0000000000002018 {{.*}} 2 .got.plt -# SEC-SYMS-GNU-NEXT: 0000000000002020 {{.*}} COM Common +# SEC-SYMS-GNU-NEXT: warning: '[[FILE]]': invalid section index: 65522 +# SEC-SYMS-GNU-NEXT: 0000000000002020 {{.*}} COM
--- !ELF FileHeader: Index: llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test +++ llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test @@ -103,49 +103,60 @@ # RUN: llvm-readelf --symbols %t1-sec | FileCheck %s --check-prefix=GNU1 ## Check the behavior for unnamed section symbols. -## TODO: we should print proper symbol names instead of descriptions. # RUN: yaml2obj --docnum=1 -DTYPE=STT_SECTION -DNAME=0 %s -o %t1-sec-unnamed -# RUN: llvm-readobj --symbols %t1-sec-unnamed | FileCheck %s --check-prefix=LLVM1-SEC-SYMS -# RUN: llvm-readelf --symbols %t1-sec-unnamed | FileCheck %s --check-prefix=GNU1-SEC-SYMS +# RUN: llvm-readobj --symbols %t1-sec-unnamed 2>&1 | \ +# RUN: FileCheck %s -DFILE=%t1-sec-unnamed --check-prefix=LLVM1-SEC-SYMS +# RUN: llvm-readelf --symbols %t1-sec-unnamed 2>&1 | \ +# RUN: FileCheck %s -DFILE=%t1-sec-unnamed --check-prefix=GNU1-SEC-SYMS # LLVM1-SEC-SYMS: Symbols [ # LLVM1-SEC-SYMS-NEXT: Symbol { # LLVM1-SEC-SYMS-NEXT: Name: (0) # LLVM1-SEC-SYMS: Section: Undefined (0x0) # LLVM1-SEC-SYMS: Symbol { -# LLVM1-SEC-SYMS-NEXT: Name: Undefined (0) +# LLVM1-SEC-SYMS-NEXT: Name: (0) # LLVM1-SEC-SYMS: Section: Undefined (0x0) # LLVM1-SEC-SYMS: Symbol { # LLVM1-SEC-SYMS-NEXT: Name: .text (0) # LLVM1-SEC-SYMS: Section: .text (0x1) -# LLVM1-SEC-SYMS: Symbol { -# LLVM1-SEC-SYMS-NEXT: Name: Common (0) +# LLVM1-SEC-SYMS: warning: '[[FILE]]': invalid section index: 65522 +# LLVM1-SEC-SYMS-NEXT: Symbol { +# LLVM1-SEC-SYMS-NEXT: Name:
(0) # LLVM1-SEC-SYMS: Section: Common (0xFFF2) -# LLVM1-SEC-SYMS: Symbol { -# LLVM1-SEC-SYMS-NEXT: Name: Absolute (0) +# LLVM1-SEC-SYMS: warning: '[[FILE]]': invalid section index: 65521 +# LLVM1-SEC-SYMS-NEXT: Symbol { +# LLVM1-SEC-SYMS-NEXT: Name:
(0) # LLVM1-SEC-SYMS: Section: Absolute (0xFFF1) +# LLVM1-SEC-SYMS: warning: '[[FILE]]': invalid section index: 65281 # LLVM1-SEC-SYMS: Symbol { -# LLVM1-SEC-SYMS-NEXT: Name: Processor Specific (0) +# LLVM1-SEC-SYMS-NEXT: Name:
(0) # LLVM1-SEC-SYMS: Section: Processor Specific (0xFF01) +# LLVM1-SEC-SYMS: warning: '[[FILE]]': invalid section index: 65313 # LLVM1-SEC-SYMS: Symbol { -# LLVM1-SEC-SYMS-NEXT: Name: Operating System Specific (0) +# LLVM1-SEC-SYMS-NEXT: Name:
(0) # LLVM1-SEC-SYMS: Section: Operating System Specific (0xFF21) +# LLVM1-SEC-SYMS: warning: '[[FILE]]': invalid section index: 65534 # LLVM1-SEC-SYMS: Symbol { -# LLVM1-SEC-SYMS-NEXT: Name: Reserved (0) +# LLVM1-SEC-SYMS-NEXT: Name:
(0) # LLVM1-SEC-SYMS: Section: Reserved (0xFFFE) # LLVM1-SEC-SYMS: Symbol { # LLVM1-SEC-SYMS-NEXT: Name: .text (0) # LLVM1-SEC-SYMS: Section: .text (0x1) # GNU1-SEC-SYMS: Num: {{.*}} Ndx Name -# GNU1-SEC-SYMS-NEXT: 0: {{.*}} UND -# GNU1-SEC-SYMS-NEXT: 1: {{.*}} UND Undefined +# GNU1-SEC-SYMS-NEXT: 0: {{.*}} UND {{$}} +# GNU1-SEC-SYMS-NEXT: 1: {{.*}} UND {{$}} # GNU1-SEC-SYMS-NEXT: 2: {{.*}} 1 .text -# GNU1-SEC-SYMS-NEXT: 3: {{.*}} COM Common -# GNU1-SEC-SYMS-NEXT: 4: {{.*}} ABS Absolute -# GNU1-SEC-SYMS-NEXT: 5: {{.*}} PRC[0xff01] Processor Specific -# GNU1-SEC-SYMS-NEXT: 6: {{.*}} OS[0xff21] Operating System Specific -# GNU1-SEC-SYMS-NEXT: 7: {{.*}} RSV[0xfffe] Reserved +# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': invalid section index: 65522 +# GNU1-SEC-SYMS-NEXT: 3: {{.*}} COM
+# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': invalid section index: 65521 +# GNU1-SEC-SYMS-NEXT: 4: {{.*}} ABS
+# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': invalid section index: 65281 +# GNU1-SEC-SYMS-NEXT: 5: {{.*}} PRC[0xff01]
+# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': invalid section index: 65313 +# GNU1-SEC-SYMS-NEXT: 6: {{.*}} OS[0xff21]
+# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': invalid section index: 65534 +# GNU1-SEC-SYMS-NEXT: 7: {{.*}} RSV[0xfffe]
# GNU1-SEC-SYMS-NEXT: 8: {{.*}} 1 .text ## In this case, the index does not correspond to a real section. Check that GNU Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1231,31 +1231,12 @@ : Symbol->st_shndx; } -// If the Symbol has a reserved st_shndx other than SHN_XINDEX, return a -// descriptive interpretation of the st_shndx value. Otherwise, return the name -// of the section with index SectionIndex. This function assumes that if the -// Symbol has st_shndx == SHN_XINDEX the SectionIndex will be the value derived -// from the SHT_SYMTAB_SHNDX section. template Expected ELFDumper::getSymbolSectionName(const Elf_Sym *Symbol, unsigned SectionIndex) const { - if (Symbol->isUndefined()) - return "Undefined"; - if (Symbol->isProcessorSpecific()) - return "Processor Specific"; - if (Symbol->isOSSpecific()) - return "Operating System Specific"; - if (Symbol->isAbsolute()) - return "Absolute"; - if (Symbol->isCommon()) - return "Common"; - if (Symbol->isReserved() && Symbol->st_shndx != SHN_XINDEX) - return "Reserved"; - const ELFFile *Obj = ObjF->getELFFile(); - Expected SecOrErr = - Obj->getSection(SectionIndex); + Expected SecOrErr = Obj->getSection(SectionIndex); if (!SecOrErr) return SecOrErr.takeError(); return Obj->getSectionName(**SecOrErr); @@ -6179,9 +6160,28 @@ return; } - Expected SectionName = - this->dumper()->getSymbolSectionName(Symbol, *SectionIndex); - if (!SectionName) { + auto GetSectionSpecialType = [&]() -> Optional { + if (Symbol->isUndefined()) + return StringRef("Undefined"); + if (Symbol->isProcessorSpecific()) + return StringRef("Processor Specific"); + if (Symbol->isOSSpecific()) + return StringRef("Operating System Specific"); + if (Symbol->isAbsolute()) + return StringRef("Absolute"); + if (Symbol->isCommon()) + return StringRef("Common"); + if (Symbol->isReserved() && Symbol->st_shndx != SHN_XINDEX) + return StringRef("Reserved"); + return None; + }; + + if (Optional Type = GetSectionSpecialType()) { + W.printHex("Section", *Type, *SectionIndex); + } else if (Expected SectionName = + this->dumper()->getSymbolSectionName(Symbol, *SectionIndex)) { + W.printHex("Section", *SectionName, *SectionIndex); + } else { // Don't report an invalid section name if the section headers are missing. // In such situations, all sections will be "invalid". if (!this->dumper()->getElfObject()->sections().empty()) @@ -6189,8 +6189,6 @@ else consumeError(SectionName.takeError()); W.printHex("Section", "", *SectionIndex); - } else { - W.printHex("Section", *SectionName, *SectionIndex); } }