Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / riscv-attributes.s
blobd0ce0941269ec4303ee0afa5a4eca1f34e0aac52
1 # REQUIRES: riscv
3 # RUN: rm -rf %t && split-file %s %t && cd %t
4 # RUN: llvm-mc -filetype=obj -triple=riscv64 a.s -o a.o
5 # RUN: ld.lld -e 0 a.o -o out 2>&1 | count 0
6 # RUN: llvm-readelf -S -l --arch-specific out | FileCheck %s --check-prefixes=HDR,CHECK
7 # RUN: ld.lld -e 0 a.o a.o -o out1 2>&1 | count 0
8 # RUN: llvm-readobj --arch-specific out1 | FileCheck %s
9 # RUN: ld.lld -r a.o a.o -o out1 2>&1 | count 0
10 # RUN: llvm-readobj --arch-specific out1 | FileCheck %s
12 # RUN: llvm-mc -filetype=obj -triple=riscv64 b.s -o b.o
13 # RUN: llvm-mc -filetype=obj -triple=riscv64 c.s -o c.o
14 # RUN: ld.lld a.o b.o c.o -o out2
15 # RUN: llvm-readobj --arch-specific out2 | FileCheck %s --check-prefix=CHECK2
17 # RUN: llvm-mc -filetype=obj -triple=riscv64 unrecognized_ext1.s -o unrecognized_ext1.o
18 # RUN: ld.lld -e 0 unrecognized_ext1.o -o unrecognized_ext1 2>&1 | count 0
19 # RUN: llvm-readobj --arch-specific unrecognized_ext1 | FileCheck %s --check-prefix=UNRECOGNIZED_EXT1
21 # RUN: llvm-mc -filetype=obj -triple=riscv64 unrecognized_ext2.s -o unrecognized_ext2.o
22 # RUN: ld.lld -e 0 unrecognized_ext2.o -o unrecognized_ext2 2>&1 | count 0
23 # RUN: llvm-readobj --arch-specific unrecognized_ext2 | FileCheck %s --check-prefix=UNRECOGNIZED_EXT2
25 # RUN: llvm-mc -filetype=obj -triple=riscv64 unrecognized_version.s -o unrecognized_version.o
26 # RUN: ld.lld -e 0 unrecognized_version.o -o unrecognized_version 2>&1 | count 0
27 # RUN: llvm-readobj --arch-specific unrecognized_version | FileCheck %s --check-prefix=UNRECOGNIZED_VERSION
29 # RUN: llvm-mc -filetype=obj -triple=riscv64 merge_version_test_input.s -o merge_version_test_input.o
30 # RUN: ld.lld -e 0 unrecognized_version.o merge_version_test_input.o -o out3 2>&1 | count 0
31 # RUN: llvm-readobj --arch-specific out3 | FileCheck %s --check-prefix=CHECK3
33 # RUN: llvm-mc -filetype=obj -triple=riscv64 invalid_arch1.s -o invalid_arch1.o
34 # RUN: not ld.lld invalid_arch1.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=INVALID_ARCH1 --implicit-check-not=error:
35 # INVALID_ARCH1: error: invalid_arch1.o:(.riscv.attributes): rv64i2: extension lacks version in expected format
37 ## A zero value attribute is not printed.
38 # RUN: llvm-mc -filetype=obj -triple=riscv64 unaligned_access_0.s -o unaligned_access_0.o
39 # RUN: ld.lld -e 0 --fatal-warnings a.o unaligned_access_0.o -o unaligned_access_0
40 # RUN: llvm-readobj -A unaligned_access_0 | FileCheck /dev/null --implicit-check-not='TagName: unaligned_access'
42 ## Differing stack_align values lead to an error.
43 # RUN: llvm-mc -filetype=obj -triple=riscv64 diff_stack_align.s -o diff_stack_align.o
44 # RUN: not ld.lld a.o b.o c.o diff_stack_align.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=STACK_ALIGN --implicit-check-not=error:
45 # STACK_ALIGN: error: diff_stack_align.o:(.riscv.attributes) has stack_align=32 but a.o:(.riscv.attributes) has stack_align=16
47 ## The deprecated priv_spec is not handled as GNU ld does.
48 ## Differing priv_spec attributes lead to an absent attribute.
49 # RUN: llvm-mc -filetype=obj -triple=riscv64 diff_priv_spec.s -o diff_priv_spec.o
50 # RUN: ld.lld -e 0 --fatal-warnings a.o b.o c.o diff_priv_spec.o -o diff_priv_spec
51 # RUN: llvm-readobj -A diff_priv_spec | FileCheck /dev/null --implicit-check-not='TagName: priv_spec'
53 ## Unknown tags currently lead to warnings.
54 # RUN: llvm-mc -filetype=obj -triple=riscv64 unknown13.s -o unknown13.o
55 # RUN: llvm-mc -filetype=obj -triple=riscv64 unknown13a.s -o unknown13a.o
56 # RUN: ld.lld -e 0 unknown13.o unknown13.o unknown13a.o -o unknown13 2>&1 | FileCheck %s --check-prefix=UNKNOWN13 --implicit-check-not=warning:
57 # UNKNOWN13-COUNT-2: warning: unknown13.o:(.riscv.attributes): invalid tag 0xd at offset 0x10
58 # UNKNOWN13: warning: unknown13a.o:(.riscv.attributes): invalid tag 0xd at offset 0x10
60 # RUN: llvm-mc -filetype=obj -triple=riscv64 unknown22.s -o unknown22.o
61 # RUN: llvm-mc -filetype=obj -triple=riscv64 unknown22a.s -o unknown22a.o
62 # RUN: ld.lld -e 0 unknown22.o unknown22.o unknown22a.o -o unknown22 2>&1 | FileCheck %s --check-prefix=UNKNOWN22 --implicit-check-not=warning:
63 # UNKNOWN22-COUNT-2: warning: unknown22.o:(.riscv.attributes): invalid tag 0x16 at offset 0x10
64 # UNKNOWN22: warning: unknown22a.o:(.riscv.attributes): invalid tag 0x16 at offset 0x10
66 # HDR: Name Type Address Off Size ES Flg Lk Inf Al
67 # HDR: .riscv.attributes RISCV_ATTRIBUTES 0000000000000000 000158 00003e 00 0 0 1{{$}}
69 # HDR: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
70 # HDR: LOAD 0x000000 0x0000000000010000 0x0000000000010000 0x000158 0x000158 R 0x1000
71 # HDR-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0
72 # HDR-NEXT: ATTRIBUTES 0x000158 0x0000000000000000 0x0000000000000000 0x00003e 0x00003e R 0x1{{$}}
74 # CHECK: BuildAttributes {
75 # CHECK-NEXT: FormatVersion: 0x41
76 # CHECK-NEXT: Section 1 {
77 # CHECK-NEXT: SectionLength: 61
78 # CHECK-NEXT: Vendor: riscv
79 # CHECK-NEXT: Tag: Tag_File (0x1)
80 # CHECK-NEXT: Size: 51
81 # CHECK-NEXT: FileAttributes {
82 # CHECK-NEXT: Attribute {
83 # CHECK-NEXT: Tag: 4
84 # CHECK-NEXT: Value: 16
85 # CHECK-NEXT: TagName: stack_align
86 # CHECK-NEXT: Description: Stack alignment is 16-bytes
87 # CHECK-NEXT: }
88 # CHECK-NEXT: Attribute {
89 # CHECK-NEXT: Tag: 5
90 # CHECK-NEXT: TagName: arch
91 # CHECK-NEXT: Value: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0{{$}}
92 # CHECK-NEXT: }
93 # CHECK-NEXT: }
94 # CHECK-NEXT: }
95 # CHECK-NEXT: }
97 # CHECK2: BuildAttributes {
98 # CHECK2-NEXT: FormatVersion: 0x41
99 # CHECK2-NEXT: Section 1 {
100 # CHECK2-NEXT: SectionLength: 104
101 # CHECK2-NEXT: Vendor: riscv
102 # CHECK2-NEXT: Tag: Tag_File (0x1)
103 # CHECK2-NEXT: Size: 94
104 # CHECK2-NEXT: FileAttributes {
105 # CHECK2-NEXT: Attribute {
106 # CHECK2-NEXT: Tag: 4
107 # CHECK2-NEXT: Value: 16
108 # CHECK2-NEXT: TagName: stack_align
109 # CHECK2-NEXT: Description: Stack alignment is 16-bytes
110 # CHECK2-NEXT: }
111 # CHECK2-NEXT: Attribute {
112 # CHECK2-NEXT: Tag: 6
113 # CHECK2-NEXT: Value: 1
114 # CHECK2-NEXT: TagName: unaligned_access
115 # CHECK2-NEXT: Description: Unaligned access
116 # CHECK2-NEXT: }
117 # CHECK2-NEXT: Attribute {
118 # CHECK2-NEXT: Tag: 8
119 # CHECK2-NEXT: TagName: priv_spec
120 # CHECK2-NEXT: Value: 2
121 # CHECK2-NEXT: }
122 # CHECK2-NEXT: Attribute {
123 # CHECK2-NEXT: Tag: 10
124 # CHECK2-NEXT: TagName: priv_spec_minor
125 # CHECK2-NEXT: Value: 2
126 # CHECK2-NEXT: }
127 # CHECK2-NEXT: Attribute {
128 # CHECK2-NEXT: Tag: 5
129 # CHECK2-NEXT: TagName: arch
130 # CHECK2-NEXT: Value: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0{{$}}
131 # CHECK2-NEXT: }
132 # CHECK2-NEXT: }
133 # CHECK2-NEXT: }
134 # CHECK2-NEXT: }
136 # CHECK3: BuildAttributes {
137 # CHECK3-NEXT: FormatVersion: 0x41
138 # CHECK3-NEXT: Section 1 {
139 # CHECK3-NEXT: SectionLength: 26
140 # CHECK3-NEXT: Vendor: riscv
141 # CHECK3-NEXT: Tag: Tag_File (0x1)
142 # CHECK3-NEXT: Size: 16
143 # CHECK3-NEXT: FileAttributes {
144 # CHECK3-NEXT: Attribute {
145 # CHECK3-NEXT: Tag: 5
146 # CHECK3-NEXT: TagName: arch
147 # CHECK3-NEXT: Value: rv64i99p0{{$}}
148 # CHECK3-NEXT: }
149 # CHECK3-NEXT: }
150 # CHECK3-NEXT: }
151 # CHECK3-NEXT: }
153 #--- a.s
154 .attribute stack_align, 16
155 .attribute arch, "rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0"
156 .attribute unaligned_access, 0
158 #--- b.s
159 .attribute stack_align, 16
160 .attribute arch, "rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0"
161 .attribute priv_spec, 2
162 .attribute priv_spec_minor, 2
164 #--- c.s
165 .attribute stack_align, 16
166 .attribute arch, "rv64i2p1_f2p2_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
167 .attribute unaligned_access, 1
168 .attribute priv_spec, 2
169 .attribute priv_spec_minor, 2
171 #--- unrecognized_ext1.s
172 # UNRECOGNIZED_EXT1: BuildAttributes {
173 # UNRECOGNIZED_EXT1-NEXT: FormatVersion: 0x41
174 # UNRECOGNIZED_EXT1-NEXT: Section 1 {
175 # UNRECOGNIZED_EXT1-NEXT: SectionLength: 30
176 # UNRECOGNIZED_EXT1-NEXT: Vendor: riscv
177 # UNRECOGNIZED_EXT1-NEXT: Tag: Tag_File (0x1)
178 # UNRECOGNIZED_EXT1-NEXT: Size: 20
179 # UNRECOGNIZED_EXT1-NEXT: FileAttributes {
180 # UNRECOGNIZED_EXT1-NEXT: Attribute {
181 # UNRECOGNIZED_EXT1-NEXT: Tag: 5
182 # UNRECOGNIZED_EXT1-NEXT: TagName: arch
183 # UNRECOGNIZED_EXT1-NEXT: Value: rv64i2p1_y2p0{{$}}
184 # UNRECOGNIZED_EXT1-NEXT: }
185 # UNRECOGNIZED_EXT1-NEXT: }
186 # UNRECOGNIZED_EXT1-NEXT: }
187 # UNRECOGNIZED_EXT1-NEXT: }
188 .section .riscv.attributes,"",@0x70000003
189 .byte 0x41
190 .long .Lend-.riscv.attributes-1
191 .asciz "riscv" # vendor
192 .Lbegin:
193 .byte 1 # Tag_File
194 .long .Lend-.Lbegin
195 .byte 5 # Tag_RISCV_arch
196 .asciz "rv64i2p1_y2p0"
197 .Lend:
199 #--- unrecognized_ext2.s
200 # UNRECOGNIZED_EXT2: BuildAttributes {
201 # UNRECOGNIZED_EXT2-NEXT: FormatVersion: 0x41
202 # UNRECOGNIZED_EXT2-NEXT: Section 1 {
203 # UNRECOGNIZED_EXT2-NEXT: SectionLength: 36
204 # UNRECOGNIZED_EXT2-NEXT: Vendor: riscv
205 # UNRECOGNIZED_EXT2-NEXT: Tag: Tag_File (0x1)
206 # UNRECOGNIZED_EXT2-NEXT: Size: 26
207 # UNRECOGNIZED_EXT2-NEXT: FileAttributes {
208 # UNRECOGNIZED_EXT2-NEXT: Attribute {
209 # UNRECOGNIZED_EXT2-NEXT: Tag: 5
210 # UNRECOGNIZED_EXT2-NEXT: TagName: arch
211 # UNRECOGNIZED_EXT2-NEXT: Value: rv64i2p1_zmadeup1p0{{$}}
212 # UNRECOGNIZED_EXT2-NEXT: }
213 # UNRECOGNIZED_EXT2-NEXT: }
214 # UNRECOGNIZED_EXT2-NEXT: }
215 # UNRECOGNIZED_EXT2-NEXT: }
216 .section .riscv.attributes,"",@0x70000003
217 .byte 0x41
218 .long .Lend-.riscv.attributes-1
219 .asciz "riscv" # vendor
220 .Lbegin:
221 .byte 1 # Tag_File
222 .long .Lend-.Lbegin
223 .byte 5 # Tag_RISCV_arch
224 .asciz "rv64i2p1_zmadeup1p0"
225 .Lend:
227 #--- unrecognized_version.s
228 # UNRECOGNIZED_VERSION: BuildAttributes {
229 # UNRECOGNIZED_VERSION-NEXT: FormatVersion: 0x41
230 # UNRECOGNIZED_VERSION-NEXT: Section 1 {
231 # UNRECOGNIZED_VERSION-NEXT: SectionLength: 26
232 # UNRECOGNIZED_VERSION-NEXT: Vendor: riscv
233 # UNRECOGNIZED_VERSION-NEXT: Tag: Tag_File (0x1)
234 # UNRECOGNIZED_VERSION-NEXT: Size: 16
235 # UNRECOGNIZED_VERSION-NEXT: FileAttributes {
236 # UNRECOGNIZED_VERSION-NEXT: Attribute {
237 # UNRECOGNIZED_VERSION-NEXT: Tag: 5
238 # UNRECOGNIZED_VERSION-NEXT: TagName: arch
239 # UNRECOGNIZED_VERSION-NEXT: Value: rv64i99p0
240 # UNRECOGNIZED_VERSION-NEXT: }
241 # UNRECOGNIZED_VERSION-NEXT: }
242 # UNRECOGNIZED_VERSION-NEXT: }
243 # UNRECOGNIZED_VERSION-NEXT: }
244 .section .riscv.attributes,"",@0x70000003
245 .byte 0x41
246 .long .Lend-.riscv.attributes-1
247 .asciz "riscv" # vendor
248 .Lbegin:
249 .byte 1 # Tag_File
250 .long .Lend-.Lbegin
251 .byte 5 # Tag_RISCV_arch
252 .asciz "rv64i99p0"
253 .Lend:
255 #--- merge_version_test_input.s
256 .section .riscv.attributes,"",@0x70000003
257 .byte 0x41
258 .long .Lend-.riscv.attributes-1
259 .asciz "riscv" # vendor
260 .Lbegin:
261 .byte 1 # Tag_File
262 .long .Lend-.Lbegin
263 .byte 5 # Tag_RISCV_arch
264 .asciz "rv64i2p1"
265 .Lend:
267 #--- invalid_arch1.s
268 .section .riscv.attributes,"",@0x70000003
269 .byte 0x41
270 .long .Lend-.riscv.attributes-1
271 .asciz "riscv" # vendor
272 .Lbegin:
273 .byte 1 # Tag_File
274 .long .Lend-.Lbegin
275 .byte 5 # Tag_RISCV_arch
276 .asciz "rv64i2"
277 .Lend:
279 #--- unaligned_access_0.s
280 .attribute unaligned_access, 0
282 #--- diff_stack_align.s
283 .attribute stack_align, 32
285 #--- diff_priv_spec.s
286 .attribute priv_spec, 3
287 .attribute priv_spec_minor, 3
289 #--- unknown13.s
290 .attribute 13, "0"
291 #--- unknown13a.s
292 .attribute 13, "1"
294 #--- unknown22.s
295 .attribute 22, 1
296 #--- unknown22a.s
297 .attribute 22, 2