Index: llvm/test/tools/llvm-readobj/ELF/section-symbols.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/section-symbols.test +++ llvm/test/tools/llvm-readobj/ELF/section-symbols.test @@ -1,7 +1,8 @@ -## ELF section symbols use the section names when printing. This test verifies -## this and also that appropriate things are printed if the section is somehow -## invalid. +## ELF section symbols use the corresponding section names when printing +## unnamed symbols. This test verifies this and also that appropriate things +## are printed if the section is somehow invalid. +## Test --symbols option. # RUN: yaml2obj %s -o %t1 # RUN: llvm-readobj %t1 --symbols 2> %t.llvm.err1 | FileCheck %s --check-prefix=LLVM1 # RUN: FileCheck %s --input-file %t.llvm.err1 --check-prefix=WARN1 --implicit-check-not=warning @@ -10,26 +11,35 @@ # LLVM1: Name: (0) # LLVM1: Name: .foo (0) +# LLVM1: Name: symbol1 (25) # LLVM1: Name:
(0) +# LLVM1: Name: symbol2 (17) # LLVM1: Name: .bar (0) +# LLVM1: Name: symbol3 (9) # LLVM1: Name:
(0) +# LLVM1: Name: symbol4 (1) -# GNU1: Symbol table '.symtab' contains 5 entries: +# GNU1: Symbol table '.symtab' contains 9 entries: # GNU1-NEXT: Num: {{.*}} Type {{.*}} Ndx Name # GNU1-NEXT: 0: {{.*}} NOTYPE {{.*}} UND {{$}} -# GNU1-NEXT: 1: {{.*}} SECTION {{.*}} 1 .foo -# GNU1-NEXT: 2: {{.*}} SECTION {{.*}} 67
-# GNU1-NEXT: 3: {{.*}} SECTION {{.*}} 2 .bar -# GNU1-NEXT: 4: {{.*}} SECTION {{.*}} 66
+# GNU1-NEXT: 1: {{.*}} SECTION {{.*}} 1 .foo +# GNU1-NEXT: 2: {{.*}} SECTION {{.*}} 1 symbol1 +# GNU1-NEXT: 3: {{.*}} SECTION {{.*}} 67
+# GNU1-NEXT: 4: {{.*}} SECTION {{.*}} 67 symbol2 +# GNU1-NEXT: 5: {{.*}} SECTION {{.*}} 2 .bar +# GNU1-NEXT: 6: {{.*}} SECTION {{.*}} 2 symbol3 +# GNU1-NEXT: 7: {{.*}} SECTION {{.*}} 66
+# GNU1-NEXT: 8: {{.*}} SECTION {{.*}} 66 symbol4 # WARN1: warning: '{{.*}}.tmp1': invalid section index: 67 # WARN1: warning: '{{.*}}.tmp1': invalid section index: 66 --- !ELF FileHeader: - Class: ELFCLASS32 - Data: ELFDATA2LSB - Type: ET_REL + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 Sections: - Name: .foo Type: SHT_PROGBITS @@ -38,22 +48,99 @@ - Name: .symtab_shndx Type: SHT_SYMTAB_SHNDX Link: .symtab - Entries: [ 0, 0, 0, 2, 0x42 ] + Entries: [ 0, 0, 0, 0, 0, 2, 2, 0x42, 0x42 ] + - Name: .rela.foo + Type: SHT_RELA + Link: .symtab + Info: .foo + Relocations: + - Offset: 0x1 + Symbol: 1 + Type: R_X86_64_NONE + - Offset: 0x2 + Symbol: 2 + Type: R_X86_64_NONE + - Offset: 0x3 + Symbol: 3 + Type: R_X86_64_NONE + - Offset: 0x4 + Symbol: 4 + Type: R_X86_64_NONE + - Offset: 0x5 + Symbol: 5 + Type: R_X86_64_NONE + - Offset: 0x6 + Symbol: 6 + Type: R_X86_64_NONE + - Offset: 0x7 + Symbol: 7 + Type: R_X86_64_NONE + - Offset: 0x8 + Symbol: 8 + Type: R_X86_64_NONE Symbols: +## Case 1: a valid unnamed section symbol. - Name: "" Section: .foo Type: STT_SECTION +## Case 2: a valid named section symbol. + - Name: "symbol1" + Section: .foo + Type: STT_SECTION +## Case 3: an unnamed section symbol with invalid index. - Name: "" Index: 0x43 Type: STT_SECTION - # Section symbol via SHT_SYMTAB_SHNDX. +## Case 4: a named section symbol with invalid index. + - Name: "symbol2" + Index: 0x43 + Type: STT_SECTION +## Case 5: a valid unnamed section symbol via SHT_SYMTAB_SHNDX. - Name: "" Index: SHN_XINDEX Type: STT_SECTION - # Section symbol via SHT_SYMTAB_SHNDX with invalid index. +## Case 6: a valid named section symbol via SHT_SYMTAB_SHNDX. + - Name: "symbol3" + Index: SHN_XINDEX + Type: STT_SECTION +## Case 7: a unnamed section symbol via SHT_SYMTAB_SHNDX with invalid index. - Name: "" Index: SHN_XINDEX Type: STT_SECTION +## Case 8: a named section symbol via SHT_SYMTAB_SHNDX with invalid index. + - Name: "symbol4" + Index: SHN_XINDEX + Type: STT_SECTION + +## Test --relocations option. +## FIXME: 1) Relocations should print section symbol names when they are not empty. +## 2) We should still print a relocation even when we are unable to lookup a symbol name. +# RUN: llvm-readobj %t1 --relocations 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=LLVM-RELOCS +# RUN: llvm-readelf %t1 --relocations 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=GNU-RELOCS + +# LLVM-RELOCS: Relocations [ +# LLVM-RELOCS-NEXT: Section (4) .rela.foo { +# LLVM-RELOCS-NEXT: 0x1 R_X86_64_NONE .foo 0x0 +# LLVM-RELOCS-NEXT: 0x2 R_X86_64_NONE .foo 0x0 +# LLVM-RELOCS-NEXT: warning: '[[FILE]]': unable to print relocation 3 in SHT_RELA section with index 4: invalid section index: 67 +# LLVM-RELOCS-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_RELA section with index 4: invalid section index: 67 +# LLVM-RELOCS-NEXT: 0x5 R_X86_64_NONE .bar 0x0 +# LLVM-RELOCS-NEXT: 0x6 R_X86_64_NONE .bar 0x0 +# LLVM-RELOCS-NEXT: warning: '[[FILE]]': unable to print relocation 7 in SHT_RELA section with index 4: invalid section index: 66 +# LLVM-RELOCS-NEXT: warning: '[[FILE]]': unable to print relocation 8 in SHT_RELA section with index 4: invalid section index: 66 +# LLVM-RELOCS-NEXT: } +# LLVM-RELOCS-NEXT: ] + +# GNU-RELOCS: Relocation section '.rela.foo' at offset 0x58 contains 8 entries: +# GNU-RELOCS-NEXT: Offset Info Type Sym. Value Symbol's Name + Addend +# GNU-RELOCS-NEXT: 00000001 00000100 R_X86_64_NONE 00000000 .foo + 0 +# GNU-RELOCS-NEXT: 00000002 00000200 R_X86_64_NONE 00000000 .foo + 0 +# GNU-RELOCS-NEXT: warning: '[[FILE]]': unable to print relocation 3 in SHT_RELA section with index 4: invalid section index: 67 +# GNU-RELOCS-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_RELA section with index 4: invalid section index: 67 +# GNU-RELOCS-NEXT: 00000005 00000500 R_X86_64_NONE 00000000 .bar + 0 +# GNU-RELOCS-NEXT: 00000006 00000600 R_X86_64_NONE 00000000 .bar + 0 +# GNU-RELOCS-NEXT: warning: '[[FILE]]': unable to print relocation 7 in SHT_RELA section with index 4: invalid section index: 66 +# GNU-RELOCS-NEXT: warning: '[[FILE]]': unable to print relocation 8 in SHT_RELA section with index 4: invalid section index: 66 # RUN: yaml2obj %s --docnum=2 -o %t2 # RUN: llvm-readobj %t2 --symbols 2> %t.llvm.err2 | FileCheck %s --check-prefix=LLVM2