1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s 2# RUN: wasm-ld --entry=callWeakFuncs --print-gc-sections %t.o \ 3# RUN: -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-GC %s 4# RUN: obj2yaml %t.wasm | FileCheck %s 5 6 7# Check that calling an undefined weak function generates an appropriate stub 8# that will fail at runtime with "unreachable". 9 10.globl callWeakFuncs 11 12callWeakFuncs: 13 .functype callWeakFuncs () -> (i32) 14 call weakFunc1 15 call weakFunc2 16 i32.const 2 17 call weakFunc3 18 i32.const weakFunc1 19 i32.const weakFunc4 20 i32.add 21 end_function 22 23.weak weakFunc1 24.weak weakFunc2 25.weak weakFunc3 26.weak weakFunc4 27.functype weakFunc1 () -> () 28.functype weakFunc2 () -> () 29.functype weakFunc3 (i32) -> () 30.functype weakFunc4 () -> () 31 32# CHECK-GC: removing unused section {{.*}}:(weakFunc4) 33 34# CHECK: --- !WASM 35# CHECK-NEXT: FileHeader: 36# CHECK-NEXT: Version: 0x1 37# CHECK-NEXT: Sections: 38# CHECK-NEXT: - Type: TYPE 39# CHECK-NEXT: Signatures: 40# CHECK-NEXT: - Index: 0 41# CHECK-NEXT: ParamTypes: 42# CHECK-NEXT: ReturnTypes: [] 43# CHECK-NEXT: - Index: 1 44# CHECK-NEXT: ParamTypes: 45# CHECK-NEXT: - I32 46# CHECK-NEXT: ReturnTypes: [] 47# CHECK-NEXT: - Index: 2 48# CHECK-NEXT: ParamTypes: 49# CHECK-NEXT: ReturnTypes: 50# CHECK-NEXT: - I32 51# CHECK-NEXT: - Type: FUNCTION 52# CHECK-NEXT: FunctionTypes: [ 0, 0, 1, 2 ] 53# CHECK-NEXT: - Type: TABLE 54# CHECK-NEXT: Tables: 55# CHECK-NEXT: - Index: 0 56# CHECK-NEXT: ElemType: FUNCREF 57# CHECK-NEXT: Limits: 58# CHECK-NEXT: Flags: [ HAS_MAX ] 59# CHECK-NEXT: Initial: 0x1 60# CHECK-NEXT: Maximum: 0x1 61# CHECK-NEXT: - Type: MEMORY 62# CHECK-NEXT: Memories: 63# CHECK-NEXT: - Initial: 0x2 64# CHECK-NEXT: - Type: GLOBAL 65# CHECK-NEXT: Globals: 66# CHECK-NEXT: - Index: 0 67# CHECK-NEXT: Type: I32 68# CHECK-NEXT: Mutable: true 69# CHECK-NEXT: InitExpr: 70# CHECK-NEXT: Opcode: I32_CONST 71# CHECK-NEXT: Value: 66560 72# CHECK-NEXT: - Type: EXPORT 73# CHECK-NEXT: Exports: 74# CHECK-NEXT: - Name: memory 75# CHECK-NEXT: Kind: MEMORY 76# CHECK-NEXT: Index: 0 77# CHECK-NEXT: - Name: callWeakFuncs 78# CHECK-NEXT: Kind: FUNCTION 79# CHECK-NEXT: Index: 3 80# CHECK-NEXT: - Type: CODE 81# CHECK-NEXT: Functions: 82# CHECK-NEXT: - Index: 0 83# CHECK-NEXT: Locals: 84# CHECK-NEXT: Body: 000B 85# CHECK-NEXT: - Index: 1 86# CHECK-NEXT: Locals: 87# CHECK-NEXT: Body: 000B 88# CHECK-NEXT: - Index: 2 89# CHECK-NEXT: Locals: 90# CHECK-NEXT: Body: 000B 91# CHECK-NEXT: - Index: 3 92# CHECK-NEXT: Locals: 93# CHECK-NEXT: Body: 10808080800010818080800041021082808080004180808080004180808080006A0B 94# CHECK-NEXT: - Type: CUSTOM 95# CHECK-NEXT: Name: name 96# CHECK-NEXT: FunctionNames: 97# CHECK-NEXT: - Index: 0 98# CHECK-NEXT: Name: 'undefined_weak:weakFunc1' 99# CHECK-NEXT: - Index: 1 100# CHECK-NEXT: Name: 'undefined_weak:weakFunc2' 101# CHECK-NEXT: - Index: 2 102# CHECK-NEXT: Name: 'undefined_weak:weakFunc3' 103# CHECK-NEXT: - Index: 3 104# CHECK-NEXT: Name: callWeakFuncs 105# CHECK-NEXT: GlobalNames: 106# CHECK-NEXT: - Index: 0 107# CHECK-NEXT: Name: __stack_pointer 108# CHECK-NEXT: ... 109