1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s 2# RUN: wasm-ld -strip-debug %t.o -o %t.wasm 3# RUN: obj2yaml %t.wasm | FileCheck %s 4 5# Test that undefined weak externals (global_var) and (foo) don't cause 6# link failures and resolve to zero. 7 8.globl get_address_of_foo 9get_address_of_foo: 10 .functype get_address_of_foo () -> (i32) 11 i32.const foo 12 end_function 13 14.globl get_address_of_global_var 15get_address_of_global_var: 16 .functype get_address_of_global_var () -> (i32) 17 i32.const global_var 18 end_function 19 20.globl _start 21_start: 22 .functype _start () -> () 23 call get_address_of_global_var 24 drop 25 call get_address_of_foo 26 drop 27 call foo 28 drop 29 end_function 30 31.weak foo 32.weak global_var 33.functype foo () -> (i32) 34 35 36# CHECK: --- !WASM 37# CHECK-NEXT: FileHeader: 38# CHECK-NEXT: Version: 0x1 39# CHECK-NEXT: Sections: 40# CHECK-NEXT: - Type: TYPE 41# CHECK-NEXT: Signatures: 42# CHECK-NEXT: - Index: 0 43# CHECK-NEXT: ParamTypes: [] 44# CHECK-NEXT: ReturnTypes: 45# CHECK-NEXT: - I32 46# CHECK-NEXT: - Index: 1 47# CHECK-NEXT: ParamTypes: [] 48# CHECK-NEXT: ReturnTypes: [] 49# CHECK-NEXT: - Type: FUNCTION 50# CHECK-NEXT: FunctionTypes: [ 0, 0, 0, 1 ] 51# CHECK-NEXT: - Type: TABLE 52# CHECK-NEXT: Tables: 53# CHECK-NEXT: - Index: 0 54# CHECK-NEXT: ElemType: FUNCREF 55# CHECK-NEXT: Limits: 56# CHECK-NEXT: Flags: [ HAS_MAX ] 57# CHECK-NEXT: Initial: 0x1 58# CHECK-NEXT: Maximum: 0x1 59# CHECK-NEXT: - Type: MEMORY 60# CHECK-NEXT: Memories: 61# CHECK-NEXT: - Initial: 0x2 62# CHECK-NEXT: - Type: GLOBAL 63# CHECK-NEXT: Globals: 64# CHECK-NEXT: - Index: 0 65# CHECK-NEXT: Type: I32 66# CHECK-NEXT: Mutable: true 67# CHECK-NEXT: InitExpr: 68# CHECK-NEXT: Opcode: I32_CONST 69# CHECK-NEXT: Value: 66560 70# CHECK-NEXT: - Type: EXPORT 71# CHECK-NEXT: Exports: 72# CHECK-NEXT: - Name: memory 73# CHECK-NEXT: Kind: MEMORY 74# CHECK-NEXT: Index: 0 75# CHECK-NEXT: - Name: _start 76# CHECK-NEXT: Kind: FUNCTION 77# CHECK-NEXT: Index: 3 78# CHECK-NEXT: - Type: CODE 79# CHECK-NEXT: Functions: 80# CHECK-NEXT: - Index: 0 81# CHECK-NEXT: Locals: 82# CHECK-NEXT: Body: 000B 83# CHECK-NEXT: - Index: 1 84# CHECK-NEXT: Locals: 85# CHECK-NEXT: Body: 4180808080000B 86# CHECK-NEXT: - Index: 2 87# CHECK-NEXT: Locals: 88# CHECK-NEXT: Body: 4180808080000B 89# CHECK-NEXT: - Index: 3 90# CHECK-NEXT: Locals: 91# CHECK-NEXT: Body: 1082808080001A1081808080001A1080808080001A0B 92# CHECK-NEXT: ... 93