Commit Graph

9255 Commits

Author SHA1 Message Date
Chris Fallin
6a4716f0f4 Two CI fixes: Windows line-endings in manifest file, and "meta deterministic check".
- The Windows line-ending canonicalization was incomplete: we need to
  canonicalize the manifest text itself too!

- The "meta deterministic check" runs the cranelift-codegen build script
  N times outside of the source tree, examining what it produces to
  ensure the output is always the same (is detministic). This works fine
  when everything comes from the internal DSL, but when reading ISLE,
  this breaks because we no longer have the ISLE source paths.

  The initial ISLE integration did not hit this because without the
  `rebuild-isle` feature, it simply did nothing in the build script;
  now, with the manifest check, we hit the issue.

  The fix for now is just to turn off all ISLE-specific behavior in the
  build script by setting a special-purpose Cargo feature in the
  specific CI job. Eventually IMHO we should remove or find a better way
  to do this check.
2021-11-16 15:02:41 -08:00
Chris Fallin
a2b9664bed ISLE: guard against stale generated source in default build config.
Currently, the `build.rs` script that generates Rust source from the
ISLE DSL will only do this generation if the `rebuild-isle` Cargo
feature is specified. By default, it is not. This is based on the
principle that we (the build script) do not modify the source tree as
managed by git; git-managed files are strictly a human-managed and
human-edited resource. By adding the opt-in Cargo feature, a developer
is requesting the build script to perform an explicit action. (In my
understanding at least, this principle comes from the general philosophy
of hermetic builds: the output should be a pure function of the input,
and part of this is that the input is read-only. If we modify the source
tree, then all bets are off.)

Unfortunately, requiring the opt-in feature also creates a footgun that
is easy to hit: if a developer modifies the ISLE DSL source, but forgets
to specify the Cargo feature, then the compiler will silently be built
successfully with stale source, and will silently exclude any changes
that were made.

The generated source is checked into git for a good reason: we want DSL
compiler to not affect build times for the overwhelmingly common case
that Cranelift is used as a dependency but the backends are not being
actively developed. (This overhead comes mainly from building `islec`
itself.)

So, what to do? This PR implements a middle ground first described in
[this conversation](https://github.com/bytecodealliance/wasmtime/pull/3506#discussion_r743113351), in which we:

- Generate a hash (SHA-512) of the ISLE DSL source and produce a
  "manifest" of ISLE inputs alongside the generated source; and
- Always read the ISLE DSL source, and see if the manifest is still
  valid, on builds that do not have the opt-in "rebuild" feature.

This allows us to know whether the ISLE compiler output would have been
the same (modulo changes to the DSL compiler itself, which are
out-of-scope here), without actually building the ISLE compiler and
running it.

If the compiler-backend developer modifies an ISLE source file and then
tries to build `cranelift-codegen` without adding the `rebuild-isle`
Cargo feature, they get the following output:

```text
  Error: the ISLE source files that resulted in the generated Rust source

        * src/isa/x64/lower/isle/generated_code.rs

  have changed but the generated source was not rebuilt! These ISLE source
  files are:

         * src/clif.isle
         * src/prelude.isle
         * src/isa/x64/inst.isle
         * src/isa/x64/lower.isle

  Please add `--features rebuild-isle` to your `cargo build` command
  if you wish to rebuild the generated source, then include these changes
  in any git commits you make that include the changes to the ISLE.

  For example:

    $ cargo build -p cranelift-codegen --features rebuild-isle

  (This build script cannot do this for you by default because we cannot
  modify checked-into-git source without your explicit opt-in.)
```

which will tell them exactly what they need to do to fix the problem!

Note that I am leaving the "Rebuild ISLE" CI job alone for now, because
otherwise, we are trusting whomever submits a PR to generate the correct
generated source. In other words, the manifest is a communication from
the checked-in tree to the developer, but we still need to verify that
the checked-in generated Rust source and the manifest are correct with
respect to the checked-in ISLE source.
2021-11-16 13:50:41 -08:00
Alex Crichton
f30c8eb464 isle: Migrate f32const/f64const to ISLE (#3537)
This moves the `f32const` and `f64const` instructions from `lower.rs` to
ISLE. I was originally going to add something else but due to the
`isle.rs`'s manual use of `constructor_imm(..)` it necessitated filling
out the `imm` cases for f32/f64 constants, so I figured I'd go ahead and
move these instructions as well.

The special case for 0 constants which use `xorp{s,d}` is preserved from
`lower.rs` today, but a special case isn't added for the all-ones
constant. The comment says to use `cmpeqp{s,d}` but as discovered on
other recent PRs that's not quite sufficient because comparing a
register against itself which happens to be NaN wouldn't work, so
something else will be required (perhaps `pcmpeq` or similar? I figured
I'd defer to later)
2021-11-16 14:19:53 -06:00
Nick Fitzgerald
306c96b461 Merge pull request #3536 from alexcrichton/swap-isle-order
isle: Move immediates to the end of extractors
2021-11-16 10:13:17 -08:00
Nick Fitzgerald
e0943b8030 Merge pull request #3535 from alexcrichton/small-isle-patches
x64: Migrate `fabs` and `bnot` vector operations to ISLE
2021-11-16 10:01:49 -08:00
Alex Crichton
1c13f62189 isle: Move immediates to the end of extractors
Otherwise I was getting type errors trying to match `insertlane`
instructions, so I think that this was the intended order.
2021-11-16 09:07:24 -08:00
Alex Crichton
92394566fc x64: Migrate fabs and bnot vector operations to ISLE
This was my first attempt at transitioning code to ISLE to originally
fix #3327 but that fix has since landed on `main`, so this is instead
now just porting a few operations to ISLE.

Closes #3336
2021-11-16 07:36:49 -08:00
Johnnie Birch
5d5629de60 Fix for issue 3327. Updates Bnot to handle case for NaN float 2021-11-15 18:47:23 -08:00
Nick Fitzgerald
b530d283e4 Merge pull request #3533 from fitzgen/isle-labeling
ISLE auto labeling
2021-11-15 17:13:27 -08:00
Nick Fitzgerald
e6fd306219 Subscribe @cfallin to issues labeled "isle" 2021-11-15 16:20:16 -08:00
Nick Fitzgerald
ff659f0098 Subscribe myself to issues labeled "isle" 2021-11-15 16:19:49 -08:00
Nick Fitzgerald
373ea93564 Remove lightbeam auto labeling
Lightbeam doesn't exist anymore.
2021-11-15 16:18:11 -08:00
Nick Fitzgerald
8e9ddca5cb Add auto labeling for ISLE-related changes 2021-11-15 16:18:02 -08:00
Nick Fitzgerald
b38a96955c Merge pull request #3506 from fitzgen/isle
Initial ISLE integration for x64
2021-11-15 15:38:09 -08:00
Alex Crichton
37adfb898b Remove deprecated --enable-* CLI flags (#3524)
These have all migrated to `--wasm-features *` and otherwise having some
for some features but not other features can lead to accidental
confusion.
2021-11-15 17:03:09 -06:00
Nick Fitzgerald
0b1bf104c6 Update miette graphical-forcing comment to reference upstream issue 2021-11-15 14:53:51 -08:00
Alex Crichton
2b0b5d0491 Add today's Cranelift meeting notes (#3522)
* Add today's Cranelift meeting notes

* Update cranelift-11-15.md
2021-11-15 15:21:01 -06:00
Nick Fitzgerald
48ef2c0b84 Clarify comment about force_graphical in miette 2021-11-15 11:26:41 -08:00
Nick Fitzgerald
6164ba3814 ISLE: match cranelift version 2021-11-15 11:17:31 -08:00
Nick Fitzgerald
f27b357702 ISLE: update repo in Cargo.toml 2021-11-15 11:16:24 -08:00
Nick Fitzgerald
4a34d2c55b Remove old ISLE-generated file 2021-11-15 11:14:06 -08:00
Dan Gohman
ea0cb971fb Update to rustix 0.26.2. (#3521)
This pulls in a fix for Android, where Android's seccomp policy on older
versions is to make `openat2` irrecoverably crash the process, so we have
to do a version check up front rather than relying on `ENOSYS` to
determine if `openat2` is supported.

And it pulls in the fix for the link errors when multiple versions of
rsix/rustix are linked in.

And it has updates for two crate renamings: rsix has been renamed to
rustix, and unsafe-io has been renamed to io-extras.
2021-11-15 10:21:13 -08:00
David Craven
81f6228c57 Fix build 32bit. (#3518)
* Fix build 32bit.

* Use ifcfg.
2021-11-15 11:47:02 -06:00
Nick Fitzgerald
b6fd3d0c40 Remove extra, unused Cargo.lock 2021-11-15 09:25:29 -08:00
Chris Fallin
4bde42e789 Merge pull request #3520 from alexcrichton/faster-fuzz
Disable `check_label_branch_invariants` in fuzzing
2021-11-15 08:05:44 -08:00
Alex Crichton
1548ca3c47 Disable check_label_branch_invariants in fuzzing
This commit disables the `MachBuffer::check_label_branch_invariants`
debug check on the fuzzers due to it causing timeouts with the test case
from #3441. Fuzzing leads to a 20-30x slowdown of executed code and
locally the fuzz time it takes to instantiate #3441 drops from 3 minutes
to 6 seconds disabling this function. Note that this should still be
executed during our testing on CI since it's still enabled for debug
assertions.
2021-11-15 07:34:09 -08:00
Alex Crichton
ff1af20479 Add a fuzz mode to stress unaligned wasm addresses (#3516)
Alignment on all memory instructions in wasm is currently best-effort
and not actually required, meaning that whatever wasm actually uses as
an address should work regardless of whether the address is aligned or
not. This is theoretically tested in the fuzzers via
wasm-smith-generated code, but wasm-smith doesn't today have too too
high of a chance of generating an actual successful load/store.

This commit adds a new configuration option to the `Config` generator
for fuzzing which forces usage of a custom linear memory implementation
which is backed by Rust's `Vec<u8>` and forces the base address of
linear memory to be off-by-one relative to the base address of the
`Vec<u8>` itself. This should theoretically force host addresses to
almost always be unaligned, even if wasm addresses are otherwise
aligned.

The main interesting fuzz coverage here is likely to be in the existing
`differential` target which compares running the same module in wasmtime
with two different `Config` values to ensure the same results are
produced. This probably won't increase coverage all that much in the
near future due to wasm-smith rarely generating successful loads/stores,
but in the meantime by hooking this up into `Config` it also means that
we'll be running in comparison against v8 and also ensuring that all
spec tests succeed if misalignment is forced at the hardware level.

As a side effect this commit also cleans up the fuzzers slightly:

* The `DifferentialConfig` struct is removed and folded into `Config`
* The `init_hang_limit` processing is removed since we don't use
  `-ttf`-generated modules from binaryen any more.
* Traps are now asserted to have the same trap code, otherwise
  differential fuzzing fails.
* Some more debug logging was added to the differential fuzzer
2021-11-15 08:24:23 -06:00
Nick Fitzgerald
bfbf2f2f49 ISLE: implement x64 lowering for band_not in ISLE 2021-11-11 15:19:28 -08:00
Chris Fallin
f2939111d9 Merge pull request #3515 from cfallin/wasmtime-meeting-20211111
Wasmtime meeting notes from 2021-11-11.
2021-11-11 09:55:46 -08:00
Chris Fallin
e50d431946 Update meetings/wasmtime/2021/wasmtime-11-11.md
typo fix

Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2021-11-11 09:55:18 -08:00
Chris Fallin
0a8b08a0d5 Wasmtime meeting notes from 2021-11-11. 2021-11-11 09:33:41 -08:00
Nick Fitzgerald
33fcd6b4a5 x64: special case 0 to use xor in Inst::gen_constant for i128s 2021-11-10 15:57:58 -08:00
Nick Fitzgerald
b5105c025c MachInst: always rematerialize constants, rather than assign them registers
There were a few previous code paths that attempted to handle this, but this new
check handles it for all callers.

Rematerializing constants, rather than assigning and reusing a register, allows
for lower register pressure.
2021-11-10 15:45:43 -08:00
Peter Huene
990f834e27 Merge pull request #3514 from peterhuene/feature-gate-pooling-allocator
Add the `pooling-allocator` feature.
2021-11-10 14:00:33 -08:00
Peter Huene
58aab85680 Add the pooling-allocator feature.
This commit adds the `pooling-allocator` feature to both the `wasmtime` and
`wasmtime-runtime` crates.

The feature controls whether or not the pooling allocator implementation is
built into the runtime and exposed as a supported instance allocation strategy
in the wasmtime API.

The feature is on by default for the `wasmtime` crate.

Closes #3513.
2021-11-10 13:25:55 -08:00
Nick Fitzgerald
bbb4949128 ISLE: use lower_to_amode inside sink_load implementation 2021-11-10 13:21:48 -08:00
Alex Crichton
00feefe9a7 Change the bump-version workflow's schedule (#3512)
* Change the bump-version workflow's schedule

Either I don't understand cron or GitHub doesn't understand cron. It's
not clear which. I think that
https://github.com/bytecodealliance/wasmtime/pull/3511 may have fallen
within our schedule but it was supposed to be on a weekday. Otherwise
https://github.com/bytecodealliance/wasmtime/pull/3499 was certainly
spurious. This commit moves to a simpler "just do it on the same day
each month" and we can manually figure out weekdays and such. Hopefully
this should reduce the number of spurious PRs we're getting to bump
versions.

This also removes the script to force a version bump since I found a
button on the GitHub UI to do the same thing. Additionally I've updated
the patch-release documentation to use this button. Note that this
button takes inputs as well which means we can further automate patch
releases to look even more like normal release process, differing only
in one part of the argument used to trigger the workflow.

* Fix a typo
2021-11-08 10:37:53 -06:00
Adam Bratschi-Kaye
12bfbdfaca Skip generating DWARF info for dead code (#3498)
When encountering a subprogram that is dead code (as indicated by the
dead code proposal
https://dwarfstd.org/ShowIssue.php?issue=200609.1), don't generate debug
output for the subprogram or any of its children.
2021-11-08 09:31:04 -06:00
Pat Hickey
2053e972b7 InstancePre can impl Clone (#3510)
Its a manually written impl, not a derive, because InstancePre<T>: Clone
does not require T: Clone.

The clone should be reasonably inexpensive: Clone for Module is just an
Arc, and Clone for Definition should also just be an Arc on the HostFunc
or Instance variants. An InstancePre shouldnt contain any
Definition::Extern variants because there is not yet a Store associated
with it- right?
2021-11-08 09:11:31 -06:00
Nick Fitzgerald
7a568b19b4 ISLE: run rustfmt on generated code 2021-11-05 15:59:49 -07:00
Nick Fitzgerald
b8494822dc ISLE: finish porting imul lowering to ISLE 2021-11-05 15:41:24 -07:00
Nick Fitzgerald
30d206779e x64: Remove some unreachable code that's been ported to ISLE 2021-11-05 14:28:03 -07:00
Nick Fitzgerald
00e7ca206f ISLE: add a missing type check for whether terms used in expressions have a constructor 2021-11-05 14:05:38 -07:00
Alex Crichton
6be0f82b96 Fix a panic with an invalid name section (#3509)
This commit fixes a panic which can happen on a module with an invalid
name section where one of the functions named has the index `u32::MAX`.
Previously Wasmtime would create a new `FuncIndex` with the indices
found in the name section but the sentinel `u32::MAX` causes a panic.

Cranelift otherwise limits the number of functions through `wasmparser`
which has a hard limit (lower than `u32::MAX`) so this commit applies a
fix of only recording function names for function indices that are
actually present in the module.
2021-11-05 15:08:58 -05:00
Alex Crichton
6bcee7f5f7 Add a configuration option to force "static" memories (#3503)
* Add a configuration option to force "static" memories

In poking around at some things earlier today I realized that one
configuration option for memories we haven't exposed from embeddings
like the CLI is to forcibly limit the size of memory growth and force
using a static memory style. This means that the CLI, for example, can't
limit memory growth by default and memories are only limited in size by
what the OS can give and the wasm's own memory type. This configuration
option means that the CLI can artificially limit the size of wasm linear
memories.

Additionally another motivation for this is for testing out various
codegen ramifications of static/dynamic memories. This is the only way
to force a static memory, by default, for wasm64 memories with no
maximum size listed for example.

* Review feedback
2021-11-03 16:50:49 -05:00
Pat Hickey
6428ac80d0 cargo update -p userfaultfd to 0.4.2 (#3505)
which has bugfixes to work correctly on linux 5.11 and above, which is
required for github's ubuntu-latest builder as of this morning
2021-11-03 16:50:40 -05:00
Benjamin Bouvier
c952969389 Remove unused dependencies (#3490)
* Remove unused dependencies in Cranelift

* add serde to the current workspace

* remove more unused dependencies in wasmtime?
2021-11-02 12:08:30 -05:00
Chris Fallin
b024603866 Merge pull request #3502 from cfallin/ifcmp-sp
Add back the `ifcmp_sp` CLIF opcode.
2021-11-01 14:04:51 -07:00
Chris Fallin
5e96a447f0 Add back the ifcmp_sp CLIF opcode.
This opcode was removed as part of the old-backend cleanup in #3446.
While this opcode will definitely go away eventually, it is
unfortunately still used today in Lucet (as we just discovered while
working to upgrade Lucet's pinned Cranelift version). Lucet is
deprecated and slated to eventually be completely sunset in favor of
Wasmtime; but until that happens, we need to keep this opcode.
2021-11-01 13:34:31 -07:00
Chris Fallin
9e7760bd83 Merge pull request #3497 from bjorn3/misc_meta_simplifications
Misc meta crate cleanups
2021-11-01 11:24:44 -07:00