Rename CODE_OWNERS -> Maintainers (#114544)
[llvm-project.git] / lld / test / wasm / weak-undefined.s
blobe1f551d6d30b6eda547c3dc475be833565d9fef4
1 # Test that undefined weak externals (global_var) and (foo) don't cause
2 # link failures and resolve to zero.
4 # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
5 # RUN: wasm-ld -strip-all %t.o -o %t.wasm
6 # RUN: obj2yaml %t.wasm | FileCheck %s
8 # Also verify test that strong references in another file do cause link
9 # failure (See https://github.com/llvm/llvm-project/issues/60806)
11 # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/strong-refs.s -o %t-strong.o
12 # RUN: not wasm-ld -strip-all %t.o %t-strong.o -o %t.wasm 2>&1 | FileCheck --check-prefix=ERROR %s
13 # RUN: not wasm-ld -strip-all %t-strong.o %t.o -o %t.wasm 2>&1 | FileCheck --check-prefix=ERROR %s
15 # ERROR: undefined symbol: global_var
17 .functype foo () -> (i32)
19 .globl get_address_of_foo
20 get_address_of_foo:
21 .functype get_address_of_foo () -> (i32)
22 i32.const foo
23 end_function
25 .globl get_address_of_global_var
26 get_address_of_global_var:
27 .functype get_address_of_global_var () -> (i32)
28 i32.const global_var
29 end_function
31 .globl _start
32 _start:
33 .functype _start () -> ()
34 call get_address_of_global_var
35 drop
36 call get_address_of_foo
37 drop
38 call foo
39 drop
40 end_function
42 .weak foo
43 .weak global_var
45 # CHECK: --- !WASM
46 # CHECK-NEXT: FileHeader:
47 # CHECK-NEXT: Version: 0x1
48 # CHECK-NEXT: Sections:
49 # CHECK-NEXT: - Type: TYPE
50 # CHECK-NEXT: Signatures:
51 # CHECK-NEXT: - Index: 0
52 # CHECK-NEXT: ParamTypes: []
53 # CHECK-NEXT: ReturnTypes:
54 # CHECK-NEXT: - I32
55 # CHECK-NEXT: - Index: 1
56 # CHECK-NEXT: ParamTypes: []
57 # CHECK-NEXT: ReturnTypes: []
58 # CHECK-NEXT: - Type: FUNCTION
59 # CHECK-NEXT: FunctionTypes: [ 0, 0, 0, 1 ]
60 # CHECK-NEXT: - Type: TABLE
61 # CHECK-NEXT: Tables:
62 # CHECK-NEXT: - Index: 0
63 # CHECK-NEXT: ElemType: FUNCREF
64 # CHECK-NEXT: Limits:
65 # CHECK-NEXT: Flags: [ HAS_MAX ]
66 # CHECK-NEXT: Minimum: 0x1
67 # CHECK-NEXT: Maximum: 0x1
68 # CHECK-NEXT: - Type: MEMORY
69 # CHECK-NEXT: Memories:
70 # CHECK-NEXT: - Minimum: 0x2
71 # CHECK-NEXT: - Type: GLOBAL
72 # CHECK-NEXT: Globals:
73 # CHECK-NEXT: - Index: 0
74 # CHECK-NEXT: Type: I32
75 # CHECK-NEXT: Mutable: true
76 # CHECK-NEXT: InitExpr:
77 # CHECK-NEXT: Opcode: I32_CONST
78 # CHECK-NEXT: Value: 66560
79 # CHECK-NEXT: - Type: EXPORT
80 # CHECK-NEXT: Exports:
81 # CHECK-NEXT: - Name: memory
82 # CHECK-NEXT: Kind: MEMORY
83 # CHECK-NEXT: Index: 0
84 # CHECK-NEXT: - Name: _start
85 # CHECK-NEXT: Kind: FUNCTION
86 # CHECK-NEXT: Index: 3
87 # CHECK-NEXT: - Type: CODE
88 # CHECK-NEXT: Functions:
89 # CHECK-NEXT: - Index: 0
90 # CHECK-NEXT: Locals:
91 # CHECK-NEXT: Body: 000B
92 # CHECK-NEXT: - Index: 1
93 # CHECK-NEXT: Locals:
94 # CHECK-NEXT: Body: 4180808080000B
95 # CHECK-NEXT: - Index: 2
96 # CHECK-NEXT: Locals:
97 # CHECK-NEXT: Body: 4180808080000B
98 # CHECK-NEXT: - Index: 3
99 # CHECK-NEXT: Locals:
100 # CHECK-NEXT: Body: 1082808080001A1081808080001A1080808080001A0B
101 # CHECK-NEXT: ...