Commit Graph

5659 Commits

Author SHA1 Message Date
Sergei Shulepov
c5d6805284 Revert "Temporarily disable fuzzing until #1216 is resolved (#1224)"
This reverts commit 589fa95a05b3bc6dfe4076ed29fa02d6f0d3d349.
2020-02-21 10:54:35 -08:00
Benjamin Bouvier
d586e0679f Replace Gitter and IRC by a Bytecode Alliance Zulip stream; 2020-02-21 18:57:45 +01:00
Andrew Brown
91727d99c0 Clean up unnecessary return 2020-02-21 09:33:43 -08:00
Andrew Brown
f9ef4948fc Translate Wasm integer min/max to Cranelift's integer min/max 2020-02-21 09:33:43 -08:00
Andrew Brown
46cfc26684 Update wasmparser to 0.49.0 2020-02-21 09:33:43 -08:00
Andrew Brown
3ae1af1ad2 Add new Cranelift instructions for integer min/max
This includes legalizations to the previously-existing x86 SIMD integer min/max.
2020-02-21 09:33:43 -08:00
Johnnie Birch
9c6150b103 Adds perf jitdump support (#360)
Patch adds support for the perf jitdump file specification.
With this patch it should be possible to see profile data for code
generated and maped at runtime. Specifically the patch adds support
for the JIT_CODE_LOAD and the JIT_DEBUG_INFO record as described in
the specification. Dumping jitfiles is enabled with the --jitdump
flag. When the -g flag is also used there is an attempt to dump file
and line number information where this option would be most useful
when the WASM file already includes DWARF debug information.

The generation of the jitdump files has been tested on only a few wasm
files. This patch is expected to be useful/serviceable where currently
there is no means for jit profiling, but future patches may benefit
line mapping and add support for additional jitdump record types.

Usage Example:
Record
  sudo perf record -k 1 -e instructions:u target/debug/wasmtime -g
  --jitdump test.wasm
Combine
  sudo perf inject -v -j -i perf.data -o perf.jit.data
Report
  sudo perf report -i perf.jit.data -F+period,srcline
2020-02-21 08:30:21 -06:00
Joshua Nelson
ec9700c70b Don't return a Result for ObjectBuilder::new
Since it always returned an `Ok(Self)`, there was no reason to have a
Result.
2020-02-21 10:51:55 +01:00
Alex Crichton
0a020918b5 Don't let the API fuzz generator run wild (#959)
We've got some OOM fuzz test cases getting reported, but these aren't
very interesting. The OOMs, after some investigation, are confirmed to
be happening because the test is simply allocating thousands of
instances with massive tables, quickly exceeding the 2GB memory
threshold for fuzzing. This isn't really interesting because this is
expected behavior if you instantiate these sorts of modules.

This commit updates the fuzz test case generator to have a "prediction"
for each module how much memory it will take to instantiate it. This
prediction is then used to avoid instantiating new modules if we predict
that it will exceed our memory limit. The limits here are intentionally
very squishy and imprecise. The goal here is to still generate lots of
interesting test cases, but not ones that simply exhaust memory
trivially.
2020-02-20 16:38:03 -06:00
Andrew Brown
7dfd159fd8 Avoid unused import warnings in generated legalizer code (#1393) 2020-02-20 09:58:19 -08:00
Yury Delendik
b96b53eafb Test basic DWARF generation (#931)
* Add obj generation with debug info
* Add simple transform check
2020-02-20 11:42:36 -06:00
Pat Hickey
4460e569cf Upgrade to witx 0.8.0 with tagged unions (#921)
* witx tagged unions: updates to wig to use new semantics

* wig: emit a `#variant: ()` union variant for empty variants

* wasi-common: translate to use tagged unions

* update to flattened layout of event struct

* wig: generate layout tests, and delete bindgen ones

the bindgen tests became out-of-date with the latest changes to the
representation of unions, and the re-jiggering of various struct
definitions that went along with it.

* wasi: point at master with tagged union PR merged

* fix event struct repr on windows
2020-02-20 16:52:03 +01:00
Alex Crichton
80b095f2e2 Add API to statically assert signature of a Func (#955)
* Add API to statically assert signature of a `Func`

This commit add a family of APIs to `Func` named `getN` where `N` is the
number of arguments. Each function will attempt to statically assert the
signature of a `Func` and, if matching, returns a corresponding closure
which can be used to invoke the underlying function.

The purpose of this commit is to add a highly optimized way to enter a
wasm module, performing type checks up front and avoiding all the costs
of boxing and unboxing arguments within a `Val`. In general this should
be much more optimized than the previous `call` API for entering a wasm
module, if the signature is statically known.

* rustfmt

* Remove stray debugging
2020-02-20 09:28:12 -06:00
Alex Crichton
b6be99c9e1 Remove memory-related cases from RelocationTarget (#949)
This commit shrinks the `RelocationTarget` enumeration to remove
intrinsic-related relocations since they are no longer used. Instead
these function calls are done indirectly via a table in the `VMContext`.
This means that all of this is essentially dead code!
2020-02-19 20:58:06 -06:00
Alex Crichton
4283fdc862 Fix a possible use-after-free with Global (#956)
* Fix a possible use-after-free with `Global`

This commit fixes an issue with the implementation of the
`wasmtime::Global` type where if it previously outlived the original
`Instance` it came from then you could run into a use-after-free. Now
the `Global` type holds onto its underlying `InstanceHandle` to ensure
it retains ownership of the underlying backing store of the global's
memory.

* rustfmt
2020-02-19 20:57:41 -06:00
Andrew Brown
1a9dc743d1 Infer REX prefix for SIMD load instruction 2020-02-19 09:24:05 -08:00
Andrew Brown
936120dcf9 Infer REX prefix for SIMD store and vconst instructions 2020-02-19 09:24:05 -08:00
Alex Crichton
b69a061d23 Add a test that segfault handlers ignore non-wasm segfaults (#941)
This is the subject of #940 which while fixed is good to have a
regression test for!
2020-02-18 16:22:18 -06:00
Peter Huene
2fd3a31c06 Merge pull request #953 from peterhuene/implement-wasm-func-type
Implement wasm_func_type in the C API.
2020-02-18 13:34:23 -08:00
Alex Crichton
a09eed97db Update wasmparser to 0.51.2 (#952)
Fixes a bug in multi-value loop validation,
bytecodealliance/wasmparser#195
2020-02-18 13:59:22 -06:00
Peter Huene
052ae684c2 Fix memory leak in wasm_importtype_type.
This commit fixes a memory leak in `wasm_importtype_type` which returns a
non-owned `wasm_externtype_t`.
2020-02-18 11:36:45 -08:00
Peter Huene
efc19b593a Implement wasm_func_type.
This commit implements the missing `wasm_func_type` C API function.
2020-02-18 11:34:54 -08:00
Alex Crichton
b15b5cd05a Use malloc/free to allocate Instance structure (#948)
Previously `Instance` was always allocated with `mmap`. This was done to
future-proof `Instance` for allowing storing the memory itself inline
with an `Instance` allocation, but this can actually be done with
`alloc`/`dealloc` since they take an alignment. By using `malloc`/`free`
we can avoid fragmentation as well as hook into standard leak tracking
mechanisms.
2020-02-18 12:33:48 -06:00
Alex Crichton
16affacafb Generate trampolines based on signatures (#947)
* Generate trampolines based on signatures

Instead of generating a trampoline-per-function generate a
trampoline-per-signature. This should hopefully greatly increase the
cache hit rate on trampolines within a module and avoid generating a
function-per-function.

* Update crates/runtime/src/traphandlers.rs

Co-Authored-By: Sergei Pepyakin <s.pepyakin@gmail.com>

Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
2020-02-18 12:32:52 -06:00
Sergei Pepyakin
c94cdc7730 Treat undeclared maximum as 4GiB (#944)
* Treat undeclared maximum as 4GiB

* Review fixes.
2020-02-18 08:33:57 -06:00
Nick Fitzgerald
9b3ac10ebc wasm: Add support for passive data and element segments (#1389)
This is part of the bulk memory and reference types proposals.
2020-02-15 14:53:32 -08:00
bjorn3
45cc95e60e Merge emit_small_memcpy and emit_small_memmove (#1301)
* Merge emit_small_memcpy and emit_small_memmove

* Fix typo
2020-02-14 16:44:40 -06:00
Peter Delevoryas
18b40d1101 Add ineg legalization for scalar integer types (#1385) 2020-02-14 13:16:02 -08:00
Joshua Nelson
4d8cf563f3 Use zeroinit API for faerie and object (#1209)
* use new zeroinit API for faerie

* use bss for cranelift-object

* don't crash when initializing bss

* fix formatting

* Improve code locality

Co-Authored-By: Philip Craig <philipjcraig@gmail.com>

* use `as` instead of try_into() for usize -> u64

* don't allocate unnecessarily in `faerie`

Co-authored-by: Philip Craig <philipjcraig@gmail.com>
2020-02-13 13:25:41 -08:00
Y-Nak
58e5a62cde Fix inverted result of is_leaf method 2020-02-13 11:02:22 +01:00
Benjamin Brittain
372cc9fa7a Update broken URL to Fuchsia docs (#936) 2020-02-12 15:37:09 +01:00
Alex Crichton
d7c9a90df9 Re-update the wat crate (#935)
This was accidentally downgraded as part of #926, but we want to be sure
to pull in wast 7.0.0!
2020-02-11 16:09:07 -08:00
Alex Crichton
ca509f8c29 Update wasmparser (#934)
Pulls in bytecodealliance/wasmparser#193 which is a good bug fix to
have!
2020-02-11 16:01:05 -08:00
Philip Craig
51229c3f58 cranelift-module: document that finalize methods may not be relevant 2020-02-10 11:42:11 +01:00
Philip Craig
3c15f8f129 cranelift-object: move relocation processing to finish
This removes the need to call `finalize_definitions` for cranelift-object.
`finalize_definitions` is only intended for backends that produce
finalized functions and data objects, which cranelift-object does not.
2020-02-10 11:42:11 +01:00
myfreeweb
699109658c wasi-common/yanix: fix FreeBSD support (#756)
* wasi-common/yanix: fix FreeBSD support

* yanix: add fadvise support on FreeBSD and NetBSD

* runtime,jit: use cfg(unix) instead of linux||macos
2020-02-09 06:44:48 -08:00
Nick Fitzgerald
2af544de8b Update to cranelift 0.58.0 and enable (but ignore) reference types and bulk memory tests (#926)
* Update cranelift to 0.58.0

* Update `wasmprinter` dep to require 0.2.1

We already had it in the lock file, but this ensures we won't ever go back down.

* Ensure that our error messages match `assert_invalid`'s

The bulk of this work was done in
https://github.com/bytecodealliance/wasmparser/pull/186 but now we can test it
at the `wasmtime` level as well.

Fixes #492

* Stop feeling guilty about not matching `assert_malformed` messages

Remove the "TODO" and stop printing warning messages. These would just be busy
work to implement, and getting all the messages the exact same relies on using
the same structure as the spec interpreter's parser, which means that where you
have a helper function and they don't, then things go wrong, and vice versa. Not
worth it.

Fixes #492

* Enable (but ignore) the reference-types proposal tests

* Match test suite directly, instead of roundabout starts/endswith

* Enable (but ignore) bulk memory operations proposal test suite
2020-02-07 16:47:55 -06:00
Nathan Froyd
d42560c7bf specify units for fields of Tunables (#930)
...since the documentation in `impl Default for Tunables` doesn't get
translated anywhere, and the various fields have different units anyway.
2020-02-07 16:41:20 -06:00
Dan Gohman
376654bdfc Bump version to 0.58.0 (#1382) 2020-02-07 13:58:06 -08:00
Gabor Greif
950dadac94 Catch a few typos (#1381) 2020-02-07 12:51:28 -08:00
Nick Fitzgerald
ce1ee2d2f5 Enable ref.func global initializers (#1380)
* Fix comment referencing an outdated instruction name

* cranelift-wasm: Enable `ref.func` global initializers
2020-02-07 11:44:07 -08:00
Alex Crichton
dfef71ea5f Add some debug logging to fuzzers (#923)
* Add some debug logging to fuzzers

This is useful when trying to figure out what happened locally when
debugging fuzz test cases. By setting `RUST_LOG=wasmtime_fuzzing=debug`
you can get wasm files written to disk and for the API calls test case
see what API calls are being made.

* Also write out `*.wat` files

* rustfmt

* Remove return value from `log_wasm`

* Remove unused import
2020-02-07 13:28:26 -06:00
Alex Crichton
9802005061 Remove the action and context modules from wasmtime_jit (#924)
* Remove the `action` and `context` modules from `wasmtime_jit`

These modules are now no longer necessary with the `wasmtime` crate
fleshed out, and they're entirely subsumed by the `wasmtime` API as
well.

* Remove some more modules
2020-02-07 13:22:07 -06:00
Ryan Hunt
832666c45e Mass rename Ebb and relatives to Block (#1365)
* Manually rename BasicBlock to BlockPredecessor

BasicBlock is a pair of (Ebb, Inst) that is used to represent the
basic block subcomponent of an Ebb that is a predecessor to an Ebb.

Eventually we will be able to remove this struct, but for now it
makes sense to give it a non-conflicting name so that we can start
to transition Ebb to represent a basic block.

I have not updated any comments that refer to BasicBlock, as
eventually we will remove BlockPredecessor and replace with Block,
which is a basic block, so the comments will become correct.

* Manually rename SSABuilder block types to avoid conflict

SSABuilder has its own Block and BlockData types. These along with
associated identifier will cause conflicts in a later commit, so
they are renamed to be more verbose here.

* Automatically rename 'Ebb' to 'Block' in *.rs

* Automatically rename 'EBB' to 'block' in *.rs

* Automatically rename 'ebb' to 'block' in *.rs

* Automatically rename 'extended basic block' to 'basic block' in *.rs

* Automatically rename 'an basic block' to 'a basic block' in *.rs

* Manually update comment for `Block`

`Block`'s wikipedia article required an update.

* Automatically rename 'an `Block`' to 'a `Block`' in *.rs

* Automatically rename 'extended_basic_block' to 'basic_block' in *.rs

* Automatically rename 'ebb' to 'block' in *.clif

* Manually rename clif constant that contains 'ebb' as substring to avoid conflict

* Automatically rename filecheck uses of 'EBB' to 'BB'

'regex: EBB' -> 'regex: BB'
'$EBB' -> '$BB'

* Automatically rename 'EBB' 'Ebb' to 'block' in *.clif

* Automatically rename 'an block' to 'a block' in *.clif

* Fix broken testcase when function name length increases

Test function names are limited to 16 characters. This causes
the new longer name to be truncated and fail a filecheck test. An
outdated comment was also fixed.
2020-02-07 10:46:47 -06:00
Alex Crichton
151075d553 Remove a panic in the cache worker (#922)
This panic can now be hit occasionally since the worker is indeed
dropped, and the comment about the static no longer applies.
2020-02-07 08:23:24 -06:00
Alex Crichton
f5b505de04 Remove the jit_function_registry global state (#915)
* Remove the `jit_function_registry` global state

This commit removes on the final pieces of global state in wasmtime
today, the `jit_function_registry` module. The purpose of this module is
to help translate a native backtrace with native program counters into a
wasm backtrace with module names, function names, and wasm module
indices. To that end this module retained a global map of function
ranges to this metadata information for each compiled function.

It turns out that we already had a `NAMES` global in the `wasmtime`
crate for symbolicating backtrace addresses, so this commit moves that
global into its own file and restructures the internals to account for
program counter ranges as well. The general set of changes here are:

* Remove `jit_function_registry`
* Remove `NAMES`
* Create a new `frame_info` module which has a singleton global
  registering compiled module's frame information.
* Update traps to use the `frame_info` module to symbolicate pcs,
  directly extracting a `FrameInfo` from the module.
* Register and unregister information on a module level instead of on a
  per-function level (at least in terms of locking granluarity).

This commit leaves the new `FRAME_INFO` global variable as the only
remaining "critical" global variable in `wasmtime`, which only exists
due to the API of `Trap` where it doesn't take in any extra context when
capturing a stack trace through which we could hang off frame
information. I'm thinking though that this is ok, and we can always
tweak the API of `Trap` in the future if necessary if we truly need to
accomodate this.

* Remove a lazy_static dep

* Add some comments and restructure
2020-02-07 07:33:21 -06:00
Alex Crichton
a6adf52429 Add more CLI flags for wasm features (#917)
* Add more CLI flags for wasm features

This commit adds a few more flags to enable wasm features via the CLI,
mirroring the existing `--enable-simd` flag:

* `--enable-reference-types`
* `--enable-multi-value`
* `--enable-threads`
* `--enable-bulk-memory`

Additionally the bulk memory feature is now automatically enabled if
`reference-types` or `threads` are enabled since those two proposals
largely depend on `bulk-memory`.

* Add --enable-all to enable all wasm features

* Update src/lib.rs

Co-Authored-By: Peter Huene <peterhuene@protonmail.com>

* Apply suggestions from code review

Co-Authored-By: Peter Huene <peterhuene@protonmail.com>

Co-authored-by: Peter Huene <peterhuene@protonmail.com>
2020-02-07 04:06:59 -06:00
Alex Crichton
344bf2d6f3 Fuzz the multi-value support (#918)
* Fuzz the multi-value support

This commit enables multi-value by default for the fuzzers, in theory
allowing us to find panics and such in the multi-value implementation.
Or even runtime errors through the differential fuzzing!

* Don't fuzz differential on multi value
2020-02-06 17:36:06 -06:00
Alex Crichton
8a7d403fce Remove a use of lazy_static! in cache.rs (#916)
There's not really much reason to amortize the cost of this mtime
calculation here since it's only done with debug assertions anyway, so
let's avoid an extra dependency and just have a function do it inline.
2020-02-06 16:39:20 -06:00
Yury Delendik
de85efc2dd Add support for DebugInfoRef during DWARF transform (#853) 2020-02-06 15:28:09 -06:00