1## ELF section symbols use the corresponding section names when printing
2## unnamed symbols. This test verifies this and also that appropriate things
3## are printed if the section is somehow invalid.
4
5# RUN: yaml2obj %s -o %t1
6# RUN: llvm-readobj %t1 --symbols --relocations 2>&1 | \
7# RUN:   FileCheck %s -DFILE=%t1 --check-prefix=LLVM1 --implicit-check-not="warning:"
8# RUN: llvm-readelf %t1 --symbols --relocations 2>&1 | \
9# RUN:   FileCheck %s -DFILE=%t1 --check-prefix=GNU1 --implicit-check-not="warning:"
10
11# LLVM1:      Relocations [
12# LLVM1-NEXT:   Section (4) .rela.foo {
13# LLVM1-NEXT:     0x1 R_X86_64_NONE .foo 0x0
14# LLVM1-NEXT:     0x2 R_X86_64_NONE symbol1 0x0
15# LLVM1-NEXT: warning: '[[FILE]]': invalid section index: 67
16# LLVM1-NEXT:     0x3 R_X86_64_NONE <section 67> 0x0
17# LLVM1-NEXT:     0x4 R_X86_64_NONE symbol2 0x0
18# LLVM1-NEXT:     0x5 R_X86_64_NONE .bar 0x0
19# LLVM1-NEXT:     0x6 R_X86_64_NONE symbol3 0x0
20# LLVM1-NEXT: warning: '[[FILE]]': invalid section index: 66
21# LLVM1-NEXT:     0x7 R_X86_64_NONE <section 66> 0x0
22# LLVM1-NEXT:     0x8 R_X86_64_NONE symbol4 0x0
23# LLVM1-NEXT:   }
24# LLVM1-NEXT: ]
25
26# LLVM1: Name: (0)
27# LLVM1: Name: .foo (0)
28# LLVM1: Name: symbol1 (25)
29# LLVM1: Name: <section 67> (0)
30# LLVM1: Name: symbol2 (17)
31# LLVM1: Name: .bar (0)
32# LLVM1: Name: symbol3 (9)
33# LLVM1: Name: <section 66> (0)
34# LLVM1: Name: symbol4 (1)
35
36# GNU1:      Relocation section '.rela.foo' at offset 0x58 contains 8 entries:
37# GNU1-NEXT:  Offset     Info    Type         Sym. Value  Symbol's Name + Addend
38# GNU1-NEXT: 00000001  00000100 R_X86_64_NONE   00000000   .foo + 0
39# GNU1-NEXT: 00000002  00000200 R_X86_64_NONE   00000000   symbol1 + 0
40# GNU1-NEXT: warning: '[[FILE]]': invalid section index: 67
41# GNU1-NEXT: 00000003  00000300 R_X86_64_NONE   00000000   <section 67> + 0
42# GNU1-NEXT: 00000004  00000400 R_X86_64_NONE   00000000   symbol2 + 0
43# GNU1-NEXT: 00000005  00000500 R_X86_64_NONE   00000000   .bar + 0
44# GNU1-NEXT: 00000006  00000600 R_X86_64_NONE   00000000   symbol3 + 0
45# GNU1-NEXT: warning: '[[FILE]]': invalid section index: 66
46# GNU1-NEXT: 00000007  00000700 R_X86_64_NONE   00000000   <section 66> + 0
47# GNU1-NEXT: 00000008  00000800 R_X86_64_NONE   00000000   symbol4 + 0
48
49# GNU1:      Symbol table '.symtab' contains 9 entries:
50# GNU1-NEXT:    Num: {{.*}} Type    {{.*}} Ndx Name
51# GNU1-NEXT:      0: {{.*}} NOTYPE  {{.*}} UND {{$}}
52# GNU1-NEXT:      1: {{.*}} SECTION {{.*}}  1 .foo
53# GNU1-NEXT:      2: {{.*}} SECTION {{.*}}  1 symbol1
54# GNU1-NEXT:      3: {{.*}} SECTION {{.*}} 67 <section 67>
55# GNU1-NEXT:      4: {{.*}} SECTION {{.*}} 67 symbol2
56# GNU1-NEXT:      5: {{.*}} SECTION {{.*}}  2 .bar
57# GNU1-NEXT:      6: {{.*}} SECTION {{.*}}  2 symbol3
58# GNU1-NEXT:      7: {{.*}} SECTION {{.*}} 66 <section 66>
59# GNU1-NEXT:      8: {{.*}} SECTION {{.*}} 66 symbol4
60
61--- !ELF
62FileHeader:
63  Class:   ELFCLASS32
64  Data:    ELFDATA2LSB
65  Type:    ET_REL
66  Machine: EM_X86_64
67Sections:
68  - Name: .foo
69    Type: SHT_PROGBITS
70  - Name: .bar
71    Type: SHT_PROGBITS
72  - Name: .symtab_shndx
73    Type: SHT_SYMTAB_SHNDX
74    Link: .symtab
75    Entries: [ 0, 0, 0, 0, 0, 2, 2, 0x42, 0x42 ]
76  - Name: .rela.foo
77    Type: SHT_RELA
78    Link: .symtab
79    Info: .foo
80    Relocations:
81      - Offset: 0x1
82        Symbol: 1
83        Type:   R_X86_64_NONE
84      - Offset: 0x2
85        Symbol: 2
86        Type:   R_X86_64_NONE
87      - Offset: 0x3
88        Symbol: 3
89        Type:   R_X86_64_NONE
90      - Offset: 0x4
91        Symbol: 4
92        Type:   R_X86_64_NONE
93      - Offset: 0x5
94        Symbol: 5
95        Type:   R_X86_64_NONE
96      - Offset: 0x6
97        Symbol: 6
98        Type:   R_X86_64_NONE
99      - Offset: 0x7
100        Symbol: 7
101        Type:   R_X86_64_NONE
102      - Offset: 0x8
103        Symbol: 8
104        Type:   R_X86_64_NONE
105Symbols:
106## Case 1: a valid unnamed section symbol.
107  - Name: ""
108    Section: .foo
109    Type: STT_SECTION
110## Case 2: a valid named section symbol.
111  - Name: "symbol1"
112    Section: .foo
113    Type: STT_SECTION
114## Case 3: an unnamed section symbol with invalid index.
115  - Name: ""
116    Index: 0x43
117    Type: STT_SECTION
118## Case 4: a named section symbol with invalid index.
119  - Name: "symbol2"
120    Index: 0x43
121    Type: STT_SECTION
122## Case 5: a valid unnamed section symbol via SHT_SYMTAB_SHNDX.
123  - Name: ""
124    Index: SHN_XINDEX
125    Type: STT_SECTION
126## Case 6: a valid named section symbol via SHT_SYMTAB_SHNDX.
127  - Name: "symbol3"
128    Index: SHN_XINDEX
129    Type: STT_SECTION
130## Case 7: a unnamed section symbol via SHT_SYMTAB_SHNDX with invalid index.
131  - Name: ""
132    Index: SHN_XINDEX
133    Type: STT_SECTION
134## Case 8: a named section symbol via SHT_SYMTAB_SHNDX with invalid index.
135  - Name: "symbol4"
136    Index: SHN_XINDEX
137    Type: STT_SECTION
138
139# RUN: yaml2obj %s --docnum=2 -o %t2
140# RUN: llvm-readobj %t2 --symbols 2> %t.llvm.err2 | FileCheck %s --check-prefix=LLVM2
141# RUN: FileCheck %s --input-file %t.llvm.err2 --check-prefix=WARN2 --implicit-check-not=warning
142# RUN: llvm-readelf %t2 --symbols 2> %t.gnu.err2 | FileCheck %s --check-prefix=GNU2
143# RUN: FileCheck %s --input-file %t.gnu.err2 --check-prefix=WARN2 --implicit-check-not=warning
144
145# LLVM2: Name: (0)
146# LLVM2: Name: <?> (0)
147
148# GNU2:      Symbol table '.symtab' contains 2 entries:
149# GNU2-NEXT:    Num: {{.*}} Type    {{.*}} Ndx Name
150# GNU2-NEXT:      0: {{.*}} NOTYPE  {{.*}} UND {{$}}
151# GNU2-NEXT:      1: {{.*}} SECTION {{.*}} RSV[0xffff] <?>
152
153# WARN2: warning: '{{.*}}.tmp2': extended symbol index (1) is past the end of the SHT_SYMTAB_SHNDX section of size 0
154
155--- !ELF
156FileHeader:
157  Class: ELFCLASS32
158  Data:  ELFDATA2LSB
159  Type:  ET_REL
160Symbols:
161  # Section symbol via SHT_SYMTAB_SHNDX when SHT_SYMTAB_SHNDX is missing.
162  - Name: ""
163    Index: SHN_XINDEX
164    Type: STT_SECTION
165