From c86e2a5234105742fd0a335beac9a8927384aceb Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 14 Feb 2019 06:23:08 -0800 Subject: [PATCH 1/5] Add a config flag for DWARF custom sections --- src/module/config.rs | 12 ++++++++++++ src/module/mod.rs | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/module/config.rs b/src/module/config.rs index 6252f5f3..580dbaa0 100644 --- a/src/module/config.rs +++ b/src/module/config.rs @@ -4,6 +4,7 @@ use crate::module::Module; /// Configuration for a `Module` which currently affects parsing. #[derive(Clone, Debug, Default)] pub struct ModuleConfig { + pub(crate) generate_dwarf: bool, pub(crate) generate_names: bool, pub(crate) skip_strict_validate: bool, } @@ -14,6 +15,17 @@ impl ModuleConfig { ModuleConfig::default() } + /// Sets a flag to whether DWARF debug sections are generated for this + /// module. + /// + /// By default this flag is `false`. Note that any emitted DWARF is + /// currently wildly incorrect and buggy, and is also larger than the wasm + /// itself! + pub fn generate_dwarf(&mut self, generate: bool) -> &mut ModuleConfig { + self.generate_dwarf = generate; + self + } + /// Sets a flag to whether debugging names are generated for /// locals/functions/etc when parsing and running passes for this module. /// diff --git a/src/module/mod.rs b/src/module/mod.rs index d59d7e37..07e48acc 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -259,6 +259,11 @@ impl Module { emit_name_section(&mut cx); self.producers.emit(&mut cx); for section in self.custom.iter() { + if !self.config.generate_dwarf && section.name.starts_with(".debug") { + log::debug!("skipping DWARF custom section {}", section.name); + continue; + } + log::debug!("emitting custom section {}", section.name); cx.custom_section(§ion.name).encoder.raw(§ion.value); } From 05028122b13fe626535d5350449ca301f621317c Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 14 Feb 2019 06:24:11 -0800 Subject: [PATCH 2/5] If we aren't configured to emit names, short circuit name section emitting This skips checking all of our items for whether they have names or not (which they won't if we aren't configured to emit names, but we don't need to do that big traversal in this case). --- src/module/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/module/mod.rs b/src/module/mod.rs index 07e48acc..879096ea 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -256,7 +256,10 @@ impl Module { self.funcs.emit(&mut cx); self.data.emit(&mut cx); - emit_name_section(&mut cx); + if self.config.generate_names { + emit_name_section(&mut cx); + } + self.producers.emit(&mut cx); for section in self.custom.iter() { if !self.config.generate_dwarf && section.name.starts_with(".debug") { From 71fbe9b6f6b838ff8c0919d9c4eb0492a387964a Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 14 Feb 2019 06:43:12 -0800 Subject: [PATCH 3/5] Rename `generate_names` to `generate_synthetic_names_for_anonymous_items` Since this is not about generating the name section or not, but whether we give names like "f0" to anonymous functions --- src/module/config.rs | 14 +++++++++----- src/module/functions/mod.rs | 6 +++--- src/module/mod.rs | 9 ++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/module/config.rs b/src/module/config.rs index 580dbaa0..22018ad1 100644 --- a/src/module/config.rs +++ b/src/module/config.rs @@ -5,7 +5,7 @@ use crate::module::Module; #[derive(Clone, Debug, Default)] pub struct ModuleConfig { pub(crate) generate_dwarf: bool, - pub(crate) generate_names: bool, + pub(crate) generate_synthetic_names_for_anonymous_items: bool, pub(crate) skip_strict_validate: bool, } @@ -26,13 +26,17 @@ impl ModuleConfig { self } - /// Sets a flag to whether debugging names are generated for - /// locals/functions/etc when parsing and running passes for this module. + /// Sets a flag to whether synthetic debugging names are generated for + /// anonymous locals/functions/etc when parsing and running passes for this + /// module. /// /// By default this flag is `false`, and it will generate quite a few names /// if enabled! - pub fn generate_names(&mut self, generate: bool) -> &mut ModuleConfig { - self.generate_names = generate; + pub fn generate_synthetic_names_for_anonymous_items( + &mut self, + generate: bool, + ) -> &mut ModuleConfig { + self.generate_synthetic_names_for_anonymous_items = generate; self } diff --git a/src/module/functions/mod.rs b/src/module/functions/mod.rs index 43757927..4561ca3d 100644 --- a/src/module/functions/mod.rs +++ b/src/module/functions/mod.rs @@ -281,7 +281,7 @@ impl Module { let id = self.funcs.arena.next_id(); self.funcs.arena.alloc(Function::new_uninitialized(id, ty)); let idx = ids.push_func(id); - if self.config.generate_names { + if self.config.generate_synthetic_names_for_anonymous_items { self.funcs.get_mut(id).name = Some(format!("f{}", idx)); } } @@ -324,7 +324,7 @@ impl Module { let local_id = self.locals.add(*ty); let idx = indices.push_local(id, local_id); args.push(local_id); - if self.config.generate_names { + if self.config.generate_synthetic_names_for_anonymous_items { let name = format!("arg{}", idx); self.locals.get_mut(local_id).name = Some(name); } @@ -349,7 +349,7 @@ impl Module { for _ in 0..count { let local_id = self.locals.add(ty); let idx = indices.push_local(id, local_id); - if self.config.generate_names { + if self.config.generate_synthetic_names_for_anonymous_items { let name = format!("l{}", idx); self.locals.get_mut(local_id).name = Some(name); } diff --git a/src/module/mod.rs b/src/module/mod.rs index 879096ea..4df0fd4f 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -256,10 +256,7 @@ impl Module { self.funcs.emit(&mut cx); self.data.emit(&mut cx); - if self.config.generate_names { - emit_name_section(&mut cx); - } - + emit_name_section(&mut cx); self.producers.emit(&mut cx); for section in self.custom.iter() { if !self.config.generate_dwarf && section.name.starts_with(".debug") { @@ -311,7 +308,9 @@ impl Module { // names for locals if they aren't specified, so // just ignore empty names which would in theory // make debugging a bit harder. - if self.config.generate_names && naming.name.is_empty() { + if self.config.generate_synthetic_names_for_anonymous_items + && naming.name.is_empty() + { continue; } let id = indices.get_local(func_id, naming.index)?; From 3d64daae32b2ba60c1ab70cf81add37c512df60d Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 14 Feb 2019 06:49:10 -0800 Subject: [PATCH 4/5] Add a configuration for generating the custom "name" section --- src/module/config.rs | 21 ++++++++++++++++++++- src/module/mod.rs | 5 ++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/module/config.rs b/src/module/config.rs index 22018ad1..01262560 100644 --- a/src/module/config.rs +++ b/src/module/config.rs @@ -5,6 +5,7 @@ use crate::module::Module; #[derive(Clone, Debug, Default)] pub struct ModuleConfig { pub(crate) generate_dwarf: bool, + pub(crate) generate_name_section: bool, pub(crate) generate_synthetic_names_for_anonymous_items: bool, pub(crate) skip_strict_validate: bool, } @@ -12,7 +13,12 @@ pub struct ModuleConfig { impl ModuleConfig { /// Creates a fresh new configuration with default settings. pub fn new() -> ModuleConfig { - ModuleConfig::default() + ModuleConfig { + generate_dwarf: false, + generate_name_section: true, + generate_synthetic_names_for_anonymous_items: false, + skip_strict_validate: false, + } } /// Sets a flag to whether DWARF debug sections are generated for this @@ -26,6 +32,19 @@ impl ModuleConfig { self } + /// Sets a flag to whether the custom "name" section is generated for this + /// module. + /// + /// The "name" section contains symbol names for the module, functions, and + /// locals. When enabled, stack traces will use these names, instead of + /// `wasm-function[123]`. + /// + /// By default this flag is `true`. + pub fn generate_name_section(&mut self, generate: bool) -> &mut ModuleConfig { + self.generate_name_section = generate; + self + } + /// Sets a flag to whether synthetic debugging names are generated for /// anonymous locals/functions/etc when parsing and running passes for this /// module. diff --git a/src/module/mod.rs b/src/module/mod.rs index 4df0fd4f..0541ded5 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -256,7 +256,10 @@ impl Module { self.funcs.emit(&mut cx); self.data.emit(&mut cx); - emit_name_section(&mut cx); + if self.config.generate_name_section { + emit_name_section(&mut cx); + } + self.producers.emit(&mut cx); for section in self.custom.iter() { if !self.config.generate_dwarf && section.name.starts_with(".debug") { From da45cc867a0cb7eafe6ec614596d39ac11c5a7d1 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 14 Feb 2019 06:55:59 -0800 Subject: [PATCH 5/5] Bump to version 0.2.0 --- CHANGELOG.md | 17 +++++++++++++++++ Cargo.toml | 4 ++-- crates/macro/Cargo.toml | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08cf81bb..bb997d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,23 @@ Released YYYY-MM-DD. -------------------------------------------------------------------------------- +## 0.2.0 + +Released 2019-02-14. + +### Added + +* Added configuration options for controlling emission of the DWARF and name + custom sections. + +### Changed + +* Changed the synthetic naming option from "generate_names" to + "generate_synthetic_names_for_anonymous_items" to more accurately reflect what + it does. + +-------------------------------------------------------------------------------- + ## 0.1.0 Released 2019-02-12. diff --git a/Cargo.toml b/Cargo.toml index 8183174c..aeed7f34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Nick Fitzgerald "] edition = "2018" name = "walrus" -version = "0.1.0" +version = "0.2.0" license = "MIT/Apache-2.0" readme = "README.md" categories = ["wasm"] @@ -19,7 +19,7 @@ id-arena = { version = "2.2.0", features = ['rayon'] } leb128 = "0.2.3" log = "0.4" rayon = "1.0.3" -walrus-macro = { path = './crates/macro', version = '=0.1.0' } +walrus-macro = { path = './crates/macro', version = '=0.2.0' } wasmparser = "0.28" [dev-dependencies] diff --git a/crates/macro/Cargo.toml b/crates/macro/Cargo.toml index dcc2900f..2dad9b80 100644 --- a/crates/macro/Cargo.toml +++ b/crates/macro/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Nick Fitzgerald "] edition = "2018" name = "walrus-macro" -version = "0.1.0" +version = "0.2.0" license = "MIT/Apache-2.0" categories = ["wasm"] repository = "https://github.com/rustwasm/walrus/tree/crates/macro"