Commit Graph

5837 Commits

Author SHA1 Message Date
Alex Crichton
ba0dc40b2b Handle select relocations while generating trampolines (#1347)
* Handle select relocations while generating trampolines

Trampoline generation for all function signatures exposed a preexisting
bug in wasmtime where trampoline generation occasionally does have
relocations, but it's asserted that trampolines don't generate
relocations, causing a panic. The relocation is currently primarily the
probestack function which happens when functions might have a huge
number of parameters, but not so huge as to blow the wasmparser limit of
how many parameters are allowed.

This commit fixes the issue by handling relocations for trampolines in
the same manner as the rest of the code. Note that dynamically-generated
trampolines via the `Func` API still panic if they have too many
arguments and generate a relocation, but it seems like we can try to fix
that later if the need truly arises.

Closes #1322

* Log trampoline relocations
2020-03-17 16:30:21 -05:00
Alex Crichton
4c3c717698 Update the filecheck dependency (#1348)
Removes an edge towards the `synstructure` dependency in our dependency
graph which, if removed entirely, is hoped to reduce build times locally
and on CI as you switch between `cargo build` and `cargo test` because
deep dependencies like `syn` won't have their features alternating back
and forth.
2020-03-17 15:33:54 -05:00
Alex Crichton
d452e5097f Build wasmtime-c-api differenty in run-examples (#1346)
* Build wasmtime-c-api differenty in run-examples

This tweaks how the wasmtime-c-api crate is built slightly, changing how
we invoke Cargo. Due to historical Cargo bugs this should help minimize
the number of rebuilds due to features since the feature selection will
be different.

* rustfmt
2020-03-17 15:08:35 -05:00
Nick Fitzgerald
3164ea55ee Merge pull request #1343 from alexcrichton/no-binaryen
Turn off binaryen in fuzzing by default
2020-03-17 13:04:52 -07:00
Nick Fitzgerald
cbd352696c Merge pull request #1344 from fitzgen/cranelift-publish-script
Re-add Cranelift publish script
2020-03-17 12:59:57 -07:00
Nick Fitzgerald
612b806ac3 Update contributing docs with new script name 2020-03-17 12:56:58 -07:00
Nick Fitzgerald
b70c3072d7 Re-add the script to publish Cranelift, which was lost in the migration 2020-03-17 12:56:58 -07:00
Andrew Brown
8598295bc4 Remove FPR32; fixes #1303
Until #1306 is resolved (some spilling/regalloc issue with larger FPR register banks), this removes FPR32 support. Only Wasm's `i64x2.mul` was using this register class and that instruction is predicated on AVX512 support; for the time being, that instruction will have to make do with the 16 FPR registers.
2020-03-17 12:46:41 -07:00
Nathan Froyd
af709ded94 bump cranelift version to 0.60.0 (#1328) 2020-03-17 15:29:20 -04:00
Alex Crichton
210bfddfa9 Fix unused imports in oracles 2020-03-17 12:02:09 -07:00
Alex Crichton
532422a5d9 Fix CI fuzz runners 2020-03-17 11:59:42 -07:00
Andrew Brown
a2d388b593 Fix types of SIMD or, xor, and
The operands of these bitwise instructions could have different types and still be valid Wasm (i.e. `v128`). Because of this, we must tell Cranelift to cast both operands to the same type--the default type, in this case. This undoes the work merged in https://github.com/bytecodealliance/cranelift/pull/1233.
2020-03-17 11:44:25 -07:00
Andrew Brown
ebaf95e507 Fix types of i8x16 and i16x8 replace_lane
Because the smallest Wasm scalar type is i32, users of the `i8x16.replace_lane` and `i16x8.replace_lane` instructions will only be able to pass `i32` values as operands. These values must be reduced by dropping the upper bits (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#replace-lane-value) using Cranelift's `ireduce` instruction.
2020-03-17 11:44:25 -07:00
Andrew Brown
27532410d2 Fix local.set and local.tee types for SIMD
Because Wasm SIMD vectors store their type as `v128`, there is a mismatch between the more specific types Cranelift uses and Wasm SIMD. Because of this mismatch, Wasm SIMD translates to the default Cranelift type `I8X16`, causing issues when more specific type information is available (e.g. `I32x4`). To fix this, all incoming values to SIMD instructions are checked during translation (not runtime) and if necessary cast from `I8X16` to the appropriate type by functions like `optionally_bitcast_vector`, `pop1_with_bitcast` and `pop2_with_bitcast`. However, there are times when we must also cast to `I8X16` for outgoing values, as with `local.set` and `local.tee`.

There are other ways of resolving this (e.g., see adding a new vector type, https://github.com/bytecodealliance/cranelift/pull/1251) but we discussed staying with this casting approach in https://github.com/bytecodealliance/wasmtime/issues/1147.
2020-03-17 11:44:25 -07:00
Pat Hickey
8bbf07c758 Merge pull request #1327 from bjorn3/linkage_hidden
Add support for hidden visibility
2020-03-17 11:34:41 -07:00
Pat Hickey
9e57532098 Merge pull request #1311 from bytecodealliance/pch/cranelift_module_errors
cranelift-{module, faerie}: minor improvements to error reporting
2020-03-17 10:56:05 -07:00
Andrew Brown
ffa467a0d0 Translate Wasm's f32x4.convert_i32x4s to Cranelift's fcvt_from_sint 2020-03-17 10:52:03 -07:00
Andrew Brown
444d021ede Add x86 implementation of fcvt_from_sint 2020-03-17 10:52:03 -07:00
Nick Fitzgerald
317c9ad43e Make Cranelift version-bumping script have similar name to Wasmtime's 2020-03-17 10:11:18 -07:00
Alex Crichton
5f47068eb1 take ttf in differential 2020-03-17 09:52:17 -07:00
Alex Crichton
23bc79f66d rustfmt 2020-03-17 09:51:59 -07:00
Alex Crichton
b0cf8c021f Turn off binaryen in fuzzing by default
... but turn it back on in CI by default. The `binaryen-sys` crate
builds binaryen from source, which is a drag on CI for a few reasons:

* This is quite large and takes a good deal of time to build
* The debug build directory for binaryen is 4GB large

In an effort to both save time and disk space on the builders this
commit adds a `binaryen` feature to the `wasmtime-fuzz` crate. This
feature is enabled specifically when running the fuzzers on CI, but it
is disabled during the typical `cargo test --all` command. This means
that the test builders should save an extra 4G of space and be a bit
speedier now that they don't build a giant wad of C++.

We'll need to update the OSS-fuzz integration to enable the `binaryen`
feature when executing `cargo fuzz build`, and I'll do that once this
gets closer to landing.
2020-03-17 09:51:59 -07:00
bjorn3
b4562c62e3 Add support for hidden visibility 2020-03-17 17:51:12 +01:00
Pat Hickey
2f6172732f wasmtime-cli, obj, debug: upgrade to faerie 0.15
eliminating the faerie 0.14 dep
2020-03-17 09:44:33 -07:00
Pat Hickey
2b87db3f55 cranelift-faerie: upgrade to faerie 0.15.0, fix error reporting
the `FaerieProduct` exposes faerie-specific types, so we can give
the `faerie::ArtifactError` on those methods.

`ModuleError::Backend` now expects an `anyhow::Error`, so we change
a .to_string into .into() and retain better error information.
2020-03-17 09:44:33 -07:00
Pat Hickey
fdfda89d59 cranelift-module: make backend error an anyhow::Error
This allows us to retain richer information from backend errors.
We already have `anyhow` as a dep in several places in the wasmtime
tree, and in cranelift-faerie. faerie is the only user of this
variant.

Existing code that puts a String into the Backend error can trivially
adapt their code to emit an anyhow::Error.
2020-03-17 09:44:33 -07:00
Alex Crichton
ec90509387 Disable incremental compilation on CI (#1341)
This should save us about 3GB of target directory disk space and it may
also be a tiny speed boost. There's no real benefit to using incremental
builds on CI because we're not changing code anyway!
2020-03-17 11:32:34 -05:00
Alex Crichton
724169d412 Remove cdylib/staticlib wasi-common crate types (#1321)
I don't think these are used right now and can lead to increased build
times, so I'd like to propose we remove them!
2020-03-17 09:27:41 -05:00
Samrat Man Singh
50496efb6b [cranelift] Fix block and value names in IR documentation 2020-03-17 11:47:59 +01:00
Benjamin Bouvier
ec5442c12a Add myself to the Cranelift watch list 2020-03-17 11:44:59 +01:00
Nick Fitzgerald
8bec21c518 Merge pull request #1333 from fitzgen/enable-ir-verifier-for-differential-fuzzing
fuzzing: Enable Cranelift's IR verifier for differential fuzzing
2020-03-16 17:02:29 -07:00
Nick Fitzgerald
3accccd5f7 fuzzing: Enable Cranelift's IR verifier for differential fuzzing 2020-03-16 16:21:45 -07:00
Prathyush
e2f6c08052 Remove superfluous are (#1326) 2020-03-15 13:15:32 +01:00
Samrat Man Singh
66aec23a0b Fix typo in comment (#1324) 2020-03-14 13:56:38 +01:00
Alex Crichton
65e32b3660 Store module name on wasmtime_environ::Module (#1309)
* Store module name on `wasmtime_environ::Module`

This keeps all name information in one place so we dont' have to keep
extra structures around in `wasmtime::Module`.

* rustfmt
2020-03-13 17:51:10 -05:00
Alex Crichton
922b49744b Remove no-longer-needed wasm-webidl-bindings dep (#1316)
Forgotten from previous interface types removal!
2020-03-13 17:50:00 -05:00
Nick Fitzgerald
aec28638a3 Merge pull request #1312 from fitzgen/labels-in-quotes
Put all labels and globs in quotes for automatic labeling config
2020-03-13 12:53:25 -07:00
Nick Fitzgerald
e595028f95 Put all labels and globs in quotes for automatic labeling config
It is too easy to run afoul of yaml syntax with all these colons an asterisks,
e.g. we recently broke the bot like this:

``
YAMLException: unidentified alias ".md" at line 58, column 9:
      - *.md
            ^
    at generateError (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:8357:10)
    at throwError (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:8363:9)
    at readAlias (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:9466:5)
    at composeNode (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:9558:20)
    at readBlockMapping (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:9226:16)
    at composeNode (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:9549:12)
    at readBlockSequence (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:9145:5)
    at composeNode (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:9548:12)
    at readBlockMapping (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:9279:11)
    at composeNode (/home/runner/work/_actions/bytecodealliance/labeler/schedule-fork/dist/index.js:9549:12)
```
2020-03-13 12:48:13 -07:00
Jakub Konka
5024d7bf09 [wiggle] Impl different formatters for flags (#1299)
* Impl different formatters for flags

Rather than forcing only binary formatting of flags types, how about
we implement all relevant traits (`Binary`, `Octal`, `LowerHex`, and
`UpperHex`) and allow the user to pick the most relevant one for their
use case?

Also, we use at least `Octal` and `LowerHex` in a couple of places
in `wasi-common`.

* fmt::Display for flags now inspired by bitflags

Flags is now by default formatted similarly to how
`bitflags` crate does it, namely, `dsync|append (0x11)`. In case
we're dealing with an empty set, we get `empty (0x0)`. Because of
this, any `Octal`, `LowerHex`, etc., formatters are redundant now.

Furthermore, while here, I've rewritten `EMPTY_FLAGS` and `ALL_FLAGS`
(where the former means `0x0` and the latter is the union of all possible
values) to be `const fn empty()` and `const fn all()` where the latter is
an expanded union of primitive representation values out of a macro.
This is again largely inspired by the `bitflags` crate.

* Test fmt::Display for flags
2020-03-13 12:27:34 -07:00
Pat Hickey
e495570f07 Merge pull request #1307 from bytecodealliance/pch/wiggle_publish_tweaks
[wiggle] missed versions and fields in wiggle cargo.toml
2020-03-12 15:54:41 -07:00
Pat Hickey
7ed829fe82 missed versions and fields in wiggle cargo.toml 2020-03-12 14:47:39 -07:00
Alex Crichton
950dc2fbc6 Fill out API docs on wasmtime::Module (#1305)
* Fill out API docs on `wasmtime::Module`

Part of #1272

* Apply suggestions from code review

Co-Authored-By: Nick Fitzgerald <fitzgen@gmail.com>

Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
2020-03-12 16:41:17 -05:00
Nick Fitzgerald
575df82760 Merge pull request #1304 from fitzgen/re-enable-subscribe-to-label-action-and-more-bot-configs
Re enable subscribe to label action and more bot configs
2020-03-12 14:23:52 -07:00
Alex Crichton
3e2be43502 Pre-generate trampoline functions (#957)
* Refactor wasmtime_runtime::Export

Instead of an enumeration with variants that have data fields have an
enumeration where each variant has a struct, and each struct has the
data fields. This allows us to store the structs in the `wasmtime` API
and avoid lots of `panic!` calls and various extraneous matches.

* Pre-generate trampoline functions

The `wasmtime` crate supports calling arbitrary function signatures in
wasm code, and to do this it generates "trampoline functions" which have
a known ABI that then internally convert to a particular signature's ABI
and call it. These trampoline functions are currently generated
on-the-fly and are cached in the global `Store` structure. This,
however, is suboptimal for a few reasons:

* Due to how code memory is managed each trampoline resides in its own
  64kb allocation of memory. This means if you have N trampolines you're
  using N * 64kb of memory, which is quite a lot of overhead!

* Trampolines are never free'd, even if the referencing module goes
  away. This is similar to #925.

* Trampolines are a source of shared state which prevents `Store` from
  being easily thread safe.

This commit refactors how trampolines are managed inside of the
`wasmtime` crate and jit/runtime internals. All trampolines are now
allocated in the same pass of `CodeMemory` that the main module is
allocated into. A trampoline is generated per-signature in a module as
well, instead of per-function. This cache of trampolines is stored
directly inside of an `Instance`. Trampolines are stored based on
`VMSharedSignatureIndex` so they can be looked up from the internals of
the `ExportFunction` value.

The `Func` API has been updated with various bits and pieces to ensure
the right trampolines are registered in the right places. Overall this
should ensure that all trampolines necessary are generated up-front
rather than lazily. This allows us to remove the trampoline cache from
the `Compiler` type, and move one step closer to making `Compiler`
threadsafe for usage across multiple threads.

Note that as one small caveat the `Func::wrap*` family of functions
don't need to generate a trampoline at runtime, they actually generate
the trampoline at compile time which gets passed in.

Also in addition to shuffling a lot of code around this fixes one minor
bug found in `code_memory.rs`, where `self.position` was loaded before
allocation, but the allocation may push a new chunk which would cause
`self.position` to be zero instead.

* Pass the `SignatureRegistry` as an argument to where it's needed.

This avoids the need for storing it in an `Arc`.

* Ignore tramoplines for functions with lots of arguments

Co-authored-by: Dan Gohman <sunfish@mozilla.com>
2020-03-12 16:17:48 -05:00
Nick Fitzgerald
b9dd91f1a4 Fix cranelift:module labeling path globs 2020-03-12 13:08:14 -07:00
Nick Fitzgerald
f88a540725 Add automatic labeling for the cranelift-wasm crate and its tests 2020-03-12 13:07:35 -07:00
Nick Fitzgerald
e2b8d26722 Sort labels alphabetically 2020-03-12 13:06:23 -07:00
Alex Crichton
34f768ddd5 Temporarily remove support for interface types (#1292)
* Temporarily remove support for interface types

This commit temporarily removes support for interface types from the
`wasmtime` CLI and removes the `wasmtime-interface-types` crate. An
error is now printed for any input wasm modules that have wasm interface
types sections to indicate that support has been removed and references
to two issues are printed as well:

* #677 - tracking work for re-adding interface types support
* #1271 - rationale for removal and links to other discussions

Closes #1271

* Update the python extension
2020-03-12 15:05:39 -05:00
Nick Fitzgerald
0b8f7d8883 Add a label for Wasmtime's documentation and guide 2020-03-12 13:04:46 -07:00
Nick Fitzgerald
687042f6ae Also label the fuzz targets with the "fuzzing" label 2020-03-12 13:03:54 -07:00