Add a compilation section to disable address maps (#3598)
* Add a compilation section to disable address maps This commit adds a new `Config::generate_address_map` compilation setting which is used to disable emission of the `.wasmtime.addrmap` section of compiled artifacts. This section is currently around the size of the entire `.text` section itself unfortunately and for size reasons may wish to be omitted. Functionality-wise all that is lost is knowing the precise wasm module offset address of a faulting instruction or in a backtrace of instructions. This also means that if the module has DWARF debugging information available with it Wasmtime isn't able to produce a filename and line number in the backtrace. This option remains enabled by default. This option may not be needed in the future with #3547 perhaps, but in the meantime it seems reasonable enough to support a configuration mode where the section is entirely omitted if the smallest module possible is desired. * Fix some CI issues * Update tests/all/traps.rs Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com> * Do less work in compilation for address maps But only when disabled Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
This commit is contained in:
@@ -63,6 +63,7 @@ impl Compiler {
|
||||
context: &Context,
|
||||
data: &FunctionBodyData<'_>,
|
||||
body_len: u32,
|
||||
tunables: &Tunables,
|
||||
) -> FunctionAddressMap {
|
||||
// Generate artificial srcloc for function start/end to identify boundary
|
||||
// within module.
|
||||
@@ -75,17 +76,21 @@ impl Compiler {
|
||||
|
||||
// New-style backend: we have a `MachCompileResult` that will give us `MachSrcLoc` mapping
|
||||
// tuples.
|
||||
let instructions = collect_address_maps(
|
||||
body_len,
|
||||
context
|
||||
.mach_compile_result
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.buffer
|
||||
.get_srclocs_sorted()
|
||||
.into_iter()
|
||||
.map(|&MachSrcLoc { start, end, loc }| (loc, start, (end - start))),
|
||||
);
|
||||
let instructions = if tunables.generate_address_map {
|
||||
collect_address_maps(
|
||||
body_len,
|
||||
context
|
||||
.mach_compile_result
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.buffer
|
||||
.get_srclocs_sorted()
|
||||
.into_iter()
|
||||
.map(|&MachSrcLoc { start, end, loc }| (loc, start, (end - start))),
|
||||
)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
FunctionAddressMap {
|
||||
instructions: instructions.into(),
|
||||
@@ -179,7 +184,7 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?;
|
||||
|
||||
let address_transform =
|
||||
self.get_function_address_map(&context, &input, code_buf.len() as u32);
|
||||
self.get_function_address_map(&context, &input, code_buf.len() as u32, tunables);
|
||||
|
||||
let ranges = if tunables.generate_native_debuginfo {
|
||||
Some(
|
||||
@@ -221,7 +226,7 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
translation: &ModuleTranslation,
|
||||
types: &TypeTables,
|
||||
funcs: PrimaryMap<DefinedFuncIndex, Box<dyn Any + Send>>,
|
||||
emit_dwarf: bool,
|
||||
tunables: &Tunables,
|
||||
obj: &mut Object<'static>,
|
||||
) -> Result<(PrimaryMap<DefinedFuncIndex, FunctionInfo>, Vec<Trampoline>)> {
|
||||
let funcs: crate::CompiledFunctions = funcs
|
||||
@@ -244,7 +249,9 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
let mut func_starts = Vec::with_capacity(funcs.len());
|
||||
for (i, func) in funcs.iter() {
|
||||
let range = builder.func(i, func);
|
||||
addrs.push(range.clone(), &func.address_map.instructions);
|
||||
if tunables.generate_address_map {
|
||||
addrs.push(range.clone(), &func.address_map.instructions);
|
||||
}
|
||||
traps.push(range.clone(), &func.traps);
|
||||
func_starts.push(range.start);
|
||||
if self.linkopts.padding_between_functions > 0 {
|
||||
@@ -266,7 +273,7 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
|
||||
builder.unwind_info();
|
||||
|
||||
if emit_dwarf && funcs.len() > 0 {
|
||||
if tunables.generate_native_debuginfo && funcs.len() > 0 {
|
||||
let ofs = VMOffsets::new(
|
||||
self.isa
|
||||
.triple()
|
||||
@@ -297,7 +304,10 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
}
|
||||
|
||||
builder.finish()?;
|
||||
addrs.append_to(obj);
|
||||
|
||||
if tunables.generate_address_map {
|
||||
addrs.append_to(obj);
|
||||
}
|
||||
traps.append_to(obj);
|
||||
|
||||
Ok((
|
||||
|
||||
Reference in New Issue
Block a user