1; RUN: llc < %s -mtriple=x86_64 -unique-section-names=0 -data-sections 2>&1 \
2; RUN:     | FileCheck %s
3
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
11
12;; Test implicit section assignment for symbols
13; CHECK: .section .data,"aw",@progbits,unique,1
14; CHECK: uniquified:
15
16;; Create a uniquified symbol (as -unique-section-names=0) to test the uniqueID
17;; interaction with mergeable symbols.
18@uniquified = global i32 1
19
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:
30
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]
35
36;; Basic checks that mergeable globals are placed into multiple distinct
37;; sections with the same name and a compatible entry size.
38
39; CHECK: .section .explicit_basic,"aM",@progbits,4,unique,3
40; CHECK: explicit_basic_1:
41; CHECK: explicit_basic_2:
42
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"
47
48; CHECK: .section .explicit_basic,"aM",@progbits,8,unique,4
49; CHECK: explicit_basic_3:
50; CHECK: explicit_basic_4:
51
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"
56
57; CHECK: .section .explicit_basic,"aMS",@progbits,4,unique,5
58; CHECK: explicit_basic_5:
59; CHECK: explicit_basic_6:
60
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"
65
66; CHECK: .section .explicit_basic,"a",@progbits
67; CHECK: explicit_basic_7:
68
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"
71
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:
76
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"
80
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:
85
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"
89
90;; Check that mergeable symbols can be explicitly assigned to "default" sections.
91
92; CHECK: .section .rodata.cst16,"a",@progbits,unique,7
93; CHECK: explicit_default_1:
94
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"
97
98; CHECK: .section .rodata.cst16,"aM",@progbits,16
99; CHECK: explicit_default_2:
100
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"
103
104; CHECK: .section .debug_str,"MS",@progbits,1
105; CHECK: explicit_default_3:
106
107;; Non-allocatable "default" sections can have allocatable mergeable symbols with compatible entry sizes assigned to them.
108@explicit_default_3 = unnamed_addr constant [2 x i8] [i8 1, i8 0], section ".debug_str"
109
110; CHECK: .section .debug_str,"a",@progbits,unique,8
111; CHECK: explicit_default_4:
112
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"
115
116;; Test implicit section assignment for globals with associated globals.
117; CHECK: .section .rodata.cst4,"aMo",@progbits,4,implicit_rodata_cst4,unique,9
118; CHECK: implicit_rodata_cst4_assoc:
119; CHECK: .section .rodata.cst8,"aMo",@progbits,8,implicit_rodata_cst4,unique,10
120; CHECK: implicit_rodata_cst8_assoc:
121
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
124
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,11
129; CHECK: explicit_assoc_1:
130; CHECK: .section .explicit,"aMo",@progbits,4,implicit_rodata_cst4,unique,12
131; CHECK: explicit_assoc_2:
132; CHECK: .section .explicit,"aMo",@progbits,8,implicit_rodata_cst4,unique,13
133; CHECK: explicit_assoc_3:
134
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
138
139!4 = !{[2 x i16]* @implicit_rodata_cst4}
140
141;; Test implicit section assignment for globals in distinct comdat groups.
142; CHECK: .section .rodata.cst4,"aGM",@progbits,4,f,comdat,unique,14
143; CHECK: implicit_rodata_cst4_comdat:
144; CHECK: .section .rodata.cst8,"aGM",@progbits,8,g,comdat,unique,15
145; CHECK: implicit_rodata_cst8_comdat:
146
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
153;; are incorrect.
154; CHECK: .section .explicit_comdat_distinct,"aM",@progbits,4,unique,16
155; CHECK: explicit_comdat_distinct_supply_uid:
156; CHECK: .section .explicit_comdat_distinct,"aGM",@progbits,4,f,comdat,unique,16
157; CHECK: explicit_comdat_distinct1:
158; CHECK: .section .explicit_comdat_distinct,"aGM",@progbits,4,g,comdat,unique,16
159; CHECK: explicit_comdat_distinct2:
160; CHECK: .section .explicit_comdat_distinct,"aGM",@progbits,8,h,comdat,unique,17
161; CHECK: explicit_comdat_distinct3:
162
163$f = comdat any
164$g = comdat any
165$h = comdat any
166
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)
169
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)
174
175;; Test implicit section assignment for globals in the same comdat group.
176; CHECK: .section .rodata.cst4,"aGM",@progbits,4,i,comdat,unique,18
177; CHECK: implicit_rodata_cst4_same_comdat:
178; CHECK: .section .rodata.cst8,"aGM",@progbits,8,i,comdat,unique,19
179; CHECK: implicit_rodata_cst8_same_comdat:
180
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
187;; are incorrect.
188; CHECK: .section .explicit_comdat_same,"aM",@progbits,4,unique,20
189; CHECK: explicit_comdat_same_supply_uid:
190; CHECK: .section .explicit_comdat_same,"aGM",@progbits,4,i,comdat,unique,20
191; CHECK: explicit_comdat_same1:
192; CHECK: explicit_comdat_same2:
193; CHECK: .section .explicit_comdat_same,"aGM",@progbits,8,i,comdat,unique,21
194; CHECK: explicit_comdat_same3:
195
196$i = comdat any
197
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)
200
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)
205
206;; Check interaction between symbols that are explicitly assigned
207;; to a section and implicitly assigned symbols.
208
209; CHECK: .section .rodata.str1.1,"aMS",@progbits,1
210; CHECK: implicit_rodata_str1_1:
211; CHECK: explicit_implicit_1:
212
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"
216
217; CHECK: .section .rodata.str1.1,"a",@progbits,unique,22
218; CHECK: explicit_implicit_2:
219
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"
222
223; CHECK: .section .rodata.str1.1,"aMS",@progbits,1
224; CHECK: explicit_implicit_3:
225; CHECK: .section .rodata.str1.1,"a",@progbits,unique,22
226; CHECK: explicit_implicit_4:
227
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"
231
232; CHECK: .section .rodata.str2.2,"aMS",@progbits,2
233; CHECK: explicit_implicit_5:
234; CHECK: implicit_rodata_str2_2:
235
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]
239
240;; Check the interaction with inline asm.
241
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,23
247; CHECK: explicit_asm_3:
248; CHECK: .section .asm_nonmergeable1,"aMS",@progbits,2,unique,24
249; CHECK: explicit_asm_4:
250; CHECK: .section .asm_mergeable2,"aM",@progbits,4,unique,25
251; CHECK: explicit_asm_5:
252; CHECK: .section .asm_nonmergeable2,"aMS",@progbits,2,unique,26
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:
258
259module asm ".section .asm_mergeable1,\22aMS\22,@progbits,2"
260module asm ".section .asm_nonmergeable1,\22a\22,@progbits"
261module asm ".section .asm_mergeable2,\22aMS\22,@progbits,2"
262module asm ".section .asm_nonmergeable2,\22a\22,@progbits"
263
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"
270
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"
277
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
281
282;; --no-integrated-as avoids the use of ",unique," for compatibility with older binutils.
283
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?
291
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
303