1 | // Test that basic ELF static initializers work. The main function in this |
2 | // test returns the value of 'x', which is initially 1 in the data section, |
3 | // and reset to 0 if the _static_init function is run. If the static initializer |
4 | // does not run then main will return 1, causing the test to be treated as a |
5 | // failure. |
6 | // |
7 | // RUN: %clang -c -o %t %s |
8 | // RUN: %llvm_jitlink %t |
9 | .text |
10 | .abiversion 2 |
11 | .file "init.c" |
12 | .globl static_init |
13 | .p2align 4 |
14 | .type static_init,@function |
15 | static_init: |
16 | .Lfunc_begin0: |
17 | .Lfunc_gep0: |
18 | addis 2, 12, .TOC.-.Lfunc_gep0@ha |
19 | addi 2, 2, .TOC.-.Lfunc_gep0@l |
20 | .Lfunc_lep0: |
21 | .localentry static_init, .Lfunc_lep0-.Lfunc_gep0 |
22 | addis 3, 2, x@toc@ha |
23 | li 4, 0 |
24 | stw 4, x@toc@l(3) |
25 | blr |
26 | .long 0 |
27 | .quad 0 |
28 | .Lfunc_end0: |
29 | .size static_init, .Lfunc_end0-.Lfunc_begin0 |
30 | |
31 | .globl main |
32 | .p2align 4 |
33 | .type main,@function |
34 | main: |
35 | .Lfunc_begin1: |
36 | .Lfunc_gep1: |
37 | addis 2, 12, .TOC.-.Lfunc_gep1@ha |
38 | addi 2, 2, .TOC.-.Lfunc_gep1@l |
39 | .Lfunc_lep1: |
40 | .localentry main, .Lfunc_lep1-.Lfunc_gep1 |
41 | addis 3, 2, x@toc@ha |
42 | lwa 3, x@toc@l(3) |
43 | blr |
44 | .long 0 |
45 | .quad 0 |
46 | .Lfunc_end1: |
47 | .size main, .Lfunc_end1-.Lfunc_begin1 |
48 | |
49 | .type x,@object |
50 | .data |
51 | .globl x |
52 | .p2align 2, 0x0 |
53 | x: |
54 | .long 1 |
55 | .size x, 4 |
56 | |
57 | .section .init_array.0,"aw" ,@init_array |
58 | .p2align 3 |
59 | .quad static_init |
60 | |