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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
use enum_iterator::Sequence;
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use std::fmt;
/// The name of a runtime library routine.
///
/// This list is likely to grow over time.
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, Sequence, RkyvSerialize, RkyvDeserialize, Archive,
)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))]
#[rkyv(derive(Debug, Hash, PartialEq, Eq), compare(PartialEq))]
#[repr(u16)]
pub enum LibCall {
/// ceil.f32
CeilF32,
/// ceil.f64
CeilF64,
/// floor.f32
FloorF32,
/// floor.f64
FloorF64,
/// nearest.f32
NearestF32,
/// nearest.f64
NearestF64,
/// sqrt.f32
SqrtF32,
/// sqrt.f64
SqrtF64,
/// trunc.f32
TruncF32,
/// trunc.f64
TruncF64,
/// memory.size for local functions
Memory32Size,
/// memory.size for imported functions
ImportedMemory32Size,
/// table.copy
TableCopy,
/// table.init
TableInit,
/// table.fill
TableFill,
/// table.size for local tables
TableSize,
/// table.size for imported tables
ImportedTableSize,
/// table.get for local tables
TableGet,
/// table.get for imported tables
ImportedTableGet,
/// table.set for local tables
TableSet,
/// table.set for imported tables
ImportedTableSet,
/// table.grow for local tables
TableGrow,
/// table.grow for imported tables
ImportedTableGrow,
/// ref.func
FuncRef,
/// elem.drop
ElemDrop,
/// memory.copy for local memories
Memory32Copy,
/// memory.copy for imported memories
ImportedMemory32Copy,
/// memory.fill for local memories
Memory32Fill,
/// memory.fill for imported memories
ImportedMemory32Fill,
/// memory.init
Memory32Init,
/// data.drop
DataDrop,
/// A custom trap
RaiseTrap,
/// probe for stack overflow. These are emitted for functions which need
/// when the `enable_probestack` setting is true.
Probestack,
/// memory.atomic.wait32 for local memories
Memory32AtomicWait32,
/// memory.atomic.wait32 for imported memories
ImportedMemory32AtomicWait32,
/// memory.atomic.wait64 for local memories
Memory32AtomicWait64,
/// memory.atomic.wait64 for imported memories
ImportedMemory32AtomicWait64,
/// memory.atomic.notify for local memories
Memory32AtomicNotify,
/// memory.atomic.notify for imported memories
ImportedMemory32AtomicNotify,
/// throw
Throw,
/// allocate exception object and get an exnref for it
AllocException,
/// Get the values buffer pointer out of an exnref
ReadExnRef,
/// Given a caught native exception pointer, get the exnref and delete the exception itself
LibunwindExceptionIntoExnRef,
/// The personality function
EHPersonality,
/// The second stage of the EH personality function
EHPersonality2,
/// debug_usize
DebugUsize,
/// debug_str
DebugStr,
// Soft-float routines emitted by LLVM when targeting platforms without hardware floating-point.
// Standard toolchains (compiler-rt / libgcc) provide these, but wasmer needs to know their
// addresses to link JIT-compiled objects.
// Ordered to match the GCC runtime library documentation (§3.2).
// https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html
// §3.2.1 Arithmetic
/// __addsf3
Addsf3,
/// __adddf3
Adddf3,
/// __subsf3
Subsf3,
/// __subdf3
Subdf3,
/// __mulsf3
Mulsf3,
/// __muldf3
Muldf3,
/// __divsf3
Divsf3,
/// __divdf3
Divdf3,
/// __negsf2
Negsf2,
/// __negdf2
Negdf2,
// §3.2.2 Conversion
/// __extendsfdf2
Extendsfdf2,
/// __truncdfsf2
Truncdfsf2,
/// __fixsfsi
Fixsfsi,
/// __fixdfsi
Fixdfsi,
/// __fixsfdi
Fixsfdi,
/// __fixdfdi
Fixdfdi,
/// __fixunssfsi
Fixunssfsi,
/// __fixunsdfsi
Fixunsdfsi,
/// __fixunssfdi
Fixunssfdi,
/// __fixunsdfdi
Fixunsdfdi,
/// __floatsisf
Floatsisf,
/// __floatsidf
Floatsidf,
/// __floatdisf
Floatdisf,
/// __floatdidf
Floatdidf,
/// __floatunsisf
Floatunsisf,
/// __floatunsidf
Floatunsidf,
/// __floatundisf
Floatundisf,
/// __floatundidf
Floatundidf,
// §3.2.3 Comparison
/// __unordsf2
Unordsf2,
/// __unorddf2
Unorddf2,
/// __eqsf2
Eqsf2,
/// __eqdf2
Eqdf2,
/// __nesf2
Nesf2,
/// __nedf2
Nedf2,
/// __gesf2
Gesf2,
/// __gedf2
Gedf2,
/// __ltsf2
Ltsf2,
/// __ltdf2
Ltdf2,
/// __lesf2
Lesf2,
/// __ledf2
Ledf2,
/// __gtsf2
Gtsf2,
/// __gtdf2
Gtdf2,
}
impl LibCall {
/// Return the function name associated to the libcall.
pub fn to_function_name(&self) -> &str {
match self {
Self::CeilF32 => "wasmer_vm_f32_ceil",
Self::CeilF64 => "wasmer_vm_f64_ceil",
Self::FloorF32 => "wasmer_vm_f32_floor",
Self::FloorF64 => "wasmer_vm_f64_floor",
Self::NearestF32 => "wasmer_vm_f32_nearest",
Self::NearestF64 => "wasmer_vm_f64_nearest",
Self::SqrtF32 => "wasmer_vm_f32_sqrt",
Self::SqrtF64 => "wasmer_vm_f64_sqrt",
Self::TruncF32 => "wasmer_vm_f32_trunc",
Self::TruncF64 => "wasmer_vm_f64_trunc",
Self::Memory32Size => "wasmer_vm_memory32_size",
Self::ImportedMemory32Size => "wasmer_vm_imported_memory32_size",
Self::TableCopy => "wasmer_vm_table_copy",
Self::TableInit => "wasmer_vm_table_init",
Self::TableFill => "wasmer_vm_table_fill",
Self::TableSize => "wasmer_vm_table_size",
Self::ImportedTableSize => "wasmer_vm_imported_table_size",
Self::TableGet => "wasmer_vm_table_get",
Self::ImportedTableGet => "wasmer_vm_imported_table_get",
Self::TableSet => "wasmer_vm_table_set",
Self::ImportedTableSet => "wasmer_vm_imported_table_set",
Self::TableGrow => "wasmer_vm_table_grow",
Self::ImportedTableGrow => "wasmer_vm_imported_table_grow",
Self::FuncRef => "wasmer_vm_func_ref",
Self::ElemDrop => "wasmer_vm_elem_drop",
Self::Memory32Copy => "wasmer_vm_memory32_copy",
Self::ImportedMemory32Copy => "wasmer_vm_imported_memory32_copy",
Self::Memory32Fill => "wasmer_vm_memory32_fill",
Self::ImportedMemory32Fill => "wasmer_vm_imported_memory32_fill",
Self::Memory32Init => "wasmer_vm_memory32_init",
Self::DataDrop => "wasmer_vm_data_drop",
Self::RaiseTrap => "wasmer_vm_raise_trap",
// We have to do this because macOS requires a leading `_` and it's not
// a normal function, it's a static variable, so we have to do it manually.
#[cfg(target_vendor = "apple")]
Self::Probestack => "_wasmer_vm_probestack",
#[cfg(not(target_vendor = "apple"))]
Self::Probestack => "wasmer_vm_probestack",
Self::Memory32AtomicWait32 => "wasmer_vm_memory32_atomic_wait32",
Self::ImportedMemory32AtomicWait32 => "wasmer_vm_imported_memory32_atomic_wait32",
Self::Memory32AtomicWait64 => "wasmer_vm_memory32_atomic_wait64",
Self::ImportedMemory32AtomicWait64 => "wasmer_vm_imported_memory32_atomic_wait64",
Self::Memory32AtomicNotify => "wasmer_vm_memory32_atomic_notify",
Self::ImportedMemory32AtomicNotify => "wasmer_vm_imported_memory32_atomic_notify",
Self::Throw => "wasmer_vm_throw",
Self::EHPersonality => "wasmer_eh_personality",
Self::EHPersonality2 => "wasmer_eh_personality2",
Self::AllocException => "wasmer_vm_alloc_exception",
Self::ReadExnRef => "wasmer_vm_read_exnref",
Self::LibunwindExceptionIntoExnRef => "wasmer_vm_exception_into_exnref",
Self::DebugUsize => "wasmer_vm_dbg_usize",
Self::DebugStr => "wasmer_vm_dbg_str",
// --- Soft-float libcalls ---
Self::Addsf3 => "__addsf3",
Self::Adddf3 => "__adddf3",
Self::Subsf3 => "__subsf3",
Self::Subdf3 => "__subdf3",
Self::Mulsf3 => "__mulsf3",
Self::Muldf3 => "__muldf3",
Self::Divsf3 => "__divsf3",
Self::Divdf3 => "__divdf3",
Self::Negsf2 => "__negsf2",
Self::Negdf2 => "__negdf2",
Self::Extendsfdf2 => "__extendsfdf2",
Self::Truncdfsf2 => "__truncdfsf2",
Self::Fixsfsi => "__fixsfsi",
Self::Fixdfsi => "__fixdfsi",
Self::Fixsfdi => "__fixsfdi",
Self::Fixdfdi => "__fixdfdi",
Self::Fixunssfsi => "__fixunssfsi",
Self::Fixunsdfsi => "__fixunsdfsi",
Self::Fixunssfdi => "__fixunssfdi",
Self::Fixunsdfdi => "__fixunsdfdi",
Self::Floatsisf => "__floatsisf",
Self::Floatsidf => "__floatsidf",
Self::Floatdisf => "__floatdisf",
Self::Floatdidf => "__floatdidf",
Self::Floatunsisf => "__floatunsisf",
Self::Floatunsidf => "__floatunsidf",
Self::Floatundisf => "__floatundisf",
Self::Floatundidf => "__floatundidf",
Self::Unordsf2 => "__unordsf2",
Self::Unorddf2 => "__unorddf2",
Self::Eqsf2 => "__eqsf2",
Self::Eqdf2 => "__eqdf2",
Self::Nesf2 => "__nesf2",
Self::Nedf2 => "__nedf2",
Self::Gesf2 => "__gesf2",
Self::Gedf2 => "__gedf2",
Self::Ltsf2 => "__ltsf2",
Self::Ltdf2 => "__ltdf2",
Self::Lesf2 => "__lesf2",
Self::Ledf2 => "__ledf2",
Self::Gtsf2 => "__gtsf2",
Self::Gtdf2 => "__gtdf2",
}
}
}
impl fmt::Display for LibCall {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self, f)
}
}