1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
2# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %S/Inputs/undefined-globals.s -o %t_globals.o
3# RUN: wasm-ld --allow-undefined -o %t1.wasm %t.o %t_globals.o
4
5.functype unused_undef_function (i64) -> (i64)
6.functype used_undef_function () -> (i32)
7.functype use_undef_global () -> (i64)
8
9foo:
10  .functype foo () -> ()
11  call unused_undef_function
12  end_function
13
14.globl _start
15
16_start:
17  .functype _start () -> ()
18  call used_undef_function
19  call use_undef_global
20  end_function
21
22# RUN: obj2yaml %t1.wasm | FileCheck %s
23
24# CHECK:        - Type:            IMPORT
25# CHECK-NEXT:     Imports:
26# CHECK-NEXT:       - Module:          env
27# CHECK-NEXT:         Field:           used_undef_function
28# CHECK-NEXT:         Kind:            FUNCTION
29# CHECK-NEXT:         SigIndex:        0
30# CHECK-NEXT:       - Module:          env
31# CHECK-NEXT:         Field:           used_undef_global
32# CHECK-NEXT:         Kind:            GLOBAL
33# CHECK-NEXT:         GlobalType:      I64
34# CHECK-NEXT:         GlobalMutable:   false
35# CHECK-NEXT:   - Type:
36# CHECK:        - Type:            CUSTOM
37# CHECK-NEXT:     Name:            name
38# CHECK-NEXT:     FunctionNames:
39# CHECK-NEXT:       - Index:           0
40# CHECK-NEXT:         Name:            used_undef_function
41# CHECK-NEXT:       - Index:           1
42# CHECK-NEXT:         Name:            _start
43# CHECK-NEXT:       - Index:           2
44# CHECK-NEXT:         Name:            use_undef_global
45# CHECK-NEXT:     GlobalNames:
46# CHECK-NEXT:       - Index:           0
47# CHECK-NEXT:         Name:            used_undef_global
48# CHECK-NEXT:       - Index:           1
49# CHECK-NEXT:         Name:            __stack_pointer
50# CHECK-NEXT: ...
51
52# RUN: wasm-ld --no-gc-sections --allow-undefined \
53# RUN:     -o %t1.no-gc.wasm %t.o %t_globals.o
54# RUN: obj2yaml %t1.no-gc.wasm | FileCheck %s -check-prefix=NO-GC
55
56# NO-GC:        - Type:            IMPORT
57# NO-GC-NEXT:     Imports:
58# NO-GC-NEXT:       - Module:          env
59# NO-GC-NEXT:         Field:           unused_undef_function
60# NO-GC-NEXT:         Kind:            FUNCTION
61# NO-GC-NEXT:         SigIndex:        0
62# NO-GC-NEXT:       - Module:          env
63# NO-GC-NEXT:         Field:           used_undef_function
64# NO-GC-NEXT:         Kind:            FUNCTION
65# NO-GC-NEXT:         SigIndex:        1
66# NO-GC-NEXT:       - Module:          env
67# NO-GC-NEXT:         Field:           unused_undef_global
68# NO-GC-NEXT:         Kind:            GLOBAL
69# NO-GC-NEXT:         GlobalType:      I64
70# NO-GC-NEXT:         GlobalMutable:   false
71# NO-GC-NEXT:       - Module:          env
72# NO-GC-NEXT:         Field:           used_undef_global
73# NO-GC-NEXT:         Kind:            GLOBAL
74# NO-GC-NEXT:         GlobalType:      I64
75# NO-GC-NEXT:         GlobalMutable:   false
76# NO-GC-NEXT:   - Type:
77# NO-GC:        - Type:            CUSTOM
78# NO-GC-NEXT:     Name:            name
79# NO-GC-NEXT:     FunctionNames:
80# NO-GC-NEXT:       - Index:           0
81# NO-GC-NEXT:         Name:            unused_undef_function
82# NO-GC-NEXT:       - Index:           1
83# NO-GC-NEXT:         Name:            used_undef_function
84# NO-GC-NEXT:       - Index:           2
85# NO-GC-NEXT:         Name:            __wasm_call_ctors
86# NO-GC-NEXT:       - Index:           3
87# NO-GC-NEXT:         Name:            foo
88# NO-GC-NEXT:       - Index:           4
89# NO-GC-NEXT:         Name:            _start
90# NO-GC-NEXT:       - Index:           5
91# NO-GC-NEXT:         Name:            use_undef_global
92# NO-GC-NEXT:     GlobalNames:
93# NO-GC-NEXT:       - Index:           0
94# NO-GC-NEXT:         Name:            unused_undef_global
95# NO-GC-NEXT:       - Index:           1
96# NO-GC-NEXT:         Name:            used_undef_global
97# NO-GC-NEXT:       - Index:           2
98# NO-GC-NEXT:         Name:            __stack_pointer
99# NO-GC-NEXT: ...
100