Commit Graph

8660 Commits

Author SHA1 Message Date
Alex Crichton
e9f33fc618 Move all trampoline compilation to wasmtime-cranelift (#3176)
* Move all trampoline compilation to `wasmtime-cranelift`

This commit moves compilation of all the trampolines used in wasmtime
behind the `Compiler` trait object to live in `wasmtime-cranelift`. The
long-term goal of this is to enable depending on cranelift *only* from
the `wasmtime-cranelift` crate, so by moving these dependencies we
should make that a little more flexible.

* Fix windows build
2021-08-12 16:58:21 -05:00
Alex Crichton
2da1b9d375 Delete unused code in wasmtime-obj (#3179)
I believe this was likely used at some point historically, but nowadays
this code isn't used so let's delete it.
2021-08-12 13:28:00 -05:00
Alex Crichton
e0c8961333 Add memory64 support to the Wasmtime CLI and C API (#3182)
Accidentally forgotten from #3153!
2021-08-12 12:33:57 -05:00
Alex Crichton
e68aa99588 Implement the memory64 proposal in Wasmtime (#3153)
* Implement the memory64 proposal in Wasmtime

This commit implements the WebAssembly [memory64 proposal][proposal] in
both Wasmtime and Cranelift. In terms of work done Cranelift ended up
needing very little work here since most of it was already prepared for
64-bit memories at one point or another. Most of the work in Wasmtime is
largely refactoring, changing a bunch of `u32` values to something else.

A number of internal and public interfaces are changing as a result of
this commit, for example:

* Acessors on `wasmtime::Memory` that work with pages now all return
  `u64` unconditionally rather than `u32`. This makes it possible to
  accommodate 64-bit memories with this API, but we may also want to
  consider `usize` here at some point since the host can't grow past
  `usize`-limited pages anyway.

* The `wasmtime::Limits` structure is removed in favor of
  minimum/maximum methods on table/memory types.

* Many libcall intrinsics called by jit code now unconditionally take
  `u64` arguments instead of `u32`. Return values are `usize`, however,
  since the return value, if successful, is always bounded by host
  memory while arguments can come from any guest.

* The `heap_addr` clif instruction now takes a 64-bit offset argument
  instead of a 32-bit one. It turns out that the legalization of
  `heap_addr` already worked with 64-bit offsets, so this change was
  fairly trivial to make.

* The runtime implementation of mmap-based linear memories has changed
  to largely work in `usize` quantities in its API and in bytes instead
  of pages. This simplifies various aspects and reflects that
  mmap-memories are always bound by `usize` since that's what the host
  is using to address things, and additionally most calculations care
  about bytes rather than pages except for the very edge where we're
  going to/from wasm.

Overall I've tried to minimize the amount of `as` casts as possible,
using checked `try_from` and checked arithemtic with either error
handling or explicit `unwrap()` calls to tell us about bugs in the
future. Most locations have relatively obvious things to do with various
implications on various hosts, and I think they should all be roughly of
the right shape but time will tell. I mostly relied on the compiler
complaining that various types weren't aligned to figure out
type-casting, and I manually audited some of the more obvious locations.
I suspect we have a number of hidden locations that will panic on 32-bit
hosts if 64-bit modules try to run there, but otherwise I think we
should be generally ok (famous last words). In any case I wouldn't want
to enable this by default naturally until we've fuzzed it for some time.

In terms of the actual underlying implementation, no one should expect
memory64 to be all that fast. Right now it's implemented with
"dynamic" heaps which have a few consequences:

* All memory accesses are bounds-checked. I'm not sure how aggressively
  Cranelift tries to optimize out bounds checks, but I suspect not a ton
  since we haven't stressed this much historically.

* Heaps are always precisely sized. This means that every call to
  `memory.grow` will incur a `memcpy` of memory from the old heap to the
  new. We probably want to at least look into `mremap` on Linux and
  otherwise try to implement schemes where dynamic heaps have some
  reserved pages to grow into to help amortize the cost of
  `memory.grow`.

The memory64 spec test suite is scheduled to now run on CI, but as with
all the other spec test suites it's really not all that comprehensive.
I've tried adding more tests for basic things as I've had to implement
guards for them, but I wouldn't really consider the testing adequate
from just this PR itself. I did try to take care in one test to actually
allocate a 4gb+ heap and then avoid running that in the pooling
allocator or in emulation because otherwise that may fail or take
excessively long.

[proposal]: https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md

* Fix some tests

* More test fixes

* Fix wasmtime tests

* Fix doctests

* Revert to 32-bit immediate offsets in `heap_addr`

This commit updates the generation of addresses in wasm code to always
use 32-bit offsets for `heap_addr`, and if the calculated offset is
bigger than 32-bits we emit a manual add with an overflow check.

* Disable memory64 for spectest fuzzing

* Fix wrong offset being added to heap addr

* More comments!

* Clarify bytes/pages
2021-08-12 09:40:20 -05:00
Andrew Brown
76a93dc112 fuzz: log Wasm contents to file when log::debug is enabled
Previously, the WAT was printed as a log message. This change
standardizes all of the oracles to use `log_wasm`, which emits a `.wasm`
and `.wat` file for each case if `log::debug` is enabled and prints a
message with the names of the created files. Closes #3140.
2021-08-11 09:10:20 -07:00
Sergei Shulepov
cbabcacb0f wasmtime: Option to disable parallel compilation (#3169)
* Introduce parallel-compilation configuration switch

* Plumb parallel_compilation config to compilation

* Adjust obj.rs

* Address review

* Fix compilation fail in `cache` crate

* Fix obj.rs

Also remove the now unneeded feature in /Cargo.toml

* fmt
2021-08-10 14:09:15 -05:00
Andrew Brown
42acb72c54 fuzz: retrieve the WebAssembly spec repository in build.rs
To avoid the large download size of the spec repository mentioned
[here](https://github.com/bytecodealliance/wasmtime/pull/3124#discussion_r684605984),
this change removes it as a submodule and instead clones it shallowly
when the directory is empty (or not present) when `build.rs` is run.
2021-08-10 11:56:07 -07:00
Andrew Brown
92b382b736 fuzz: count successful executions of differential_spec target 2021-08-10 11:56:07 -07:00
Andrew Brown
651a321f1a fuzz: add differential_spec fuzzing target
This new target compares the outputs of executing the first exported
function of a Wasm module in Wasmtime and in the official Wasm spec
interpreter (using the `wasm-spec-interpreter` crate). This is an
initial step towards more fully-featured fuzzing (e.g. compare memories,
add `v128`, add references, add other proposals, etc.)
2021-08-10 11:56:07 -07:00
Andrew Brown
f3955fa62a refactor: rename DifferentialWasmiModuleConfig to SingleFunctionModuleConfig
Since we plan to reuse this configuration, we rename it and ensure it
has at least 1 type (this resulted in invalid modules).
2021-08-10 11:56:07 -07:00
Andrew Brown
ddb80d2d14 ci: install OCaml packages necessary for 'differential_spec' fuzz target 2021-08-10 11:56:07 -07:00
Andrew Brown
a7f592a026 Add a crate to interface with the WebAssembly spec interpreter
The WebAssembly spec interpreter is written in OCaml and the new crate
uses `ocaml-interop` along with a small OCaml wrapper to interpret Wasm
modules in-process. The build process for this crate is currently
Linux-specific: it requires several OCaml packages (e.g. `apt install -y
ocaml-nox ocamlbuild`) as well as `make`, `cp`, and `ar`.
2021-08-10 11:56:07 -07:00
Andrew Brown
2e95d4e7c6 wasi-nn: refactor wasi-nn context to use multiple backends 2021-08-10 10:05:52 -07:00
Andrew Brown
f0147f23e8 wiggle: emit From<#ident> for #tag_type for variants 2021-08-10 10:05:52 -07:00
Andrew Brown
c3bbdead7c wasi-nn: add backend abstraction 2021-08-10 10:05:52 -07:00
Alex Crichton
44f9ccd316 Publish import library for MinGW release artifacts (#3170)
This is produced by rust and forgotten to be placed into the release tarball.

Closes #3169
2021-08-09 11:37:25 -05:00
Nick Fitzgerald
a7cf6bf9aa Merge pull request #3171 from bytecodealliance/fitzgen-patch-1
Add notes for 2021-08-09 Cranelift meeting
2021-08-09 09:35:44 -07:00
Nick Fitzgerald
ec1a1514aa Update 2021-08-09 meeting notes 2021-08-09 09:35:03 -07:00
Nick Fitzgerald
33a9384bfe Add notes for 2021-08-09 Cranelift meeting 2021-08-09 09:25:03 -07:00
Till Schneidereit
2de091eb99 Add stub agendas for Wasmtime and Cranelift project meetings through mid-December (#3167) 2021-08-09 11:50:44 +02:00
Till Schneidereit
13b9ce8902 Add notes for 21-08-05 wasmtime meeting (#3165) 2021-08-09 11:22:36 +02:00
Chris Fallin
9c550fcf41 Merge pull request #3128 from sparker-arm/aarch64-atomics
Re-implement AArch64 atomic load and stores
2021-08-06 14:38:25 -07:00
Alex Crichton
480dff21e8 fuzz: Disable more features for spectests fuzzer (#3159)
The previous commit to eanble multi-memory and simd leaked into the
spectest fuzzer, but to pass the spec tests we can't enable these features.
2021-08-06 16:27:42 -05:00
Chris Fallin
ca6325f06c Merge pull request #3162 from jlb6740/cranelift-meeting-8-9-agenda-update-jlb6740
cranelift-meeting-8-9-agenda-update - Discuss approach to SIMD loweri…
2021-08-06 13:45:32 -07:00
Johnnie Birch
ce3a0f1185 cranelift-meeting-8-9-agenda-update - Discuss approach to SIMD lowering when fixing latest fuzzing bugs 2021-08-06 12:09:18 -07:00
Alex Crichton
33c3d00f10 Remove rss prediction from api_calls fuzzer (#3156)
This functionality is now subsumed by the limiter built-in to all
fuzzing stores, so there's no longer any need for it. It was also
triggering arithmetic overflows in fuzzing, so instead of fixing I'm
removing it!
2021-08-06 12:43:22 -05:00
Nick Fitzgerald
e5ef1455a3 Merge pull request #3157 from alexcrichton/centralize-error-handling
fuzz: Centralize handling instantiation errors
2021-08-06 10:38:48 -07:00
Alex Crichton
45896e0533 Decrease memory limit in fuzzing to 1gb (#3155)
This should keep us under the default 2gb limit when fuzzing
2021-08-06 12:28:49 -05:00
Alex Crichton
ee3ff52661 Refactor cranelift immediates slightly
I've run up against the `Into`-vs-`From` impls a few times and figured
I'd go ahead and put up a refactoring. This switches `Into` impls into
`From` impls which allows using both traits instead of just the `Into`
version. Additionally this removes a few small `as` casts in favor of
infallible `from`/`into` or `try_from` with error handling.
2021-08-06 09:14:25 -07:00
Alex Crichton
3bdf6c7a48 fuzz: Centralize handling instantiation errors
At the same time remove some string matching in favor of checking for
oom explicitly.
2021-08-06 07:47:28 -07:00
Alex Crichton
bb85366a3b Enable simd fuzzing on oss-fuzz (#3152)
* Enable simd fuzzing on oss-fuzz

This commit generally enables the simd feature while fuzzing, which
should affect almost all fuzzers. For fuzzers that just throw random
data at the wall and see what sticks, this means that they'll now be
able to throw simd-shaped data at the wall and have it stick. For
wasm-smith-based fuzzers this commit also updates wasm-smith to 0.6.0
which allows further configuring the `SwarmConfig` after generation,
notably allowing `instantiate-swarm` to generate modules using simd
using `wasm-smith`. This should much more reliably feed simd-related
things into the fuzzers.

Finally, this commit updates wasmtime to avoid usage of the general
`wasm_smith::Module` generator to instead use a Wasmtime-specific custom
default configuration which enables various features we have
implemented.

* Allow dummy table creation to fail

Tables might creation for imports may exceed the memory limit on the
store, which we'll want to gracefully recover from and not fail the
fuzzers.
2021-08-05 16:24:42 -05:00
Alex Crichton
214c5f862d fuzz: Implement finer memory limits per-store (#3149)
* fuzz: Implement finer memory limits per-store

This commit implements a custom resource limiter for fuzzing. Locally I
was seeing a lot of ooms while fuzzing and I believe it was generally
caused from not actually having any runtime limits for wasm modules. I'm
actually surprised that this hasn't come up more on oss-fuzz more in
reality, but with a custom store limiter I think this'll get the job
done where we have an easier knob to turn for controlling the memory
usage of fuzz-generated modules.

For now I figure a 2gb limit should be good enough for limiting fuzzer
execution. Additionally the "out of resources" check if instantiation
fails now looks for the `oom` flag to be set instead of pattern matching
on some error messages about resources.

* Fix tests
2021-08-05 15:07:33 -05:00
Chris Fallin
2c70d1d6f6 Merge pull request #3151 from cfallin/cranelift-meeting-20210809
Add agenda for Cranelift meeting on 2021-08-09.
2021-08-05 12:39:28 -07:00
Alex Crichton
d8c4ac2c25 Improve output of expectation failures of the wast commands (#3150)
This commit updates the output of failed expectations in the `wast`
crate to fold in the check-is-the-value-the-same with the
generate-a-nice-message. Additionally this tries to make sure that
everything is aligned in the output to make it a bit more easily
readable. Vectors should notably be improved where lane differences can
be compared vertically in the case of integers and printed out
specifically in the case of floats.
2021-08-05 14:31:55 -05:00
Chris Fallin
2b51f75e78 Add agenda for Cranelift meeting on 2021-08-09. 2021-08-05 12:17:31 -07:00
Alex Crichton
c6b095f9a3 cranelift: Implement nan canonicalization for vectors (#3146)
This fixes some fuzz bugs that came about enabling simd where nan
canonicalization is performed on the fuzzers but cranelift would panic
on these ops for vectors. This adds some custom codegen with `bitselect`
to ensure any nan lanes are canonical-nan lanes in the canonicalized
operations.
2021-08-05 13:44:16 -05:00
Alex Crichton
9e142f8792 Fix some warnings on nightly Rust (#3148)
Looks like these trailing-semicolons-in-macros are likely to become a
hard error in the future, so this updates to remove them as necessary.
2021-08-05 13:02:44 -05:00
Alex Crichton
4cfa031c5f Implement API support for v128-globals (#3147)
Found via fuzzing, and looks like these were accidentally left out along
the way SIMD was taking shape.
2021-08-05 13:02:34 -05:00
Till Schneidereit
79638791fd Add information for Cranelift and Wasmtime project meetings (#3145) 2021-08-05 16:37:36 +02:00
Sam Parker
b6f6ac116a Revert IR changes
Along with the x64 and s390x changes. Now pattern matching the
uextend(atomic_load) in the aarch64 backend.
2021-08-05 09:35:32 +01:00
Sam Parker
cbb7229457 Re-implement atomic load and stores
The AArch64 support was a bit broken and was using Armv7 style
barriers, which aren't required with Armv8 acquire-release
load/stores.

The fallback CAS loops and RMW, for AArch64, have also been updated
to use acquire-release, exclusive, instructions which, again, remove
the need for barriers. The CAS loop has also been further optimised
by using the extending form of the cmp instruction.

Copyright (c) 2021, Arm Limited.
2021-08-05 09:08:08 +01:00
Alex Crichton
85f16f488d Consolidate address calculations for atomics (#3143)
* Consolidate address calculations for atomics

This commit consolidates all calcuations of guest addresses into one
`prepare_addr` function. This notably remove the atomics-specifics paths
as well as the `prepare_load` function (now renamed to `prepare_addr`
and folded into `get_heap_addr`).

The goal of this commit is to simplify how addresses are managed in the
code generator for atomics to use all the shared infrastrucutre of other
loads/stores as well. This additionally fixes #3132 via the use of
`heap_addr` in clif for all operations.

I also added a number of tests for loads/stores with varying alignments.
Originally I was going to allow loads/stores to not be aligned since
that's what the current formal specification says, but the overview of
the threads proposal disagrees with the formal specification, so I
figured I'd leave it as-is but adding tests probably doesn't hurt.

Closes #3132

* Fix old backend

* Guarantee misalignment checks happen before out-of-bounds
2021-08-04 15:57:56 -05:00
Alex Crichton
91d24b8448 Fix pooling tests on high-cpu-count systems (#3141)
This commit fixes an issue where `cargo test` was failing pretty
reliably on an 80-thread system where many of the pooling tests would
fail in `mmap` to reserve address space for the linear memories
allocated for a pooling allocator. Each test wants to reserve about 6TB
of address space, and if we let 80 tests do that apparently Linux
doesn't like that and starts returning errors from `mmap`.

The implementation here is a relatively simple semaphore-lookalike
which allows a fixed amount of concurrency in pooling tests.
2021-08-04 11:55:52 -05:00
Alex Crichton
8e06b78177 Update the spec test suite submodule (#3142)
Mostly just updating it to HEAD, no major changes here expected.
2021-08-04 11:12:39 -05:00
Alex Crichton
a33caec9be Bump the wasm-tools crates (#3139)
* Bump the wasm-tools crates

Pulls in some updates here and there, mostly for updating crates to the
latest version to prepare for later memory64 work.

* Update lightbeam
2021-08-04 09:53:47 -05:00
Chris Fallin
9419d635c6 Merge pull request #3138 from sparker-arm/aarch64-extadd-pairwise
Enable simd_X_extadd_pairwise_X for AArch64
2021-08-03 15:47:48 -07:00
Sam Parker
3bc2f0c701 Enable simd_X_extadd_pairwise_X for AArch64
Lower to [u|s]addlp for AArch64.

Copyright (c) 2021, Arm Limited.
2021-08-03 10:25:09 +01:00
Chris Fallin
d551997657 Merge pull request #3137 from cfallin/release-0.29-date
Adjust date of v0.29 release in RELEASES.md to today.
2021-08-02 17:43:47 -07:00
Chris Fallin
4dfb0a6138 Adjust date of v0.29 release in RELEASES.md to today.
This was a bit of an oversight in the relnotes updates for the
just-released v0.29: since the release PR was prepared a few days before
the actual release, I should have updated the "released on" date in
RELEASES.md (oops!). I don't think it's a big enough deal to re-roll
anything but we should have the correct date in the version on `main`.
2021-08-02 16:44:16 -07:00
Chris Fallin
81f1dc944f Merge pull request #3123 from cfallin/release-0.29
Bump to Wasmtime v0.29.0 and Cranelift 0.76.0.
2021-08-02 13:08:58 -07:00