1 | // Test that ELF static initializers with different constructor priorities work |
2 | // and are executed in the proper order. |
3 | // |
4 | // RUN: %clang -c -o %t %s |
5 | // RUN: %llvm_jitlink %t | FileCheck %s |
6 | |
7 | // CHECK: constructor 100 |
8 | // CHECK-NEXT: constructor 200 |
9 | // CHECK-NEXT: constructor 65535 |
10 | // CHECK-NEXT: main |
11 | // CHECK-NEXT: destructor |
12 | |
13 | .text |
14 | .globl destructor |
15 | .p2align 2 |
16 | .type destructor,@function |
17 | destructor: |
18 | .Ldestructor$local: |
19 | |
20 | adrp x0, .L.str.2 |
21 | add x0, x0, :lo12:.L.str.2 |
22 | b puts |
23 | |
24 | .globl main |
25 | .p2align 2 |
26 | .type main,@function |
27 | main: |
28 | |
29 | str x30, [sp, #-16]! |
30 | adrp x0, .L.str |
31 | add x0, x0, :lo12:.L.str |
32 | bl puts |
33 | mov w0, wzr |
34 | ldr x30, [sp], #16 |
35 | ret |
36 | |
37 | .p2align 2 |
38 | .type constructor.65535,@function |
39 | constructor.65535: |
40 | |
41 | str x30, [sp, #-16]! |
42 | adrp x0, .L.str.65535 |
43 | add x0, x0, :lo12:.L.str.65535 |
44 | bl puts |
45 | adrp x0, .Ldestructor$local |
46 | add x0, x0, :lo12:.Ldestructor$local |
47 | adrp x2, __dso_handle |
48 | add x2, x2, :lo12:__dso_handle |
49 | mov x1, xzr |
50 | ldr x30, [sp], #16 |
51 | b __cxa_atexit |
52 | |
53 | .p2align 2 |
54 | .type constructor.100,@function |
55 | constructor.100: |
56 | |
57 | str x30, [sp, #-16]! |
58 | adrp x0, .L.str.100 |
59 | add x0, x0, :lo12:.L.str.100 |
60 | bl puts |
61 | ldr x30, [sp], #16 |
62 | ret |
63 | |
64 | .p2align 2 |
65 | .type constructor.200,@function |
66 | constructor.200: |
67 | |
68 | str x30, [sp, #-16]! |
69 | adrp x0, .L.str.200 |
70 | add x0, x0, :lo12:.L.str.200 |
71 | bl puts |
72 | ldr x30, [sp], #16 |
73 | ret |
74 | |
75 | .hidden __dso_handle |
76 | .type .L.str,@object |
77 | .section .rodata.str1.1,"aMS" ,@progbits,1 |
78 | .L.str: |
79 | .asciz "main" |
80 | .size .L.str, 5 |
81 | |
82 | .type .L.str.100,@object |
83 | .L.str.100: |
84 | .asciz "constructor 100" |
85 | .size .L.str.100, 16 |
86 | |
87 | .type .L.str.200,@object |
88 | .L.str.200: |
89 | .asciz "constructor 200" |
90 | .size .L.str.200, 16 |
91 | |
92 | .type .L.str.65535,@object |
93 | .L.str.65535: |
94 | .asciz "constructor 65535" |
95 | .size .L.str.65535, 18 |
96 | |
97 | |
98 | .type .L.str.2,@object |
99 | .L.str.2: |
100 | .asciz "destructor" |
101 | .size .L.str.2, 11 |
102 | |
103 | .section .init_array.100,"aw" ,@init_array |
104 | .p2align 3 |
105 | .xword constructor.100 |
106 | .section .init_array.200,"aw" ,@init_array |
107 | .p2align 3 |
108 | .xword constructor.200 |
109 | .section .init_array,"aw" ,@init_array |
110 | .p2align 3 |
111 | .xword constructor.65535 |
112 | |