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
17destructor:
18.Ldestructor$local:
19
20 pcalau12i $a0, %pc_hi20(.L.str.2)
21 addi.d $a0, $a0, %pc_lo12(.L.str.2)
22 b %plt(puts)
23
24 .globl main
25 .p2align 2
26 .type main,@function
27main:
28
29 addi.d $sp, $sp, -16
30 st.d $ra, $sp, 8 # 8-byte Folded Spill
31 pcalau12i $a0, %pc_hi20(.L.str)
32 addi.d $a0, $a0, %pc_lo12(.L.str)
33 bl %plt(puts)
34 move $a0, $zero
35 ld.d $ra, $sp, 8 # 8-byte Folded Reload
36 addi.d $sp, $sp, 16
37 ret
38
39 .p2align 2
40 .type constructor.65535,@function
41constructor.65535:
42
43 addi.d $sp, $sp, -16
44 st.d $ra, $sp, 8 # 8-byte Folded Spill
45 pcalau12i $a0, %pc_hi20(.L.str.65535)
46 addi.d $a0, $a0, %pc_lo12(.L.str.65535)
47 bl %plt(puts)
48 pcalau12i $a0, %got_pc_hi20(__dso_handle)
49 ld.d $a0, $a0, %got_pc_lo12(__dso_handle)
50 ld.d $a2, $a0, 0
51 pcalau12i $a0, %pc_hi20(.Ldestructor$local)
52 addi.d $a0, $a0, %pc_lo12(.Ldestructor$local)
53 move $a1, $zero
54 ld.d $ra, $sp, 8 # 8-byte Folded Reload
55 addi.d $sp, $sp, 16
56 b %plt(__cxa_atexit)
57
58 .p2align 2
59 .type constructor.100,@function
60constructor.100:
61
62 addi.d $sp, $sp, -16
63 st.d $ra, $sp, 8 # 8-byte Folded Spill
64 st.d $fp, $sp, 0 # 8-byte Folded Spill
65 addi.d $fp, $sp, 16
66 pcalau12i $a0, %pc_hi20(.L.str.100)
67 addi.d $a0, $a0, %pc_lo12(.L.str.100)
68 bl %plt(puts)
69 ld.d $fp, $sp, 0 # 8-byte Folded Reload
70 ld.d $ra, $sp, 8 # 8-byte Folded Reload
71 addi.d $sp, $sp, 16
72 ret
73
74 .p2align 2
75 .type constructor.200,@function
76constructor.200:
77
78 addi.d $sp, $sp, -16
79 st.d $ra, $sp, 8 # 8-byte Folded Spill
80 st.d $fp, $sp, 0 # 8-byte Folded Spill
81 addi.d $fp, $sp, 16
82 pcalau12i $a0, %pc_hi20(.L.str.200)
83 addi.d $a0, $a0, %pc_lo12(.L.str.200)
84 bl %plt(puts)
85 ld.d $fp, $sp, 0 # 8-byte Folded Reload
86 ld.d $ra, $sp, 8 # 8-byte Folded Reload
87 addi.d $sp, $sp, 16
88 ret
89
90 .hidden __dso_handle
91 .type .L.str,@object
92 .section .rodata.str1.1,"aMS",@progbits,1
93.L.str:
94 .asciz "main"
95 .size .L.str, 5
96
97 .type .L.str.100,@object
98.L.str.100:
99 .asciz "constructor 100"
100 .size .L.str.100, 16
101
102 .type .L.str.200,@object
103.L.str.200:
104 .asciz "constructor 200"
105 .size .L.str.200, 16
106
107 .type .L.str.65535,@object
108.L.str.65535:
109 .asciz "constructor 65535"
110 .size .L.str.65535, 18
111
112
113 .type .L.str.2,@object
114.L.str.2:
115 .asciz "destructor"
116 .size .L.str.2, 11
117
118 .section .init_array.100,"aw",@init_array
119 .p2align 3
120 .dword constructor.100
121 .section .init_array.200,"aw",@init_array
122 .p2align 3
123 .dword constructor.200
124 .section .init_array,"aw",@init_array
125 .p2align 3
126 .dword constructor.65535
127

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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