Handle select relocations while generating trampolines (#1347)

* Handle select relocations while generating trampolines

Trampoline generation for all function signatures exposed a preexisting
bug in wasmtime where trampoline generation occasionally does have
relocations, but it's asserted that trampolines don't generate
relocations, causing a panic. The relocation is currently primarily the
probestack function which happens when functions might have a huge
number of parameters, but not so huge as to blow the wasmparser limit of
how many parameters are allowed.

This commit fixes the issue by handling relocations for trampolines in
the same manner as the rest of the code. Note that dynamically-generated
trampolines via the `Func` API still panic if they have too many
arguments and generate a relocation, but it seems like we can try to fix
that later if the need truly arises.

Closes #1322

* Log trampoline relocations
This commit is contained in:
Alex Crichton
2020-03-17 16:30:21 -05:00
committed by GitHub
parent 4c3c717698
commit ba0dc40b2b
8 changed files with 310 additions and 154 deletions

View File

@@ -80,26 +80,14 @@ impl<'data> RawCompiledModule<'data> {
None
};
let (
finished_functions,
trampolines,
jt_offsets,
relocations,
dbg_image,
trap_registration,
) = compiler.compile(
let compilation = compiler.compile(
&translation.module,
translation.module_translation.as_ref().unwrap(),
translation.function_body_inputs,
debug_data,
)?;
link_module(
&translation.module,
&finished_functions,
&jt_offsets,
relocations,
);
link_module(&translation.module, &compilation);
// Compute indices into the shared signature table.
let signatures = {
@@ -121,7 +109,7 @@ impl<'data> RawCompiledModule<'data> {
Some(_) => {
let region_name = String::from("wasm_module");
let mut profiler = profiler.unwrap().lock().unwrap();
match &dbg_image {
match &compilation.dbg_image {
Some(dbg) => {
compiler.profiler_module_load(&mut profiler, &region_name, Some(&dbg))
}
@@ -131,7 +119,7 @@ impl<'data> RawCompiledModule<'data> {
_ => (),
};
let dbg_jit_registration = if let Some(img) = dbg_image {
let dbg_jit_registration = if let Some(img) = compilation.dbg_image {
let mut bytes = Vec::new();
bytes.write_all(&img).expect("all written");
let reg = GdbJitImageRegistration::register(bytes);
@@ -142,12 +130,12 @@ impl<'data> RawCompiledModule<'data> {
Ok(Self {
module: translation.module,
finished_functions: finished_functions.into_boxed_slice(),
trampolines,
finished_functions: compilation.finished_functions.into_boxed_slice(),
trampolines: compilation.trampolines,
data_initializers: translation.data_initializers.into_boxed_slice(),
signatures: signatures.into_boxed_slice(),
dbg_jit_registration,
trap_registration,
trap_registration: compilation.trap_registration,
})
}
}