| 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 | adrp x8, :got:x |
| 17 | ldr x8, [x8, :got_lo12:x] |
| 18 | ldr w0, [x8] |
| 19 | ret |
| 20 | .Lfunc_end0: |
| 21 | .size main, .Lfunc_end0-main |
| 22 | |
| 23 | // static initializer sets the value of 'x' to zero. |
| 24 | |
| 25 | .section .text.startup,"ax" ,@progbits |
| 26 | .p2align 2 |
| 27 | .type static_init,@function |
| 28 | static_init: |
| 29 | |
| 30 | adrp x8, :got:x |
| 31 | ldr x8, [x8, :got_lo12:x] |
| 32 | str wzr, [x8] |
| 33 | ret |
| 34 | .Lfunc_end1: |
| 35 | .size static_init, .Lfunc_end1-static_init |
| 36 | |
| 37 | .type x,@object |
| 38 | .data |
| 39 | .globl x |
| 40 | .p2align 2 |
| 41 | x: |
| 42 | .word 1 |
| 43 | .size x, 4 |
| 44 | |
| 45 | .section .init_array,"aw" ,@init_array |
| 46 | .p2align 3 |
| 47 | .xword static_init |
| 48 | |