Skip to content

Commit

Permalink
Merge branch 'master' into features/llvm
Browse files Browse the repository at this point in the history
  • Loading branch information
nlewycky authored Jul 30, 2019
2 parents c42f47d + c21a91e commit 9b815cb
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Blocks of changes will separated by version increments.
- makes wasitests-generate output stdout/stderr by default & adds function to print stdout and stderr for a command if it fails
- compiles wasm with size optimizations & strips generated wasm with wasm-strip
- [#554](https://github.com/wasmerio/wasmer/pull/554) Finish implementation of `wasi::fd_seek`, fix bug in filestat
- [#550](https://github.com/wasmerio/wasmer/pull/550) Fix singlepass compilation error with `imul` instruction


## 0.5.5 - 2019-07-10
- [#541](https://github.com/wasmerio/wasmer/pull/541) Fix dependency graph by making separate test crates; ABI implementations should not depend on compilers. Add Cranelift fork as git submodule of clif-backend
Expand All @@ -41,6 +43,7 @@ Blocks of changes will separated by version increments.
- [#523](https://github.com/wasmerio/wasmer/pull/523) Update wapm version to fix bug related to signed packages in the global namespace and locally-stored public keys

## 0.5.2 - 2019-07-02
- [#516](https://github.com/wasmerio/wasmer/pull/516) Add workaround for singlepass miscompilation on GetLocal
- [#521](https://github.com/wasmerio/wasmer/pull/521) Update Wapm-cli, bump version numbers
- [#518](https://github.com/wasmerio/wasmer/pull/518) Update Cranelift and WasmParser
- [#514](https://github.com/wasmerio/wasmer/pull/514) [#519](https://github.com/wasmerio/wasmer/pull/519) Improved Emscripten network related calls, added a null check to `WasmPtr`
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:19.04

ARG RUST_TOOLCHAIN="nightly"

ENV CARGO_HOME=/usr/local/rust
ENV RUSTUP_HOME=/usr/local/rust
ENV PATH="$PATH:$CARGO_HOME/bin"

RUN apt-get update \
&& apt-get -y install sudo strace curl cmake pkg-config python libssl-dev llvm-dev libz-dev gnuplot-nox \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& echo '%wheel ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN"
79 changes: 79 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# Wasmer build tool
#
# This is a script to build Wasmer in a Docker sandbox.
#
# To use the script, first make sure Docker is installed. Then build the
# sandbox image with:
#
# docker build --file Dockerfile.build --tag wasmer-build .
#
# After the sandbox image is built successfully, you can run commands in it
# with this script.
#
# For example, to build Wasmer, run:
#
# ./build make
#
# To test Wasmer, run:
#
# ./build make test
#
# and so on.

docker_hostname="wasmer-build"

docker_img="wasmer-build"

docker_workdir="/wasmer"

docker_args=(
#
# General config.
#
--hostname=${docker_hostname}
--interactive
--network=host
--rm
--tty

#
# User and group config.
#
# Use the same user and group permissions as host to make integration
# between host and container simple.
#
--user "$(id --user):$(id --group)"
--volume "/etc/group:/etc/group:ro"
--volume "/etc/passwd:/etc/passwd:ro"
--volume "/etc/shadow:/etc/shadow:ro"

#
# Time zone config.
#
# Use the same time zone as the host.
#
--volume "/etc/localtime:/etc/localtime:ro"

#
# Linux capabilities.
#
# Add SYS_PTRACE capability to the container so that people can run
# `strace'.
#
--cap-add SYS_PTRACE

#
# Source directory.
#
--workdir=${docker_workdir}
--volume "$(pwd):${docker_workdir}:z"

#
# Environment variables.
#
--env "CARGO_HOME=${docker_workdir}/.cargo"
)

docker run ${docker_args[@]} ${docker_img} $*
13 changes: 13 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ INFO: seed corpus: files: 8 min: 1b max: 1b total: 8b rss: 133Mb
```
It will continue to generate random inputs forever, until it finds a bug or is terminated. The testcases for bugs it finds go into `fuzz/artifacts/simple_instantiate` and you can rerun the fuzzer on a single input by passing it on the command line `cargo fuzz run simple_instantiate my_testcase.wasm`.

## Seeding the corpus, optional

The fuzzer works best when it has examples of small Wasm files to start with. Using `wast2json` from [wabt](https://github.com/WebAssembly/wabt), we can easily produce `.wasm` files out of the WebAssembly spec tests.

```sh
mkdir spec-test-corpus
for i in lib/spectests/spectests/*.wast; do wast2json $i -o spec-test-corpus/$(basename $i).json; done
mv spec-test-corpus/*.wasm fuzz/corpus/simple_instantiate/
rm -r spec-test-corpus
```

The corpus directory is created on the first run of the fuzzer. If it doesn't exist, run it first and then seed the corpus. The fuzzer will pick up new files added to the corpus while it is running.

## Trophy case

- [x] https://github.com/wasmerio/wasmer/issues/558
12 changes: 6 additions & 6 deletions lib/runtime-core/src/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
backend::RunnableModule,
backend::{Backend, CacheGen, Compiler, CompilerConfig, Token},
backend::{Backend, CacheGen, Compiler, CompilerConfig, Features, Token},
cache::{Artifact, Error as CacheError},
error::{CompileError, CompileResult},
module::{ModuleInfo, ModuleInner},
Expand Down Expand Up @@ -137,22 +137,22 @@ impl<
}
}

pub fn default_validating_parser_config() -> wasmparser::ValidatingParserConfig {
pub fn validating_parser_config(features: &Features) -> wasmparser::ValidatingParserConfig {
wasmparser::ValidatingParserConfig {
operator_config: wasmparser::OperatorValidatorConfig {
enable_threads: false,
enable_reference_types: false,
enable_simd: true,
enable_simd: features.simd,
enable_bulk_memory: false,
enable_multi_value: false,
},
mutable_global_imports: false,
}
}

fn validate(bytes: &[u8]) -> CompileResult<()> {
fn validate_with_features(bytes: &[u8], features: &Features) -> CompileResult<()> {
let mut parser =
wasmparser::ValidatingParser::new(bytes, Some(default_validating_parser_config()));
wasmparser::ValidatingParser::new(bytes, Some(validating_parser_config(features)));
loop {
let state = parser.read();
match *state {
Expand Down Expand Up @@ -180,7 +180,7 @@ impl<
_: Token,
) -> CompileResult<ModuleInner> {
if requires_pre_validation(MCG::backend_id()) {
validate(wasm)?;
validate_with_features(wasm, &compiler_config.features)?;
}

let mut mcg = MCG::new();
Expand Down
6 changes: 4 additions & 2 deletions lib/runtime-core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ pub fn read_module<
custom_sections: HashMap::new(),
}));

let mut parser =
wasmparser::ValidatingParser::new(wasm, Some(default_validating_parser_config()));
let mut parser = wasmparser::ValidatingParser::new(
wasm,
Some(validating_parser_config(&compiler_config.features)),
);

let mut namespace_builder = Some(StringTableBuilder::new());
let mut name_builder = Some(StringTableBuilder::new());
Expand Down
9 changes: 2 additions & 7 deletions lib/runtime/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use wasmer_runtime_core::cache::Error as CacheError;
pub use wasmer_runtime_core::{
backend::Backend,
cache::{Artifact, Cache, WasmHash, WASMER_VERSION_HASH},
cache::{Artifact, Cache, WasmHash},
};

/// Representation of a directory that contains compiled wasm artifacts.
Expand Down Expand Up @@ -49,12 +49,7 @@ impl FileSystemCache {
/// This method is unsafe because there's no way to ensure the artifacts
/// stored in this cache haven't been corrupted or tampered with.
pub unsafe fn new<P: Into<PathBuf>>(path: P) -> io::Result<Self> {
let path: PathBuf = {
let mut path = path.into();
path.push(WASMER_VERSION_HASH);
path
};

let path: PathBuf = path.into();
if path.exists() {
let metadata = path.metadata()?;
if metadata.is_dir() {
Expand Down
10 changes: 5 additions & 5 deletions lib/spectests/build/spectests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use wasmer_runtime_core::types::Value;
use wasmer_runtime_core::{{Instance, module::Module}};
use wasmer_runtime_core::error::Result;
use wasmer_runtime_core::vm::Ctx;
use wasmer_runtime_core::backend::Compiler;
use wasmer_runtime_core::backend::{Compiler, CompilerConfig, Features};
static IMPORT_MODULE: &str = r#"
(module
Expand Down Expand Up @@ -136,7 +136,7 @@ pub fn generate_imports() -> ImportObject {
let mut features = wabt::Features::new();
features.enable_simd();
let wasm_binary = wat2wasm_with_features(IMPORT_MODULE.as_bytes(), features).expect("WAST not valid or malformed");
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &get_compiler())
let module = wasmer_runtime_core::compile_with_config(&wasm_binary[..], &get_compiler(), CompilerConfig { features: Features { simd: true }, ..Default::default() })
.expect("WASM can't be compiled");
let instance = module
.instantiate(&ImportObject::new())
Expand Down Expand Up @@ -408,7 +408,7 @@ fn test_module_{}() {{
let module_str = \"{}\";
println!(\"{{}}\", module_str);
let wasm_binary = wat2wasm(module_str.as_bytes()).expect(\"WAST not valid or malformed\");
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &get_compiler()).expect(\"WASM can't be compiled\");
let module = wasmer_runtime_core::compile_with_config(&wasm_binary[..], &get_compiler(), CompilerConfig {{ features: Features {{ simd: true }}, ..Default::default() }}).expect(\"WASM can't be compiled\");
module.instantiate(&generate_imports()).expect(\"WASM can't be instantiated\")
}}\n",
self.last_module,
Expand All @@ -431,7 +431,7 @@ fn test_module_{}() {{
"#[test]
fn {}_assert_invalid() {{
let wasm_binary = {:?};
let module = wasmer_runtime_core::compile_with(&wasm_binary, &get_compiler());
let module = wasmer_runtime_core::compile_with_config(&wasm_binary, &get_compiler(), CompilerConfig {{ features: Features {{ simd: true }}, ..Default::default() }});
assert!(module.is_err(), \"WASM should not compile as is invalid\");
}}\n",
command_name,
Expand Down Expand Up @@ -562,7 +562,7 @@ fn {}_assert_invalid() {{
"#[test]
fn {}_assert_malformed() {{
let wasm_binary = {:?};
let compilation = wasmer_runtime_core::compile_with(&wasm_binary, &get_compiler());
let compilation = wasmer_runtime_core::compile_with_config(&wasm_binary, &get_compiler(), CompilerConfig {{ features: Features {{ simd: true }}, ..Default::default() }});
assert!(compilation.is_err(), \"WASM should not compile as is malformed\");
}}\n",
command_name,
Expand Down
35 changes: 20 additions & 15 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use wasmer_clif_backend::CraneliftCompiler;
#[cfg(feature = "backend-llvm")]
use wasmer_llvm_backend::LLVMCompiler;
use wasmer_runtime::{
cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH},
Func, Value,
cache::{Cache as BaseCache, FileSystemCache, WasmHash},
Func, Value, VERSION,
};
use wasmer_runtime_core::{
self,
Expand Down Expand Up @@ -216,12 +216,16 @@ fn read_file_contents(path: &PathBuf) -> Result<Vec<u8>, io::Error> {

fn get_cache_dir() -> PathBuf {
match env::var("WASMER_CACHE_DIR") {
Ok(dir) => PathBuf::from(dir),
Ok(dir) => {
let mut path = PathBuf::from(dir);
path.push(VERSION);
path
}
Err(_) => {
// We use a temporal directory for saving cache files
let mut temp_dir = env::temp_dir();
temp_dir.push("wasmer");
temp_dir.push(WASMER_VERSION_HASH);
temp_dir.push(VERSION);
temp_dir
}
}
Expand Down Expand Up @@ -270,10 +274,6 @@ fn get_env_var_args(input: &[String]) -> Result<Vec<(&str, &str)>, String> {

/// Execute a wasm/wat file
fn execute_wasm(options: &Run) -> Result<(), String> {
// force disable caching on windows
#[cfg(target_os = "windows")]
let disable_cache = true;
#[cfg(not(target_os = "windows"))]
let disable_cache = options.disable_cache;

let mapped_dirs = get_mapped_dirs(&options.mapped_dirs[..])?;
Expand Down Expand Up @@ -401,7 +401,6 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
.map_err(|e| format!("Can't compile module: {:?}", e))?
} else {
// If we have cache enabled

let wasmer_cache_dir = get_cache_dir();

// We create a new cache instance.
Expand All @@ -421,7 +420,6 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
return Ok(module);
}
}

// We generate a hash for the given binary, so we can use it as key
// for the Filesystem cache
let hash = WasmHash::generate(&wasm_binary);
Expand All @@ -440,6 +438,9 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
CompilerConfig {
symbol_map: em_symbol_map,
track_state,
features: Features {
simd: options.features.simd || options.features.all,
},
..Default::default()
},
&*compiler,
Expand Down Expand Up @@ -796,7 +797,6 @@ fn main() {
CLIOptions::SelfUpdate => {
println!("Self update is not supported on Windows. Use install instructions on the Wasmer homepage: https://wasmer.io");
}
#[cfg(not(target_os = "windows"))]
CLIOptions::Cache(cache) => match cache {
Cache::Clean => {
use std::fs;
Expand All @@ -813,9 +813,14 @@ fn main() {
CLIOptions::Validate(validate_options) => {
validate(validate_options);
}
#[cfg(target_os = "windows")]
CLIOptions::Cache(_) => {
println!("Caching is disabled for Windows.");
}
}
}

#[test]
fn filesystem_cache_should_work() -> Result<(), String> {
let wasmer_cache_dir = get_cache_dir();

unsafe { FileSystemCache::new(wasmer_cache_dir).map_err(|e| format!("Cache error: {:?}", e))? };

Ok(())
}

0 comments on commit 9b815cb

Please sign in to comment.