xref: /llvm-project/lld/test/wasm/data-layout.s (revision cb4f94db83d9c4373b485493ef079e318f63bf13)
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-entry --initial-memory=327680 --no-growable-memory \
107# RUN:     -o %t_max.wasm %t.hello32.o
108# RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-NO-GROWTH
109
110# CHECK-NO-GROWTH:        - Type:            MEMORY
111# CHECK-NO-GROWTH-NEXT:     Memories:
112# CHECK-NO-GROWTH-NEXT:       - Flags:           [ HAS_MAX ]
113# CHECK-NO-GROWTH-NEXT:         Minimum:         0x5
114# CHECK-NO-GROWTH-NEXT:         Maximum:         0x5
115
116# RUN: not wasm-ld --max-memory=262144 --no-growable-memory \
117# RUN:     --no-entry -o %t_max.wasm %t.hello32.o 2>&1 \
118# RUN: | FileCheck %s --check-prefix CHECK-NO-GROWTH-COMPAT-ERROR
119
120# CHECK-NO-GROWTH-COMPAT-ERROR: --max-memory is incompatible with --no-growable-memory
121
122# RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry --shared-memory \
123# RUN:     --features=atomics,bulk-memory --initial-memory=131072 \
124# RUN:     --max-memory=131072 -o %t_max.wasm %t32.o %t.hello32.o
125# RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-SHARED
126
127# CHECK-SHARED:        - Type:            MEMORY
128# CHECK-SHARED-NEXT:     Memories:
129# CHECK-SHARED-NEXT:       - Flags:           [ HAS_MAX, IS_SHARED ]
130# CHECK-SHARED-NEXT:         Minimum:         0x2
131# CHECK-SHARED-NEXT:         Maximum:         0x2
132
133# XUN: wasm-ld --relocatable -o %t_reloc.wasm %t32.o %t.hello32.o
134# XUN: obj2yaml %t_reloc.wasm | FileCheck %s -check-prefix=RELOC
135
136# RELOC:       - Type:            DATA
137# RELOC-NEXT:     Relocations:
138# RELOC-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I32
139# RELOC-NEXT:         Index:           3
140# RELOC-NEXT:         Offset:          0x24
141# RELOC-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I32
142# RELOC-NEXT:         Index:           4
143# RELOC-NEXT:         Offset:          0x2D
144# RELOC-NEXT:         Addend:          4
145# RELOC-NEXT:     Segments:
146# RELOC-NEXT:       - SectionOffset:   6
147# RELOC-NEXT:         InitFlags:       0
148# RELOC-NEXT:         Offset:
149# RELOC-NEXT:           Opcode:          I32_CONST
150# RELOC-NEXT:           Value:           0
151# RELOC-NEXT:         Content:         68656C6C6F0A00
152# RELOC-NEXT:       - SectionOffset:   18
153# RELOC-NEXT:         InitFlags:       0
154# RELOC-NEXT:         Offset:
155# RELOC-NEXT:           Opcode:          I32_CONST
156# RELOC-NEXT:           Value:           8
157# RELOC-NEXT:         Content:         '01000000'
158# RELOC-NEXT:       - SectionOffset:   27
159# RELOC-NEXT:         InitFlags:       0
160# RELOC-NEXT:         Offset:
161# RELOC-NEXT:           Opcode:          I32_CONST
162# RELOC-NEXT:           Value:           16
163# RELOC-NEXT:         Content:         '03000000'
164# RELOC-NEXT:       - SectionOffset:   36
165# RELOC-NEXT:         InitFlags:       0
166# RELOC-NEXT:         Offset:
167# RELOC-NEXT:           Opcode:          I32_CONST
168# RELOC-NEXT:           Value:           24
169# RELOC-NEXT:         Content:         '00000000'
170# RELOC-NEXT:       - SectionOffset:   45
171# RELOC-NEXT:         InitFlags:       0
172# RELOC-NEXT:         Offset:
173# RELOC-NEXT:           Opcode:          I32_CONST
174# RELOC-NEXT:           Value:           28
175# RELOC-NEXT:         Content:         '24000000'
176# RELOC-NEXT:       - SectionOffset:   54
177# RELOC-NEXT:         InitFlags:       0
178# RELOC-NEXT:         Offset:
179# RELOC-NEXT:           Opcode:          I32_CONST
180# RELOC-NEXT:           Value:           32
181# RELOC-NEXT:         Content:         '0000000000000000'
182
183# RELOC:          SymbolTable:
184# RELOC-NEXT:       - Index:           0
185# RELOC-NEXT:         Kind:            DATA
186# RELOC-NEXT:         Name:            foo
187# RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
188# RELOC-NEXT:         Segment:         1
189# RELOC-NEXT:         Size:            4
190# RELOC-NEXT:       - Index:           1
191# RELOC-NEXT:         Kind:            DATA
192# RELOC-NEXT:         Name:            aligned_bar
193# RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
194# RELOC-NEXT:         Segment:         2
195# RELOC-NEXT:         Size:            4
196# RELOC-NEXT:       - Index:           2
197# RELOC-NEXT:         Kind:            DATA
198# RELOC-NEXT:         Name:            external_ref
199# RELOC-NEXT:         Flags:           [  ]
200# RELOC-NEXT:         Segment:         3
201# RELOC-NEXT:         Size:            4
202# RELOC-NEXT:       - Index:           3
203# RELOC-NEXT:         Kind:            DATA
204# RELOC-NEXT:         Name:            hello_str
205# RELOC-NEXT:         Flags:           [  ]
206# RELOC-NEXT:         Segment:         0
207# RELOC-NEXT:         Size:            7
208