1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/hello.s -o %t.hello32.o
2# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t32.o
3# RUN: wasm-ld -m wasm32 -no-gc-sections --export=__data_end --export=__heap_base --allow-undefined --no-entry -o %t32.wasm %t32.o %t.hello32.o
4# RUN: obj2yaml %t32.wasm | FileCheck -DPTR=I32 %s
5#
6# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-unknown %p/Inputs/hello.s -o %t.hello64.o
7# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-unknown %s -o %t64.o
8# RUN: wasm-ld -m wasm64 -no-gc-sections --export=__data_end --export=__heap_base --allow-undefined --no-entry -o %t64.wasm %t64.o %t.hello64.o
9# RUN: obj2yaml %t64.wasm | FileCheck --check-prefixes CHECK,CHK64 -DPTR=I64 %s
10
11        .section .data.foo,"",@
12        .globl  foo
13        .hidden  foo
14        .p2align        2
15foo:
16        .int32  1
17        .size   foo, 4
18
19
20        .section .data.aligned_bar,"",@
21        .globl  aligned_bar
22        .hidden  aligned_bar
23        .p2align        4
24aligned_bar:
25        .int32  3
26        .size   aligned_bar, 4
27
28
29        .section .data.external_ref,"",@
30        .globl  external_ref
31        .p2align        3
32external_ref:
33        .int32  hello_str
34        .size   external_ref, 4
35
36
37        .section .bss.local_struct,"",@
38        .globl  local_struct
39        .hidden  local_struct
40        .p2align        2
41local_struct:
42        .skip   8
43        .size   local_struct, 8
44
45
46        .section .data.local_struct_internal_ptr,"",@
47        .globl  local_struct_internal_ptr
48        .hidden  local_struct_internal_ptr
49        .p2align        2
50local_struct_internal_ptr:
51        .int32  local_struct+4
52        .size   local_struct_internal_ptr, 4
53        .size   hello_str, 4
54
55# CHECK:        - Type:            MEMORY
56# CHECK-NEXT:     Memories:
57# CHK64-NEXT:       - Flags:           [ IS_64 ]
58# CHECK-NEXT:         Minimum:         0x2
59# CHECK-NEXT:   - Type:            GLOBAL
60# CHECK-NEXT:     Globals:
61# CHECK-NEXT:       - Index:           0
62# CHECK-NEXT:         Type:            [[PTR]]
63# CHECK-NEXT:         Mutable:         true
64# CHECK-NEXT:         InitExpr:
65# CHECK-NEXT:           Opcode:          [[PTR]]_CONST
66# CHECK-NEXT:           Value:           66624
67# CHECK-NEXT:       - Index:           1
68# CHECK-NEXT:         Type:            [[PTR]]
69# CHECK-NEXT:         Mutable:         false
70# CHECK-NEXT:         InitExpr:
71# CHECK-NEXT:           Opcode:          [[PTR]]_CONST
72# CHECK-NEXT:           Value:           1080
73# CHECK-NEXT:       - Index:           2
74# CHECK-NEXT:         Type:            [[PTR]]
75# CHECK-NEXT:         Mutable:         false
76# CHECK-NEXT:         InitExpr:
77# CHECK-NEXT:           Opcode:          [[PTR]]_CONST
78# CHECK-NEXT:           Value:           66624
79
80# CHECK:        - Type:            DATA
81# CHECK-NEXT:     Segments:
82# CHECK-NEXT:       - SectionOffset:   7
83# CHECK-NEXT:         InitFlags:       0
84# CHECK-NEXT:         Offset:
85# CHECK-NEXT:           Opcode:          [[PTR]]_CONST
86# CHECK-NEXT:           Value:           1024
87# CHECK-NEXT:         Content:         68656C6C6F0A00
88# CHECK-NEXT:       - SectionOffset:   20
89# CHECK-NEXT:         InitFlags:       0
90# CHECK-NEXT:         Offset:
91# CHECK-NEXT:           Opcode:          [[PTR]]_CONST
92# CHECK-NEXT:           Value:           1040
93
94
95# RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry \
96# RUN:     --initial-memory=131072 --max-memory=131072 -o %t_max.wasm %t32.o \
97# RUN:     %t.hello32.o
98# RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-MAX
99
100# CHECK-MAX:        - Type:            MEMORY
101# CHECK-MAX-NEXT:     Memories:
102# CHECK-MAX-NEXT:       - Flags:           [ HAS_MAX ]
103# CHECK-MAX-NEXT:         Minimum:         0x2
104# CHECK-MAX-NEXT:         Maximum:         0x2
105
106# RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry --shared-memory \
107# RUN:     --features=atomics,bulk-memory --initial-memory=131072 \
108# RUN:     --max-memory=131072 -o %t_max.wasm %t32.o %t.hello32.o
109# RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-SHARED
110
111# CHECK-SHARED:        - Type:            MEMORY
112# CHECK-SHARED-NEXT:     Memories:
113# CHECK-SHARED-NEXT:       - Flags:           [ HAS_MAX, IS_SHARED ]
114# CHECK-SHARED-NEXT:         Minimum:         0x2
115# CHECK-SHARED-NEXT:         Maximum:         0x2
116
117# XUN: wasm-ld --relocatable -o %t_reloc.wasm %t32.o %t.hello32.o
118# XUN: obj2yaml %t_reloc.wasm | FileCheck %s -check-prefix=RELOC
119
120# RELOC:       - Type:            DATA
121# RELOC-NEXT:     Relocations:
122# RELOC-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I32
123# RELOC-NEXT:         Index:           3
124# RELOC-NEXT:         Offset:          0x24
125# RELOC-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I32
126# RELOC-NEXT:         Index:           4
127# RELOC-NEXT:         Offset:          0x2D
128# RELOC-NEXT:         Addend:          4
129# RELOC-NEXT:     Segments:
130# RELOC-NEXT:       - SectionOffset:   6
131# RELOC-NEXT:         InitFlags:       0
132# RELOC-NEXT:         Offset:
133# RELOC-NEXT:           Opcode:          I32_CONST
134# RELOC-NEXT:           Value:           0
135# RELOC-NEXT:         Content:         68656C6C6F0A00
136# RELOC-NEXT:       - SectionOffset:   18
137# RELOC-NEXT:         InitFlags:       0
138# RELOC-NEXT:         Offset:
139# RELOC-NEXT:           Opcode:          I32_CONST
140# RELOC-NEXT:           Value:           8
141# RELOC-NEXT:         Content:         '01000000'
142# RELOC-NEXT:       - SectionOffset:   27
143# RELOC-NEXT:         InitFlags:       0
144# RELOC-NEXT:         Offset:
145# RELOC-NEXT:           Opcode:          I32_CONST
146# RELOC-NEXT:           Value:           16
147# RELOC-NEXT:         Content:         '03000000'
148# RELOC-NEXT:       - SectionOffset:   36
149# RELOC-NEXT:         InitFlags:       0
150# RELOC-NEXT:         Offset:
151# RELOC-NEXT:           Opcode:          I32_CONST
152# RELOC-NEXT:           Value:           24
153# RELOC-NEXT:         Content:         '00000000'
154# RELOC-NEXT:       - SectionOffset:   45
155# RELOC-NEXT:         InitFlags:       0
156# RELOC-NEXT:         Offset:
157# RELOC-NEXT:           Opcode:          I32_CONST
158# RELOC-NEXT:           Value:           28
159# RELOC-NEXT:         Content:         '24000000'
160# RELOC-NEXT:       - SectionOffset:   54
161# RELOC-NEXT:         InitFlags:       0
162# RELOC-NEXT:         Offset:
163# RELOC-NEXT:           Opcode:          I32_CONST
164# RELOC-NEXT:           Value:           32
165# RELOC-NEXT:         Content:         '0000000000000000'
166
167# RELOC:          SymbolTable:
168# RELOC-NEXT:       - Index:           0
169# RELOC-NEXT:         Kind:            DATA
170# RELOC-NEXT:         Name:            foo
171# RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
172# RELOC-NEXT:         Segment:         1
173# RELOC-NEXT:         Size:            4
174# RELOC-NEXT:       - Index:           1
175# RELOC-NEXT:         Kind:            DATA
176# RELOC-NEXT:         Name:            aligned_bar
177# RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
178# RELOC-NEXT:         Segment:         2
179# RELOC-NEXT:         Size:            4
180# RELOC-NEXT:       - Index:           2
181# RELOC-NEXT:         Kind:            DATA
182# RELOC-NEXT:         Name:            external_ref
183# RELOC-NEXT:         Flags:           [  ]
184# RELOC-NEXT:         Segment:         3
185# RELOC-NEXT:         Size:            4
186# RELOC-NEXT:       - Index:           3
187# RELOC-NEXT:         Kind:            DATA
188# RELOC-NEXT:         Name:            hello_str
189# RELOC-NEXT:         Flags:           [  ]
190# RELOC-NEXT:         Segment:         0
191# RELOC-NEXT:         Size:            7
192