1 ; RUN: llc < %s -mtriple=x86_64 -unique-section-names=0 -data-sections 2>&1 \
4 ;; Several sections are created via inline assembly. We add checks
5 ;; for these lines as we want to use --implicit-check-not to reduce the
6 ;; number of checks in this file.
7 ; CHECK: .section .asm_mergeable1,"aMS",@progbits,2{{$}}
8 ; CHECK-NEXT: .section .asm_nonmergeable1,"a",@progbits{{$}}
9 ; CHECK-NEXT: .section .asm_mergeable2,"aMS",@progbits,2{{$}}
10 ; CHECK-NEXT: .section .asm_nonmergeable2,"a",@progbits{{$}}
12 ;; Test implicit section assignment for symbols
13 ; CHECK: .section .data,"aw",@progbits,unique,1
16 ;; Create a uniquified symbol (as -unique-section-names=0) to test the uniqueID
17 ;; interaction with mergeable symbols.
18 @uniquified = global i32 1
20 ;; Test implicit section assignment for symbols to ensure that the symbols
21 ;; have the expected properties.
22 ; CHECK: .section .rodata,"a",@progbits,unique,2
23 ; CHECK: implicit_nonmergeable:
24 ; CHECK: .section .rodata.cst4,"aM",@progbits,4{{$}}
25 ; CHECK: implicit_rodata_cst4:
26 ; CHECK: .section .rodata.cst8,"aM",@progbits,8{{$}}
27 ; CHECK: implicit_rodata_cst8:
28 ; CHECK: .section .rodata.str4.4,"aMS",@progbits,4{{$}}
29 ; CHECK: implicit_rodata_str4_4:
31 @implicit_nonmergeable = constant [2 x i16] [i16 1, i16 1]
32 @implicit_rodata_cst4 = unnamed_addr constant [2 x i16] [i16 1, i16 1]
33 @implicit_rodata_cst8 = unnamed_addr constant [2 x i32] [i32 1, i32 1]
34 @implicit_rodata_str4_4 = unnamed_addr constant [2 x i32] [i32 1, i32 0]
36 ;; Basic checks that mergeable globals are placed into multiple distinct
37 ;; sections with the same name and a compatible entry size.
39 ; CHECK: .section .explicit_basic,"aM",@progbits,4,unique,3
40 ; CHECK: explicit_basic_1:
41 ; CHECK: explicit_basic_2:
43 ;; Assign a mergeable global to a non-existing section.
44 @explicit_basic_1 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_basic"
45 ;; Assign a compatible mergeable global to the previous section.
46 @explicit_basic_2 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_basic"
48 ; CHECK: .section .explicit_basic,"aM",@progbits,8,unique,4
49 ; CHECK: explicit_basic_3:
50 ; CHECK: explicit_basic_4:
52 ;; Assign a symbol with an incompatible entsize (different size) to a section with the same name.
53 @explicit_basic_3 = unnamed_addr constant [2 x i32] [i32 1, i32 1], section ".explicit_basic"
54 ;; Assign a compatible mergeable global to the previous section.
55 @explicit_basic_4 = unnamed_addr constant [2 x i32] [i32 1, i32 1], section ".explicit_basic"
57 ; CHECK: .section .explicit_basic,"aMS",@progbits,4,unique,5
58 ; CHECK: explicit_basic_5:
59 ; CHECK: explicit_basic_6:
61 ;; Assign a symbol with an incompatible entsize (string vs non-string) to a section with the same name.
62 @explicit_basic_5 = unnamed_addr constant [2 x i32] [i32 1, i32 0], section ".explicit_basic"
63 ;; Assign a compatible mergeable global to the previous section.
64 @explicit_basic_6 = unnamed_addr constant [2 x i32] [i32 1, i32 0], section ".explicit_basic"
66 ; CHECK: .section .explicit_basic,"a",@progbits{{$}}
67 ; CHECK: explicit_basic_7:
69 ;; Assign a symbol with an incompatible entsize (non-mergeable) to a mergeable section created explicitly.
70 @explicit_basic_7 = constant [2 x i16] [i16 1, i16 1], section ".explicit_basic"
72 ; CHECK: .section .explicit_initially_nonmergeable,"a",@progbits{{$}}
73 ; CHECK: explicit_basic_8:
74 ; CHECK: .section .explicit_initially_nonmergeable,"aM",@progbits,4,unique,6
75 ; CHECK: explicit_basic_9:
77 ;; Assign a mergeble symbol to a section that initially had a non-mergeable symbol explicitly assigned to it.
78 @explicit_basic_8 = constant [2 x i16] [i16 1, i16 1], section ".explicit_initially_nonmergeable"
79 @explicit_basic_9 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_initially_nonmergeable"
81 ; CHECK: .section .explicit_initially_nonmergeable,"a",@progbits{{$}}
82 ; CHECK: explicit_basic_10:
83 ; CHECK: .section .explicit_initially_nonmergeable,"aM",@progbits,4,unique,6
84 ; CHECK: explicit_basic_11:
86 ;; Assign compatible globals to the previously created sections.
87 @explicit_basic_10 = constant [2 x i16] [i16 1, i16 1], section ".explicit_initially_nonmergeable"
88 @explicit_basic_11 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_initially_nonmergeable"
90 ;; Check that mergeable symbols can be explicitly assigned to "default" sections.
92 ; CHECK: .section .rodata.cst16,"a",@progbits,unique,7
93 ; CHECK: explicit_default_1:
95 ;; Assign an incompatible (non-mergeable) symbol to a "default" mergeable section.
96 @explicit_default_1 = constant [2 x i64] [i64 1, i64 1], section ".rodata.cst16"
98 ; CHECK: .section .rodata.cst16,"aM",@progbits,16{{$}}
99 ; CHECK: explicit_default_2:
101 ;; Assign a compatible global to a "default" mergeable section.
102 @explicit_default_2 = unnamed_addr constant [2 x i64] [i64 1, i64 1], section ".rodata.cst16"
104 ; CHECK: .section .debug_str,"aMS",@progbits,1,unique,[[#U:8]]
105 ; CHECK: explicit_default_3:
107 ;; Non-allocatable "default" sections can be re-emitted with allocatable flag and uniqued
108 @explicit_default_3 = unnamed_addr constant [2 x i8] [i8 1, i8 0], section ".debug_str"
110 ; CHECK: .section .debug_str,"a",@progbits,unique,[[#U+1]]
111 ; CHECK: explicit_default_4:
113 ;; Non-allocatable "default" sections cannot have allocatable mergeable symbols with incompatible (non-mergeable) entry sizes assigned to them.
114 @explicit_default_4 = constant [2 x i16] [i16 1, i16 1], section ".debug_str"
116 ;; Test implicit section assignment for globals with associated globals.
117 ; CHECK: .section .rodata.cst4,"aMo",@progbits,4,implicit_rodata_cst4,unique,[[#U+2]]
118 ; CHECK: implicit_rodata_cst4_assoc:
119 ; CHECK: .section .rodata.cst8,"aMo",@progbits,8,implicit_rodata_cst4,unique,[[#U+3]]
120 ; CHECK: implicit_rodata_cst8_assoc:
122 @implicit_rodata_cst4_assoc = unnamed_addr constant [2 x i16] [i16 1, i16 1], !associated !4
123 @implicit_rodata_cst8_assoc = unnamed_addr constant [2 x i32] [i32 1, i32 1], !associated !4
125 ;; Check that globals with associated globals that are explicitly assigned
126 ;; to a section have been placed into distinct sections with the same name, but
127 ;; different entry sizes.
128 ; CHECK: .section .explicit,"aMo",@progbits,4,implicit_rodata_cst4,unique,[[#U+4]]
129 ; CHECK: explicit_assoc_1:
130 ; CHECK: .section .explicit,"aMo",@progbits,4,implicit_rodata_cst4,unique,[[#U+5]]
131 ; CHECK: explicit_assoc_2:
132 ; CHECK: .section .explicit,"aMo",@progbits,8,implicit_rodata_cst4,unique,[[#U+6]]
133 ; CHECK: explicit_assoc_3:
135 @explicit_assoc_1 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit", !associated !4
136 @explicit_assoc_2 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit", !associated !4
137 @explicit_assoc_3 = unnamed_addr constant [2 x i32] [i32 1, i32 1], section ".explicit", !associated !4
139 !4 = !{ptr @implicit_rodata_cst4}
141 ;; Test implicit section assignment for globals in distinct comdat groups.
142 ; CHECK: .section .rodata.cst4,"aMG",@progbits,4,f,comdat,unique,[[#U+7]]
143 ; CHECK: implicit_rodata_cst4_comdat:
144 ; CHECK: .section .rodata.cst8,"aMG",@progbits,8,g,comdat,unique,[[#U+8]]
145 ; CHECK: implicit_rodata_cst8_comdat:
147 ;; Check that globals in distinct comdat groups that are explicitly assigned
148 ;; to a section have been placed into distinct sections with the same name, but
149 ;; different entry sizes. Due to the way that MC currently works the unique ID
150 ;; does not have any effect here, although it appears in the assembly. The unique ID's
151 ;; appear incorrect as comdats are not taken into account when looking up the unique ID
152 ;; for a mergeable section. However, as they have no effect it doesn't matter that they
154 ; CHECK: .section .explicit_comdat_distinct,"aM",@progbits,4,unique,[[#U+9]]
155 ; CHECK: explicit_comdat_distinct_supply_uid:
156 ; CHECK: .section .explicit_comdat_distinct,"aMG",@progbits,4,f,comdat,unique,[[#U+10]]
157 ; CHECK: explicit_comdat_distinct1:
158 ; CHECK: .section .explicit_comdat_distinct,"aMG",@progbits,4,g,comdat,unique,[[#U+10]]
159 ; CHECK: explicit_comdat_distinct2:
160 ; CHECK: .section .explicit_comdat_distinct,"aMG",@progbits,8,h,comdat,unique,[[#U+11]]
161 ; CHECK: explicit_comdat_distinct3:
167 @implicit_rodata_cst4_comdat = unnamed_addr constant [2 x i16] [i16 1, i16 1], comdat($f)
168 @implicit_rodata_cst8_comdat = unnamed_addr constant [2 x i32] [i32 1, i32 1], comdat($g)
170 @explicit_comdat_distinct_supply_uid = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_comdat_distinct"
171 @explicit_comdat_distinct1 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_comdat_distinct", comdat($f)
172 @explicit_comdat_distinct2 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_comdat_distinct", comdat($g)
173 @explicit_comdat_distinct3 = unnamed_addr constant [2 x i32] [i32 1, i32 1], section ".explicit_comdat_distinct", comdat($h)
175 ;; Test implicit section assignment for globals in the same comdat group.
176 ; CHECK: .section .rodata.cst4,"aMG",@progbits,4,i,comdat,unique,[[#U+12]]
177 ; CHECK: implicit_rodata_cst4_same_comdat:
178 ; CHECK: .section .rodata.cst8,"aMG",@progbits,8,i,comdat,unique,[[#U+13]]
179 ; CHECK: implicit_rodata_cst8_same_comdat:
181 ;; Check that globals in the same comdat group that are explicitly assigned
182 ;; to a section have been placed into distinct sections with the same name, but
183 ;; different entry sizes. Due to the way that MC currently works the unique ID
184 ;; does not have any effect here, although it appears in the assembly. The unique ID's
185 ;; appear incorrect as comdats are not taken into account when looking up the unique ID
186 ;; for a mergeable section. However, as they have no effect it doesn't matter that they
188 ; CHECK: .section .explicit_comdat_same,"aM",@progbits,4,unique,[[#U+14]]
189 ; CHECK: explicit_comdat_same_supply_uid:
190 ; CHECK: .section .explicit_comdat_same,"aMG",@progbits,4,i,comdat,unique,[[#U+15]]
191 ; CHECK: explicit_comdat_same1:
192 ; CHECK: explicit_comdat_same2:
193 ; CHECK: .section .explicit_comdat_same,"aMG",@progbits,8,i,comdat,unique,[[#U+16]]
194 ; CHECK: explicit_comdat_same3:
198 @implicit_rodata_cst4_same_comdat = unnamed_addr constant [2 x i16] [i16 1, i16 1], comdat($i)
199 @implicit_rodata_cst8_same_comdat = unnamed_addr constant [2 x i32] [i32 1, i32 1], comdat($i)
201 @explicit_comdat_same_supply_uid = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_comdat_same"
202 @explicit_comdat_same1 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_comdat_same", comdat($i)
203 @explicit_comdat_same2 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit_comdat_same", comdat($i)
204 @explicit_comdat_same3 = unnamed_addr constant [2 x i32] [i32 1, i32 1], section ".explicit_comdat_same", comdat($i)
206 ;; Check interaction between symbols that are explicitly assigned
207 ;; to a section and implicitly assigned symbols.
209 ; CHECK: .section .rodata.str1.1,"aMS",@progbits,1{{$}}
210 ; CHECK: implicit_rodata_str1_1:
211 ; CHECK: explicit_implicit_1:
213 ;; Assign a compatible global to an existing mergeable section created implicitly.
214 @implicit_rodata_str1_1 = unnamed_addr constant [2 x i8] [i8 1, i8 0]
215 @explicit_implicit_1 = unnamed_addr constant [2 x i8] [i8 1, i8 0], section ".rodata.str1.1"
217 ; CHECK: .section .rodata.str1.1,"a",@progbits,unique,[[#U+17]]
218 ; CHECK: explicit_implicit_2:
220 ;; Assign an incompatible symbol (non-mergeable) to an existing mergeable section created implicitly.
221 @explicit_implicit_2 = constant [2 x i16] [i16 1, i16 1], section ".rodata.str1.1"
223 ; CHECK: .section .rodata.str1.1,"aMS",@progbits,1{{$}}
224 ; CHECK: explicit_implicit_3:
225 ; CHECK: .section .rodata.str1.1,"a",@progbits,unique,[[#U+17]]
226 ; CHECK: explicit_implicit_4:
228 ;; Assign compatible globals to the previously created sections.
229 @explicit_implicit_3 = unnamed_addr constant [2 x i8] [i8 1, i8 0], section ".rodata.str1.1"
230 @explicit_implicit_4 = constant [2 x i16] [i16 1, i16 1], section ".rodata.str1.1"
232 ; CHECK: .section .rodata.str2.2,"aMS",@progbits,2{{$}}
233 ; CHECK: explicit_implicit_5:
234 ; CHECK: implicit_rodata_str2_2:
236 ;; Implicitly assign a compatible global to an existing mergeable section created explicitly.
237 @explicit_implicit_5 = unnamed_addr constant [2 x i16] [i16 1, i16 0], section ".rodata.str2.2"
238 @implicit_rodata_str2_2 = unnamed_addr constant [2 x i16] [i16 1, i16 0]
240 ;; Check the interaction with inline asm.
242 ; CHECK: .section .asm_mergeable1,"aMS",@progbits,2{{$}}
243 ; CHECK: explicit_asm_1:
244 ; CHECK: .section .asm_nonmergeable1,"a",@progbits{{$}}
245 ; CHECK: explicit_asm_2:
246 ; CHECK: .section .asm_mergeable1,"aM",@progbits,4,unique,[[#U+18]]
247 ; CHECK: explicit_asm_3:
248 ; CHECK: .section .asm_nonmergeable1,"aMS",@progbits,2,unique,[[#U+19]]
249 ; CHECK: explicit_asm_4:
250 ; CHECK: .section .asm_mergeable2,"aM",@progbits,4,unique,[[#U+20]]
251 ; CHECK: explicit_asm_5:
252 ; CHECK: .section .asm_nonmergeable2,"aMS",@progbits,2,unique,[[#U+21]]
253 ; CHECK: explicit_asm_6:
254 ; CHECK: .section .asm_mergeable2,"aMS",@progbits,2{{$}}
255 ; CHECK: explicit_asm_7:
256 ; CHECK: .section .asm_nonmergeable2,"a",@progbits{{$}}
257 ; CHECK: explicit_asm_8:
259 module asm ".section .asm_mergeable1,\22aMS\22,@progbits,2"
260 module asm ".section .asm_nonmergeable1,\22a\22,@progbits"
261 module asm ".section .asm_mergeable2,\22aMS\22,@progbits,2"
262 module asm ".section .asm_nonmergeable2,\22a\22,@progbits"
264 ;; Assign compatible symbols to sections created using inline asm.
265 @explicit_asm_1 = unnamed_addr constant [2 x i16] [i16 1, i16 0], section ".asm_mergeable1"
266 @explicit_asm_2 = constant [2 x i16] [i16 1, i16 0], section ".asm_nonmergeable1"
267 ;; Assign incompatible globals to the same sections.
268 @explicit_asm_3 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".asm_mergeable1"
269 @explicit_asm_4 = unnamed_addr constant [2 x i16] [i16 1, i16 0], section ".asm_nonmergeable1"
271 ;; Assign incompatible globals to sections created using inline asm.
272 @explicit_asm_5 = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".asm_mergeable2"
273 @explicit_asm_6 = unnamed_addr constant [2 x i16] [i16 1, i16 0], section ".asm_nonmergeable2"
274 ;; Assign compatible globals to the same sections.
275 @explicit_asm_7 = unnamed_addr constant [2 x i16] [i16 1, i16 0], section ".asm_mergeable2"
276 @explicit_asm_8 = constant [2 x i16] [i16 1, i16 0], section ".asm_nonmergeable2"
278 ;; A .note.GNU-stack section is created implicitly. We add a check for this as we want to use
279 ;; --implicit-check-not to reduce the number of checks in this file.
280 ; CHECK: .section ".note.GNU-stack","",@progbits{{$}}
282 ;; --no-integrated-as avoids the use of ",unique," for compatibility with older binutils.
284 ;; Error if an incompatible symbol is explicitly placed into a mergeable section.
285 ; RUN: not llc < %s -mtriple=x86_64 --no-integrated-as -binutils-version=2.34 2>&1 \
286 ; RUN: | FileCheck %s --check-prefix=NO-I-AS-ERR
287 ; NO-I-AS-ERR: error: Symbol 'explicit_default_1' from module '<stdin>' required a section with entry-size=0 but was placed in section '.rodata.cst16' with entry-size=16: Explicit assignment by pragma or attribute of an incompatible symbol to this section?
288 ; NO-I-AS-ERR: error: Symbol 'explicit_default_4' from module '<stdin>' required a section with entry-size=0 but was placed in section '.debug_str' with entry-size=1: Explicit assignment by pragma or attribute of an incompatible symbol to this section?
289 ; NO-I-AS-ERR: error: Symbol 'explicit_implicit_2' from module '<stdin>' required a section with entry-size=0 but was placed in section '.rodata.str1.1' with entry-size=1: Explicit assignment by pragma or attribute of an incompatible symbol to this section?
290 ; NO-I-AS-ERR: error: Symbol 'explicit_implicit_4' from module '<stdin>' required a section with entry-size=0 but was placed in section '.rodata.str1.1' with entry-size=1: Explicit assignment by pragma or attribute of an incompatible symbol to this section?
292 ;; For GNU as before 2.35,
293 ;; Don't create mergeable sections for globals with an explicit section name.
294 ; RUN: echo '@explicit = unnamed_addr constant [2 x i16] [i16 1, i16 1], section ".explicit"' > %t.no_i_as.ll
295 ; RUN: llc < %t.no_i_as.ll -mtriple=x86_64 --no-integrated-as -binutils-version=2.34 2>&1 \
296 ; RUN: | FileCheck %s --check-prefix=NO-I-AS-OLD
297 ; NO-I-AS-OLD: .section .explicit,"a",@progbits{{$}}
298 ; RUN: llc < %t.no_i_as.ll -mtriple=x86_64 --no-integrated-as -binutils-version=2.35 2>&1 \
299 ; RUN: | FileCheck %s --check-prefix=NO-I-AS-NEW
300 ; RUN: llc < %t.no_i_as.ll -mtriple=x86_64 --no-integrated-as -binutils-version=none 2>&1 \
301 ; RUN: | FileCheck %s --check-prefix=NO-I-AS-NEW
302 ; NO-I-AS-NEW: .section .explicit,"aM",@progbits,4,unique,1