Commit Graph

1648 Commits

Author SHA1 Message Date
Peter Huene
37bb7af454 Fix incorrect range in ininitialize_instance.
This commit fixes a bug where the wrong destination range was used when copying
data from the module's memory initialization upon instance initialization.

This affects the on-demand allocator only when using the `uffd` feature on
Linux and when the Wasm page being initialized is not the last in the module's
initial pages.

Fixes #2784.
2021-04-02 16:27:22 -07:00
Chris Fallin
cb48ea406e Switch default to new x86_64 backend.
This PR switches the default backend on x86, for both the
`cranelift-codegen` crate and for Wasmtime, to the new
(`MachInst`-style, `VCode`-based) backend that has been under
development and testing for some time now.

The old backend is still available by default in builds with the
`old-x86-backend` feature, or by requesting `BackendVariant::Legacy`
from the appropriate APIs.

As part of that switch, it adds some more runtime-configurable plumbing
to the testing infrastructure so that tests can be run using the
appropriate backend. `clif-util test` is now capable of parsing a
backend selector option from filetests and instantiating the correct
backend.

CI has been updated so that the old x86 backend continues to run its
tests, just as we used to run the new x64 backend separately.

At some point, we will remove the old x86 backend entirely, once we are
satisfied that the new backend has not caused any unforeseen issues and
we do not need to revert.
2021-04-02 11:35:53 -07:00
Peter Huene
0ddfe97a09 Change how flags are stored in serialized modules.
This commit changes how both the shared flags and ISA flags are stored in the
serialized module to detect incompatibilities when a serialized module is
instantiated.

It improves the error reporting when a compiled module has mismatched shared
flags.
2021-04-01 21:39:57 -07:00
Peter Huene
4ad0099da4 Update wat crate.
Update the `wat` crate to latest version and use `Error::set_path` in
`Module::from_file` to properly record the path associated with errors.
2021-04-01 20:11:26 -07:00
Peter Huene
3da03bcfcf Code review feedback.
* Expand doc comment on `Engine::precompile_module`.
* Add FIXME comment regarding a future ISA flag compatibility check before
  doing a JIT from `Module::from_binary`.
* Remove no-longer-needed CLI groups from the `compile` command.
2021-04-01 19:38:20 -07:00
Peter Huene
d1313b1291 Code review feedback.
* Move `Module::compile` to `Engine::precompile_module`.
* Remove `Module::deserialize` method.
* Make `Module::serialize` the same format as `Engine::precompile_module`.
* Make `Engine::precompile_module` return a `Vec<u8>`.
* Move the remaining serialization-related code to `serialization.rs`.
2021-04-01 19:38:19 -07:00
Peter Huene
abf3bf29f9 Add a wasmtime settings command to print Cranelift settings.
This commit adds the `wasmtime settings` command to print out available
Cranelift settings for a target (defaults to the host).

The compile command has been updated to remove the Cranelift ISA options in
favor of encouraging users to use `wasmtime settings` to discover what settings
are available.  This will reduce the maintenance cost for syncing the compile
command with Cranelift ISA flags.
2021-04-01 19:38:19 -07:00
Peter Huene
a474524d3b Code review feedback.
* Removed `Config::cranelift_clear_cpu_flags`.
* Renamed `Config::cranelift_other_flag` to `Config::cranelift::flag_set`.
* Renamed `--cranelift-flag` to `--cranelift-set`.
* Renamed `--cranelift-preset` to `--cranelift-enable`.
2021-04-01 19:38:19 -07:00
Peter Huene
1ce2a87149 Code review feedback.
* Remove `Config::for_target` in favor of setter `Config::target`.
* Remove explicit setting of Cranelift flags in `Config::new` in favor of
  calling the `Config` methods that do the same thing.
* Serialize the package version independently of the data when serializing a
  module.
* Use struct deconstructing in module serialization to ensure tunables and
  features aren't missed.
* Move common log initialization in the CLI into `CommonOptions`.
2021-04-01 19:38:19 -07:00
Peter Huene
273597903b Fix spelling error. 2021-04-01 19:38:18 -07:00
Peter Huene
7e02940c72 Add Wasmtime to AOT header.
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2021-04-01 19:38:18 -07:00
Peter Huene
29d366db7b Add a compile command to Wasmtime.
This commit adds a `compile` command to the Wasmtime CLI.

The command can be used to Ahead-Of-Time (AOT) compile WebAssembly modules.

With the `all-arch` feature enabled, AOT compilation can be performed for
non-native architectures (i.e. cross-compilation).

The `Module::compile` method has been added to perform AOT compilation.

A few of the CLI flags relating to "on by default" Wasm features have been
changed to be "--disable-XYZ" flags.

A simple example of using the `wasmtime compile` command:

```text
$ wasmtime compile input.wasm
$ wasmtime input.cwasm
```
2021-04-01 19:38:18 -07:00
Alex Crichton
90aa5cf49f Daily update of wasm-smith (#2798)
Because apparently it's daily now!
2021-04-01 15:05:38 -05:00
Pat Hickey
0508394c62 Revert "wiggle: generate a span that is present at all levels"
This reverts commit 0466f47cb4.
2021-04-01 09:33:37 -07:00
Alex Crichton
dfffc69150 Update wasm-smith again (#2794)
More fuzz tweaks!
2021-03-31 15:39:37 -05:00
Alex Crichton
6748dfa43a Disable module linking in spectest fuzzing
Module linking implicitly enables multiple tables but that isn't
supported by the spec tests today.
2021-03-31 07:20:22 -07:00
Nick Fitzgerald
27ce383306 Merge pull request #2792 from alexcrichton/update-wasm-smith
Update wasm-smith dependency
2021-03-30 10:33:11 -07:00
Alex Crichton
e0440eebb7 Update wasm-smith dependency
Brings in a fuzzing bug fix!
2021-03-30 07:13:10 -07:00
Alex Crichton
a301202b7d Remove the type-driven ability for duplicates in a Linker (#2789)
When `Linker` was first created it was attempted to be created with the
ability to instantiate any wasm modules, including those with duplicate
import strings of different types. In an effort to support this a
`Linker` supports defining the same names twice so long as they're
defined with differently-typed values.

This ended up causing wast testsuite failures module linking is enabled,
however, because the wrong error message is returned. While it would be
possible to fix this there's already the possibility for confusing error
messages today due to the `Linker` trying to take on this type-level
complexity. In a way this is yet-another type checker for wasm imports,
but sort of a bad one because it only supports things like
globals/functions, and otherwise you can only define one `Memory`, for
example, with a particular name.

This commit completely removes this feature from `Linker` to simplify
the implementation and make error messages more straightforward. This
means that any error message coming from a `Linker` is purely "this
thing wasn't defined" rather than a hybrid of "maybe the types didn't
match?". I think this also better aligns with the direction that we see
conventional wasm modules going which is that duplicate imports are not
ever present.
2021-03-29 17:26:02 -05:00
Pat Hickey
e38166ac3f wiggle::async_trait is defined as async_trait::async_trait(?Send)
async methods used by wiggle currently need to Not have the Send
constraint, so rather than make all use sites pass the argument
to the re-exported async_trait macro, define a new macro that
applies the argument.
2021-03-29 10:04:42 -07:00
Alex Crichton
b1a3c9047f Actually make spectest fuzzing deterministic
Turns out #2106 missed the actual sorting operation. Silly me!
2021-03-29 09:12:16 -07:00
Pat Hickey
0a255c19de Merge pull request #2782 from bytecodealliance/pch/wiggle_tracing_span_fix
wiggle: generate a span that is present at all levels
2021-03-28 15:04:33 -07:00
Pat Hickey
3c00440b0e Merge pull request #2785 from bytecodealliance/pch/bugfix_wiggle_wasmtime_async
wiggle-wasmtime: use fully qualified Rc, RefCell in expansion
2021-03-28 15:03:42 -07:00
Pat Hickey
3abc29e279 Merge pull request #2776 from bytecodealliance/pch/wasmtime_wasi_usability
`wasmtime-wasi` usability: re-exports of common siblings
2021-03-26 17:36:44 -07:00
Pat Hickey
8da3de6756 wiggle-wasmtime: use fully qualified std::rc::Rc<std::cell::RefCell<>> in expansion 2021-03-26 17:21:51 -07:00
Pat Hickey
0466f47cb4 wiggle: generate a span that is present at all levels
The code I wrote here prior was incorrect: a span is present at the
level specified and below; previously I thought it was present at the
level specified and above. So, previously, a TRACE-level event inside
this span would be associated with the module and function name provided
here. Now all events inside this span should be associated with it.
2021-03-26 14:25:10 -07:00
Alex Crichton
550c774c1d fuzz: Allow incompatible import types in instantiation (#2778)
Yesterday fuzzing was switched to using a `Linker` to improve coverage
when using module linking since we can fake instance imports with
definitions of each individual item. Using a `Linker`, however, means
that we can't necessarily instantiate all modules, such as

    (module
      (import "" "" (memory (;0;) 0 1))
      (import "" "" (memory (;1;) 2)))

As a result this just allows these sorts of "incompatible import type"
errors when fuzzing to not trigger crashes.
2021-03-26 14:38:34 -05:00
Alex Crichton
7d8931c517 Compile fewer trampolines with module linking (#2774)
Previously each module in a module-linking-using-module would compile
all the trampolines for all signatures for all modules. In forest-like
situations with lots of modules this would cause quite a few trampolines
to get compiled. The original intention was to have one global list of
trampolines for all modules in the module-linking graph that they could
all share. With the current design of module linking, however, the
intention is for modules to be relatively isolated from one another
which would make achieving this difficult.

In lieu of total sharing (which would be good for the global scope
anyway but we also don't do that right now) this commit implements an
alternative strategy where each module simply compiles its own
trampolines that it itself can reach. This should mean that
module-linking modules behave more similarly to standalone modules in
terms of trampoline duplication. If we ever do global trampoline
deduplication we can likely batch this all together into one, but for
now this should fix the performance issues seen in fuzzing.

Closes #2525
2021-03-25 19:11:02 -05:00
Pat Hickey
af7030197d wasmtime-cli: drop direct dep on cap_std by using re-export 2021-03-25 17:05:04 -07:00
Pat Hickey
07245a8763 wasi-cap-std-sync: re-export Dir while we're at it 2021-03-25 17:05:02 -07:00
Pat Hickey
183ee9d6d8 wasmtime cli: use wasmtime_wasi's re-exports more deliberately
this drops the direct dep on wasi-cap-std-sync and wasi-common.
2021-03-25 17:04:10 -07:00
Pat Hickey
19a802549f wasmtime-wasi: re-export wasi-cap-std-sync 2021-03-25 17:04:10 -07:00
Alex Crichton
211731b876 Update wasm-tools crates (#2773)
Brings in some fuzzing-related bug-fixes
2021-03-25 18:44:31 -05:00
Alex Crichton
654156714c Deduplicate function signatures in wasm modules (#2772)
Currently wasmtime will generate a `SignatureIndex`-per-type in the
module itself, even if the module itself declares the same type multiple
times. To make matters worse if the same type is declared across
multiple modules used in a module-linking-using-module then the
signature will be recorded each time it's declared.

This commit adds a simple map to module translation to deduplicate these
function types. This should improve the performance of module-linking
graphs where the same function type may be declared in a number of
modules. For modules that don't use module linking this adds an extra
map that's not used too often, but the time spent managing it should be
dwarfed by other compile tasks.
2021-03-25 18:44:22 -05:00
Alex Crichton
516a97b3f3 A few more small fuzzing fixes (#2770)
* Increase allowances for values when fuzzing

The wasm-smith limits for generating modules are a bit higher than what
we specify, so sync those up to avoid getting too many false positives
with limits getting blown.

* Ensure fuzzing `*.wat` files are in sync

I keep looking at `*.wat` files that are actually stale, so remove stale
files if we write out a `*.wasm` file and can't disassemble it.

* Enable shadowing in dummy_linker

Fixes an issues where the same name is imported twice and we generated
two values for that. We don't mind the error here, we just want to
ignore the shadowing errors.
2021-03-25 18:44:04 -05:00
Pat Hickey
8bb1f8adc9 wasmtime-wiggle: make it possible to add host funcs to a config under an alias (#2761)
* wasmtime-wiggle: make it possible to add host funcs to a config under an alias

* remove debugging printlns
2021-03-25 15:31:45 -05:00
Alex Crichton
81c44033d6 Disable module-linking in differential fuzzing (#2769)
Currently this exposes a bug where modules broken by module linking
cause failures in the fuzzer, but we want to fuzz those modules since
module linking isn't enabled when generating these modules.
2021-03-25 13:56:34 -05:00
Alex Crichton
9476581ae6 Instantiate fewer instances when fuzzing (#2768)
This commit fixes an issue where when module linking was enabled for
fuzzing (which it is) import types of modules show as imports of
instances. In an attempt to satisfy the dummy values of such imports the
fuzzing integration would create instances for each import. This would,
however, count towards instance limits and isn't always desired.

This commit refactors the creation of dummy import values to decompose
imports of instances into imports of each individual item. This should
retain the pre-module-linking behavior of dummy imports for various
fuzzers.
2021-03-25 13:35:38 -05:00
Alex Crichton
30d9164b6e Fix a number of warnings cropping up on nightly Rust (#2767)
Various small issues here and there, nothing major
2021-03-25 13:19:37 -05:00
Alex Crichton
3f694ae319 Use stable Rust on CI to test the x64 backend (#2766)
* Use stable Rust on CI to test the x64 backend

This commit leverages the newly-released 1.51.0 compiler to test the
new backend on Windows and Linux with a stable compiler instead of a
nightly compiler. This isolates the nightly build to just the nightly
documentation generation and fuzzing, both of which rely on nightly for
the best results right now.

* Use updated stable in book build job

* Run rustfmt for new stable

* Silence new warnings for wasi-nn

* Allow some dead code in the x64 backend

Looks like new rustc is better about emitting some dead-code warnings

* Update rust in peepmatic job

* Fix a test in the pooling allocator

* Remove `package.metdata.docs.rs` temporarily

Needs resolution of https://github.com/rust-lang/cargo/pull/9300 first

* Fix a warning in a wasi-nn example
2021-03-25 13:18:59 -05:00
Xingqang Bai
55006b5044 Update wasmtime.h (#2762) 2021-03-25 10:48:44 +01:00
Pat Hickey
db7ec9552c Merge pull request #2760 from bytecodealliance/pch/wiggle_error_reporting
wiggle: delete GuestErrorConversion, improve some error reporting
2021-03-24 13:39:04 -07:00
Pat Hickey
df18b44c53 oops 2021-03-24 11:37:42 -07:00
Pat Hickey
1d663bfd71 delete straggler InDataField 2021-03-24 11:19:12 -07:00
Pat Hickey
e6c7e00a52 wiggle-using crates: delete GuestErrorConversion 2021-03-24 10:39:06 -07:00
Alex Crichton
d4b54ee0a8 More optimizations for calling into WebAssembly (#2759)
* Combine stack-based cleanups for faster wasm calls

This commit is an extension of #2757 where the goal is to optimize entry
into WebAssembly. Currently wasmtime has two stack-based cleanups when
entering wasm, one for the externref activation table and another for
stack limits getting reset. This commit fuses these two cleanups
together into one and moves some code around which enables less captures
for fewer closures and such to speed up calls in to wasm a bit more.
Overall this drops the execution time from 88ns to 80ns locally for me.

This also updates the atomic orderings when updating the stack limit
from `SeqCst` to `Relaxed`. While `SeqCst` is a reasonable starting
point the usage here should be safe to use `Relaxed` since we're not
using the atomics to actually protect any memory, it's simply receiving
signals from other threads.

* Determine whether a pc is wasm via a global map

The macOS implementation of traps recently changed to using mach ports
for handlers instead of signal handlers. This means that a previously
relied upon invariant, each thread fixes its own trap, was broken. The
macOS implementation worked around this by maintaining a global map from
thread id to thread local information, however, to solve the problem.

This global map is quite slow though. It involves taking a lock and
updating a hash map on all calls into WebAssembly. In my local testing
this accounts for >70% of the overhead of calling into WebAssembly on
macOS. Naturally it'd be great to remove this!

This commit fixes this issue and removes the global lock/map that is
updated on all calls into WebAssembly. The fix is to maintain a global
map of wasm modules and their trap addresses in the `wasmtime` crate.
Doing so is relatively simple since we're already tracking this
information at the `Store` level.

Once we've got a global map then the macOS implementation can use this
from a foreign thread and everything works out.

Locally this brings the overhead, on macOS specifically, of calling into
wasm from 80ns to ~20ns.

* Fix compiles

* Review comments
2021-03-24 11:41:33 -05:00
Pat Hickey
1c4af27f2d delete GuestErrorConversion from docs, tests 2021-03-23 22:20:29 -07:00
Pat Hickey
f74b0291ad dead code: remove GuestErrorConversion, it now is never called 2021-03-23 22:14:49 -07:00
Pat Hickey
4a9ce90d34 GuestError::InDataField never constructed, so delete it 2021-03-23 22:04:34 -07:00
Pat Hickey
1151f630b8 wiggle GuestError: improve Display of InFunc, InDataField 2021-03-23 22:03:25 -07:00