1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
2#
3# Should fail without mutable globals feature enabled.
4# RUN: not wasm-ld --export-all %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-ERR %s
5# RUN: not wasm-ld --export=foo_global %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-ERR %s
6#
7# RUN: wasm-ld --features=mutable-globals --export=foo_global %t.o -o %t.wasm
8# RUN: obj2yaml %t.wasm | FileCheck %s
9
10# Explcitly check that __stack_pointer can be exported
11# RUN: wasm-ld --features=mutable-globals --export=__stack_pointer %t.o -o %t.wasm
12# RUN: obj2yaml %t.wasm | FileCheck -check-prefix=CHECK-SP %s
13
14# RUN: wasm-ld --features=mutable-globals --export-all %t.o -o %t.wasm
15# RUN: obj2yaml %t.wasm | FileCheck -check-prefix=CHECK-ALL %s
16
17
18.globl _start
19.globl foo_global
20
21.globaltype foo_global, i32
22foo_global:
23
24_start:
25  .functype _start () -> ()
26  end_function
27
28# CHECK-ERR: mutable global exported but 'mutable-globals' feature not present in inputs: `foo_global`. Use --no-check-features to suppress
29
30#      CHECK:  - Type:            EXPORT
31# CHECK-NEXT:    Exports:
32# CHECK-NEXT:      - Name:            memory
33# CHECK-NEXT:        Kind:            MEMORY
34# CHECK-NEXT:        Index:           0
35# CHECK-NEXT:      - Name:            _start
36# CHECK-NEXT:        Kind:            FUNCTION
37# CHECK-NEXT:        Index:           0
38# CHECK-NEXT:      - Name:            foo_global
39# CHECK-NEXT:        Kind:            GLOBAL
40# CHECK-NEXT:        Index:           1
41# CHECK-NEXT:  - Type:            CODE
42
43#      CHECK-SP:  - Type:            EXPORT
44# CHECK-SP-NEXT:    Exports:
45# CHECK-SP-NEXT:      - Name:            memory
46# CHECK-SP-NEXT:        Kind:            MEMORY
47# CHECK-SP-NEXT:        Index:           0
48# CHECK-SP-NEXT:      - Name:            __stack_pointer
49# CHECK-SP-NEXT:        Kind:            GLOBAL
50# CHECK-SP-NEXT:        Index:           0
51# CHECK-SP-NEXT:      - Name:            _start
52# CHECK-SP-NEXT:        Kind:            FUNCTION
53# CHECK-SP-NEXT:        Index:           0
54# CHECK-SP-NEXT:  - Type:            CODE
55
56#      CHECK-ALL:  - Type:            EXPORT
57# CHECK-ALL-NEXT:    Exports:
58# CHECK-ALL-NEXT:      - Name:            memory
59# CHECK-ALL-NEXT:        Kind:            MEMORY
60# CHECK-ALL-NEXT:        Index:           0
61# CHECK-ALL-NEXT:      - Name:            __wasm_call_ctors
62# CHECK-ALL-NEXT:        Kind:            FUNCTION
63# CHECK-ALL-NEXT:        Index:           0
64# CHECK-ALL-NEXT:      - Name:            _start
65# CHECK-ALL-NEXT:        Kind:            FUNCTION
66# CHECK-ALL-NEXT:        Index:           1
67# CHECK-ALL-NEXT:      - Name:            foo_global
68# CHECK-ALL-NEXT:        Kind:            GLOBAL
69# CHECK-ALL-NEXT:        Index:           1
70# CHECK-ALL-NEXT:      - Name:            __dso_handle
71# CHECK-ALL-NEXT:        Kind:            GLOBAL
72# CHECK-ALL-NEXT:        Index:           2
73# CHECK-ALL-NEXT:      - Name:            __data_end
74# CHECK-ALL-NEXT:        Kind:            GLOBAL
75# CHECK-ALL-NEXT:        Index:           3
76# CHECK-ALL-NEXT:      - Name:            __global_base
77# CHECK-ALL-NEXT:        Kind:            GLOBAL
78# CHECK-ALL-NEXT:        Index:           4
79# CHECK-ALL-NEXT:      - Name:            __heap_base
80# CHECK-ALL-NEXT:        Kind:            GLOBAL
81# CHECK-ALL-NEXT:        Index:           5
82# CHECK-ALL-NEXT:      - Name:            __memory_base
83# CHECK-ALL-NEXT:        Kind:            GLOBAL
84# CHECK-ALL-NEXT:        Index:           6
85# CHECK-ALL-NEXT:      - Name:            __table_base
86# CHECK-ALL-NEXT:        Kind:            GLOBAL
87# CHECK-ALL-NEXT:        Index:           7
88# CHECK-ALL-NEXT:  - Type:            CODE
89