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 .abiversion 2
15 .globl constructor.100
16 .p2align 4
17 .type constructor.100,@function
18constructor.100:
19.Lfunc_begin0:
20.Lfunc_gep0:
21 addis 2, 12, .TOC.-.Lfunc_gep0@ha
22 addi 2, 2, .TOC.-.Lfunc_gep0@l
23.Lfunc_lep0:
24 .localentry constructor.100, .Lfunc_lep0-.Lfunc_gep0
25 mflr 0
26 stdu 1, -32(1)
27 std 0, 48(1)
28 addis 3, 2, .L.str@toc@ha
29 addi 3, 3, .L.str@toc@l
30 bl puts
31 nop
32 addi 1, 1, 32
33 ld 0, 16(1)
34 mtlr 0
35 blr
36 .long 0
37 .quad 0
38.Lfunc_end0:
39 .size constructor.100, .Lfunc_end0-.Lfunc_begin0
40
41 .globl constructor.200
42 .p2align 4
43 .type constructor.200,@function
44constructor.200:
45.Lfunc_begin1:
46.Lfunc_gep1:
47 addis 2, 12, .TOC.-.Lfunc_gep1@ha
48 addi 2, 2, .TOC.-.Lfunc_gep1@l
49.Lfunc_lep1:
50 .localentry constructor.200, .Lfunc_lep1-.Lfunc_gep1
51 mflr 0
52 stdu 1, -32(1)
53 std 0, 48(1)
54 addis 3, 2, .L.str.1@toc@ha
55 addi 3, 3, .L.str.1@toc@l
56 bl puts
57 nop
58 addi 1, 1, 32
59 ld 0, 16(1)
60 mtlr 0
61 blr
62 .long 0
63 .quad 0
64.Lfunc_end1:
65 .size constructor.200, .Lfunc_end1-.Lfunc_begin1
66
67 .globl constructor.65535
68 .p2align 4
69 .type constructor.65535,@function
70constructor.65535:
71.Lfunc_begin2:
72.Lfunc_gep2:
73 addis 2, 12, .TOC.-.Lfunc_gep2@ha
74 addi 2, 2, .TOC.-.Lfunc_gep2@l
75.Lfunc_lep2:
76 .localentry constructor.65535, .Lfunc_lep2-.Lfunc_gep2
77 mflr 0
78 stdu 1, -32(1)
79 std 0, 48(1)
80 addis 3, 2, .L.str.2@toc@ha
81 addi 3, 3, .L.str.2@toc@l
82 bl puts
83 nop
84 addis 3, 2, destructor@toc@ha
85 addi 3, 3, destructor@toc@l
86 addis 5, 2, __dso_handle@toc@ha
87 addi 5, 5, __dso_handle@toc@l
88 li 4, 0
89 bl __cxa_atexit
90 nop
91 addi 1, 1, 32
92 ld 0, 16(1)
93 mtlr 0
94 blr
95 .long 0
96 .quad 0
97.Lfunc_end2:
98 .size constructor.65535, .Lfunc_end2-.Lfunc_begin2
99
100 .globl destructor
101 .p2align 4
102 .type destructor,@function
103destructor:
104.Lfunc_begin3:
105.Lfunc_gep3:
106 addis 2, 12, .TOC.-.Lfunc_gep3@ha
107 addi 2, 2, .TOC.-.Lfunc_gep3@l
108.Lfunc_lep3:
109 .localentry destructor, .Lfunc_lep3-.Lfunc_gep3
110 mflr 0
111 stdu 1, -32(1)
112 std 0, 48(1)
113 addis 3, 2, .L.str.3@toc@ha
114 addi 3, 3, .L.str.3@toc@l
115 bl puts
116 nop
117 addi 1, 1, 32
118 ld 0, 16(1)
119 mtlr 0
120 blr
121 .long 0
122 .quad 0
123.Lfunc_end3:
124 .size destructor, .Lfunc_end3-.Lfunc_begin3
125
126 .globl main
127 .p2align 4
128 .type main,@function
129main:
130.Lfunc_begin4:
131.Lfunc_gep4:
132 addis 2, 12, .TOC.-.Lfunc_gep4@ha
133 addi 2, 2, .TOC.-.Lfunc_gep4@l
134.Lfunc_lep4:
135 .localentry main, .Lfunc_lep4-.Lfunc_gep4
136 mflr 0
137 stdu 1, -32(1)
138 std 0, 48(1)
139 addis 3, 2, .L.str.4@toc@ha
140 addi 3, 3, .L.str.4@toc@l
141 bl puts
142 nop
143 li 3, 0
144 addi 1, 1, 32
145 ld 0, 16(1)
146 mtlr 0
147 blr
148 .long 0
149 .quad 0
150.Lfunc_end4:
151 .size main, .Lfunc_end4-.Lfunc_begin4
152
153 .hidden __dso_handle
154 .type .L.str,@object
155 .section .rodata.str1.1,"aMS",@progbits,1
156.L.str:
157 .asciz "constructor 100"
158 .size .L.str, 16
159
160 .type .L.str.1,@object
161.L.str.1:
162 .asciz "constructor 200"
163 .size .L.str.1, 16
164
165 .type .L.str.2,@object
166.L.str.2:
167 .asciz "constructor 65535"
168 .size .L.str.2, 18
169
170 .type .L.str.3,@object
171.L.str.3:
172 .asciz "destructor"
173 .size .L.str.3, 11
174
175 .type .L.str.4,@object
176.L.str.4:
177 .asciz "main"
178 .size .L.str.4, 5
179
180 .section .init_array.100,"aw",@init_array
181 .p2align 3
182 .quad constructor.100
183 .section .init_array.200,"aw",@init_array
184 .p2align 3
185 .quad constructor.200
186 .section .init_array,"aw",@init_array
187 .p2align 3
188 .quad constructor.65535
189

source code of compiler-rt/test/orc/TestCases/Linux/ppc64/priority-static-initializer.S