aboutsummaryrefslogtreecommitdiff
path: root/test/wasm/relocatable.ll
blob: 5ccaadf124650dbf6e18de3ab990428a4242056d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.o
; RUN: llc -filetype=obj %s -o %t.o
; RUN: wasm-ld -r -o %t.wasm %t.hello.o %t.o
; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes CHECK,NORMAL

; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.bm.o -mattr=+bulk-memory,+atomics
; RUN: llc -filetype=obj %s -o %t.bm.o -mattr=+bulk-memory
; RUN: wasm-ld -r -o %t.mt.wasm %t.hello.bm.o %t.bm.o --shared-memory --max-memory=131072
; RUN: obj2yaml %t.mt.wasm | FileCheck %s --check-prefixes CHECK,SHARED

target triple = "wasm32-unknown-unknown"

; Function Attrs: nounwind
define hidden i32 @my_func() local_unnamed_addr {
entry:
  %call = tail call i32 @foo_import()
  %call2 = tail call i32 @bar_import()
  ret i32 1
}

declare i32 @foo_import() local_unnamed_addr
declare extern_weak i32 @bar_import() local_unnamed_addr
@data_import = external global i64

@func_addr1 = hidden global i32()* @my_func, align 4
@func_addr2 = hidden global i32()* @foo_import, align 4
@func_addr3 = hidden global i32()* @bar_import, align 4
@data_addr1 = hidden global i64* @data_import, align 8

$func_comdat = comdat any
@data_comdat = weak_odr constant [3 x i8] c"abc", comdat($func_comdat)
define linkonce_odr i32 @func_comdat() comdat {
entry:
  ret i32 ptrtoint ([3 x i8]* @data_comdat to i32)
}

; Test that __attribute__(used) (i.e NO_STRIP) is preserved in the relocated symbol table
@llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @my_func to i8*)], section "llvm.metadata"

; CHECK:      --- !WASM
; CHECK-NEXT: FileHeader:
; CHECK-NEXT:   Version:         0x00000001
; CHECK-NEXT: Sections:
; CHECK-NEXT:   - Type:            TYPE
; CHECK-NEXT:     Signatures:
; CHECK-NEXT:       - Index:           0
; CHECK-NEXT:         ReturnType:      NORESULT
; CHECK-NEXT:         ParamTypes:
; CHECK-NEXT:           - I32
; CHECK-NEXT:       - Index:           1
; CHECK-NEXT:         ReturnType:      I32
; CHECK-NEXT:         ParamTypes:
; CHECK-NEXT:       - Index:           2
; CHECK-NEXT:         ReturnType:      NORESULT
; CHECK-NEXT:         ParamTypes:
; CHECK-NEXT:   - Type:            IMPORT
; CHECK-NEXT:     Imports:
; CHECK-NEXT:       - Module:          env
; CHECK-NEXT:         Field:           puts
; CHECK-NEXT:         Kind:            FUNCTION
; CHECK-NEXT:         SigIndex:        0
; CHECK-NEXT:       - Module:          env
; CHECK-NEXT:         Field:           foo_import
; CHECK-NEXT:         Kind:            FUNCTION
; CHECK-NEXT:         SigIndex:        1
; CHECK-NEXT:       - Module:          env
; CHECK-NEXT:         Field:           bar_import
; CHECK-NEXT:         Kind:            FUNCTION
; CHECK-NEXT:         SigIndex:        1
; CHECK-NEXT:   - Type:            FUNCTION
; CHECK-NEXT:     FunctionTypes:   [ 2, 1, 1 ]
; CHECK-NEXT:   - Type:            TABLE
; CHECK-NEXT:     Tables:
; CHECK-NEXT:       - ElemType:        FUNCREF
; CHECK-NEXT:         Limits:
; CHECK-NEXT:           Flags:           [ HAS_MAX ]
; CHECK-NEXT:           Initial:         0x00000004
; CHECK-NEXT:           Maximum:         0x00000004
; CHECK-NEXT:   - Type:            MEMORY
; CHECK-NEXT:     Memories:
; NORMAL-NEXT:      - Initial:         0x00000001
; SHARED-NEXT:      - Flags:           [ HAS_MAX, IS_SHARED ]
; SHARED-NEXT:        Initial:         0x00000001
; SHARED-NEXT:        Maximum:         0x00000002
; CHECK-NEXT:   - Type:            ELEM
; CHECK-NEXT:     Segments:
; CHECK-NEXT:       - Offset:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           1
; CHECK-NEXT:         Functions:       [ 4, 1, 2 ]
; SHARED-NEXT:  - Type:            DATACOUNT
; SHARED-NEXT:    Count:           6
; CHECK-NEXT:   - Type:            CODE
; CHECK-NEXT:     Relocations:
; CHECK-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB
; CHECK-NEXT:         Index:           1
; CHECK-NEXT:         Offset:          0x00000004
; CHECK-NEXT:       - Type:            R_WASM_FUNCTION_INDEX_LEB
; CHECK-NEXT:         Index:           2
; CHECK-NEXT:         Offset:          0x0000000A
; CHECK-NEXT:       - Type:            R_WASM_FUNCTION_INDEX_LEB
; CHECK-NEXT:         Index:           4
; CHECK-NEXT:         Offset:          0x00000013
; CHECK-NEXT:       - Type:            R_WASM_FUNCTION_INDEX_LEB
; CHECK-NEXT:         Index:           5
; CHECK-NEXT:         Offset:          0x0000001A
; CHECK-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB
; CHECK-NEXT:         Index:           7
; CHECK-NEXT:         Offset:          0x00000026
; CHECK-NEXT:     Functions:
; CHECK-NEXT:       - Index:         3
; CHECK-NEXT:         Locals:
; CHECK-NEXT:         Body:          4180808080001080808080000B
; CHECK-NEXT:       - Index:         4
; CHECK-NEXT:         Locals:
; CHECK-NEXT:         Body:          1081808080001A1082808080001A41010B
; CHECK-NEXT:       - Index:         5
; CHECK-NEXT:         Locals:
; CHECK-NEXT:         Body:          4187808080000B
; NORMAL-NEXT:  - Type:            DATA
; NORMAL-NEXT:    Relocations:
; NORMAL-NEXT:      - Type:            R_WASM_TABLE_INDEX_I32
; NORMAL-NEXT:        Index:           3
; NORMAL-NEXT:        Offset:          0x0000001A
; NORMAL-NEXT:      - Type:            R_WASM_TABLE_INDEX_I32
; NORMAL-NEXT:        Index:           4
; NORMAL-NEXT:        Offset:          0x00000023
; NORMAL-NEXT:      - Type:            R_WASM_TABLE_INDEX_I32
; NORMAL-NEXT:        Index:           5
; NORMAL-NEXT:        Offset:          0x0000002C
; NORMAL-NEXT:      - Type:            R_WASM_MEMORY_ADDR_I32
; NORMAL-NEXT:        Index:           12
; NORMAL-NEXT:        Offset:          0x00000035
; NORMAL-NEXT:    Segments:
; NORMAL-NEXT:      - SectionOffset:   6
; NORMAL-NEXT:        InitFlags:       0
; NORMAL-NEXT:        Offset:
; NORMAL-NEXT:          Opcode:          I32_CONST
; NORMAL-NEXT:          Value:           0
; NORMAL-NEXT:        Content:         68656C6C6F0A00
; NORMAL-NEXT:      - SectionOffset:   18
; NORMAL-NEXT:        InitFlags:       0
; NORMAL-NEXT:        Offset:
; NORMAL-NEXT:          Opcode:          I32_CONST
; NORMAL-NEXT:          Value:           7
; NORMAL-NEXT:        Content:         '616263'
; NORMAL-NEXT:      - SectionOffset:   26
; NORMAL-NEXT:        InitFlags:       0
; NORMAL-NEXT:        Offset:
; NORMAL-NEXT:          Opcode:          I32_CONST
; NORMAL-NEXT:          Value:           12
; NORMAL-NEXT:        Content:         '01000000'
; NORMAL-NEXT:      - SectionOffset:   35
; NORMAL-NEXT:        InitFlags:       0
; NORMAL-NEXT:        Offset:
; NORMAL-NEXT:          Opcode:          I32_CONST
; NORMAL-NEXT:          Value:           16
; NORMAL-NEXT:        Content:         '02000000'
; NORMAL-NEXT:      - SectionOffset:   44
; NORMAL-NEXT:        InitFlags:       0
; NORMAL-NEXT:        Offset:
; NORMAL-NEXT:          Opcode:          I32_CONST
; NORMAL-NEXT:          Value:           20
; NORMAL-NEXT:        Content:         '03000000'
; NORMAL-NEXT:      - SectionOffset:   53
; NORMAL-NEXT:        InitFlags:       0
; NORMAL-NEXT:        Offset:
; NORMAL-NEXT:          Opcode:          I32_CONST
; NORMAL-NEXT:          Value:           24
; NORMAL-NEXT:        Content:         '00000000'
; NORMAL-NEXT:  - Type:            CUSTOM
; NORMAL-NEXT:    Name:            linking
; NORMAL-NEXT:    Version:         2
; NORMAL-NEXT:    SymbolTable:
; NORMAL-NEXT:      - Index:           0
; NORMAL-NEXT:        Kind:            FUNCTION
; NORMAL-NEXT:        Name:            hello
; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
; NORMAL-NEXT:        Function:        3
; NORMAL-NEXT:      - Index:           1
; NORMAL-NEXT:        Kind:            DATA
; NORMAL-NEXT:        Name:            hello_str
; NORMAL-NEXT:        Flags:           [  ]
; NORMAL-NEXT:        Segment:         0
; NORMAL-NEXT:        Size:            7
; NORMAL-NEXT:      - Index:           2
; NORMAL-NEXT:        Kind:            FUNCTION
; NORMAL-NEXT:        Name:            puts
; NORMAL-NEXT:        Flags:           [ UNDEFINED ]
; NORMAL-NEXT:        Function:        0
; NORMAL-NEXT:      - Index:           3
; NORMAL-NEXT:        Kind:            FUNCTION
; NORMAL-NEXT:        Name:            my_func
; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN, NO_STRIP ]
; NORMAL-NEXT:        Function:        4
; NORMAL-NEXT:      - Index:           4
; NORMAL-NEXT:        Kind:            FUNCTION
; NORMAL-NEXT:        Name:            foo_import
; NORMAL-NEXT:        Flags:           [ UNDEFINED ]
; NORMAL-NEXT:        Function:        1
; NORMAL-NEXT:      - Index:           5
; NORMAL-NEXT:        Kind:            FUNCTION
; NORMAL-NEXT:        Name:            bar_import
; NORMAL-NEXT:        Flags:           [ BINDING_WEAK, UNDEFINED ]
; NORMAL-NEXT:        Function:        2
; NORMAL-NEXT:      - Index:           6
; NORMAL-NEXT:        Kind:            FUNCTION
; NORMAL-NEXT:        Name:            func_comdat
; NORMAL-NEXT:        Flags:           [ BINDING_WEAK ]
; NORMAL-NEXT:        Function:        5
; NORMAL-NEXT:      - Index:           7
; NORMAL-NEXT:        Kind:            DATA
; NORMAL-NEXT:        Name:            data_comdat
; NORMAL-NEXT:        Flags:           [ BINDING_WEAK ]
; NORMAL-NEXT:        Segment:         1
; NORMAL-NEXT:        Size:            3
; NORMAL-NEXT:      - Index:           8
; NORMAL-NEXT:        Kind:            DATA
; NORMAL-NEXT:        Name:            func_addr1
; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
; NORMAL-NEXT:        Segment:         2
; NORMAL-NEXT:        Size:            4
; NORMAL-NEXT:      - Index:           9
; NORMAL-NEXT:        Kind:            DATA
; NORMAL-NEXT:        Name:            func_addr2
; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
; NORMAL-NEXT:        Segment:         3
; NORMAL-NEXT:        Size:            4
; NORMAL-NEXT:      - Index:           10
; NORMAL-NEXT:        Kind:            DATA
; NORMAL-NEXT:        Name:            func_addr3
; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
; NORMAL-NEXT:        Segment:         4
; NORMAL-NEXT:        Size:            4
; NORMAL-NEXT:      - Index:           11
; NORMAL-NEXT:        Kind:            DATA
; NORMAL-NEXT:        Name:            data_addr1
; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
; NORMAL-NEXT:        Segment:         5
; NORMAL-NEXT:        Size:            4
; NORMAL-NEXT:      - Index:           12
; NORMAL-NEXT:        Kind:            DATA
; NORMAL-NEXT:        Name:            data_import
; NORMAL-NEXT:        Flags:           [ UNDEFINED ]
; NORMAL-NEXT:    SegmentInfo:
; NORMAL-NEXT:      - Index:           0
; NORMAL-NEXT:        Name:            .rodata.hello_str
; NORMAL-NEXT:        Alignment:       0
; NORMAL-NEXT:        Flags:           [  ]
; NORMAL-NEXT:      - Index:           1
; NORMAL-NEXT:        Name:            .rodata.data_comdat
; NORMAL-NEXT:        Alignment:       0
; NORMAL-NEXT:        Flags:           [  ]
; NORMAL-NEXT:      - Index:           2
; NORMAL-NEXT:        Name:            .data.func_addr1
; NORMAL-NEXT:        Alignment:       2
; NORMAL-NEXT:        Flags:           [  ]
; NORMAL-NEXT:      - Index:           3
; NORMAL-NEXT:        Name:            .data.func_addr2
; NORMAL-NEXT:        Alignment:       2
; NORMAL-NEXT:        Flags:           [  ]
; NORMAL-NEXT:      - Index:           4
; NORMAL-NEXT:        Name:            .data.func_addr3
; NORMAL-NEXT:        Alignment:       2
; NORMAL-NEXT:        Flags:           [  ]
; NORMAL-NEXT:      - Index:           5
; NORMAL-NEXT:        Name:            .data.data_addr1
; NORMAL-NEXT:        Alignment:       3
; NORMAL-NEXT:        Flags:           [  ]
; NORMAL-NEXT:    Comdats:
; NORMAL-NEXT:      - Name:            func_comdat
; NORMAL-NEXT:        Entries:
; NORMAL-NEXT:          - Kind:            FUNCTION
; NORMAL-NEXT:            Index:           5
; NORMAL-NEXT:          - Kind:            DATA
; NORMAL-NEXT:            Index:           1
; NORMAL-NEXT:  - Type:            CUSTOM
; NORMAL-NEXT:    Name:            name
; NORMAL-NEXT:    FunctionNames:
; NORMAL-NEXT:      - Index:           0
; NORMAL-NEXT:        Name:            puts
; NORMAL-NEXT:      - Index:           1
; NORMAL-NEXT:        Name:            foo_import
; NORMAL-NEXT:      - Index:           2
; NORMAL-NEXT:        Name:            bar_import
; NORMAL-NEXT:      - Index:           3
; NORMAL-NEXT:        Name:            hello
; NORMAL-NEXT:      - Index:           4
; NORMAL-NEXT:        Name:            my_func
; NORMAL-NEXT:      - Index:           5
; NORMAL-NEXT:        Name:            func_comdat
; NORMAL-NEXT:...