blob: b2c0908122b164f05fb965d47871112dcdaf3feb [file] [log] [blame]
Jim Stichnothde4ca712014-06-29 08:13:48 -07001; Test of global initializers.
2
Karl Schimpfb6c96af2014-11-17 10:58:39 -08003; REQUIRES: allow_dump
4
Jan Voung58eea4d2015-06-15 15:11:56 -07005; Test initializers with -filetype=asm.
6; RUN: %if --need=target_X8632 --command %p2i --filetype=asm --target x8632 \
7; RUN: -i %s --args -O2 | %if --need=target_X8632 --command FileCheck %s
Jan Voungfe14fb82014-10-13 15:56:32 -07008
Jan Voung58eea4d2015-06-15 15:11:56 -07009; RUN: %if --need=target_ARM32 --command %p2i --filetype=asm --target arm32 \
10; RUN: -i %s --args -O2 --skip-unimplemented \
11; RUN: | %if --need=target_ARM32 --command FileCheck %s
12
13; Test instructions for materializing addresses.
14; RUN: %if --need=target_X8632 --command %p2i --filetype=asm --target x8632 \
15; RUN: -i %s --args -O2 \
16; RUN: | %if --need=target_X8632 --command FileCheck %s --check-prefix=X8632
17
18; Test instructions with -filetype=obj and try to cross reference instructions
19; w/ the symbol table.
20; RUN: %if --need=target_X8632 --command %p2i --assemble --disassemble \
21; RUN: --target x8632 -i %s --args --verbose none \
22; RUN: | %if --need=target_X8632 --command FileCheck --check-prefix=IAS %s
23
24; RUN: %if --need=target_X8632 --command %p2i --assemble --disassemble \
25; RUN: --dis-flags=-t --target x8632 -i %s --args --verbose none \
26; RUN: | %if --need=target_X8632 --command FileCheck --check-prefix=SYMTAB %s
27
Jan Voungb0a8c242015-06-18 15:00:14 -070028; This is not really IAS, but we can switch when that is implemented.
29; For now we can at least see the instructions / relocations.
30; RUN: %if --need=target_ARM32 --command %p2i --filetype=asm --assemble \
31; RUN: --disassemble --target arm32 -i %s \
32; RUN: --args --verbose none --skip-unimplemented \
33; RUN: | %if --need=target_ARM32 --command FileCheck \
34; RUN: --check-prefix=IASARM32 %s
35
Jan Voung58eea4d2015-06-15 15:11:56 -070036; RUN: %if --need=target_ARM32 --command %p2i --filetype=asm --assemble \
37; RUN: --disassemble --dis-flags=-t --target arm32 -i %s \
38; RUN: --args --verbose none --skip-unimplemented \
39; RUN: | %if --need=target_ARM32 --command FileCheck --check-prefix=SYMTAB %s
Jan Voungfe14fb82014-10-13 15:56:32 -070040
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -070041define internal i32 @main(i32 %argc, i32 %argv) {
42entry:
43 %expanded1 = ptrtoint [4 x i8]* @PrimitiveInit to i32
44 call void @use(i32 %expanded1)
45 %expanded3 = ptrtoint [4 x i8]* @PrimitiveInitConst to i32
46 call void @use(i32 %expanded3)
47 %expanded5 = ptrtoint [4 x i8]* @PrimitiveInitStatic to i32
48 call void @use(i32 %expanded5)
49 %expanded7 = ptrtoint [4 x i8]* @PrimitiveUninit to i32
50 call void @use(i32 %expanded7)
51 %expanded9 = ptrtoint [20 x i8]* @ArrayInit to i32
52 call void @use(i32 %expanded9)
53 %expanded11 = ptrtoint [40 x i8]* @ArrayInitPartial to i32
54 call void @use(i32 %expanded11)
55 %expanded13 = ptrtoint [20 x i8]* @ArrayUninit to i32
56 call void @use(i32 %expanded13)
57 ret i32 0
58}
Jan Voung58eea4d2015-06-15 15:11:56 -070059; X8632-LABEL: main
60; X8632: movl $PrimitiveInit,
61; X8632: movl $PrimitiveInitConst,
62; X8632: movl $PrimitiveInitStatic,
63; X8632: movl $PrimitiveUninit,
64; X8632: movl $ArrayInit,
65; X8632: movl $ArrayInitPartial,
66; X8632: movl $ArrayUninit,
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -070067
68; objdump does not indicate what symbol the mov/relocation applies to
69; so we grep for "mov {{.*}}, OFFSET, sec", along with
70; "OFFSET {{.*}} sec {{.*}} symbol" in the symbol table as a sanity check.
71; NOTE: The symbol table sorting has no relation to the code's references.
72; IAS-LABEL: main
73; SYMTAB-LABEL: SYMBOL TABLE
74
75; SYMTAB-DAG: 00000000 {{.*}} .data {{.*}} PrimitiveInit
76; IAS: mov {{.*}},0x0 {{.*}} .data
77; IAS: call
Jan Voungb0a8c242015-06-18 15:00:14 -070078; IASARM32: movw {{.*}} PrimitiveInit
79; IASARM32: movt {{.*}} PrimitiveInit
80; IASARM32: bl
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -070081
82; SYMTAB-DAG: 00000000 {{.*}} .rodata {{.*}} PrimitiveInitConst
83; IAS: mov {{.*}},0x0 {{.*}} .rodata
84; IAS: call
Jan Voungb0a8c242015-06-18 15:00:14 -070085; IASARM32: movw {{.*}} PrimitiveInitConst
86; IASARM32: movt {{.*}} PrimitiveInitConst
87; IASARM32: bl
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -070088
89; SYMTAB-DAG: 00000000 {{.*}} .bss {{.*}} PrimitiveInitStatic
90; IAS: mov {{.*}},0x0 {{.*}} .bss
91; IAS: call
Jan Voungb0a8c242015-06-18 15:00:14 -070092; IASARM32: movw {{.*}} PrimitiveInitStatic
93; IASARM32: movt {{.*}} PrimitiveInitStatic
94; IASARM32: bl
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -070095
96; SYMTAB-DAG: 00000004 {{.*}} .bss {{.*}} PrimitiveUninit
97; IAS: mov {{.*}},0x4 {{.*}} .bss
98; IAS: call
Jan Voungb0a8c242015-06-18 15:00:14 -070099; IASARM32: movw {{.*}} PrimitiveUninit
100; IASARM32: movt {{.*}} PrimitiveUninit
101; IASARM32: bl
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -0700102
103; SYMTAB-DAG: 00000004{{.*}}.data{{.*}}ArrayInit
104; IAS: mov {{.*}},0x4 {{.*}} .data
105; IAS: call
Jan Voungb0a8c242015-06-18 15:00:14 -0700106; IASARM32: movw {{.*}} ArrayInit
107; IASARM32: movt {{.*}} ArrayInit
108; IASARM32: bl
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -0700109
110; SYMTAB-DAG: 00000018 {{.*}} .data {{.*}} ArrayInitPartial
111; IAS: mov {{.*}},0x18 {{.*}} .data
112; IAS: call
Jan Voungb0a8c242015-06-18 15:00:14 -0700113; IASARM32: movw {{.*}} ArrayInitPartial
114; IASARM32: movt {{.*}} ArrayInitPartial
115; IASARM32: bl
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -0700116
117; SYMTAB-DAG: 00000008 {{.*}} .bss {{.*}} ArrayUninit
118; IAS: mov {{.*}},0x8 {{.*}} .bss
119; IAS: call
Jan Voungb0a8c242015-06-18 15:00:14 -0700120; IASARM32: movw {{.*}} ArrayUninit
121; IASARM32: movt {{.*}} ArrayUninit
122; IASARM32: bl
Jim Stichnothd9f1f9f2015-06-11 10:19:32 -0700123
124declare void @use(i32)
125
126define internal i32 @nacl_tp_tdb_offset(i32 %__0) {
127entry:
128 ret i32 0
129}
130
131define internal i32 @nacl_tp_tls_offset(i32 %size) {
132entry:
133 %result = sub i32 0, %size
134 ret i32 %result
135}
136
137
Jim Stichnothde4ca712014-06-29 08:13:48 -0700138@PrimitiveInit = internal global [4 x i8] c"\1B\00\00\00", align 4
Jan Voung58eea4d2015-06-15 15:11:56 -0700139; CHECK: .type PrimitiveInit,%object
140; CHECK-NEXT: .section .data,"aw",%progbits
141; CHECK-NEXT: .p2align 2
Jim Stichnothde4ca712014-06-29 08:13:48 -0700142; CHECK-NEXT: PrimitiveInit:
143; CHECK-NEXT: .byte
144; CHECK: .size PrimitiveInit, 4
145
146@PrimitiveInitConst = internal constant [4 x i8] c"\0D\00\00\00", align 4
Jan Voung58eea4d2015-06-15 15:11:56 -0700147; CHECK: .type PrimitiveInitConst,%object
148; CHECK-NEXT: .section .rodata,"a",%progbits
149; CHECK-NEXT: .p2align 2
Jim Stichnothde4ca712014-06-29 08:13:48 -0700150; CHECK-NEXT: PrimitiveInitConst:
151; CHECK-NEXT: .byte
152; CHECK: .size PrimitiveInitConst, 4
153
154@ArrayInit = internal global [20 x i8] c"\0A\00\00\00\14\00\00\00\1E\00\00\00(\00\00\002\00\00\00", align 4
Jan Voung58eea4d2015-06-15 15:11:56 -0700155; CHECK: .type ArrayInit,%object
156; CHECK-NEXT: .section .data,"aw",%progbits
157; CHECK-NEXT: .p2align 2
Jim Stichnothde4ca712014-06-29 08:13:48 -0700158; CHECK-NEXT: ArrayInit:
159; CHECK-NEXT: .byte
160; CHECK: .size ArrayInit, 20
161
162@ArrayInitPartial = internal global [40 x i8] c"<\00\00\00F\00\00\00P\00\00\00Z\00\00\00d\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", align 4
Jan Voung58eea4d2015-06-15 15:11:56 -0700163; CHECK: .type ArrayInitPartial,%object
164; CHECK-NEXT: .section .data,"aw",%progbits
165; CHECK-NEXT: .p2align 2
Jim Stichnothde4ca712014-06-29 08:13:48 -0700166; CHECK-NEXT: ArrayInitPartial:
167; CHECK-NEXT: .byte
168; CHECK: .size ArrayInitPartial, 40
169
170@PrimitiveInitStatic = internal global [4 x i8] zeroinitializer, align 4
Jan Voung58eea4d2015-06-15 15:11:56 -0700171; CHECK: .type PrimitiveInitStatic,%object
172; CHECK-NEXT: .section .bss,"aw",%nobits
173; CHECK-NEXT: .p2align 2
Jan Voungfed97af2015-01-25 10:46:00 -0800174; CHECK-NEXT: PrimitiveInitStatic:
175; CHECK-NEXT: .zero 4
176; CHECK-NEXT: .size PrimitiveInitStatic, 4
Jim Stichnothde4ca712014-06-29 08:13:48 -0700177
178@PrimitiveUninit = internal global [4 x i8] zeroinitializer, align 4
Jan Voung58eea4d2015-06-15 15:11:56 -0700179; CHECK: .type PrimitiveUninit,%object
180; CHECK-NEXT: .section .bss,"aw",%nobits
181; CHECK-NEXT: .p2align 2
Jan Voungfed97af2015-01-25 10:46:00 -0800182; CHECK-NEXT: PrimitiveUninit:
183; CHECK-NEXT: .zero 4
184; CHECK-NEXT: .size PrimitiveUninit, 4
Jim Stichnothde4ca712014-06-29 08:13:48 -0700185
186@ArrayUninit = internal global [20 x i8] zeroinitializer, align 4
Jan Voung58eea4d2015-06-15 15:11:56 -0700187; CHECK: .type ArrayUninit,%object
188; CHECK-NEXT: .section .bss,"aw",%nobits
189; CHECK-NEXT: .p2align 2
Jan Voungfed97af2015-01-25 10:46:00 -0800190; CHECK-NEXT: ArrayUninit:
191; CHECK-NEXT: .zero 20
192; CHECK-NEXT: .size ArrayUninit, 20
Jim Stichnothde4ca712014-06-29 08:13:48 -0700193
194@ArrayUninitConstDouble = internal constant [200 x i8] zeroinitializer, align 8
Jan Voung58eea4d2015-06-15 15:11:56 -0700195; CHECK: .type ArrayUninitConstDouble,%object
196; CHECK-NEXT: .section .rodata,"a",%progbits
197; CHECK-NEXT: .p2align 3
Jim Stichnothde4ca712014-06-29 08:13:48 -0700198; CHECK-NEXT: ArrayUninitConstDouble:
199; CHECK-NEXT: .zero 200
200; CHECK-NEXT: .size ArrayUninitConstDouble, 200
201
202@ArrayUninitConstInt = internal constant [20 x i8] zeroinitializer, align 4
Jan Voung58eea4d2015-06-15 15:11:56 -0700203; CHECK: .type ArrayUninitConstInt,%object
204; CHECK: .section .rodata,"a",%progbits
205; CHECK-NEXT: .p2align 2
Jim Stichnothde4ca712014-06-29 08:13:48 -0700206; CHECK-NEXT: ArrayUninitConstInt:
207; CHECK-NEXT: .zero 20
208; CHECK-NEXT: .size ArrayUninitConstInt, 20
209
210@__init_array_start = internal constant [0 x i8] zeroinitializer, align 4
211@__fini_array_start = internal constant [0 x i8] zeroinitializer, align 4
212@__tls_template_start = internal constant [0 x i8] zeroinitializer, align 8
213@__tls_template_alignment = internal constant [4 x i8] c"\01\00\00\00", align 4