Commit Graph

7212 Commits

Author SHA1 Message Date
Alex Crichton
b73b831892 Replace binaryen -ttf based fuzzing with wasm-smith (#2336)
This commit removes the binaryen support for fuzzing from wasmtime,
instead switching over to `wasm-smith`. In general it's great to have
what fuzzing we can, but our binaryen support suffers from a few issues:

* The Rust crate, binaryen-sys, seems largely unmaintained at this
  point. While we could likely take ownership and/or send PRs to update
  the crate it seems like the maintenance is largely on us at this point.

* Currently the binaryen-sys crate doesn't support fuzzing anything
  beyond MVP wasm, but we're interested at least in features like bulk
  memory and reference types. Additionally we'll also be interested in
  features like module-linking. New features would require either
  implementation work in binaryen or the binaryen-sys crate to support.

* We have 4-5 fuzz-bugs right now related to timeouts simply in
  generating a module for wasmtime to fuzz. One investigation along
  these lines in the past revealed a bug in binaryen itself, and in any
  case these bugs would otherwise need to get investigated, reported,
  and possibly fixed ourselves in upstream binaryen.

Overall I'm not sure at this point if maintaining binaryen fuzzing is
worth it with the advent of `wasm-smith` which has similar goals for
wasm module generation, but is much more readily maintainable on our
end.

Additonally in this commit I've added a fuzzer for wasm-smith's
`SwarmConfig`-based fuzzer which should expand the coverage of tested
modules.

Closes #2163
2020-10-29 10:02:59 -05:00
Qinxuan Chen
3cd9d52d32 Update the hashbrown to use the same version (#2338)
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
2020-10-29 09:59:56 -05:00
Alex Crichton
61f0b8fc56 Remove Windows-specific code for static memory bounds
Added in c4e10227de I think the original
reason (which I'm not entirely knowledgeable of) may no longer be
applicable? In any case this is a significant difference on Windows from
other platforms because it makes loads/stores of wasm code have manual
checks instead of relying on the guard page, causing runtime and
compile-time slowdowns on Windows-only.

I originally rediscovered this when investigating #2318 and saw that
both the compile time of the module in question and trap information
tables were much larger than they were on Linux. Removing this
Windows-specific configuration fixed the discrepancies and afterwards
Linux and Windows were basically the same.
2020-10-28 16:49:53 -07:00
Andrew Brown
6c6d958f38 [machinst x64]: implement packed pmin/pmax 2020-10-28 16:03:53 -07:00
Andrew Brown
6725b6b129 [machinst x64]: implement bitmask 2020-10-28 15:16:36 -07:00
Andrew Brown
5b9a21e099 Add missing SourceLoc to newly-emitted instructions
The changes in https://github.com/bytecodealliance/wasmtime/pull/2278 added `SourceLoc`s to several x64 `Inst` variants; between when that PR was last run in CI and when it was merged, new instructions were added that require this new parameter. This change adds the parameter in order to fix CI.
2020-10-28 14:33:09 -07:00
Johnnie Birch
fa66daea25 Add filetests for fcvt_from_sint.f32x4
Add portions of filetests simd-conversion-legalize.clif and simd-conversion-run.clif
that test fcvt_from_sint.f32x4
2020-10-28 13:02:50 -07:00
Johnnie Birch
8bbe6a25a9 Add support for packed float to signed int conversion
Implements i32x4.trunc_sat_f32x4_s
2020-10-28 13:02:50 -07:00
Johnnie Birch
97392eae3d Adds support for converting packed unsigned integer to packed float 2020-10-28 13:02:50 -07:00
Chris Fallin
c35904a8bf Merge pull request #2278 from akirilov-arm/load_splat
Introduce the Cranelift IR instruction `LoadSplat`
2020-10-28 12:54:03 -07:00
Alex Crichton
3461ffa563 Remove source_loc from TrapInformation (#2325)
Turns out this wasn't needed anywhere! Additionally we can construct it
from `InstructionAddressMap` anyway. There's so many pieces of trap
information that it's best to keep these structures small as well.
2020-10-28 13:05:05 -05:00
Nick Fitzgerald
a1db0ff6a9 Merge pull request #2329 from fitzgen/upload-serialized-peepholes
CI: upload built peepholes as artifacts
2020-10-27 16:03:54 -07:00
Leonardo Yvens
bde9555793 Add Trap::trap_code (#2309)
* add Trap::trap_code

* Add non-exhaustive wasmtime::TrapCode

* wasmtime: Better document TrapCode

* move and refactor test
2020-10-27 16:30:45 -05:00
Nick Fitzgerald
9fe900ae89 CI: upload built peepholes as artifacts
For people who can't build Z3, this lets them update the peephole optimizers
when necessary.
2020-10-27 13:02:17 -07:00
Alex Crichton
f6d5b8772c Compress in-memory representation of FunctionAddressMap (#2321)
This commit compresses `FunctionAddressMap` by performing a simple
coalescing of adjacent `InstructionAddressMap` descriptors if they
describe the same source location. This is intended to handle the common
case where a sequene of machine instructions describes a high-level wasm
instruction.

For the module on #2318 this reduces the cache entry size from 306MB to
161MB.
2020-10-26 13:22:25 -05:00
Alex Crichton
27233857c5 Encode modules with variable-length integers (#2322)
Update `Module::{serialize,deserialize}` to use variable-length integers
with `bincode` to make the output artifacts smaller. Locally this
reduces the size of #2318 from 160 to 110 MB, a 30% decrease in size!
Deserialization performance is slightly slower, but seemingly within the
range of noise locally for me.
2020-10-26 09:52:29 -05:00
Julian Seward
c15d9bd61b CL/aarch64: implement the wasm SIMD pseudo-max/min and FP-rounding instructions
This patch implements, for aarch64, the following wasm SIMD extensions

  Floating-point rounding instructions
  https://github.com/WebAssembly/simd/pull/232

  Pseudo-Minimum and Pseudo-Maximum instructions
  https://github.com/WebAssembly/simd/pull/122

The changes are straightforward:

* `build.rs`: the relevant tests have been enabled

* `cranelift/codegen/meta/src/shared/instructions.rs`: new CLIF instructions
  `fmin_pseudo` and `fmax_pseudo`.  The wasm rounding instructions do not need
  any new CLIF instructions.

* `cranelift/wasm/src/code_translator.rs`: translation into CLIF; this is
  pretty much the same as any other unary or binary vector instruction (for
  the rounding and the pmin/max respectively)

* `cranelift/codegen/src/isa/aarch64/lower_inst.rs`:
  - `fmin_pseudo` and `fmax_pseudo` are converted into a two instruction
    sequence, `fcmpgt` followed by `bsl`
  - the CLIF rounding instructions are converted to a suitable vector
    `frint{n,z,p,m}` instruction.

* `cranelift/codegen/src/isa/aarch64/inst/mod.rs`: minor extension of `pub
  enum VecMisc2` to handle the rounding operations.  And corresponding `emit`
  cases.
2020-10-26 10:37:07 +01:00
Till Schneidereit
fc1cedb2ff Add docs.wasmtime.dev as a CNAME for the Wasmtime docs (#2317)
* Update version of mdbook used in CI

* Configure cname for wasmtime docs
2020-10-25 15:48:20 -05:00
Andrew Brown
6ebbab61b9 Update cfg-if dependency 2020-10-23 16:50:51 -07:00
Yury Delendik
de4af90af6 machinst x64: New backend unwind (#2266)
Addresses unwind for experimental x64 backend. The preliminary code enables backtrace on SystemV call convension.
2020-10-23 15:19:41 -05:00
Julian Seward
2702942050 CL/aarch64 back end: implement the wasm SIMD bitmask instructions
The `bitmask.{8x16,16x8,32x4}` instructions do not map neatly to any single
AArch64 SIMD instruction, and instead need a sequence of around ten
instructions.  Because of this, this patch is somewhat longer and more complex
than it would be for (eg) x64.

Main changes are:

* the relevant testsuite test (`simd_boolean.wast`) has been enabled on aarch64.

* at the CLIF level, add a new instruction `vhigh_bits`, into which these wasm
  instructions are to be translated.

* in the wasm->CLIF translation (code_translator.rs), translate into
  `vhigh_bits`.  This is straightforward.

* in the CLIF->AArch64 translation (lower_inst.rs), translate `vhigh_bits`
  into equivalent sequences of AArch64 instructions.  There is a different
  sequence for each of the `{8x16, 16x8, 32x4}` variants.

All other changes are AArch64-specific, and add instruction definitions needed
by the previous step:

* Add two new families of AArch64 instructions: `VecShiftImm` (vector shift by
  immediate) and `VecExtract` (effectively a double-length vector shift)

* To the existing AArch64 family `VecRRR`, add a `zip1` variant.  To the
  `VecLanesOp` family add an `addv` variant.

* Add supporting code for the above changes to AArch64 instructions:
  - getting the register uses (`aarch64_get_regs`)
  - mapping the registers (`aarch64_map_regs`)
  - printing instructions
  - emitting instructions (`impl MachInstEmit for Inst`).  The handling of
    `VecShiftImm` is a bit complex.
  - emission tests for new instructions and variants.
2020-10-23 05:26:25 +02:00
Yury Delendik
b10e027fef Refactor UnwindInfo codes and frame_register (#2307)
* Refactor UnwindInfo codes and frame_register

* use isa word_size

* fix filetests

* Add comment about UnwindCode::PushRegister
2020-10-22 14:52:42 -05:00
Nick Fitzgerald
4f104d3a4e CI: fix rebuilding peepmatic peephole optimizers (#2311)
The test that triggers the rebuild of the peephole optimizers is in the
`cranelift-codegen` crate, not the umbrella cranelift crate. This was previously
successfully running zero tests, and then successfully reporting no `git diff`
because no peephole optimizers were ever rebuilt.

This change fixes it so that we run the correct test that triggers the
rebuilding of the peephole optimizers.
2020-10-22 12:39:40 -05:00
Nick Fitzgerald
c5a2bd3215 Merge pull request #2298 from EmbarkStudios/directories-next2
Replace unmaintained directories crate - RUSTSEC-2020-0054
2020-10-21 15:16:57 -07:00
Nick Fitzgerald
1532834f3e Merge pull request #2305 from alexcrichton/no-arc
Don't store `Arc<VMInterrupts>` in instances
2020-10-21 13:21:51 -07:00
Nick Fitzgerald
aa04917ddf Merge pull request #2306 from alexcrichton/no-finished-functions
Remove the `finished_functions` field in `Instance`
2020-10-21 13:21:04 -07:00
Alex Crichton
461ed42772 Remove the finished_functions field in Instance
Turns out we don't actually need it anywhere any more! This removes an
allocation when instantiating.
2020-10-21 11:43:11 -07:00
Alex Crichton
04e85b044e Don't store Arc<VMInterrupts> in instances
Similar to other data structures owned by the `Store` there's no need
for `Instance` to have a strong `Arc` reference, instead it's sufficient
for `Store` to have the owning reference.
2020-10-21 11:42:57 -07:00
Julian Seward
ab65d8f10c wasm->CLIF translation: consistently bitcast V128 values that are block formal parameters.
In the current translation of wasm (128-bit) SIMD into CLIF, we work around differences in the
type system models of wasm vs CLIF by inserting `bitcast` (a no-op cast) CLIF instructions before
more or less every use of a SIMD value.  Unfortunately this was not being done consistently and
even small examples with a single if-then-else diamond that produces a SIMD value, could cause a
verification failure downstream.  In this case, the jump out of the "else" block needed a
bitcast, but didn't have one.

This patch wraps creation of CLIF jumps and conditional branches up into three functions,
`canonicalise_then_jump` and `canonicalise_then_br{z,nz}`, and uses them consistently.  They
first cast the relevant block formal parameters, then generate the relevant kind of branch/jump.
Hence, provided they are also used consistently in future to generate branches/jumps in this
file, we are protected against such failures.

The patch also adds a large(ish) comment at the top explaining this in more detail.
2020-10-21 17:43:49 +02:00
Nick Fitzgerald
76998f0404 Merge pull request #2300 from alexcrichton/no-allocate-isa
Don't allocate a new ISA for each `Func::wrap`
2020-10-18 13:36:29 -07:00
Nick Fitzgerald
1a0a2bc259 Merge pull request #2301 from alexcrichton/no-name-alloc
Avoid allocations in trampoline shims
2020-10-18 13:34:08 -07:00
Alex Crichton
b8794448b0 Avoid allocations in trampoline shims
There's no need to name each export since each synthetic instance we're
creating only has one export, so let's use the empty string which
doesn't require any allocations.
2020-10-18 11:54:52 -07:00
Johan Andersson
9820c5c3dd Replace unmaintained directories crate
Fixes RUSTSEC-2020-0054 warning from cargo-audit/cargo-deny, follows the recommendation to switch to the new maintained `directories-next` crate fork

Only affects the cache directory determination for the environment and was a simple search'n'replace to this fork so don't think behavior has changed.

https://rustsec.org/advisories/RUSTSEC-2020-0054
2020-10-17 13:08:59 +02:00
Johnnie Birch
f27c0f3434 Adds support for signed packed integer conversion to float
f32x4.convert_i32x4_s
2020-10-16 14:16:53 -07:00
Alex Crichton
4a82f17d91 Don't allocate a new ISA for each Func::wrap
Instead we can reuse the existing one in `Store`.
2020-10-16 08:21:32 -07:00
Nick Fitzgerald
2dad74f9d0 Merge pull request #2292 from abrown/fix-typo
Fix typo
2020-10-15 16:13:15 -07:00
Andrew Brown
f36ceac010 Fix typo 2020-10-15 11:31:04 -07:00
Yury Delendik
3c68845813 Cranelift: refactoring of unwind info (#2289)
* factor common code

* move fde/unwind emit to more abstract level

* code_len -> function_size

* speedup block scanning

* better function_size calciulation

* Rename UnwindCode enums
2020-10-15 08:34:50 -05:00
Andrew Brown
a26e9e9a20 [machinst x64]: lower load_splat using memory addressing 2020-10-14 09:43:33 -07:00
Andrew Brown
d990dd4c9a [machinst x64]: add source locations to more instruction formats
In order to register traps for `load_splat`, several instruction formats need knowledge of `SourceLoc`s; however, since the x64 backend does not correctly and completely register traps for `RegMem::Mem` variants I opened https://github.com/bytecodealliance/wasmtime/issues/2290 to discuss and resolve this issue. In the meantime, the current behavior (i.e. remaining largely unaware of `SourceLoc`s) is retained.
2020-10-14 09:43:33 -07:00
Anton Kirilov
e0b911a4df Introduce the Cranelift IR instruction LoadSplat
It corresponds to WebAssembly's `load*_splat` operations, which
were previously represented as a combination of `Load` and `Splat`
instructions. However, there are architectures such as Armv8-A
that have a single machine instruction equivalent to the Wasm
operations. In order to generate it, it is necessary to merge the
`Load` and the `Splat` in the backend, which is not possible
because the load may have side effects. The new IR instruction
works around this limitation.

The AArch64 backend leverages the new instruction to improve code
generation.

Copyright (c) 2020, Arm Limited.
2020-10-14 13:07:13 +01:00
Alex Crichton
e659d5cecd Add initial support for the multi-memory proposal (#2263)
This commit adds initial (gated) support for the multi-memory wasm
proposal. This was actually quite easy since almost all of wasmtime
already expected multi-memory to be implemented one day. The only real
substantive change is the `memory.copy` intrinsic changes, which now
accounts for the source/destination memories possibly being different.
2020-10-13 19:13:52 -05:00
Nick Fitzgerald
c2d01fe56f Merge pull request #2257 from fitzgen/peepmatic-no-paths-in-linear-ir
Peepmatic: Do not use paths in linear IR
2020-10-13 12:18:26 -07:00
Nick Fitzgerald
122c67d90a peepmatic: Update example automata image
The linear IR that the automata uses has changed, so the image needs to be
updated to reflect that.
2020-10-13 11:03:48 -07:00
Nick Fitzgerald
c015d69eb8 peepmatic: Do not use paths in linear IR
Rather than using paths from the root instruction to the instruction we are
matching against or checking if it is constant or whatever, use temporary
variables. When we successfully match an instruction's opcode, we simultaneously
define these temporaries for the instruction's operands. This is similar to how
open-coding these matches in Rust would use `match` expressions with pattern
matching to bind the operands to variables at the same time.

This saves about 1.8% of instructions retired when Peepmatic is enabled.
2020-10-13 11:03:48 -07:00
Nick Fitzgerald
4fd90dccab Merge pull request #2284 from alexcrichton/fix-interrupts
Fix enabling interrupts in fuzzers
2020-10-09 13:11:52 -07:00
Alex Crichton
cdf158cd50 Fix enabling interrupts in fuzzers
Modifying the `Config` after the gneine has been created has no effect,
so be sure to flag the configuration as interruptible earlier.
2020-10-09 10:09:27 -07:00
Andrew Brown
0ba35171fb [machinst x64]: port more CLIF filetests 2020-10-09 10:04:50 -07:00
Andrew Brown
d5d84e2ec3 [machinst x64]: enable simd_bitwise.wast 2020-10-09 10:04:50 -07:00
Andrew Brown
1799b0947f [machinst x64]: implement packed bitselect 2020-10-09 10:04:50 -07:00