1// Test that basic MachO 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 .section __TEXT,__text,regular,pure_instructions 11 .build_version macos, 11, 0 12 13# main returns the value of 'x', which is defined as 1 in the data section.. 14 .globl _main 15 .p2align 4, 0x90 16_main: 17 movl _x(%rip), %eax 18 retq 19 20# static initializer sets the value of 'x' to zero. 21 .section __TEXT,__StaticInit,regular,pure_instructions 22 .p2align 4, 0x90 23_static_init: 24 movl $0, _x(%rip) 25 retq 26 27 .section __DATA,__data 28 .globl _x 29 .p2align 2 30_x: 31 .long 1 32 33 .section __DATA,__mod_init_func,mod_init_funcs 34 .p2align 3 35 .quad _static_init 36 37.subsections_via_symbols 38