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 | |
10 | .text |
11 | .globl main |
12 | .p2align 2 |
13 | .type main,@function |
14 | main: |
15 | |
16 | pcalau12i $a0, %pc_hi20(x) |
17 | ld.w $a0, $a0, %pc_lo12(x) |
18 | ret |
19 | .Lfunc_end0: |
20 | .size main, .Lfunc_end0-main |
21 | |
22 | // static initializer sets the value of 'x' to zero. |
23 | |
24 | .section .text.startup,"ax" ,@progbits |
25 | .p2align 2 |
26 | .type static_init,@function |
27 | static_init: |
28 | |
29 | pcalau12i $a0, %pc_hi20(x) |
30 | st.w $zero, $a0, %pc_lo12(x) |
31 | ret |
32 | .Lfunc_end1: |
33 | .size static_init, .Lfunc_end1-static_init |
34 | |
35 | .type x,@object |
36 | .data |
37 | .globl x |
38 | .p2align 2 |
39 | x: |
40 | .word 1 |
41 | .size x, 4 |
42 | |
43 | .section .init_array,"aw" ,@init_array |
44 | .p2align 3 |
45 | .dword static_init |
46 | |