1## Here we test how the --stackmap option can be used to dump .llvm_stackmaps sections.
2
3## Check we are able to dump an empty .llvm_stackmaps section. Document that
4## we are only trying to dump the first stack map section and ignore others if any.
5
6# RUN: yaml2obj %s -o %t
7# RUN: llvm-readobj %t --stackmap 2>&1 | \
8# RUN:   FileCheck %s --check-prefix=EMPTY --implicit-check-not=warning:
9# RUN: llvm-readelf %t --stackmap 2>&1 | \
10# RUN:   FileCheck %s --check-prefix=EMPTY --implicit-check-not=warning:
11
12# EMPTY:      LLVM StackMap Version: 3
13# EMPTY-NEXT: Num Functions: 0
14# EMPTY-NEXT: Num Constants: 0
15# EMPTY-NEXT: Num Records: 0
16# EMPTY-NOT:  {{.}}
17
18--- !ELF
19FileHeader:
20  Class: ELFCLASS64
21  Data:  ELFDATA2LSB
22  Type:  ET_REL
23Sections:
24  - Name:         [[NAME=.llvm_stackmaps]]
25    Type:         SHT_PROGBITS
26    ContentArray: [ [[VERSION=0x3]] ]
27    Size:         [[SIZE=16]]
28    ShSize:       [[SHSIZE=<none>]]
29    ShOffset:     [[SHOFFSET=<none>]]
30## An arbitrary second broken .llvm_stackmaps section.
31  - Name:         .llvm_stackmaps (1)
32    Type:         SHT_PROGBITS
33    ContentArray: [ 0xFF ]
34    Size:         0x1
35
36## Hide the first stack map section to allow dumpers to locate and validate the second one, which is broken.
37## Check we are able to find it and report a warning properly.
38
39# RUN: yaml2obj %s -DNAME=.foo -o %t.second
40# RUN: llvm-readobj %t.second --stackmap 2>&1 | \
41# RUN:   FileCheck %s --check-prefix=SECOND -DFILE=%t.second --implicit-check-not=warning:
42# RUN: llvm-readelf %t.second --stackmap 2>&1 | \
43# RUN:   FileCheck %s --check-prefix=SECOND -DFILE=%t.second --implicit-check-not=warning:
44
45# SECOND: warning: '[[FILE]]': unable to read the stack map from SHT_PROGBITS section with index 2: the stack map section size (1) is less than the minimum possible size of its header (16)
46
47## Check we report a warning when the size of the .llvm_stackmaps section is less
48## than the minimum possible size of its header.
49
50# RUN: yaml2obj %s -DSHSIZE=0 -o %t.trunc0
51# RUN: llvm-readobj %t.trunc0 --stackmap 2>&1 | FileCheck %s -DFILE=%t.trunc0 --check-prefix=TRUNC -DVAL=0
52# RUN: llvm-readelf %t.trunc0 --stackmap 2>&1 | FileCheck %s -DFILE=%t.trunc0 --check-prefix=TRUNC -DVAL=0
53
54# RUN: yaml2obj %s -DSIZE=1 -o %t.trunc1
55# RUN: llvm-readobj %t.trunc1 --stackmap 2>&1 | FileCheck %s -DFILE=%t.trunc1 --check-prefix=TRUNC -DVAL=1
56# RUN: llvm-readelf %t.trunc1 --stackmap 2>&1 | FileCheck %s -DFILE=%t.trunc1 --check-prefix=TRUNC -DVAL=1
57
58# RUN: yaml2obj %s -DSIZE=15 -o %t.trunc15
59# RUN: llvm-readobj %t.trunc15 --stackmap 2>&1 | FileCheck %s -DFILE=%t.trunc15 --check-prefix=TRUNC -DVAL=15
60# RUN: llvm-readelf %t.trunc15 --stackmap 2>&1 | FileCheck %s -DFILE=%t.trunc15 --check-prefix=TRUNC -DVAL=15
61
62# TRUNC: warning: '[[FILE]]': unable to read the stack map from SHT_PROGBITS section with index 1: the stack map section size ([[VAL]]) is less than the minimum possible size of its header (16)
63
64## Check that we report a warning when the version of the stack map section is not supported.
65
66# RUN: yaml2obj %s -DVERSION=2 -o %t.ver2
67# RUN: llvm-readobj %t.ver2 --stackmap 2>&1 | \
68# RUN:   FileCheck %s --check-prefix=VERSION -DFILE=%t.ver2 --implicit-check-not=warning: -DVERSION=2
69# RUN: llvm-readelf %t.ver2 --stackmap 2>&1 | \
70# RUN:   FileCheck %s --check-prefix=VERSION -DFILE=%t.ver2 --implicit-check-not=warning: -DVERSION=2
71
72# RUN: yaml2obj %s -DVERSION=4 -o %t.ver4
73# RUN: llvm-readobj %t.ver4 --stackmap 2>&1 | \
74# RUN:   FileCheck %s --check-prefix=VERSION -DFILE=%t.ver4 --implicit-check-not=warning: -DVERSION=4
75# RUN: llvm-readelf %t.ver4 --stackmap 2>&1 | \
76# RUN:   FileCheck %s --check-prefix=VERSION -DFILE=%t.ver4 --implicit-check-not=warning: -DVERSION=4
77
78# VERSION: warning: '[[FILE]]': unable to read the stack map from SHT_PROGBITS section with index 1: the version ([[VERSION]]) of the stack map section is unsupported, the supported version is 3
79
80## Check that we report a warning when we are unable to read the content of the stack map section.
81# RUN: yaml2obj %s -DSHOFFSET=0xffff -o %t.offset
82# RUN: llvm-readobj %t.offset --stackmap 2>&1 | FileCheck %s -DFILE=%t.offset --check-prefix=OFFSET
83# RUN: llvm-readelf %t.offset --stackmap 2>&1 | FileCheck %s -DFILE=%t.offset --check-prefix=OFFSET
84
85# OFFSET: warning: '[[FILE]]': unable to read the stack map from SHT_PROGBITS section with index 1: section [index 1] has a sh_offset (0xffff) + sh_size (0x10) that is greater than the file size (0x1b8)
86