Browse Source

Fix build of wmemcheck feature (#8444)

The `wmemcheck` feature of Wasmtime is currently broken and does not
compile. This commit fixes it and updates CI to account for it as well.

cc #8443
pull/8450/head
Alex Crichton 7 months ago
committed by GitHub
parent
commit
04ada884fd
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      .github/workflows/main.yml
  2. 109
      crates/cranelift/src/func_environ.rs
  3. 1
      crates/environ/Cargo.toml
  4. 2
      crates/runtime/Cargo.toml

3
.github/workflows/main.yml

@ -326,6 +326,7 @@ jobs:
- run: cargo check -p wasmtime --no-default-features --features cranelift,wat,async,cache
- run: cargo check -p wasmtime --no-default-features --features winch
- run: cargo check -p wasmtime --no-default-features --features wmemcheck
- run: cargo check -p wasmtime --no-default-features --features wmemcheck,cranelift,runtime
- run: cargo check -p wasmtime --no-default-features --features demangle
- run: cargo check -p wasmtime --no-default-features --features addr2line
- run: cargo check -p wasmtime --no-default-features --features gc
@ -337,6 +338,7 @@ jobs:
- run: cargo check -p wasmtime --no-default-features --features cranelift,threads
- run: cargo check --features component-model
- run: cargo check -p wasmtime --features incremental-cache
- run: cargo check -p wasmtime --all-features
# Feature combinations of the `wasmtime-cli`
- run: cargo check -p wasmtime-cli --no-default-features
@ -345,6 +347,7 @@ jobs:
- run: cargo check -p wasmtime-cli --no-default-features --features compile
- run: cargo check -p wasmtime-cli --no-default-features --features compile,cranelift
- run: cargo check -p wasmtime-cli --no-default-features --features compile,cranelift,component-model
- run: cargo check -p wasmtime-cli --all-features
# Check that benchmarks of the cranelift project build
- run: cargo check --benches -p cranelift-codegen

109
crates/cranelift/src/func_environ.rs

@ -530,12 +530,9 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
}
#[cfg(feature = "wmemcheck")]
fn hook_malloc_exit(&mut self, builder: &mut FunctionBuilder, retvals: &[Value]) {
let check_malloc_sig = self.builtin_functions.check_malloc(builder.func);
let (vmctx, check_malloc) = self.translate_load_builtin_function_address(
&mut builder.cursor(),
BuiltinFunctionIndex::check_malloc(),
);
fn hook_malloc_exit(&mut self, builder: &mut FunctionBuilder, retvals: &[ir::Value]) {
let check_malloc = self.builtin_functions.check_malloc(builder.func);
let vmctx = self.vmctx_val(&mut builder.cursor());
let func_args = builder
.func
.dfg
@ -552,18 +549,13 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
} else {
retvals[0]
};
builder
.ins()
.call_indirect(check_malloc_sig, check_malloc, &[vmctx, retval, len]);
builder.ins().call(check_malloc, &[vmctx, retval, len]);
}
#[cfg(feature = "wmemcheck")]
fn hook_free_exit(&mut self, builder: &mut FunctionBuilder) {
let check_free_sig = self.builtin_functions.check_free(builder.func);
let (vmctx, check_free) = self.translate_load_builtin_function_address(
&mut builder.cursor(),
BuiltinFunctionIndex::check_free(),
);
let check_free = self.builtin_functions.check_free(builder.func);
let vmctx = self.vmctx_val(&mut builder.cursor());
let func_args = builder
.func
.dfg
@ -575,9 +567,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
// first argument is a pointer to memory.
func_args[2]
};
builder
.ins()
.call_indirect(check_free_sig, check_free, &[vmctx, ptr]);
builder.ins().call(check_free, &[vmctx, ptr]);
}
fn epoch_ptr(&mut self, builder: &mut FunctionBuilder<'_>) -> ir::Value {
@ -871,32 +861,22 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
#[cfg(feature = "wmemcheck")]
fn check_malloc_start(&mut self, builder: &mut FunctionBuilder) {
let malloc_start_sig = self.builtin_function_signatures.malloc_start(builder.func);
let (vmctx, malloc_start) = self.translate_load_builtin_function_address(
&mut builder.cursor(),
BuiltinFunctionIndex::malloc_start(),
);
builder
.ins()
.call_indirect(malloc_start_sig, malloc_start, &[vmctx]);
let malloc_start = self.builtin_functions.malloc_start(builder.func);
let vmctx = self.vmctx_val(&mut builder.cursor());
builder.ins().call(malloc_start, &[vmctx]);
}
#[cfg(feature = "wmemcheck")]
fn check_free_start(&mut self, builder: &mut FunctionBuilder) {
let free_start_sig = self.builtin_function_signatures.free_start(builder.func);
let (vmctx, free_start) = self.translate_load_builtin_function_address(
&mut builder.cursor(),
BuiltinFunctionIndex::free_start(),
);
builder
.ins()
.call_indirect(free_start_sig, free_start, &[vmctx]);
let free_start = self.builtin_functions.free_start(builder.func);
let vmctx = self.vmctx_val(&mut builder.cursor());
builder.ins().call(free_start, &[vmctx]);
}
#[cfg(feature = "wmemcheck")]
fn current_func_name(&self, builder: &mut FunctionBuilder) -> Option<&str> {
let func_index = match &builder.func.name {
UserFuncName::User(user) => FuncIndex::from_u32(user.index),
ir::UserFuncName::User(user) => FuncIndex::from_u32(user.index),
_ => {
panic!("function name not a UserFuncName::User as expected")
}
@ -2561,7 +2541,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
}
#[cfg(feature = "wmemcheck")]
fn handle_before_return(&mut self, retvals: &[Value], builder: &mut FunctionBuilder) {
fn handle_before_return(&mut self, retvals: &[ir::Value], builder: &mut FunctionBuilder) {
if self.wmemcheck {
let func_name = self.current_func_name(builder);
if func_name == Some("malloc") {
@ -2581,18 +2561,13 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
offset: u64,
) {
if self.wmemcheck {
let check_load_sig = self.builtin_function_signatures.check_load(builder.func);
let (vmctx, check_load) = self.translate_load_builtin_function_address(
&mut builder.cursor(),
BuiltinFunctionIndex::check_load(),
);
let check_load = self.builtin_functions.check_load(builder.func);
let vmctx = self.vmctx_val(&mut builder.cursor());
let num_bytes = builder.ins().iconst(I32, val_size as i64);
let offset_val = builder.ins().iconst(I64, offset as i64);
builder.ins().call_indirect(
check_load_sig,
check_load,
&[vmctx, num_bytes, addr, offset_val],
);
builder
.ins()
.call(check_load, &[vmctx, num_bytes, addr, offset_val]);
}
}
@ -2605,18 +2580,13 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
offset: u64,
) {
if self.wmemcheck {
let check_store_sig = self.builtin_function_signatures.check_store(builder.func);
let (vmctx, check_store) = self.translate_load_builtin_function_address(
&mut builder.cursor(),
BuiltinFunctionIndex::check_store(),
);
let check_store = self.builtin_functions.check_store(builder.func);
let vmctx = self.vmctx_val(&mut builder.cursor());
let num_bytes = builder.ins().iconst(I32, val_size as i64);
let offset_val = builder.ins().iconst(I64, offset as i64);
builder.ins().call_indirect(
check_store_sig,
check_store,
&[vmctx, num_bytes, addr, offset_val],
);
builder
.ins()
.call(check_store, &[vmctx, num_bytes, addr, offset_val]);
}
}
@ -2630,18 +2600,10 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
if self.wmemcheck {
if global_index == 0 {
// We are making the assumption that global 0 is the auxiliary stack pointer.
let update_stack_pointer_sig = self
.builtin_function_signatures
.update_stack_pointer(builder.func);
let (vmctx, update_stack_pointer) = self.translate_load_builtin_function_address(
&mut builder.cursor(),
BuiltinFunctionIndex::update_stack_pointer(),
);
builder.ins().call_indirect(
update_stack_pointer_sig,
update_stack_pointer,
&[vmctx, value],
);
let update_stack_pointer =
self.builtin_functions.update_stack_pointer(builder.func);
let vmctx = self.vmctx_val(&mut builder.cursor());
builder.ins().call(update_stack_pointer, &[vmctx, value]);
}
}
}
@ -2654,16 +2616,9 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
mem_index: MemoryIndex,
) {
if self.wmemcheck && mem_index.as_u32() == 0 {
let update_mem_size_sig = self
.builtin_function_signatures
.update_mem_size(builder.func);
let (vmctx, update_mem_size) = self.translate_load_builtin_function_address(
&mut builder.cursor(),
BuiltinFunctionIndex::update_mem_size(),
);
builder
.ins()
.call_indirect(update_mem_size_sig, update_mem_size, &[vmctx, num_pages]);
let update_mem_size = self.builtin_functions.update_mem_size(builder.func);
let vmctx = self.vmctx_val(&mut builder.cursor());
builder.ins().call(update_mem_size, &[vmctx, num_pages]);
}
}
}

1
crates/environ/Cargo.toml

@ -52,3 +52,4 @@ demangle = ['dep:rustc-demangle', 'dep:cpp_demangle']
gc = []
compile = ['gimli/write', 'object/write_core']
threads = []
wmemcheck = []

2
crates/runtime/Cargo.toml

@ -69,7 +69,7 @@ wasmtime-versioned-export-macros = { workspace = true }
async = ["dep:wasmtime-fiber"]
pooling-allocator = []
component-model = ["wasmtime-environ/component-model", "dep:encoding_rs"]
wmemcheck = ['dep:wasmtime-wmemcheck']
wmemcheck = ['dep:wasmtime-wmemcheck', 'wasmtime-environ/wmemcheck']
debug-builtins = ['dep:wasmtime-jit-debug']
gc = ["wasmtime-environ/gc"]
coredump = ["dep:wasm-encoder"]

Loading…
Cancel
Save