1 ; RUN: llc -mcpu=mvp -filetype=obj -o %t.o %s
2 ; RUN: llc -mcpu=mvp -filetype=obj %S/Inputs/global-ctor-dtor.ll -o %t.global-ctor-dtor.o
4 target triple = "wasm32-unknown-unknown"
6 define hidden void @func1() {
11 define hidden void @func2() {
16 define hidden void @func3() {
21 define hidden void @func4() {
26 declare hidden void @externCtor()
27 declare hidden void @externDtor()
28 declare hidden void @__wasm_call_ctors()
29 declare i32 @__cxa_atexit(i32 %func, i32 %arg, i32 %dso_handle)
31 define hidden void @_start() {
33 call void @__wasm_call_ctors();
37 @llvm.global_ctors = appending global [4 x { i32, ptr, ptr }] [
38 { i32, ptr, ptr } { i32 1001, ptr @func1, ptr null },
39 { i32, ptr, ptr } { i32 101, ptr @func1, ptr null },
40 { i32, ptr, ptr } { i32 101, ptr @func2, ptr null },
41 { i32, ptr, ptr } { i32 4000, ptr @externCtor, ptr null }
44 @llvm.global_dtors = appending global [4 x { i32, ptr, ptr }] [
45 { i32, ptr, ptr } { i32 1001, ptr @func3, ptr null },
46 { i32, ptr, ptr } { i32 101, ptr @func3, ptr null },
47 { i32, ptr, ptr } { i32 101, ptr @func4, ptr null },
48 { i32, ptr, ptr } { i32 4000, ptr @externDtor, ptr null }
51 ; RUN: wasm-ld --allow-undefined %t.o %t.global-ctor-dtor.o -o %t.wasm
52 ; RUN: obj2yaml %t.wasm | FileCheck %s
54 ; CHECK: - Type: IMPORT
55 ; CHECK-NEXT: Imports:
56 ; CHECK-NEXT: - Module: env
57 ; CHECK-NEXT: Field: __cxa_atexit
58 ; CHECK-NEXT: Kind: FUNCTION
59 ; CHECK-NEXT: SigIndex: 0
60 ; CHECK-NEXT: - Module: env
61 ; CHECK-NEXT: Field: externDtor
62 ; CHECK-NEXT: Kind: FUNCTION
63 ; CHECK-NEXT: SigIndex: 1
64 ; CHECK-NEXT: - Module: env
65 ; CHECK-NEXT: Field: externCtor
66 ; CHECK-NEXT: Kind: FUNCTION
67 ; CHECK-NEXT: SigIndex: 1
69 ; CHECK-NEXT: Segments:
70 ; CHECK-NEXT: - Offset:
71 ; CHECK-NEXT: Opcode: I32_CONST
72 ; CHECK-NEXT: Value: 1
73 ; CHECK-NEXT: Functions: [ 9, 11, 13, 17, 19, 21 ]
74 ; CHECK-NEXT: - Type: CODE
75 ; CHECK-NEXT: Functions:
76 ; CHECK-NEXT: - Index: 3
78 ; CHECK-NEXT: Body: 10041005100A100F1012100F10141004100C100F10161002100E0B
81 ; CHECK-NEXT: Body: 02404186808080004100418088808000108080808000450D0000000B0B
82 ; CHECK-NEXT: - Type: CUSTOM
83 ; CHECK-NEXT: Name: name
84 ; CHECK-NEXT: FunctionNames:
85 ; CHECK-NEXT: - Index: 0
86 ; CHECK-NEXT: Name: __cxa_atexit
87 ; CHECK-NEXT: - Index: 1
88 ; CHECK-NEXT: Name: externDtor
89 ; CHECK-NEXT: - Index: 2
90 ; CHECK-NEXT: Name: externCtor
91 ; CHECK-NEXT: - Index: 3
92 ; CHECK-NEXT: Name: __wasm_call_ctors
93 ; CHECK-NEXT: - Index: 4
94 ; CHECK-NEXT: Name: func1
95 ; CHECK-NEXT: - Index: 5
96 ; CHECK-NEXT: Name: func2
97 ; CHECK-NEXT: - Index: 6
98 ; CHECK-NEXT: Name: func3
99 ; CHECK-NEXT: - Index: 7
100 ; CHECK-NEXT: Name: func4
101 ; CHECK-NEXT: - Index: 8
102 ; CHECK-NEXT: Name: _start
103 ; CHECK-NEXT: - Index: 9
104 ; CHECK-NEXT: Name: .Lcall_dtors.101
105 ; CHECK-NEXT: - Index: 10
106 ; CHECK-NEXT: Name: .Lregister_call_dtors.101
107 ; CHECK-NEXT: - Index: 11
108 ; CHECK-NEXT: Name: .Lcall_dtors.1001
109 ; CHECK-NEXT: - Index: 12
110 ; CHECK-NEXT: Name: .Lregister_call_dtors.1001
111 ; CHECK-NEXT: - Index: 13
112 ; CHECK-NEXT: Name: .Lcall_dtors.4000
113 ; CHECK-NEXT: - Index: 14
114 ; CHECK-NEXT: Name: .Lregister_call_dtors.4000
115 ; CHECK-NEXT: - Index: 15
116 ; CHECK-NEXT: Name: myctor
117 ; CHECK-NEXT: - Index: 16
118 ; CHECK-NEXT: Name: mydtor
119 ; CHECK-NEXT: - Index: 17
120 ; CHECK-NEXT: Name: .Lcall_dtors.101
121 ; CHECK-NEXT: - Index: 18
122 ; CHECK-NEXT: Name: .Lregister_call_dtors.101
123 ; CHECK-NEXT: - Index: 19
124 ; CHECK-NEXT: Name: .Lcall_dtors.202
125 ; CHECK-NEXT: - Index: 20
126 ; CHECK-NEXT: Name: .Lregister_call_dtors.202
127 ; CHECK-NEXT: - Index: 21
128 ; CHECK-NEXT: Name: .Lcall_dtors.2002
129 ; CHECK-NEXT: - Index: 22
130 ; CHECK-NEXT: Name: .Lregister_call_dtors.2002
131 ; CHECK-NEXT: GlobalNames:
132 ; CHECK-NEXT: - Index: 0
133 ; CHECK-NEXT: Name: __stack_pointer
136 ; RUN: wasm-ld -r %t.o %t.global-ctor-dtor.o -o %t.reloc.wasm
137 ; RUN: llvm-readobj --symbols --sections %t.reloc.wasm | FileCheck -check-prefix=RELOC %s
139 ; RELOC: Name: linking
140 ; RELOC-NEXT: InitFunctions [
141 ; RELOC-NEXT: 0 (priority=101)
142 ; RELOC-NEXT: 1 (priority=101)
143 ; RELOC-NEXT: 15 (priority=101)
144 ; RELOC-NEXT: 11 (priority=101)
145 ; RELOC-NEXT: 21 (priority=101)
146 ; RELOC-NEXT: 11 (priority=202)
147 ; RELOC-NEXT: 23 (priority=202)
148 ; RELOC-NEXT: 0 (priority=1001)
149 ; RELOC-NEXT: 17 (priority=1001)
150 ; RELOC-NEXT: 11 (priority=2002)
151 ; RELOC-NEXT: 25 (priority=2002)
152 ; RELOC-NEXT: 9 (priority=4000)
153 ; RELOC-NEXT: 19 (priority=4000)