1 ; RUN: llc -filetype=obj -o %t.o %s
2 ; RUN: wasm-ld %t.o -o %t.wasm
3 ; RUN: obj2yaml %t.wasm | FileCheck %s
5 ; RUN: wasm-ld --export=__wasm_call_ctors %t.o -o %t.export.wasm
6 ; RUN: obj2yaml %t.export.wasm | FileCheck %s -check-prefix=EXPORT
8 ; Test that we emit wrappers and call __wasm_call_ctor when not referenced.
10 target triple = "wasm32-unknown-unknown"
12 define hidden void @_start() {
17 define hidden void @func1() {
22 define hidden void @func2() {
27 define hidden i32 @__cxa_atexit(i32 %func, i32 %arg, i32 %dso_handle) {
31 @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [
32 { i32, ptr, ptr } { i32 1, ptr @func1, ptr null }
35 @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [
36 { i32, ptr, ptr } { i32 1, ptr @func2, ptr null }
39 ; Check that we have exactly the needed exports: `memory` because that's
40 ; currently on by default, and `_start`, because that's the default entrypoint.
42 ; CHECK: - Type: EXPORT
43 ; CHECK-NEXT: Exports:
44 ; CHECK-NEXT: - Name: memory
45 ; CHECK-NEXT: Kind: MEMORY
46 ; CHECK-NEXT: Index: 0
47 ; CHECK-NEXT: - Name: _start
48 ; CHECK-NEXT: Kind: FUNCTION
49 ; CHECK-NEXT: Index: 7
51 ; Check the body of `_start`'s command-export wrapper.
56 ; CHECK-NEXT: Locals: []
57 ; CHECK-NEXT: Body: 100010010B
59 ; Check the symbol table to ensure all the functions are here, and that
60 ; index 7 above refers to the function we think it does.
62 ; CHECK: - Type: CUSTOM
63 ; CHECK-NEXT: Name: name
64 ; CHECK-NEXT: FunctionNames:
65 ; CHECK-NEXT: - Index: 0
66 ; CHECK-NEXT: Name: __wasm_call_ctors
67 ; CHECK-NEXT: - Index: 1
68 ; CHECK-NEXT: Name: _start
69 ; CHECK-NEXT: - Index: 2
70 ; CHECK-NEXT: Name: func1
71 ; CHECK-NEXT: - Index: 3
72 ; CHECK-NEXT: Name: func2
73 ; CHECK-NEXT: - Index: 4
74 ; CHECK-NEXT: Name: __cxa_atexit
75 ; CHECK-NEXT: - Index: 5
76 ; CHECK-NEXT: Name: .Lcall_dtors.1
77 ; CHECK-NEXT: - Index: 6
78 ; CHECK-NEXT: Name: .Lregister_call_dtors.1
79 ; CHECK-NEXT: - Index: 7
80 ; CHECK-NEXT: Name: _start.command_export
82 ; EXPORT: __wasm_call_ctors
85 ; EXPORT: __cxa_atexit