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 4 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 7 8; Test that we emit wrappers and call __wasm_call_ctor when not referenced. 9 10target triple = "wasm32-unknown-unknown" 11 12define hidden void @_start() { 13entry: 14 ret void 15} 16 17define hidden void @func1() { 18entry: 19 ret void 20} 21 22define hidden void @func2() { 23entry: 24 ret void 25} 26 27define hidden i32 @__cxa_atexit(i32 %func, i32 %arg, i32 %dso_handle) { 28 ret i32 0 29} 30 31@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [ 32 { i32, void ()*, i8* } { i32 1, void ()* @func1, i8* null } 33] 34 35@llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [ 36 { i32, void ()*, i8* } { i32 1, void ()* @func2, i8* null } 37] 38 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. 41 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 50 51; Check the body of `_start`'s command-export wrapper. 52 53; CHECK: - Type: CODE 54 55; CHECK: - Index: 7 56; CHECK-NEXT: Locals: [] 57; CHECK-NEXT: Body: 100010010B 58 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. 61 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 81 82; EXPORT: __wasm_call_ctors 83; EXPORT: func1 84; EXPORT: func2 85; EXPORT: __cxa_atexit 86