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
12 .globl main
13 .p2align 4, 0x90
14main: # @main
15 movq x@GOTPCREL(%rip), %rax
16 movl (%rax), %eax
17 retq
18
19# static initializer sets the value of 'x' to zero.
20
21 .p2align 4, 0x90
22static_init:
23 movq x@GOTPCREL(%rip), %rax
24 movl $0, (%rax)
25 retq
26
27 .data
28 .globl x
29 .p2align 2
30x:
31 .long 1
32 .size x, 4
33
34 .section .init_array,"aw",@init_array
35 .p2align 3
36 .quad static_init
37

source code of compiler-rt/test/orc/TestCases/FreeBSD/x86-64/trivial-static-initializer.S