1## Check that we correctly display the contents of the .stack_sizes section
2## in a relocatable object file.
3
4# RUN: yaml2obj --docnum=1 %s -o %t01
5# RUN: llvm-readelf --stack-sizes %t01 \
6# RUN:   | FileCheck %s --check-prefix=RELOC-GNU --strict-whitespace --match-full-lines
7# RUN: llvm-readobj --stack-sizes %t01 | FileCheck %s --check-prefix=RELOC-LLVM
8
9#      RELOC-GNU:         Size     Function
10# RELOC-GNU-NEXT:           16     referenced_by_symbol_foo
11# RELOC-GNU-NEXT:           32     referenced_via_section_bar
12# RELOC-GNU-NEXT:            8     separate_text_section_baz
13#  RELOC-GNU-NOT:{{.}}
14
15# RELOC-LLVM:      StackSizes [
16# RELOC-LLVM-NEXT:   Entry {
17# RELOC-LLVM-NEXT:     Function: referenced_by_symbol_foo
18# RELOC-LLVM-NEXT:     Size: 0x10
19# RELOC-LLVM-NEXT:   }
20# RELOC-LLVM-NEXT:   Entry {
21# RELOC-LLVM-NEXT:     Function: referenced_via_section_bar
22# RELOC-LLVM-NEXT:     Size: 0x20
23# RELOC-LLVM-NEXT:   }
24# RELOC-LLVM-NEXT:   Entry {
25# RELOC-LLVM-NEXT:     Function: separate_text_section_baz
26# RELOC-LLVM-NEXT:     Size: 0x8
27# RELOC-LLVM-NEXT:   }
28# RELOC-LLVM-NEXT: ]
29
30--- !ELF
31FileHeader:
32  Class:   ELFCLASS64
33  Data:    ELFDATA2LSB
34  Type:    ET_REL
35  Machine: EM_X86_64
36Sections:
37  - Name:    .text
38    Type:    SHT_PROGBITS
39    Flags:   [SHF_ALLOC]
40    Size:    16
41  - Name:    .text.baz
42    Type:    SHT_PROGBITS
43    Flags:   [SHF_ALLOC]
44    Size:    16
45  - Name:    .stack_sizes
46    Type:    SHT_PROGBITS
47    Entries:
48      - Size: 0x10
49      - Size: 0x20
50    Link:    .text
51  - Name:    '.stack_sizes (1)'
52    Type:    SHT_PROGBITS
53    Entries:
54      - Address: 0x20
55        Size:    0x8
56    Link:    .text.baz
57  - Name:    .rela.stack_sizes
58    Type:    SHT_RELA
59    Info:    .stack_sizes
60    Relocations:
61## A symbol relative reference.
62      - Offset: 0
63        Symbol: referenced_by_symbol_foo
64        Type:   R_X86_64_64
65## A section relative reference.
66      - Offset: 9
67        Addend: 16
68        Symbol: .text
69        Type:   R_X86_64_64
70  - Name:   '.rela.stack_sizes (1)'
71    Type:   SHT_RELA
72    Info:   '.stack_sizes (1)'
73    Relocations:
74      - Offset: 0
75        Symbol: separate_text_section_baz
76        Type:   R_X86_64_64
77Symbols:
78  - Name:    separate_text_section_baz
79    Section: .text.baz
80    Type:    STT_FUNC
81  - Name:    .text
82    Section: .text
83    Type:    STT_SECTION
84  - Name:    referenced_by_symbol_foo
85    Section: .text
86    Type:    STT_FUNC
87    Binding: STB_GLOBAL
88  - Name:    referenced_via_section_bar
89    Section: .text
90    Value:   0x10
91    Type:    STT_FUNC
92    Binding: STB_GLOBAL
93
94## Check that we correctly report the stack sizes in an executable (non-relocatable)
95## object file. This also shows that the sh_link field is ignored in this situation
96## without warning.
97
98# RUN: yaml2obj --docnum=2 %s -o %t02
99# RUN: llvm-readelf --stack-sizes %t02 2>&1 \
100# RUN:   | FileCheck %s --check-prefix=EXEC-GNU --strict-whitespace \
101# RUN:                  --match-full-lines --implicit-check-not=warning:
102# RUN: llvm-readobj --stack-sizes %t02 2>&1 \
103# RUN:   | FileCheck %s --check-prefix=EXEC-LLVM --implicit-check-not=warning:
104
105#      EXEC-GNU:         Size     Function
106# EXEC-GNU-NEXT:           16     other
107# EXEC-GNU-NEXT:           32     other_end
108# EXEC-GNU-NEXT:           48     bar
109#  EXEC-GNU-NOT:{{.}}
110
111# EXEC-LLVM:      StackSizes [
112# EXEC-LLVM-NEXT:   Entry {
113# EXEC-LLVM-NEXT:     Function: other
114# EXEC-LLVM-NEXT:     Size: 0x10
115# EXEC-LLVM-NEXT:   }
116# EXEC-LLVM-NEXT:   Entry {
117# EXEC-LLVM-NEXT:     Function: other_end
118# EXEC-LLVM-NEXT:     Size: 0x20
119# EXEC-LLVM-NEXT:   }
120# EXEC-LLVM-NEXT:   Entry {
121# EXEC-LLVM-NEXT:     Function: bar
122# EXEC-LLVM-NEXT:     Size: 0x30
123# EXEC-LLVM-NEXT:   }
124# EXEC-LLVM-NEXT: ]
125
126--- !ELF
127FileHeader:
128  Class: ELFCLASS64
129  Data:  ELFDATA2LSB
130  Type:  ET_EXEC
131Sections:
132  - Name:    .text
133    Type:    SHT_PROGBITS
134    Flags:   [SHF_ALLOC]
135    Size:    16
136  - Name:    .text2
137    Type:    SHT_PROGBITS
138    Flags:   [SHF_ALLOC]
139    Size:    16
140  - Name:    .stack_sizes
141    Type:    SHT_PROGBITS
142    Entries:
143      - Address: 0x0
144        Size:    0x10
145      - Address: 0x10
146        Size:    0x20
147      - Address: 0x20
148        Size:    0x30
149    Link:    .text2
150Symbols:
151  ## Undefined symbols are ignored.
152  - Name:    undefined
153    Type:    STT_FUNC
154    Binding: STB_GLOBAL
155  ## sh_link of .stack_sizes is ignored for non-reloctable objects.
156  - Name:    other
157    Section: .text
158    Value:   0
159    Type:    STT_FUNC
160    Binding: STB_GLOBAL
161  ## If two symbols have the same value, the first is picked, regardless of
162  ## the sh_link value of the .stack_sizes section.
163  - Name:    other_end
164    Section: .text
165    Value:   0x10
166    Type:    STT_FUNC
167    Binding: STB_GLOBAL
168  - Name:    foo
169    Section: .text2
170    Value:   0x10
171    Type:    STT_FUNC
172    Binding: STB_GLOBAL
173  - Name:    bar
174    Section: .text2
175    Value:   0x20
176    Type:    STT_FUNC
177    Binding: STB_GLOBAL
178
179## Check that we report a warning when we find relocations whose offsets point outside
180## of the .stack_sizes section.
181
182# RUN: yaml2obj --docnum=3 %s -o %t03
183# RUN: llvm-readelf --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT-GNU -DFILE=%t03
184# RUN: llvm-readobj --stack-sizes %t03 2>&1 | FileCheck %s --check-prefix=SHORT-LLVM -DFILE=%t03
185
186# SHORT-GNU:      Stack Sizes:
187# SHORT-GNU-NEXT:  Size     Function
188# SHORT-GNU-NEXT:     8     foo
189# SHORT-GNU-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into SHT_PROGBITS section with index 2 while trying to extract a stack size entry
190# SHORT-GNU-NEXT:     8     foo
191
192# SHORT-LLVM:     StackSizes [
193# SHORT-LLVM-NEXT:   Entry {
194# SHORT-LLVM-NEXT:     Function: foo
195# SHORT-LLVM-NEXT:     Size: 0x8
196# SHORT-LLVM-NEXT:   }
197# SHORT-LLVM-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into SHT_PROGBITS section with index 2 while trying to extract a stack size entry
198# SHORT-LLVM-NEXT:   Entry {
199# SHORT-LLVM-NEXT:     Function: foo
200# SHORT-LLVM-NEXT:     Size: 0x8
201# SHORT-LLVM-NEXT:   }
202# SHORT-LLVM-NEXT: ]
203
204--- !ELF
205FileHeader:
206  Class:   ELFCLASS64
207  Data:    ELFDATA2LSB
208  Type:    ET_REL
209  Machine: EM_X86_64
210Sections:
211  - Name:    .text
212    Type:    SHT_PROGBITS
213    Flags:   [SHF_ALLOC]
214    Size:    16
215  - Name:    .stack_sizes
216    Type:    SHT_PROGBITS
217    Link:    .text
218    Entries:
219      - Size: 0x8
220  - Name:    .rela.stack_sizes
221    Type:    SHT_RELA
222    Info:    .stack_sizes
223    Relocations:
224      - Offset: 0x0
225        Symbol: foo
226        Type:   R_X86_64_64
227      - Offset: 0x1
228        Symbol: foo
229        Type:   R_X86_64_64
230      - Offset: 0x1
231        Symbol: foo
232        Type:   R_X86_64_64
233      - Offset: 0x0
234        Symbol: foo
235        Type:   R_X86_64_64
236Symbols:
237  - Name:    foo
238    Section: .text
239    Type:    STT_FUNC
240    Binding: STB_GLOBAL
241
242## Check that we warn about a function symbol that is not in the section
243## that is referenced by the stack sizes section's sh_link, for relocatable
244## output.
245
246# RUN: yaml2obj --docnum=4 %s -o %t04
247# RUN: llvm-readelf --stack-sizes %t04 2> %t04-gnu.err | FileCheck %s --check-prefix=WRONGSECTION-GNU
248# RUN: FileCheck %s < %t04-gnu.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04
249# RUN: llvm-readobj --stack-sizes %t04 2> %t04-llvm.err | FileCheck %s --check-prefix=WRONGSECTION-LLVM
250# RUN: FileCheck %s < %t04-llvm.err --check-prefix=WRONGSECTION-ERR -DFILE=%t04
251
252# RUN: llvm-readelf --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04
253# RUN: llvm-readobj --stack-sizes --demangle %t04 2>&1 | FileCheck %s --check-prefix=WRONGSECTION-DEMANGLE-ERR -DFILE=%t04
254
255# WRONGSECTION-GNU:      Size Function
256# WRONGSECTION-GNU-NEXT: 8 _Z3foof
257
258# WRONGSECTION-LLVM:      StackSizes [
259# WRONGSECTION-LLVM-NEXT:   Entry {
260# WRONGSECTION-LLVM-NEXT:     Function: _Z3foof
261# WRONGSECTION-LLVM-NEXT:     Size: 0x8
262# WRONGSECTION-LLVM-NEXT:   }
263# WRONGSECTION-LLVM-NEXT: ]
264
265# WRONGSECTION-ERR:           warning: '[[FILE]]': relocation symbol '_Z3foof' is not in the expected section
266# WRONGSECTION-DEMANGLE-ERR:  warning: '[[FILE]]': relocation symbol 'foo(float)' is not in the expected section
267
268--- !ELF
269FileHeader:
270  Class:   ELFCLASS64
271  Data:    ELFDATA2LSB
272  Type:    ET_REL
273  Machine: EM_X86_64
274Sections:
275  - Name:    .text
276    Type:    SHT_PROGBITS
277    Size:    8
278  - Name:    .text2
279    Type:    SHT_PROGBITS
280    Size:    8
281    Flags:   [SHF_ALLOC]
282  - Name:    .stack_sizes
283    Type:    SHT_PROGBITS
284    Entries:
285      - Size: 0x8
286    Link:    .text2
287  - Name:    .rela.stack_sizes
288    Type:    SHT_RELA
289    Info:    .stack_sizes
290    Relocations:
291      - Offset: 0
292        Symbol: _Z3foof
293        Type:   R_X86_64_64
294Symbols:
295  - Name:    _Z3foof
296    Section: .text
297    Type:    STT_FUNC
298    Binding: STB_GLOBAL
299
300## Check that we report a warning when a stack sizes section ends with an incomplete stack size entry.
301
302# RUN: yaml2obj --docnum=5 %s -o %t05
303# RUN: llvm-readelf --stack-sizes %t05 2>&1 | \
304# RUN:   FileCheck %s --check-prefix=SUDDENEND-GNU -DFILE=%t05
305# RUN: llvm-readobj --stack-sizes %t05 2>&1 | \
306# RUN:   FileCheck %s --check-prefix=SUDDENEND-LLVM -DFILE=%t05
307
308# SUDDENEND-GNU:      Stack Sizes:
309# SUDDENEND-GNU-NEXT:  Size     Function
310# SUDDENEND-GNU-NEXT:     8     foo
311# SUDDENEND-GNU-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 2 ended while trying to extract a stack size entry
312# SUDDENEND-GNU-NEXT:     8     foo
313# SUDDENEND-GNU-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 3 ended while trying to extract a stack size entry
314
315# SUDDENEND-LLVM:      StackSizes [
316# SUDDENEND-LLVM-NEXT:   Entry {
317# SUDDENEND-LLVM-NEXT:     Function: foo
318# SUDDENEND-LLVM-NEXT:     Size: 0x8
319# SUDDENEND-LLVM-NEXT:   }
320# SUDDENEND-LLVM-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 2 ended while trying to extract a stack size entry
321# SUDDENEND-LLVM-NEXT:   Entry {
322# SUDDENEND-LLVM-NEXT:     Function: foo
323# SUDDENEND-LLVM-NEXT:     Size: 0x8
324# SUDDENEND-LLVM-NEXT:   }
325# SUDDENEND-LLVM-NEXT: warning: '[[FILE]]': SHT_PROGBITS section with index 3 ended while trying to extract a stack size entry
326# SUDDENEND-LLVM-NEXT: ]
327
328--- !ELF
329FileHeader:
330  Class:   ELFCLASS64
331  Data:    ELFDATA2LSB
332  Type:    ET_EXEC
333  Machine: EM_X86_64
334Sections:
335  - Name: .text
336    Type: SHT_PROGBITS
337  - Name: .stack_sizes
338    Type: SHT_PROGBITS
339    Link: .text
340    Entries:
341      - Size: 0x8
342      - Size: 0x10
343## 0x11 == the normal size minus 1.
344    ShSize: 0x11
345  - Name: .stack_sizes (1)
346    Type: SHT_PROGBITS
347    Link: .text
348    Entries:
349      - Size: 0x8
350      - Size: 0x10
351    ShSize: 0x11
352Symbols:
353  - Name:    foo
354    Section: .text
355    Type:    STT_FUNC
356
357## Check that we report an invalid stack size, which is represented by a ULEB that
358## ends in a byte with the high bit set.
359
360# RUN: yaml2obj --docnum=6 %s -o %t06
361# RUN: llvm-readelf --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06
362# RUN: llvm-readobj --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06
363
364# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size in SHT_PROGBITS section with index 2
365# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size in SHT_PROGBITS section with index 3
366
367--- !ELF
368FileHeader:
369  Class: ELFCLASS64
370  Data:  ELFDATA2LSB
371  Type:  ET_EXEC
372Sections:
373  - Name:    .text
374    Type:    SHT_PROGBITS
375    Flags:   [SHF_ALLOC]
376    Size:    16
377  - Name:    .stack_sizes
378    Type:    SHT_PROGBITS
379    Content: "100000000000000080"
380    Link:    .text
381  - Name:    .stack_sizes (1)
382    Type:    SHT_PROGBITS
383    Content: "100000000000000080"
384    Link:    .text
385Symbols:
386  - Name:    foo
387    Section: .text
388    Value:   0x10
389    Type:    STT_FUNC
390    Binding: STB_GLOBAL
391
392## Check that we report a warning when a relocation symbol does not belong to a
393## valid section. We expect a stack size entry with an unknown symbol in the
394## output.
395
396# RUN: yaml2obj --docnum=7 %s -o %t07
397# RUN: llvm-readelf --stack-sizes %t07 2> %t07-gnu.err | FileCheck %s --check-prefix=BADSECTION-OUT-GNU
398# RUN: FileCheck %s < %t07-gnu.err --check-prefix=BADSECTION-ERR -DFILE=%t07
399# RUN: llvm-readobj --stack-sizes %t07 2> %t07-llvm.err | FileCheck %s --check-prefix=BADSECTION-OUT-LLVM
400# RUN: FileCheck %s < %t07-llvm.err --check-prefix=BADSECTION-ERR -DFILE=%t07
401
402# RUN: llvm-readelf --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07
403# RUN: llvm-readobj --stack-sizes --demangle %t07 2>&1 | FileCheck %s --check-prefix=BADSECTION-DEMANGLE-ERR -DFILE=%t07
404
405# BADSECTION-OUT-GNU: Size Function
406# BADSECTION-OUT-GNU:    8 ?
407
408# BADSECTION-OUT-LLVM:      StackSizes [
409# BADSECTION-OUT-LLVM-NEXT:   Entry {
410# BADSECTION-OUT-LLVM-NEXT:     Function: ?
411# BADSECTION-OUT-LLVM-NEXT:     Size: 0x8
412# BADSECTION-OUT-LLVM-NEXT:   }
413# BADSECTION-OUT-LLVM-NEXT: ]
414
415# BADSECTION-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol '_Z3foof'
416# BADSECTION-DEMANGLE-ERR: warning: '[[FILE]]': cannot identify the section for relocation symbol 'foo(float)'
417
418--- !ELF
419FileHeader:
420  Class:   ELFCLASS64
421  Data:    ELFDATA2LSB
422  Type:    ET_REL
423  Machine: EM_X86_64
424Sections:
425  - Name:    .text
426    Type:    SHT_PROGBITS
427    Size:    8
428  - Name:    .stack_sizes
429    Type:    SHT_PROGBITS
430    Link:    .text
431    Entries:
432      - Size: 0x8
433  - Name:    .rela.stack_sizes
434    Type:    SHT_RELA
435    Info:    .stack_sizes
436    Relocations:
437    - Offset: 0
438      Symbol: _Z3foof
439      Type:   R_X86_64_64
440Symbols:
441  - Name:    _Z3foof
442## An invalid section index.
443    Index:   10
444    Type:    STT_FUNC
445    Binding: STB_GLOBAL
446
447## Check that we report a warning when a stack sizes section does not come with
448## a corresponding relocation section.
449
450# RUN: yaml2obj --docnum=8 %s -o %t08
451# RUN: llvm-readelf --stack-sizes %t08 2> %t08-gnu.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-GNU
452# RUN: FileCheck %s < %t08-gnu.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08
453# RUN: llvm-readobj --stack-sizes %t08 2> %t08-llvm.err | FileCheck %s --check-prefix=NORELOCSECTION-OUT-LLVM
454# RUN: FileCheck %s < %t08-llvm.err --check-prefix=NORELOCSECTION-ERR -DFILE=%t08
455
456# NORELOCSECTION-OUT-GNU:     Size Function
457# NORELOCSECTION-OUT-GNU-NOT: {{.}}
458
459# NORELOCSECTION-OUT-LLVM:      StackSizes [
460# NORELOCSECTION-OUT-LLVM-NEXT: ]
461
462# NORELOCSECTION-ERR: warning: '[[FILE]]': .stack_sizes (SHT_PROGBITS section with index 2) does not have a corresponding relocation section
463
464--- !ELF
465FileHeader:
466  Class: ELFCLASS64
467  Data:  ELFDATA2LSB
468  Type:  ET_REL
469Sections:
470  - Name:    .text
471    Type:    SHT_PROGBITS
472    Size:    8
473  - Name:    .stack_sizes
474    Type:    SHT_PROGBITS
475    Link:    .text
476    Entries:
477      - Size: 0x1
478
479## Check that we handle multiple object files, separately and when they
480## are in an archive. This also checks whether we have blank lines between the
481## tables.
482
483# RUN: llvm-ar rc %t1.a %t01 %t02
484# RUN: llvm-readelf --stack-sizes %t01 %t02 \
485# RUN:   | FileCheck %s --check-prefixes=MULTIPLE-GNU,OBJECT -DFILE1=%t01 -DFILE2=%t02
486# RUN: llvm-readelf --stack-sizes %t1.a \
487# RUN:   | FileCheck %s --check-prefixes=MULTIPLE-GNU,ARCHIVE --strict-whitespace\
488# RUN:   --match-full-lines -DFILE=%t1.a
489# RUN: llvm-readobj --stack-sizes %t01 %t02 \
490# RUN:   | FileCheck %s --check-prefixes=MULTIPLE-LLVM,OBJECT -DFILE1=%t01 -DFILE2=%t02
491# RUN: llvm-readobj --stack-sizes %t1.a \
492# RUN:   | FileCheck %s --check-prefixes=MULTIPLE-LLVM,ARCHIVE -DFILE=%t1.a
493
494#        OBJECT:File: [[FILE1]]
495#       ARCHIVE:File: [[FILE]]({{.*01}})
496
497#      MULTIPLE-GNU:Stack Sizes:
498# MULTIPLE-GNU-NEXT:         Size     Function
499# MULTIPLE-GNU-NEXT:           16     referenced_by_symbol_foo
500# MULTIPLE-GNU-NEXT:           32     referenced_via_section_bar
501# MULTIPLE-GNU-NEXT:            8     separate_text_section_baz
502# MULTIPLE-GNU-EMPTY:
503
504# MULTIPLE-LLVM:      StackSizes [
505# MULTIPLE-LLVM-NEXT:   Entry {
506# MULTIPLE-LLVM-NEXT:     Function: referenced_by_symbol_foo
507# MULTIPLE-LLVM-NEXT:     Size: 0x10
508# MULTIPLE-LLVM-NEXT:   }
509# MULTIPLE-LLVM-NEXT:   Entry {
510# MULTIPLE-LLVM-NEXT:     Function: referenced_via_section_bar
511# MULTIPLE-LLVM-NEXT:     Size: 0x20
512# MULTIPLE-LLVM-NEXT:   }
513# MULTIPLE-LLVM-NEXT:   Entry {
514# MULTIPLE-LLVM-NEXT:     Function: separate_text_section_baz
515# MULTIPLE-LLVM-NEXT:     Size: 0x8
516# MULTIPLE-LLVM-NEXT:   }
517# MULTIPLE-LLVM-NEXT: ]
518
519#        OBJECT:File: [[FILE2]]
520#       ARCHIVE:File: [[FILE]]({{.*02}})
521
522# MULTIPLE-GNU-EMPTY:
523# MULTIPLE-GNU-NEXT:Stack Sizes:
524# MULTIPLE-GNU-NEXT:         Size     Function
525# MULTIPLE-GNU-NEXT:           16     other
526# MULTIPLE-GNU-NEXT:           32     other_end
527# MULTIPLE-GNU-NEXT:           48     bar
528
529# MULTIPLE-LLVM:      StackSizes [
530# MULTIPLE-LLVM-NEXT:   Entry {
531# MULTIPLE-LLVM-NEXT:     Function: other
532# MULTIPLE-LLVM-NEXT:     Size: 0x10
533# MULTIPLE-LLVM-NEXT:   }
534# MULTIPLE-LLVM-NEXT:   Entry {
535# MULTIPLE-LLVM-NEXT:     Function: other_end
536# MULTIPLE-LLVM-NEXT:     Size: 0x20
537# MULTIPLE-LLVM-NEXT:   }
538# MULTIPLE-LLVM-NEXT:   Entry {
539# MULTIPLE-LLVM-NEXT:     Function: bar
540# MULTIPLE-LLVM-NEXT:     Size: 0x30
541# MULTIPLE-LLVM-NEXT:   }
542# MULTIPLE-LLVM-NEXT: ]
543
544## Check that we do not consider symbols that are not function symbols, even though
545## a relocation references them.
546
547# RUN: yaml2obj --docnum=9 %s -o %t14
548# RUN: llvm-readelf --stack-sizes %t14 2> %t14-gnu.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-GNU
549# RUN: FileCheck %s < %t14-gnu.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14
550# RUN: llvm-readobj --stack-sizes %t14 2> %t14-llvm.err | FileCheck %s --check-prefix=NONFUNCTIONSYM-LLVM
551# RUN: FileCheck %s < %t14-llvm.err --check-prefix=NONFUNCTIONSYM-ERR -DFILE=%t14
552
553# NONFUNCTIONSYM-GNU:     Stack Sizes:
554# NONFUNCTIONSYM-GNU:     0 ?
555
556# NONFUNCTIONSYM-LLVM:      StackSizes [
557# NONFUNCTIONSYM-LLVM-NEXT:   Entry {
558# NONFUNCTIONSYM-LLVM-NEXT:     Function: ?
559# NONFUNCTIONSYM-LLVM-NEXT:     Size: 0x0
560# NONFUNCTIONSYM-LLVM-NEXT:   }
561# NONFUNCTIONSYM-LLVM-NEXT: ]
562
563# NONFUNCTIONSYM-ERR: warning: '[[FILE]]': could not identify function symbol for stack size entry
564
565--- !ELF
566FileHeader:
567  Class:   ELFCLASS64
568  Data:    ELFDATA2LSB
569  Type:    ET_REL
570  Machine: EM_X86_64
571Sections:
572  - Name: .text
573    Type: SHT_PROGBITS
574    Size: 16
575  - Name: .stack_sizes
576    Type: SHT_PROGBITS
577    Entries:
578      - Size: 0
579    Link: .text
580  - Name: .rela.stack_sizes
581    Type: SHT_RELA
582    Info: .stack_sizes
583    Relocations:
584      - Offset: 0
585        Symbol: foo
586        Type:   R_X86_64_64
587Symbols:
588  - Name:    foo
589    Section: .text
590    Type:    STT_OBJECT
591    Binding: STB_GLOBAL
592
593## Check that we report a warning when we find an unsupported relocation
594## in the section that contains the stack size entries' relocations.
595
596# RUN: yaml2obj --docnum=10 %s -o %t15
597# RUN: llvm-readelf --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC-GNU -DFILE=%t15
598# RUN: llvm-readobj --stack-sizes %t15 2>&1 | FileCheck %s --check-prefix=UNSUPPRELOC-LLVM -DFILE=%t15
599
600# UNSUPPRELOC-GNU:      Stack Sizes:
601# UNSUPPRELOC-GNU-NEXT:   Size     Function
602# UNSUPPRELOC-GNU-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 1: R_X86_64_RELATIVE
603# UNSUPPRELOC-GNU-NEXT:      0     foo
604# UNSUPPRELOC-GNU-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 3: R_X86_64_RELATIVE
605
606# UNSUPPRELOC-LLVM:      StackSizes [
607# UNSUPPRELOC-LLVM-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 1: R_X86_64_RELATIVE
608# UNSUPPRELOC-LLVM-NEXT:   Entry {
609# UNSUPPRELOC-LLVM-NEXT:     Function: foo
610# UNSUPPRELOC-LLVM-NEXT:     Size: 0x0
611# UNSUPPRELOC-LLVM-NEXT:   }
612# UNSUPPRELOC-LLVM-NEXT: warning: '[[FILE]]': SHT_RELA section with index 3 contains an unsupported relocation with index 3: R_X86_64_RELATIVE
613# UNSUPPRELOC-LLVM-NEXT: ]
614
615--- !ELF
616FileHeader:
617  Class:   ELFCLASS64
618  Data:    ELFDATA2LSB
619  Type:    ET_REL
620  Machine: EM_X86_64
621Sections:
622  - Name: .text
623    Type: SHT_PROGBITS
624    Size: 8
625  - Name: .stack_sizes
626    Type: SHT_PROGBITS
627    Link: .text
628    Entries:
629      - Size: 0
630  - Name: .rela.stack_sizes
631    Type: SHT_RELA
632    Info: .stack_sizes
633    Relocations:
634      - Offset: 0
635        Symbol: foo
636        Type:   R_X86_64_RELATIVE
637      - Offset: 0
638        Symbol: foo
639        Type:   R_X86_64_64
640      - Offset: 0
641        Symbol: foo
642        Type:   R_X86_64_RELATIVE
643Symbols:
644  - Name:    foo
645    Section: .text
646    Type:    STT_FUNC
647    Binding: STB_GLOBAL
648
649## Check that warning messages in archives do not impact other members. In the following
650## test, the first archive member generates a warning and we make sure all the information
651## is still dumped.
652
653# RUN: llvm-ar rc %t2.a %t04 %t01
654# RUN: llvm-readelf --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-GNU \
655# RUN:   -DFILE=%t2.a --strict-whitespace --match-full-lines
656# RUN: llvm-readobj --stack-sizes %t2.a 2>&1 | FileCheck %s --check-prefix=ARCHIVEWARN-LLVM -DFILE=%t2.a
657
658#      ARCHIVEWARN-GNU:File: [[FILE]]({{.*04}})
659#      ARCHIVEWARN-GNU:Stack Sizes:
660# ARCHIVEWARN-GNU-NEXT:         Size     Function
661#      ARCHIVEWARN-GNU:{{.*}}: warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section
662#      ARCHIVEWARN-GNU:            8     _Z3foof
663#      ARCHIVEWARN-GNU:File: [[FILE]]({{.*01}})
664#      ARCHIVEWARN-GNU:Stack Sizes:
665# ARCHIVEWARN-GNU-NEXT:         Size     Function
666# ARCHIVEWARN-GNU-NEXT:           16     referenced_by_symbol_foo
667# ARCHIVEWARN-GNU-NEXT:           32     referenced_via_section_bar
668# ARCHIVEWARN-GNU-NEXT:            8     separate_text_section_baz
669#  ARCHIVEWARN-GNU-NOT:{{.}}
670
671
672# ARCHIVEWARN-LLVM:      File: [[FILE]]({{.*04}})
673# ARCHIVEWARN-LLVM:      StackSizes [
674# ARCHIVEWARN-LLVM:      warning: '{{.*04}}': relocation symbol '_Z3foof' is not in the expected section
675# ARCHIVEWARN-LLVM-NEXT:   Entry {
676# ARCHIVEWARN-LLVM-NEXT:     Function: _Z3foof
677# ARCHIVEWARN-LLVM-NEXT:     Size: 0x8
678# ARCHIVEWARN-LLVM-NEXT:   }
679# ARCHIVEWARN-LLVM-NEXT: ]
680# ARCHIVEWARN-LLVM:      File: [[FILE]]({{.*01}})
681# ARCHIVEWARN-LLVM:      StackSizes [
682# ARCHIVEWARN-LLVM-NEXT:   Entry {
683# ARCHIVEWARN-LLVM-NEXT:     Function: referenced_by_symbol_foo
684# ARCHIVEWARN-LLVM-NEXT:     Size: 0x10
685# ARCHIVEWARN-LLVM-NEXT:   }
686# ARCHIVEWARN-LLVM-NEXT:   Entry {
687# ARCHIVEWARN-LLVM-NEXT:     Function: referenced_via_section_bar
688# ARCHIVEWARN-LLVM-NEXT:     Size: 0x20
689# ARCHIVEWARN-LLVM-NEXT:   }
690# ARCHIVEWARN-LLVM-NEXT:   Entry {
691# ARCHIVEWARN-LLVM-NEXT:     Function: separate_text_section_baz
692# ARCHIVEWARN-LLVM-NEXT:     Size: 0x8
693# ARCHIVEWARN-LLVM-NEXT:   }
694# ARCHIVEWARN-LLVM-NEXT: ]
695
696## Check that we demangle function names when requested.
697
698# RUN: yaml2obj --docnum=11 %s -o %t16
699# RUN: llvm-readelf --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-GNU
700# RUN: llvm-readobj --stack-sizes --demangle %t16 | FileCheck %s --check-prefix=DEMANGLE-LLVM
701
702# DEMANGLE-GNU:  16 foo(float)
703# DEMANGLE-LLVM: Function: foo(float)
704
705--- !ELF
706FileHeader:
707  Class: ELFCLASS64
708  Data:  ELFDATA2LSB
709  Type:  ET_EXEC
710Sections:
711  - Name:    .text
712    Type:    SHT_PROGBITS
713    Flags:   [SHF_ALLOC]
714    Size:    16
715  - Name:    .stack_sizes
716    Type:    SHT_PROGBITS
717    Entries:
718      - Address: 0x10
719        Size:    0x10
720    Link:    .text
721Symbols:
722  - Name:    _Z3foof
723    Section: .text
724    Value:   0x10
725    Type:    STT_FUNC
726    Binding: STB_GLOBAL
727
728## Check that we report a warning when we are unable to resolve a relocation for a given ELF architecture.
729## Here we have a 64-bit relocation used in a 32-bit object.
730
731# RUN: yaml2obj --docnum=12 %s -o %t17
732# RUN: llvm-readelf --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2
733# RUN: llvm-readobj --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2
734
735# UNSUPPRELOC2: warning: '[[FILE]]': SHT_RELA section with index 2 contains an unsupported relocation with index 1: R_X86_64_64
736
737--- !ELF
738FileHeader:
739  Class:   ELFCLASS32
740  Data:    ELFDATA2MSB
741  Type:    ET_REL
742  Machine: EM_X86_64
743Sections:
744  - Name: .stack_sizes
745    Type: SHT_PROGBITS
746    Content: "00"
747  - Name: .rela.stack_sizes
748    Type: SHT_RELA
749    Info: .stack_sizes
750    Relocations:
751      - Offset: 0
752        Type:   R_X86_64_64
753
754## Check we report a warning when dumping stack sizes if the relocated section
755## identified by the sh_info field is invalid. Here the sh_info value is larger than
756## the number of sections.
757
758# RUN: yaml2obj --docnum=13 %s -o %t18
759# RUN: llvm-readelf --stack-sizes %t18 2>&1 | \
760# RUN:   FileCheck %s --implicit-check-not="warning:" -DFILE=%t18 --check-prefix=INVALID-TARGET
761# RUN: llvm-readobj --stack-sizes %t18 2>&1 | \
762# RUN:   FileCheck %s --implicit-check-not="warning:" -DFILE=%t18 --check-prefix=INVALID-TARGET
763
764# INVALID-TARGET: warning: '[[FILE]]': SHT_RELA section with index 1: failed to get a relocated section: invalid section index: 255
765# INVALID-TARGET: warning: '[[FILE]]': SHT_RELA section with index 2: failed to get a relocated section: invalid section index: 255
766
767--- !ELF
768FileHeader:
769  Class: ELFCLASS32
770  Data:  ELFDATA2MSB
771  Type:  ET_REL
772Sections:
773  - Name: .rela.stack_sizes
774    Type: SHT_RELA
775    Link: 0
776    Info: 0xFF
777    Relocations: []
778  - Name: .rela.stack_sizes (1)
779    Type: SHT_RELA
780    Link: 0
781    Info: 0xFF
782    Relocations: []
783