diff --git a/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test b/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test --- a/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test +++ b/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test @@ -322,8 +322,32 @@ - NonDefault DynamicSymbols: - Name: foo - - Name: bar - - Name: zed + - Name: [[NAME=bar]] + Type: [[TYPE=STT_NOTYPE]] + Index: [[INDEX=]] + - Name: [[NAME=zed]] + Type: [[TYPE=STT_NOTYPE]] + +## 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="''" -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 + +# VERSIONED-SEC-SYM-LLVM: DynamicSymbols [ +# VERSIONED-SEC-SYM-LLVM: Name: foo (12) +# VERSIONED-SEC-SYM-LLVM: Name: Absolute (0) +# VERSIONED-SEC-SYM-LLVM: Name: Undefined (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-GNU: Symbol table '.dynsym' contains 4 entries: +# 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 ## Case 8: Check what we print when: ## a) The dynamic symbol table does not exist. diff --git a/llvm/test/tools/llvm-readobj/ELF/hash-symbols.test b/llvm/test/tools/llvm-readobj/ELF/hash-symbols.test --- a/llvm/test/tools/llvm-readobj/ELF/hash-symbols.test +++ b/llvm/test/tools/llvm-readobj/ELF/hash-symbols.test @@ -81,23 +81,28 @@ - Tag: DT_NULL Value: 0x0000000000000000 DynamicSymbols: - - Name: ccc + - Name: [[NAME=ccc]] Binding: STB_GLOBAL - - Name: aaa + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=aaa]] Section: .hash Binding: STB_GLOBAL Value: 0x0000000000001000 - - Name: ddd + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=ddd]] Index: SHN_ABS Binding: STB_GLOBAL Value: 0x0000000000000001 - - Name: eee + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=eee]] Section: .gnu.hash Binding: STB_GLOBAL - - Name: bbb + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=bbb]] Section: .hash Binding: STB_WEAK Value: 0x0000000000001001 + Type: [[TYPE=STT_NOTYPE]] ProgramHeaders: - Type: PT_LOAD Flags: [ PF_R, PF_X ] @@ -106,6 +111,26 @@ - Section: .gnu.hash - 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="''" %s -o %t1-sec-syms.so +# RUN: llvm-readelf --hash-symbols %t1-sec-syms.so | FileCheck %s --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: 5 {{.*}} 1 .hash +# UNNAMED-SEC-SYMS-NEXT: 3 {{.*}} ABS Absolute +# 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: 4 {{.*}} 2 .gnu.hash +# UNNAMED-SEC-SYMS-NEXT: 5 {{.*}} 1 .hash + ## Check the output when only .hash section is present. # RUN: yaml2obj --docnum=2 %s -o %t2-32.so diff --git a/llvm/test/tools/llvm-readobj/ELF/mips-got.test b/llvm/test/tools/llvm-readobj/ELF/mips-got.test --- a/llvm/test/tools/llvm-readobj/ELF/mips-got.test +++ b/llvm/test/tools/llvm-readobj/ELF/mips-got.test @@ -651,3 +651,58 @@ Value: 0x1122 DynamicSymbols: - 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 + +# 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: } +# SEC-SYMS-LLVM-NEXT: Entry { +# SEC-SYMS-LLVM: Section: .got (0x1) +# SEC-SYMS-LLVM-NEXT: Name: .got (0) +# 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: } +# 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: {{.*}} 1 .got +# SEC-SYMS-GNU-NEXT: {{.*}} COM Common + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS +Sections: + - Name: .got + Type: SHT_PROGBITS + Address: 0x1122 + Size: 48 + - Name: .dynamic + Type: SHT_DYNAMIC + Entries: + - Tag: DT_MIPS_LOCAL_GOTNO + Value: 1 + - Tag: DT_MIPS_GOTSYM + Value: 1 + - Tag: DT_PLTGOT + Value: 0x1122 +DynamicSymbols: + - Type: STT_SECTION + Index: SHN_ABS + - Type: STT_SECTION + Section: .got + - Type: STT_SECTION + Index: SHN_COMMON diff --git a/llvm/test/tools/llvm-readobj/ELF/mips-plt.test b/llvm/test/tools/llvm-readobj/ELF/mips-plt.test --- a/llvm/test/tools/llvm-readobj/ELF/mips-plt.test +++ b/llvm/test/tools/llvm-readobj/ELF/mips-plt.test @@ -140,3 +140,75 @@ # RUN: not llvm-readobj -A %t.err7.o 2>&1 | FileCheck %s -DFILE=%t.err7.o -check-prefix ERR7 # 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 + +# 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: } +# SEC-SYMS-LLVM-NEXT: Entry { +# SEC-SYMS-LLVM: Section: .got.plt (0x2) +# SEC-SYMS-LLVM-NEXT: Name: .got.plt (0) +# 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: } +# SEC-SYMS-LLVM-NEXT: ] +# SEC-SYMS-LLVM-NEXT: } + +# 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: 0000000000002018 {{.*}} 2 .got.plt +# SEC-SYMS-GNU-NEXT: 0000000000002020 {{.*}} COM Common + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS +Sections: + - Name: .rel.plt + Type: SHT_REL + Flags: [ SHF_ALLOC ] + Address: 0x1000 + Link: .dynsym + Relocations: + - Offset: 0x1 + Symbol: 1 + Type: R_MIPS_JUMP_SLOT + - Offset: 0x2 + Symbol: 2 + Type: R_MIPS_JUMP_SLOT + - Offset: 0x2 + Symbol: 3 + Type: R_MIPS_JUMP_SLOT + - Name: .got.plt + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x2000 + Size: 40 ## (dynamic symbols number + 2) * 8 + - Name: .dynamic + Type: SHT_DYNAMIC + Entries: + - Tag: DT_JMPREL + Value: 0x1000 + - Tag: DT_MIPS_PLTGOT + Value: 0x2000 +DynamicSymbols: + - Type: STT_SECTION + Index: SHN_ABS + - Type: STT_SECTION + Section: .got.plt + - Type: STT_SECTION + Index: SHN_COMMON diff --git a/llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test b/llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test --- a/llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test +++ b/llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test @@ -57,29 +57,88 @@ Link: .symtab Entries: [ 0, 0, 0, 0, 0, 0, 0, 0, 1 ] Symbols: - - Name: undef + - Name: [[NAME=undef]] Binding: STB_GLOBAL - - Name: normal + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=normal]] Section: .text Binding: STB_GLOBAL - - Name: common + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=common]] Index: SHN_COMMON Binding: STB_GLOBAL - - Name: absolute + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=absolute]] Index: SHN_ABS Binding: STB_GLOBAL - - Name: proc + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=proc]] Index: 0xff01 Binding: STB_GLOBAL - - Name: os + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=os]] Index: 0xff21 Binding: STB_GLOBAL - - Name: reserved + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=reserved]] Index: 0xfffe Binding: STB_GLOBAL - - Name: xindex + Type: [[TYPE=STT_NOTYPE]] + - Name: [[NAME=xindex]] Index: SHN_XINDEX Binding: STB_GLOBAL + Type: [[TYPE=STT_NOTYPE]] + +## Check the behavior for section symbols. +# RUN: yaml2obj --docnum=1 -DTYPE=STT_SECTION %s -o %t1-sec +# RUN: llvm-readobj --symbols %t1-sec | FileCheck %s --check-prefix=LLVM1 +# 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="''" %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 + +# 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: 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: Section: Common (0xFFF2) +# LLVM1-SEC-SYMS: Symbol { +# LLVM1-SEC-SYMS-NEXT: Name: Absolute (0) +# LLVM1-SEC-SYMS: Section: Absolute (0xFFF1) +# LLVM1-SEC-SYMS: Symbol { +# LLVM1-SEC-SYMS-NEXT: Name: Processor Specific (0) +# LLVM1-SEC-SYMS: Section: Processor Specific (0xFF01) +# LLVM1-SEC-SYMS: Symbol { +# LLVM1-SEC-SYMS-NEXT: Name: Operating System Specific (0) +# LLVM1-SEC-SYMS: Section: Operating System Specific (0xFF21) +# LLVM1-SEC-SYMS: Symbol { +# LLVM1-SEC-SYMS-NEXT: Name: Reserved (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: 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: 8: {{.*}} 1 .text ## In this case, the index does not correspond to a real section. Check that GNU ## style just prints the section index as normal and LLVM style prints a warning