Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream merge #2

Merged
merged 487 commits into from
Apr 29, 2020
Merged

Upstream merge #2

merged 487 commits into from
Apr 29, 2020

Conversation

NikVolf
Copy link

@NikVolf NikVolf commented Apr 29, 2020

alexcrichton and others added 30 commits March 20, 2020 10:37
This commit adds a safe method to wiggle pointers to copy slices of data
from the host to the guest.
* Enable jitdump profiling support by default

This the result of some of the investigation I was doing for bytecodealliance#1017. I've
done a number of refactorings here which culminated in a number of
changes that all amount to what I think should result in jitdump support being
enabled by default:

* Pass in a list of finished functions instead of just a range to
  ensure that we're emitting jit dump data for a specific module rather
  than a whole `CodeMemory` which may have other modules.
* Define `ProfilingStrategy` in the `wasmtime` crate to have everything
  locally-defined
* Add support to the C API to enable profiling
* Documentation added for profiling with jitdump to the book
* Split out supported/unsupported files in `jitdump.rs` to avoid having
  lots of `#[cfg]`.
* Make dependencies optional that are only used for `jitdump`.
* Move initialization up-front to `JitDumpAgent::new()` instead of
  deferring it to the first module.
* Pass around `Arc<dyn ProfilingAgent>` instead of
  `Option<Arc<Mutex<Box<dyn ProfilingAgent>>>>`

The `jitdump` Cargo feature is now enabled by default which means that
our published binaries, C API artifacts, and crates will support
profiling at runtime by default. The support I don't think is fully
fleshed out and working but I think it's probably in a good enough spot
we can get users playing around with it!
* Simplify SSABuilder with basic block

* Simplify FunctionBuilder with basic block

* Update SSABuilder test

* Update SSABuilder doc
* Fix the tests for correctly following symlinks.

* Correctly follow symlinks in path_link.
* Remove C++ dependency from `wasmtime`

This commit removes the last wads of C++ that we have in wasmtime,
meaning that building wasmtime no longer requires a C++ compiler. It
still does require a C toolchain for some minor purposes, but hopefully
we can remove that over time too!

The motivation for doing this is to consolidate all our signal-handling
code into one location in one language so you don't have to keep
crossing back and forth when understanding what's going on. This also
allows us to remove some extra cruft that wasn't necessary from the C++
original implementation. Additionally this should also make building
wasmtime a bit more portable since it's often easier to acquire a C
toolchain than it is to acquire a C++ toolchain. (e.g. if you're
cross-compiling to a musl target)

* Typos
* Use wiggle in place of wig in wasi-common

This is a rather massive commit that introduces `wiggle` into the
picture. We still use `wig`'s macro in `old` snapshot and to generate
`wasmtime-wasi` glue, but everything else is now autogenerated by `wiggle`.
In summary, thanks to `wiggle`, we no longer need to worry about
serialising and deserialising to and from the guest memory, and
all guest (WASI) types are now proper idiomatic Rust types.

While we're here, in preparation for the ephemeral snapshot, I went
ahead and reorganised the internal structure of the crate. Instead of
modules like `hostcalls_impl` or `hostcalls_impl::fs`, the structure
now resembles that in ephemeral with modules like `path`, `fd`, etc.
Now, I'm not requiring we leave it like this, but I reckon it looks
cleaner this way after all.

* Fix wig to use new first-class access to caller's mem

* Ignore warning in proc_exit for the moment

* Group unsafes together in args and environ calls

* Simplify pwrite; more unsafe blocks

* Simplify fd_read

* Bundle up unsafes in fd_readdir

* Simplify fd_write

* Add comment to path_readlink re zero-len buffers

* Simplify unsafes in random_get

* Hide GuestPtr<str> to &str in path::get

* Rewrite pread and pwrite using SeekFrom and read/write_vectored

I've left the implementation of VirtualFs pretty much untouched
as I don't feel that comfortable in changing the API too much.
Having said that, I reckon `pread` and `pwrite` could be refactored
out, and `preadv` and `pwritev` could be entirely rewritten using
`seek` and `read_vectored` and `write_vectored`.

* Add comment about VirtFs unsafety

* Fix all mentions of FdEntry to Entry

* Fix warnings on Win

* Add aux struct EntryTable responsible for Fds and Entries

This commit adds aux struct `EntryTable` which is private to `WasiCtx`
and is basically responsible for `Fd` alloc/dealloc as well as storing
matching `Entry`s. This struct is entirely private to `WasiCtx` and
as such as should remain transparent to `WasiCtx` users.

* Remove redundant check for empty buffer in path_readlink

* Preserve and rewind file cursor in pread/pwrite

* Use GuestPtr<[u8]>::copy_from_slice wherever copying bytes directly

* Use GuestPtr<[u8]>::copy_from_slice in fd_readdir

* Clean up unsafes around WasiCtx accessors

* Fix bugs in args_get and environ_get

* Fix conflicts after rebase
with the prev approach, it would be passed by reference sometimes
(e.g. when used as an Array argument) but by value most of the time.
this was inconsistient.

theres no need to pass the owned version, all operations are &self.
…ggle_tweaks_for_lucet

[wiggle] Tweaks from lucet integration
* Add examples of linking and WASI

This commit adds two example programs, one for linking two modules
together and one for instantiating WASI. The linkage example
additionally uses WASI to get some meaningful output at this time.

cc bytecodealliance#1272

* Add examples to the book as well

* More links!

* Ignore examples from rustdoc testsing

* More example updates

* More ignored
…#1374)

`exit` doesn't return, so code after it is unreachable.
* Remove the old wast and wasm2obj commands.

These are subsumed by the `wasmtime wast` and `wasmtime wasm2obj` commands.

Fixes bytecodealliance#827.

* Remove wasm2obj install commands.
This allows `ctx` to avoid depending on wasi::FileType.
* Add a .gitattributes file specifying LF-style line endings.

This is similar to [Rust's .gitattributes file] though simplified.
Most of our source and documentation files already used LF-style line
endings, including *.cs files, so this makes things more consistent.

[Rust's .gitattributes file]: https://github.com/rust-lang/rust/blob/master/.gitattributes

* Remove UTF-8 BOMs in *.cs files.

Most of our *.cs files don't have UTF-8 BOMs, so this makes things more
consistent.
This adds the following build setups in CI:

- only x86,
- only arm64,
- disable debug assertions.
* Add wasmtime docs badge

* Add cranelift docs badge, closes bytecodealliance#1160
* Add additional links to embedding and tutorial documentation.

* Fix a broken link to CONTRIBUTING.md.

Fixes bytecodealliance#1280.
Some structs and unions are large enough that making them `Copy` isn't
ideal. wasi-common only needed `Copy` in a few places that were easy to
fix. `SubscriptionClock` is 32 bytes, so it's not a bad a idea to pass
it by reference anyway.
The crates/debug/src/transform/address_transform.rs is unoptimized in terms of data structures. This PR refactors this file to remove creation of intermediate in-heap structures, thus improves overall performance of the DWARF transformation.

* Reduce amount of memory allocated in translate_ranges_raw
* refactor translate_ranges
* Don't transform non-unit .debug_line
* type annotation for TransformRangeXXXIter's
* Fix empty generated wasm positions
* Add a `wasmtime::Linker` type

This commit adds a new type to the `wasmtime` crate, a `Linker`. This
linker is intended to vastly simplify calling `Instance::new` by easily
performing name resolution and incrementally defining state over time.
The goal here is to start down a path of making linking wasm modules in
`wasmtime` a first-class and ergonomic operation. This is highly likely
to evolve over time and get tweaked through releases as we iterate
towards a design well-suited for `wasmtime`, but this is intended to at
least be the initial foundation for such functionality.

This commit additionally also adds a C API for the linker and switches
the existing linking examples to using this linker in both Rust and C.

One piece of future work I'd like to tackle next is to integrate WASI
into the `wasmtime` crate in a more first-class manner. This [`Linker`]
type provides a great location to hook into the instantiation process to
easily instantiate modules with WASI imports. That's a relatively large
refactoring for now though and I figured it'd be best left for a
different time.

Closes bytecodealliance#727
* Fix instructions for building rust modules in python examples

When I ran `rustc +nightly ...` the compiler just looked for a source file
called `+nightly`. I changed these instructions to use rustup + rustc instead.

* Initial documentation for python users

Added documentation for using the Wasmtime loader in python, and explained the
first two examples in the repo. Changed the import example to demonstrate
working with module linear memory.

* Fix include in python guide

* Wording

* Clarify memory usage

* Flow through the example better

* More word choice

* Make rustup a prereq

* Fix source code paths in python guide

* Fix rustup example in python guide

Co-Authored-By: Samrat Man Singh <[email protected]>

* Replace command examples with preformat blocks

* Revert "Fix instructions for building rust modules in python examples"

This reverts commit 1738888.

* Left a block quote in a preformat example

Co-authored-by: Samrat Man Singh <[email protected]>
Experience with the `define_function` API has shown that returning
borrowed slices of `TrapSite` is not ideal: the returned slice
represents a borrow on the entire `Module`, which makes calling back
into methods taking `&mut self` a bit tricky.

To eliminate the problem, let's require the callers of `define_function`
to provide `TrapSink` instances.  This style of API enables them to
control when and how traps are collected, and makes the `object` and
`faerie` backends simpler/more efficient by not having to worry about
trap collection.
* Add initial 0.13.0 (unreleased) release notes

* Update RELEASES.md

Co-Authored-By: Andrew Brown <[email protected]>

Co-authored-by: Andrew Brown <[email protected]>
bnjbvr and others added 23 commits April 24, 2020 17:41
aarch64: emit SP copies when SP is involved in an explicit add during address lowering
This commit implements the stack limit checks in cranelift for the
AArch64 backend. This gets the `stack_limit` argument purpose as well as
a function's global `stack_limit` directive working for the AArch64
backend. I've tested this locally on some hardware and in an emulator
and it looks to be working for basic tests, but I've never really done
AArch64 before so some scrutiny on the instructions would be most
welcome!
…#1590)

This commit removes the `should_panic` function now that all wasm spec
tests are passing on arm64 (yay!). The remaining case, SIMD, has been
folded into `#[ignore]`. This should prevent tons of panics from showing
up in the logs while on CI because it's likely going to be some time
before SIMD for aarch64 is tackled.
This change adds SourceLoc information per instruction in a `VCode<Inst>`
container, and keeps this information up-to-date across register allocation
and branch reordering. The information is initially collected during
instruction lowering, eventually collected on the MachSection, and finally
provided to the environment that wraps the codegen crate for wasmtime.
This test creates a cycle between two `Func` objects (and indirectly
through their instance) which prevents anything from being collected.
This was found when running tests locally with address sanitizer, and
using a `Weak<T>` breaks the cycle to allow collecting resources.
This removes the `--nocapture` argument from Rust tests which enables
capturing the output of tests by default, only printing the output if
the test fails. I've seen that this otherwise seems to largely just dump
a very large amount of information to CI and makes it difficult to
diagnose a failure quickly from CI logs since you have to search
backwards to find the reason something failed.
MachInst backend: pass through SourceLoc information.
Support a few DWARF-5 only features:

* read .debug_addr
* read .debug_rnglists
* read .debug_loclists when present
* add dwarf-5 test
* read .debug_addr
* read .debug_rnglists
* read .debug_loclists when present
* support .debug_line_str and .debug_str_offsets

Co-authored-by: Yury Delendik <[email protected]>
* perform lldb DWARF-5 test too

* allow test_debug_dwarf5_
This adds a new `wasmtime_config_cache_config_load` C API function to
allow enabling and configuring the cache via the API. This was
originally requested over at bytecodealliance/wasmtime-py#3
* a few typofixes

* more tyops
# Conflicts:
#	crates/api/src/callable.rs
#	crates/api/src/runtime.rs
#	crates/api/src/trampoline/create_handle.rs
#	crates/api/src/trampoline/func.rs
#	crates/jit/src/compiler.rs
#	crates/jit/src/instantiate.rs
#	crates/jit/src/link.rs
#	crates/runtime/src/instance.rs
@NikVolf
Copy link
Author

NikVolf commented Apr 29, 2020

Don't squash!

@arkpar arkpar merged commit c7ca83a into master Apr 29, 2020
arkpar pushed a commit that referenced this pull request Apr 29, 2020
* Add some (incomplete set) basic sanity end-to-end tests

This commit adds some (an incomplete set of) basic sanity end-to-end
tests. It uses `test.witx` to autogenerate types and module interface
functions (aka the syscalls), and tests their implementation. For
the host memory, it uses simplistic `&mut [u8]` where we have full
control of the addressing and contents.

* Add sanity test for baz interface func

This commit adds a sanity test for the `Foo::baz` interface func.

* Upcast start/len for Region to avoid overflow

* Reenable alignment checking for memory

* use an array to implement hostmemory

Co-authored-by: Pat Hickey <[email protected]>
@arkpar arkpar deleted the upstream-merge branch April 29, 2020 09:26
@arkpar
Copy link
Member

arkpar commented Apr 29, 2020

crates.io release was made from some branch @gnunicorn?

@gnunicorn
Copy link

yes, looks like we kept the threadsafe-api and the pre-release in branches: bytecodealliance/wasmtime@master...paritytech:ben-prep-release .

The issue still isn't fixed though. You want to make a new release? We could do another pre-release...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.