Home | History | Annotate | Download | only in llvm2ice_tests
      1 ; Test of global initializers.
      2 
      3 ; REQUIRES: allow_dump
      4 
      5 ; Test initializers with -filetype=asm.
      6 ; RUN: %if --need=target_X8632 --command %p2i --filetype=asm --target x8632 \
      7 ; RUN:   -i %s --args -O2 -allow-externally-defined-symbols \
      8 ; RUN:   | %if --need=target_X8632 --command FileCheck %s
      9 
     10 ; RUN: %if --need=target_ARM32 --command %p2i --filetype=asm --target arm32 \
     11 ; RUN:   -i %s --args -O2 \
     12 ; RUN:   -allow-externally-defined-symbols \
     13 ; RUN:   | %if --need=target_ARM32 --command FileCheck %s
     14 
     15 ; Test instructions for materializing addresses.
     16 ; RUN: %if --need=target_X8632 --command %p2i --filetype=asm --target x8632 \
     17 ; RUN:   -i %s --args -O2 -allow-externally-defined-symbols \
     18 ; RUN: | %if --need=target_X8632 --command FileCheck %s --check-prefix=X8632
     19 
     20 ; Test instructions with -filetype=obj and try to cross reference instructions
     21 ; w/ the symbol table.
     22 ; RUN: %if --need=target_X8632 --command %p2i --assemble --disassemble \
     23 ; RUN:   --target x8632 -i %s --args --verbose none \
     24 ; RUN:   -allow-externally-defined-symbols \
     25 ; RUN:   | %if --need=target_X8632 --command FileCheck --check-prefix=IAS %s
     26 
     27 ; RUN: %if --need=target_X8632 --command %p2i --assemble --disassemble \
     28 ; RUN:   --dis-flags=-t --target x8632 -i %s --args --verbose none \
     29 ; RUN:   -allow-externally-defined-symbols \
     30 ; RUN:   | %if --need=target_X8632 --command FileCheck --check-prefix=SYMTAB %s
     31 
     32 ; This is not really IAS, but we can switch when that is implemented.
     33 ; For now we can at least see the instructions / relocations.
     34 ; RUN: %if --need=target_ARM32 --command %p2i --filetype=asm --assemble \
     35 ; RUN:   --disassemble --target arm32 -i %s \
     36 ; RUN:   --args --verbose none \
     37 ; RUN:   -allow-externally-defined-symbols \
     38 ; RUN:   | %if --need=target_ARM32 --command FileCheck \
     39 ; RUN:   --check-prefix=IASARM32 %s
     40 
     41 ; RUN: %if --need=target_ARM32 --command %p2i --filetype=asm --assemble \
     42 ; RUN:   --disassemble --dis-flags=-t --target arm32 -i %s \
     43 ; RUN:   --args --verbose none \
     44 ; RUN:   -allow-externally-defined-symbols \
     45 ; RUN:   | %if --need=target_ARM32 --command FileCheck --check-prefix=SYMTAB %s
     46 
     47 ; RUN: %if --need=target_MIPS32 --need=allow_dump \
     48 ; RUN:   --command %p2i --filetype=asm --assemble --disassemble --target \
     49 ; RUN:   mips32 -i %s --args -O2 -allow-externally-defined-symbols \
     50 ; RUN:   | %if --need=target_MIPS32 --need=allow_dump \
     51 ; RUN:   --command FileCheck --check-prefix=IASMIPS32 %s
     52 
     53 ; RUN: %if --need=target_MIPS32 --need=allow_dump --command %p2i \
     54 ; RUN:   --filetype=asm --assemble --disassemble --dis-flags=-t \
     55 ; RUN:   --target mips32 -i %s --args --verbose none \
     56 ; RUN:   -allow-externally-defined-symbols \
     57 ; RUN:   | %if --need=target_MIPS32 --need=allow_dump \
     58 ; RUN:   --command FileCheck --check-prefix=SYMTAB %s
     59 
     60 define internal i32 @main(i32 %argc, i32 %argv) {
     61 entry:
     62   %expanded1 = ptrtoint [4 x i8]* @PrimitiveInit to i32
     63   call void @use(i32 %expanded1)
     64   %expanded3 = ptrtoint [4 x i8]* @PrimitiveInitConst to i32
     65   call void @use(i32 %expanded3)
     66   %expanded5 = ptrtoint [4 x i8]* @PrimitiveInitStatic to i32
     67   call void @use(i32 %expanded5)
     68   %expanded7 = ptrtoint [4 x i8]* @PrimitiveUninit to i32
     69   call void @use(i32 %expanded7)
     70   %expanded9 = ptrtoint [20 x i8]* @ArrayInit to i32
     71   call void @use(i32 %expanded9)
     72   %expanded11 = ptrtoint [40 x i8]* @ArrayInitPartial to i32
     73   call void @use(i32 %expanded11)
     74   %expanded13 = ptrtoint [20 x i8]* @ArrayUninit to i32
     75   call void @use(i32 %expanded13)
     76   ret i32 0
     77 }
     78 ; X8632-LABEL: main
     79 ; X8632: movl $PrimitiveInit,
     80 ; X8632: movl $PrimitiveInitConst,
     81 ; X8632: movl $PrimitiveInitStatic,
     82 ; X8632: movl $PrimitiveUninit,
     83 ; X8632: movl $ArrayInit,
     84 ; X8632: movl $ArrayInitPartial,
     85 ; X8632: movl $ArrayUninit,
     86 
     87 ; objdump does not indicate what symbol the mov/relocation applies to
     88 ; so we grep for "mov {{.*}}, OFFSET, sec", along with
     89 ; "OFFSET {{.*}} sec {{.*}} symbol" in the symbol table as a sanity check.
     90 ; NOTE: The symbol table sorting has no relation to the code's references.
     91 ; IAS-LABEL: main
     92 ; SYMTAB-LABEL: SYMBOL TABLE
     93 
     94 ; SYMTAB-DAG: 00000000 {{.*}} .data {{.*}} PrimitiveInit
     95 ; IAS: mov {{.*}},0x0 {{.*}} .data
     96 ; IAS: call
     97 ; IASARM32: movw {{.*}} PrimitiveInit
     98 ; IASARM32: movt {{.*}} PrimitiveInit
     99 ; IASARM32: bl
    100 ; IASMIPS32: 	lui	{{.*}}	PrimitiveInit
    101 ; IASMIPS32: 	addiu	{{.*}}	PrimitiveInit
    102 ; IASMIPS32: 	jal
    103 
    104 ; SYMTAB-DAG: 00000000 {{.*}} .rodata {{.*}} PrimitiveInitConst
    105 ; IAS: mov {{.*}},0x0 {{.*}} .rodata
    106 ; IAS: call
    107 ; IASARM32: movw {{.*}} PrimitiveInitConst
    108 ; IASARM32: movt {{.*}} PrimitiveInitConst
    109 ; IASARM32: bl
    110 ; IASMIPS32: 	lui	{{.*}}	PrimitiveInitConst
    111 ; IASMIPS32: 	addiu	{{.*}}	PrimitiveInitConst
    112 ; IASMIPS32: 	jal
    113 
    114 ; SYMTAB-DAG: 00000000 {{.*}} .bss {{.*}} PrimitiveInitStatic
    115 ; IAS: mov {{.*}},0x0 {{.*}} .bss
    116 ; IAS: call
    117 ; IASARM32: movw {{.*}} PrimitiveInitStatic
    118 ; IASARM32: movt {{.*}} PrimitiveInitStatic
    119 ; IASARM32: bl
    120 ; IASMIPS32: 	lui	{{.*}}	PrimitiveInitStatic
    121 ; IASMIPS32: 	addiu	{{.*}}	PrimitiveInitStatic
    122 ; IASMIPS32: 	jal
    123 
    124 ; SYMTAB-DAG: 00000004 {{.*}} .bss {{.*}} PrimitiveUninit
    125 ; IAS: mov {{.*}},0x4 {{.*}} .bss
    126 ; IAS: call
    127 ; IASARM32: movw {{.*}} PrimitiveUninit
    128 ; IASARM32: movt {{.*}} PrimitiveUninit
    129 ; IASARM32: bl
    130 ; IASMIPS32: 	lui	{{.*}}	PrimitiveUninit
    131 ; IASMIPS32: 	addiu	{{.*}}	PrimitiveUninit
    132 ; IASMIPS32: 	jal
    133 
    134 ; SYMTAB-DAG: 00000004{{.*}}.data{{.*}}ArrayInit
    135 ; IAS: mov {{.*}},0x4 {{.*}} .data
    136 ; IAS: call
    137 ; IASARM32: movw {{.*}} ArrayInit
    138 ; IASARM32: movt {{.*}} ArrayInit
    139 ; IASARM32: bl
    140 ; IASMIPS32: 	lui	{{.*}}	ArrayInit
    141 ; IASMIPS32: 	addiu	{{.*}}	ArrayInit
    142 ; IASMIPS32: 	jal
    143 
    144 ; SYMTAB-DAG: 00000018 {{.*}} .data {{.*}} ArrayInitPartial
    145 ; IAS: mov {{.*}},0x18 {{.*}} .data
    146 ; IAS: call
    147 ; IASARM32: movw {{.*}} ArrayInitPartial
    148 ; IASARM32: movt {{.*}} ArrayInitPartial
    149 ; IASARM32: bl
    150 ; IASMIPS32: 	lui	{{.*}}	ArrayInitPartial
    151 ; IASMIPS32: 	addiu	{{.*}}	ArrayInitPartial
    152 ; IASMIPS32: 	jal
    153 
    154 ; SYMTAB-DAG: 00000008 {{.*}} .bss {{.*}} ArrayUninit
    155 ; IAS: mov {{.*}},0x8 {{.*}} .bss
    156 ; IAS: call
    157 ; IASARM32: movw {{.*}} ArrayUninit
    158 ; IASARM32: movt {{.*}} ArrayUninit
    159 ; IASARM32: bl
    160 ; IASMIPS32: 	lui	{{.*}}	ArrayUninit
    161 ; IASMIPS32: 	addiu	{{.*}}	ArrayUninit
    162 ; IASMIPS32: 	jal
    163 
    164 declare void @use(i32)
    165 
    166 define internal i32 @nacl_tp_tdb_offset(i32 %__0) {
    167 entry:
    168   ret i32 0
    169 }
    170 
    171 define internal i32 @nacl_tp_tls_offset(i32 %size) {
    172 entry:
    173   %result = sub i32 0, %size
    174   ret i32 %result
    175 }
    176 
    177 
    178 @PrimitiveInit = internal global [4 x i8] c"\1B\00\00\00", align 4
    179 ; CHECK: .type PrimitiveInit,%object
    180 ; CHECK-NEXT: .section .data,"aw",%progbits
    181 ; CHECK-NEXT: .p2align 2
    182 ; CHECK-NEXT: PrimitiveInit:
    183 ; CHECK-NEXT: .byte
    184 ; CHECK: .size PrimitiveInit, 4
    185 
    186 @PrimitiveInitConst = internal constant [4 x i8] c"\0D\00\00\00", align 4
    187 ; CHECK: .type PrimitiveInitConst,%object
    188 ; CHECK-NEXT: .section .rodata,"a",%progbits
    189 ; CHECK-NEXT: .p2align 2
    190 ; CHECK-NEXT: PrimitiveInitConst:
    191 ; CHECK-NEXT: .byte
    192 ; CHECK: .size PrimitiveInitConst, 4
    193 
    194 @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
    195 ; CHECK: .type ArrayInit,%object
    196 ; CHECK-NEXT: .section .data,"aw",%progbits
    197 ; CHECK-NEXT: .p2align 2
    198 ; CHECK-NEXT: ArrayInit:
    199 ; CHECK-NEXT: .byte
    200 ; CHECK: .size ArrayInit, 20
    201 
    202 @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
    203 ; CHECK: .type ArrayInitPartial,%object
    204 ; CHECK-NEXT: .section .data,"aw",%progbits
    205 ; CHECK-NEXT: .p2align 2
    206 ; CHECK-NEXT: ArrayInitPartial:
    207 ; CHECK-NEXT: .byte
    208 ; CHECK: .size ArrayInitPartial, 40
    209 
    210 @PrimitiveInitStatic = internal global [4 x i8] zeroinitializer, align 4
    211 ; CHECK: .type PrimitiveInitStatic,%object
    212 ; CHECK-NEXT: .section .bss,"aw",%nobits
    213 ; CHECK-NEXT: .p2align 2
    214 ; CHECK-NEXT: PrimitiveInitStatic:
    215 ; CHECK-NEXT: .zero 4
    216 ; CHECK-NEXT: .size PrimitiveInitStatic, 4
    217 
    218 @PrimitiveUninit = internal global [4 x i8] zeroinitializer, align 4
    219 ; CHECK: .type PrimitiveUninit,%object
    220 ; CHECK-NEXT: .section .bss,"aw",%nobits
    221 ; CHECK-NEXT: .p2align 2
    222 ; CHECK-NEXT: PrimitiveUninit:
    223 ; CHECK-NEXT: .zero 4
    224 ; CHECK-NEXT: .size PrimitiveUninit, 4
    225 
    226 @ArrayUninit = internal global [20 x i8] zeroinitializer, align 4
    227 ; CHECK: .type ArrayUninit,%object
    228 ; CHECK-NEXT: .section .bss,"aw",%nobits
    229 ; CHECK-NEXT: .p2align 2
    230 ; CHECK-NEXT: ArrayUninit:
    231 ; CHECK-NEXT: .zero 20
    232 ; CHECK-NEXT: .size ArrayUninit, 20
    233 
    234 @ArrayUninitConstDouble = internal constant [200 x i8] zeroinitializer, align 8
    235 ; CHECK: .type ArrayUninitConstDouble,%object
    236 ; CHECK-NEXT: .section .rodata,"a",%progbits
    237 ; CHECK-NEXT: .p2align 3
    238 ; CHECK-NEXT: ArrayUninitConstDouble:
    239 ; CHECK-NEXT: .zero 200
    240 ; CHECK-NEXT: .size ArrayUninitConstDouble, 200
    241 
    242 @ArrayUninitConstInt = internal constant [20 x i8] zeroinitializer, align 4
    243 ; CHECK: .type ArrayUninitConstInt,%object
    244 ; CHECK: .section .rodata,"a",%progbits
    245 ; CHECK-NEXT: .p2align 2
    246 ; CHECK-NEXT: ArrayUninitConstInt:
    247 ; CHECK-NEXT: .zero 20
    248 ; CHECK-NEXT: .size ArrayUninitConstInt, 20
    249 
    250 @__init_array_start = internal constant [0 x i8] zeroinitializer, align 4
    251 @__fini_array_start = internal constant [0 x i8] zeroinitializer, align 4
    252 @__tls_template_start = internal constant [0 x i8] zeroinitializer, align 8
    253 @__tls_template_alignment = internal constant [4 x i8] c"\01\00\00\00", align 4
    254