1; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/hello.s -o %t.hello32.o
2; RUN: llc -mtriple=wasm32-unknown-unknown -filetype=obj %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 --check-prefixes CHECK,CHK32 %s
5
6; RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-unknown %p/Inputs/hello.s -o %t.hello64.o
7; RUN: llc -mtriple=wasm64-unknown-unknown -filetype=obj %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 %s
10
11@foo = hidden global i32 1, align 4
12@aligned_bar = hidden global i32 3, align 16
13
14@hello_str = external global i8*
15@external_ref = global i8** @hello_str, align 8
16
17%struct.s = type { i32, i32 }
18@local_struct = hidden global %struct.s zeroinitializer, align 4
19@local_struct_internal_ptr = hidden local_unnamed_addr global i32* getelementptr inbounds (%struct.s, %struct.s* @local_struct, i32 0, i32 1), align 4
20
21; CHECK:        - Type:            MEMORY
22; CHECK-NEXT:     Memories:
23; CHK32-NEXT:       - Initial:         0x2
24; CHK64-NEXT:       - Flags:           [ IS_64 ]
25; CHK64-NEXT:         Initial:         0x2
26; CHECK-NEXT:   - Type:            GLOBAL
27; CHECK-NEXT:     Globals:
28; CHECK-NEXT:       - Index:           0
29; CHK32-NEXT:         Type:            I32
30; CHK64-NEXT:         Type:            I64
31; CHECK-NEXT:         Mutable:         true
32; CHECK-NEXT:         InitExpr:
33; CHK32-NEXT:           Opcode:          I32_CONST
34; CHK64-NEXT:           Opcode:          I64_CONST
35; CHECK-NEXT:           Value:           66624
36; CHECK-NEXT:       - Index:           1
37; CHECK-NEXT:         Type:            I32
38; CHECK-NEXT:         Mutable:         false
39; CHECK-NEXT:         InitExpr:
40; CHECK-NEXT:           Opcode:          I32_CONST
41; CHK32-NEXT:           Value:           1080
42; CHK64-NEXT:           Value:           1088
43; CHECK-NEXT:       - Index:           2
44; CHECK-NEXT:         Type:            I32
45; CHECK-NEXT:         Mutable:         false
46; CHECK-NEXT:         InitExpr:
47; CHECK-NEXT:           Opcode:          I32_CONST
48; CHECK-NEXT:           Value:           66624
49
50; CHECK:        - Type:            DATA
51; CHECK-NEXT:     Segments:
52; CHECK-NEXT:       - SectionOffset:   7
53; CHECK-NEXT:         InitFlags:       0
54; CHECK-NEXT:         Offset:
55; CHECK-NEXT:           Opcode:          I32_CONST
56; CHECK-NEXT:           Value:           1024
57; CHECK-NEXT:         Content:         68656C6C6F0A00
58; CHECK-NEXT:       - SectionOffset:   20
59; CHECK-NEXT:         InitFlags:       0
60; CHECK-NEXT:         Offset:
61; CHECK-NEXT:           Opcode:          I32_CONST
62; CHECK-NEXT:           Value:           1040
63
64
65; RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry \
66; RUN:     --initial-memory=131072 --max-memory=131072 -o %t_max.wasm %t32.o \
67; RUN:     %t.hello32.o
68; RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-MAX
69
70; CHECK-MAX:        - Type:            MEMORY
71; CHECK-MAX-NEXT:     Memories:
72; CHECK-MAX-NEXT:       - Flags:           [ HAS_MAX ]
73; CHECK-MAX-NEXT:         Initial:         0x2
74; CHECK-MAX-NEXT:         Maximum:         0x2
75
76; RUN: wasm-ld -no-gc-sections --allow-undefined --no-entry --shared-memory \
77; RUN:     --features=atomics,bulk-memory --initial-memory=131072 \
78; RUN:     --max-memory=131072 -o %t_max.wasm %t32.o %t.hello32.o
79; RUN: obj2yaml %t_max.wasm | FileCheck %s -check-prefix=CHECK-SHARED
80
81; CHECK-SHARED:        - Type:            MEMORY
82; CHECK-SHARED-NEXT:     Memories:
83; CHECK-SHARED-NEXT:       - Flags:           [ HAS_MAX, IS_SHARED ]
84; CHECK-SHARED-NEXT:         Initial:         0x2
85; CHECK-SHARED-NEXT:         Maximum:         0x2
86
87; RUN: wasm-ld --relocatable -o %t_reloc.wasm %t32.o %t.hello32.o
88; RUN: obj2yaml %t_reloc.wasm | FileCheck %s -check-prefix=RELOC
89
90; RELOC:       - Type:            DATA
91; RELOC-NEXT:     Relocations:
92; RELOC-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I32
93; RELOC-NEXT:         Index:           3
94; RELOC-NEXT:         Offset:          0x24
95; RELOC-NEXT:       - Type:            R_WASM_MEMORY_ADDR_I32
96; RELOC-NEXT:         Index:           4
97; RELOC-NEXT:         Offset:          0x2D
98; RELOC-NEXT:         Addend:          4
99; RELOC-NEXT:     Segments:
100; RELOC-NEXT:       - SectionOffset:   6
101; RELOC-NEXT:         InitFlags:       0
102; RELOC-NEXT:         Offset:
103; RELOC-NEXT:           Opcode:          I32_CONST
104; RELOC-NEXT:           Value:           0
105; RELOC-NEXT:         Content:         68656C6C6F0A00
106; RELOC-NEXT:       - SectionOffset:   18
107; RELOC-NEXT:         InitFlags:       0
108; RELOC-NEXT:         Offset:
109; RELOC-NEXT:           Opcode:          I32_CONST
110; RELOC-NEXT:           Value:           8
111; RELOC-NEXT:         Content:         '01000000'
112; RELOC-NEXT:       - SectionOffset:   27
113; RELOC-NEXT:         InitFlags:       0
114; RELOC-NEXT:         Offset:
115; RELOC-NEXT:           Opcode:          I32_CONST
116; RELOC-NEXT:           Value:           16
117; RELOC-NEXT:         Content:         '03000000'
118; RELOC-NEXT:       - SectionOffset:   36
119; RELOC-NEXT:         InitFlags:       0
120; RELOC-NEXT:         Offset:
121; RELOC-NEXT:           Opcode:          I32_CONST
122; RELOC-NEXT:           Value:           24
123; RELOC-NEXT:         Content:         '00000000'
124; RELOC-NEXT:       - SectionOffset:   45
125; RELOC-NEXT:         InitFlags:       0
126; RELOC-NEXT:         Offset:
127; RELOC-NEXT:           Opcode:          I32_CONST
128; RELOC-NEXT:           Value:           28
129; RELOC-NEXT:         Content:         '24000000'
130; RELOC-NEXT:       - SectionOffset:   54
131; RELOC-NEXT:         InitFlags:       0
132; RELOC-NEXT:         Offset:
133; RELOC-NEXT:           Opcode:          I32_CONST
134; RELOC-NEXT:           Value:           32
135; RELOC-NEXT:         Content:         '0000000000000000'
136
137; RELOC:          SymbolTable:
138; RELOC-NEXT:       - Index:           0
139; RELOC-NEXT:         Kind:            DATA
140; RELOC-NEXT:         Name:            foo
141; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
142; RELOC-NEXT:         Segment:         1
143; RELOC-NEXT:         Size:            4
144; RELOC-NEXT:       - Index:           1
145; RELOC-NEXT:         Kind:            DATA
146; RELOC-NEXT:         Name:            aligned_bar
147; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
148; RELOC-NEXT:         Segment:         2
149; RELOC-NEXT:         Size:            4
150; RELOC-NEXT:       - Index:           2
151; RELOC-NEXT:         Kind:            DATA
152; RELOC-NEXT:         Name:            external_ref
153; RELOC-NEXT:         Flags:           [  ]
154; RELOC-NEXT:         Segment:         3
155; RELOC-NEXT:         Size:            4
156; RELOC-NEXT:       - Index:           3
157; RELOC-NEXT:         Kind:            DATA
158; RELOC-NEXT:         Name:            hello_str
159; RELOC-NEXT:         Flags:           [  ]
160; RELOC-NEXT:         Segment:         0
161; RELOC-NEXT:         Size:            7
162