From a2366febb83464a40cda6f7a1c3126f7105535e3 Mon Sep 17 00:00:00 2001 From: William Mbotta Date: Fri, 25 Oct 2019 04:08:01 +0200 Subject: [PATCH 1/6] fix #326 (help-wanted) --- ir/ir.rs | 1 + parser/wasm_parse/mod.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/ir/ir.rs b/ir/ir.rs index 2d9b60cc..0d82ff05 100644 --- a/ir/ir.rs +++ b/ir/ir.rs @@ -50,6 +50,7 @@ impl ItemsBuilder { self.items.insert(id, item); let old_value = self.parsed.insert(id); + // panic happen as this is call 2 times with 7, assert!( old_value, "should not parse the same key into multiple items" diff --git a/parser/wasm_parse/mod.rs b/parser/wasm_parse/mod.rs index 634f3c97..8df6b026 100644 --- a/parser/wasm_parse/mod.rs +++ b/parser/wasm_parse/mod.rs @@ -125,12 +125,18 @@ impl<'a> Parse<'a> for wasmparser::ModuleReader<'a> { section.get_data_section_reader()?.parse_items(items, idx)?; } wasmparser::SectionCode::DataCount => { + let msg = "the last iteration of the loop take 7 as id"; + dbg!(msg, idx); DataCountSection(section).parse_items(items, idx)?; } wasmparser::SectionCode::Code | wasmparser::SectionCode::Function => { unreachable!("unexpected code or function section found"); } }; + if idx == 7 { + let msg = "At some point just after the debug above this also is 7 so the panic"; + dbg!(msg, &idx); + } let id = Id::section(idx); let added = items.size_added() - start; let size = sizes @@ -799,8 +805,10 @@ impl<'a> Parse<'a> for DataCountSection<'a> { ) -> Result<(), traits::Error> { let range = self.0.range(); let size = (range.end - range.start) as u32; + //dbg!("section", &idx); let id = Id::section(idx); let name = "\"data count\" section"; + //dbg!("YEAH", &id); items.add_root(ir::Item::new(id, name, size, ir::Misc::new())); Ok(()) } From 1fbb2b592335272dc4487c6bc9ebe500eca183a4 Mon Sep 17 00:00:00 2001 From: Katelyn Martin Date: Sun, 21 Jun 2020 13:28:10 -0400 Subject: [PATCH 2/6] thread example --- .../all/expectations/top_threaded_module | 0 twiggy/tests/all/fixtures/threads.wasm | Bin 0 -> 616 bytes twiggy/tests/all/fixtures/threads.wat | 299 ++++++++++++++++++ twiggy/tests/all/top_tests.rs | 9 + 4 files changed, 308 insertions(+) create mode 100644 twiggy/tests/all/expectations/top_threaded_module create mode 100644 twiggy/tests/all/fixtures/threads.wasm create mode 100644 twiggy/tests/all/fixtures/threads.wat diff --git a/twiggy/tests/all/expectations/top_threaded_module b/twiggy/tests/all/expectations/top_threaded_module new file mode 100644 index 00000000..e69de29b diff --git a/twiggy/tests/all/fixtures/threads.wasm b/twiggy/tests/all/fixtures/threads.wasm new file mode 100644 index 0000000000000000000000000000000000000000..1bd3ae2f4e08015981d069995d65f232e84762a0 GIT binary patch literal 616 zcmZwDu};G<5C-5o$99^y&;>CdhM;ypNM!)jg{208gapq(BGj~oHm#a;piSy7Oh~*3 zPr^$v;8sG2Q%}0HKL5VOkmMr-0Brd&ppDT&j7!&*>k{Ict;({j78a`*fEnIMXY;wq z`t5u+nT)4}KOFbl=KKtBd(yc8wlzuJj<-E=JKPf-P)N>k;!cjPSkbT^)!%+FBUN}hd!9#B}p1uN?=`4GC?10=GBw7F7j7)KtnZhJPGw)5o z4}1g-3S}KJ{9^o_AzJ-*as&}*QAF^pp$(A#Hxe^qkC+n+VoB^1*N6k+kXRAdiFb&1 wi5nZMePG?DxZ&M~Y6^`nEup>xPzS%)k@yQ(6$zyz=+M1V;pSKQp_g3#0Ms9PdjJ3c literal 0 HcmV?d00001 diff --git a/twiggy/tests/all/fixtures/threads.wat b/twiggy/tests/all/fixtures/threads.wat new file mode 100644 index 00000000..6be45994 --- /dev/null +++ b/twiggy/tests/all/fixtures/threads.wat @@ -0,0 +1,299 @@ +(module + (type $FUNCSIG$i (func (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$vj (func (param i64))) + (type $FUNCSIG$vf (func (param f32))) + (type $FUNCSIG$vd (func (param f64))) + (type $FUNCSIG$fifdddfVi (func (param i32 f32 f64 f64 f64 f32 v128 i32) (result f32))) + (import "fuzzing-support" "log-i32" (func $log-i32 (param i32))) + (import "fuzzing-support" "log-i64" (func $log-i64 (param i64))) + (import "fuzzing-support" "log-f32" (func $log-f32 (param f32))) + (import "fuzzing-support" "log-f64" (func $log-f64 (param f64))) + (memory $0 1 1) + (data (i32.const 0) "\1c\03a;") + (table $0 1 funcref) + (elem (i32.const 0) $func_6) + (global $global$0 (mut i32) (i32.const 2)) + (global $global$1 (mut i32) (i32.const -268435456)) + (global $global$2 (mut i64) (i64.const 1024)) + (global $global$3 (mut i64) (i64.const -87)) + (global $global$4 (mut f32) (f32.const 18231)) + (global $hangLimit (mut i32) (i32.const 10)) + (export "hashMemory" (func $hashMemory)) + (export "func_6" (func $func_6)) + (export "hangLimitInitializer" (func $hangLimitInitializer)) + (func $hashMemory (; 4 ;) (type $FUNCSIG$i) (result i32) + (local $0 i32) + (local.set $0 + (i32.const 5381) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=1 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=2 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=3 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=4 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=5 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=6 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=7 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=8 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=9 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=10 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=11 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=12 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=13 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=14 + (i32.const 0) + ) + ) + ) + (local.set $0 + (i32.xor + (i32.add + (i32.shl + (local.get $0) + (i32.const 5) + ) + (local.get $0) + ) + (i32.load8_u offset=15 + (i32.const 0) + ) + ) + ) + (local.get $0) + ) + (func $func_5 (; 5 ;) (param $0 i32) + (block + (if + (i32.eqz + (global.get $hangLimit) + ) + (return) + ) + (global.set $hangLimit + (i32.sub + (global.get $hangLimit) + (i32.const 1) + ) + ) + ) + (data.drop 0) + ) + (func $func_6 (; 6 ;) (type $FUNCSIG$fifdddfVi) (param $0 i32) (param $1 f32) (param $2 f64) (param $3 f64) (param $4 f64) (param $5 f32) (param $6 v128) (param $7 i32) (result f32) + (block + (if + (i32.eqz + (global.get $hangLimit) + ) + (return + (local.get $5) + ) + ) + (global.set $hangLimit + (i32.sub + (global.get $hangLimit) + (i32.const 1) + ) + ) + ) + (block $label$0 (result f32) + (local.get $5) + ) + ) + (func $hangLimitInitializer (; 7 ;) + (global.set $hangLimit + (i32.const 10) + ) + ) +) diff --git a/twiggy/tests/all/top_tests.rs b/twiggy/tests/all/top_tests.rs index 6e8173ef..c53d3b57 100644 --- a/twiggy/tests/all/top_tests.rs +++ b/twiggy/tests/all/top_tests.rs @@ -68,6 +68,15 @@ test!( "csv" ); +// Threaded modules should not cause a panic. +test!( + top_threaded_module, + "top", + "-n", + "25", + "./fixtures/threads.wasm" +); + // This should not fail to open and write `whatever-output.txt`. test!( output_to_file, From 928c3b3ef5017e73daee5988af1754a15a33fc57 Mon Sep 17 00:00:00 2001 From: Katelyn Martin Date: Sun, 21 Jun 2020 21:06:56 -0400 Subject: [PATCH 3/6] wip, check in before reduce... --- ir/ir.rs | 16 ++++-- parser/wasm_parse/mod.rs | 9 +--- twiggy/tests/all/fixtures/threads_test.wasm | Bin 0 -> 616 bytes .../tests/all/fixtures/threads_working.wasm | Bin 0 -> 616 bytes twiggy/tests/all/top_tests.rs | 50 ++++++++++++++---- 5 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 twiggy/tests/all/fixtures/threads_test.wasm create mode 100644 twiggy/tests/all/fixtures/threads_working.wasm diff --git a/ir/ir.rs b/ir/ir.rs index 0d82ff05..70cb60e2 100644 --- a/ir/ir.rs +++ b/ir/ir.rs @@ -45,16 +45,22 @@ impl ItemsBuilder { /// Add the given item to to the graph and return the `Id` that it was /// assigned. pub fn add_item(&mut self, item: Item) -> Id { + // --- --- 8< --- --- + let dbg_clone = item.clone(); + // --- --- 8< --- --- + let id = item.id; self.size_added += item.size; self.items.insert(id, item); let old_value = self.parsed.insert(id); - // panic happen as this is call 2 times with 7, - assert!( - old_value, - "should not parse the same key into multiple items" - ); + + // --- --- 8< --- --- + if !old_value { + dbg!(dbg_clone); + panic!("value with id {:?} parsed into multiple items!", id); + } + // --- --- 8< --- --- id } diff --git a/parser/wasm_parse/mod.rs b/parser/wasm_parse/mod.rs index 8df6b026..2ae15a4f 100644 --- a/parser/wasm_parse/mod.rs +++ b/parser/wasm_parse/mod.rs @@ -125,18 +125,12 @@ impl<'a> Parse<'a> for wasmparser::ModuleReader<'a> { section.get_data_section_reader()?.parse_items(items, idx)?; } wasmparser::SectionCode::DataCount => { - let msg = "the last iteration of the loop take 7 as id"; - dbg!(msg, idx); DataCountSection(section).parse_items(items, idx)?; } wasmparser::SectionCode::Code | wasmparser::SectionCode::Function => { unreachable!("unexpected code or function section found"); } }; - if idx == 7 { - let msg = "At some point just after the debug above this also is 7 so the panic"; - dbg!(msg, &idx); - } let id = Id::section(idx); let added = items.size_added() - start; let size = sizes @@ -798,6 +792,7 @@ struct DataCountSection<'a>(wasmparser::Section<'a>); impl<'a> Parse<'a> for DataCountSection<'a> { type ItemsExtra = usize; + // Worth looking here... fn parse_items( &mut self, items: &mut ir::ItemsBuilder, @@ -805,10 +800,8 @@ impl<'a> Parse<'a> for DataCountSection<'a> { ) -> Result<(), traits::Error> { let range = self.0.range(); let size = (range.end - range.start) as u32; - //dbg!("section", &idx); let id = Id::section(idx); let name = "\"data count\" section"; - //dbg!("YEAH", &id); items.add_root(ir::Item::new(id, name, size, ir::Misc::new())); Ok(()) } diff --git a/twiggy/tests/all/fixtures/threads_test.wasm b/twiggy/tests/all/fixtures/threads_test.wasm new file mode 100644 index 0000000000000000000000000000000000000000..1bd3ae2f4e08015981d069995d65f232e84762a0 GIT binary patch literal 616 zcmZwDu};G<5C-5o$99^y&;>CdhM;ypNM!)jg{208gapq(BGj~oHm#a;piSy7Oh~*3 zPr^$v;8sG2Q%}0HKL5VOkmMr-0Brd&ppDT&j7!&*>k{Ict;({j78a`*fEnIMXY;wq z`t5u+nT)4}KOFbl=KKtBd(yc8wlzuJj<-E=JKPf-P)N>k;!cjPSkbT^)!%+FBUN}hd!9#B}p1uN?=`4GC?10=GBw7F7j7)KtnZhJPGw)5o z4}1g-3S}KJ{9^o_AzJ-*as&}*QAF^pp$(A#Hxe^qkC+n+VoB^1*N6k+kXRAdiFb&1 wi5nZMePG?DxZ&M~Y6^`nEup>xPzS%)k@yQ(6$zyz=+M1V;pSKQp_g3#0Ms9PdjJ3c literal 0 HcmV?d00001 diff --git a/twiggy/tests/all/fixtures/threads_working.wasm b/twiggy/tests/all/fixtures/threads_working.wasm new file mode 100644 index 0000000000000000000000000000000000000000..1bd3ae2f4e08015981d069995d65f232e84762a0 GIT binary patch literal 616 zcmZwDu};G<5C-5o$99^y&;>CdhM;ypNM!)jg{208gapq(BGj~oHm#a;piSy7Oh~*3 zPr^$v;8sG2Q%}0HKL5VOkmMr-0Brd&ppDT&j7!&*>k{Ict;({j78a`*fEnIMXY;wq z`t5u+nT)4}KOFbl=KKtBd(yc8wlzuJj<-E=JKPf-P)N>k;!cjPSkbT^)!%+FBUN}hd!9#B}p1uN?=`4GC?10=GBw7F7j7)KtnZhJPGw)5o z4}1g-3S}KJ{9^o_AzJ-*as&}*QAF^pp$(A#Hxe^qkC+n+VoB^1*N6k+kXRAdiFb&1 wi5nZMePG?DxZ&M~Y6^`nEup>xPzS%)k@yQ(6$zyz=+M1V;pSKQp_g3#0Ms9PdjJ3c literal 0 HcmV?d00001 diff --git a/twiggy/tests/all/top_tests.rs b/twiggy/tests/all/top_tests.rs index c53d3b57..3781710a 100644 --- a/twiggy/tests/all/top_tests.rs +++ b/twiggy/tests/all/top_tests.rs @@ -68,15 +68,6 @@ test!( "csv" ); -// Threaded modules should not cause a panic. -test!( - top_threaded_module, - "top", - "-n", - "25", - "./fixtures/threads.wasm" -); - // This should not fail to open and write `whatever-output.txt`. test!( output_to_file, @@ -88,3 +79,44 @@ test!( // Regression test for https://github.com/rustwasm/twiggy/issues/151 test!(top_mono, "top", "./fixtures/mono.wasm", "-n", "10"); + +// // Threaded modules should not cause a panic. +// test!( +// top_threaded_module, +// "top", +// "-n", +// "25", +// "./fixtures/threads.wasm" +// ); + +// DEV KTM: TEMPORARY WHILE REDUCING BINARY +#[test] +fn top_threaded_module() { + use std::process::Command; + + let output = Command::new("cargo") + .arg("run") + .arg("--") + .arg("top") + .arg("-n") + .arg("25") + .arg("./fixtures/threads_test.wasm") + .current_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/all/")) + .output() + .unwrap(); + + assert_eq!(output.status.code(), Some(101),); + // assert!(output.status.success()); + + let stderr = String::from_utf8_lossy(&output.stderr); + + let is_error_about_data_count_header = stderr + .lines() + .any(|l| l.contains("data count section headers")); + let contains_correct_panic = stderr.lines().any(|l| l.contains("ir.rs:61:13")); + assert!( + contains_correct_panic && is_error_about_data_count_header, + "incorrect panic!:\n{}", + stderr + ); +} From 82b75bc7b8294d79e5baf8ac32521efcffb88ed6 Mon Sep 17 00:00:00 2001 From: Katelyn Martin Date: Sun, 21 Jun 2020 22:14:50 -0400 Subject: [PATCH 4/6] minified! --- twiggy/tests/all/fixtures/threads.wasm | Bin 616 -> 44 bytes twiggy/tests/all/fixtures/threads.wat | 298 +------------------------ 2 files changed, 2 insertions(+), 296 deletions(-) diff --git a/twiggy/tests/all/fixtures/threads.wasm b/twiggy/tests/all/fixtures/threads.wasm index 1bd3ae2f4e08015981d069995d65f232e84762a0..dbc758347ce8be27b1ea9b709234d21beb26225f 100644 GIT binary patch literal 44 wcmWN;!4ZHU3;@A94Kfm%vJ)wQm+kw2UB)*B3|}}8DdE<&RSW-3<|Plw0#wigPXGV_ literal 616 zcmZwDu};G<5C-5o$99^y&;>CdhM;ypNM!)jg{208gapq(BGj~oHm#a;piSy7Oh~*3 zPr^$v;8sG2Q%}0HKL5VOkmMr-0Brd&ppDT&j7!&*>k{Ict;({j78a`*fEnIMXY;wq z`t5u+nT)4}KOFbl=KKtBd(yc8wlzuJj<-E=JKPf-P)N>k;!cjPSkbT^)!%+FBUN}hd!9#B}p1uN?=`4GC?10=GBw7F7j7)KtnZhJPGw)5o z4}1g-3S}KJ{9^o_AzJ-*as&}*QAF^pp$(A#Hxe^qkC+n+VoB^1*N6k+kXRAdiFb&1 wi5nZMePG?DxZ&M~Y6^`nEup>xPzS%)k@yQ(6$zyz=+M1V;pSKQp_g3#0Ms9PdjJ3c diff --git a/twiggy/tests/all/fixtures/threads.wat b/twiggy/tests/all/fixtures/threads.wat index 6be45994..34667d10 100644 --- a/twiggy/tests/all/fixtures/threads.wat +++ b/twiggy/tests/all/fixtures/threads.wat @@ -1,299 +1,5 @@ (module - (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$vj (func (param i64))) - (type $FUNCSIG$vf (func (param f32))) - (type $FUNCSIG$vd (func (param f64))) - (type $FUNCSIG$fifdddfVi (func (param i32 f32 f64 f64 f64 f32 v128 i32) (result f32))) - (import "fuzzing-support" "log-i32" (func $log-i32 (param i32))) - (import "fuzzing-support" "log-i64" (func $log-i64 (param i64))) - (import "fuzzing-support" "log-f32" (func $log-f32 (param f32))) - (import "fuzzing-support" "log-f64" (func $log-f64 (param f64))) (memory $0 1 1) - (data (i32.const 0) "\1c\03a;") - (table $0 1 funcref) - (elem (i32.const 0) $func_6) - (global $global$0 (mut i32) (i32.const 2)) - (global $global$1 (mut i32) (i32.const -268435456)) - (global $global$2 (mut i64) (i64.const 1024)) - (global $global$3 (mut i64) (i64.const -87)) - (global $global$4 (mut f32) (f32.const 18231)) - (global $hangLimit (mut i32) (i32.const 10)) - (export "hashMemory" (func $hashMemory)) - (export "func_6" (func $func_6)) - (export "hangLimitInitializer" (func $hangLimitInitializer)) - (func $hashMemory (; 4 ;) (type $FUNCSIG$i) (result i32) - (local $0 i32) - (local.set $0 - (i32.const 5381) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=1 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=2 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=3 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=4 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=5 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=6 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=7 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=8 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=9 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=10 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=11 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=12 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=13 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=14 - (i32.const 0) - ) - ) - ) - (local.set $0 - (i32.xor - (i32.add - (i32.shl - (local.get $0) - (i32.const 5) - ) - (local.get $0) - ) - (i32.load8_u offset=15 - (i32.const 0) - ) - ) - ) - (local.get $0) - ) - (func $func_5 (; 5 ;) (param $0 i32) - (block - (if - (i32.eqz - (global.get $hangLimit) - ) - (return) - ) - (global.set $hangLimit - (i32.sub - (global.get $hangLimit) - (i32.const 1) - ) - ) - ) - (data.drop 0) - ) - (func $func_6 (; 6 ;) (type $FUNCSIG$fifdddfVi) (param $0 i32) (param $1 f32) (param $2 f64) (param $3 f64) (param $4 f64) (param $5 f32) (param $6 v128) (param $7 i32) (result f32) - (block - (if - (i32.eqz - (global.get $hangLimit) - ) - (return - (local.get $5) - ) - ) - (global.set $hangLimit - (i32.sub - (global.get $hangLimit) - (i32.const 1) - ) - ) - ) - (block $label$0 (result f32) - (local.get $5) - ) - ) - (func $hangLimitInitializer (; 7 ;) - (global.set $hangLimit - (i32.const 10) - ) - ) + (data (i32.const 0) "") + (func $f (data.drop 0)) ) From e53824224d25d713080a53db283a83e69c87c581 Mon Sep 17 00:00:00 2001 From: Katelyn Martin Date: Sun, 21 Jun 2020 23:08:48 -0400 Subject: [PATCH 5/6] it seems to, kinda work --- ir/ir.rs | 23 ++++----- .../all/expectations/top_threaded_module | 13 +++++ twiggy/tests/all/fixtures/threads.wat | 1 + twiggy/tests/all/top_tests.rs | 48 ++++--------------- 4 files changed, 32 insertions(+), 53 deletions(-) diff --git a/ir/ir.rs b/ir/ir.rs index 70cb60e2..bd23a03f 100644 --- a/ir/ir.rs +++ b/ir/ir.rs @@ -45,22 +45,19 @@ impl ItemsBuilder { /// Add the given item to to the graph and return the `Id` that it was /// assigned. pub fn add_item(&mut self, item: Item) -> Id { - // --- --- 8< --- --- - let dbg_clone = item.clone(); - // --- --- 8< --- --- - let id = item.id; - self.size_added += item.size; - self.items.insert(id, item); - - let old_value = self.parsed.insert(id); + let size = item.size; - // --- --- 8< --- --- - if !old_value { - dbg!(dbg_clone); - panic!("value with id {:?} parsed into multiple items!", id); + match self.items.get_mut(&id) { + None => { + self.size_added += size; + self.items.insert(id, item); + self.parsed.insert(id); + } + Some(prev) => { + prev.size += size; + } } - // --- --- 8< --- --- id } diff --git a/twiggy/tests/all/expectations/top_threaded_module b/twiggy/tests/all/expectations/top_threaded_module index e69de29b..3f566e60 100644 --- a/twiggy/tests/all/expectations/top_threaded_module +++ b/twiggy/tests/all/expectations/top_threaded_module @@ -0,0 +1,13 @@ + Shallow Bytes │ Shallow % │ Item +───────────────┼───────────┼─────────────────────── + 8 ┊ 18.18% ┊ wasm magic bytes + 7 ┊ 15.91% ┊ code[0] + 6 ┊ 13.64% ┊ code section headers + 5 ┊ 11.36% ┊ data[0] + 3 ┊ 6.82% ┊ type[0]: () -> nil + 3 ┊ 6.82% ┊ type section headers + 3 ┊ 6.82% ┊ memory[0] + 3 ┊ 6.82% ┊ memory section headers + 3 ┊ 6.82% ┊ "data count" section + 3 ┊ 6.82% ┊ data section headers + 44 ┊ 100.00% ┊ Σ [10 Total Rows] diff --git a/twiggy/tests/all/fixtures/threads.wat b/twiggy/tests/all/fixtures/threads.wat index 34667d10..fa5d5903 100644 --- a/twiggy/tests/all/fixtures/threads.wat +++ b/twiggy/tests/all/fixtures/threads.wat @@ -1,3 +1,4 @@ +;; Built with `wat2wasm --enable-bulk-memory --enable-threads` (module (memory $0 1 1) (data (i32.const 0) "") diff --git a/twiggy/tests/all/top_tests.rs b/twiggy/tests/all/top_tests.rs index 3781710a..f32c4eb8 100644 --- a/twiggy/tests/all/top_tests.rs +++ b/twiggy/tests/all/top_tests.rs @@ -80,43 +80,11 @@ test!( // Regression test for https://github.com/rustwasm/twiggy/issues/151 test!(top_mono, "top", "./fixtures/mono.wasm", "-n", "10"); -// // Threaded modules should not cause a panic. -// test!( -// top_threaded_module, -// "top", -// "-n", -// "25", -// "./fixtures/threads.wasm" -// ); - -// DEV KTM: TEMPORARY WHILE REDUCING BINARY -#[test] -fn top_threaded_module() { - use std::process::Command; - - let output = Command::new("cargo") - .arg("run") - .arg("--") - .arg("top") - .arg("-n") - .arg("25") - .arg("./fixtures/threads_test.wasm") - .current_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/all/")) - .output() - .unwrap(); - - assert_eq!(output.status.code(), Some(101),); - // assert!(output.status.success()); - - let stderr = String::from_utf8_lossy(&output.stderr); - - let is_error_about_data_count_header = stderr - .lines() - .any(|l| l.contains("data count section headers")); - let contains_correct_panic = stderr.lines().any(|l| l.contains("ir.rs:61:13")); - assert!( - contains_correct_panic && is_error_about_data_count_header, - "incorrect panic!:\n{}", - stderr - ); -} +// Threaded modules should not cause a panic. +test!( + top_threaded_module, + "top", + "-n", + "25", + "./fixtures/threads.wasm" +); From b426267ab26756c46e5fcc28a091d8c38bdf20b2 Mon Sep 17 00:00:00 2001 From: Katelyn Martin Date: Mon, 22 Jun 2020 10:45:24 -0400 Subject: [PATCH 6/6] add notes file --- notes.txt | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 notes.txt diff --git a/notes.txt b/notes.txt new file mode 100644 index 00000000..18443b41 --- /dev/null +++ b/notes.txt @@ -0,0 +1,74 @@ +``` +;; `threads.wat` fixture +;; +;; Built with `wat2wasm --enable-bulk-memory --enable-threads` +(module + (memory $0 1 1) + (data (i32.const 0) "") + (func $f (data.drop 0)) +) +``` + +``` +; wasm-objdump --headers twiggy/tests/all/fixtures/threads.wasm + +threads.wasm: file format wasm 0x1 + +Sections: + + Type start=0x0000000a end=0x0000000e (size=0x00000004) count: 1 + Function start=0x00000010 end=0x00000012 (size=0x00000002) count: 1 + Memory start=0x00000014 end=0x00000018 (size=0x00000004) count: 1 +DataCount start=0x0000001a end=0x0000001b (size=0x00000001) count: 1 + Code start=0x0000001d end=0x00000024 (size=0x00000007) count: 1 + Data start=0x00000026 end=0x0000002c (size=0x00000006) count: 1 +``` + +``` +; wasm-objdump --full-contents twiggy/tests/all/fixtures/threads.wasm + +threads.wasm: file format wasm 0x1 + +Contents of section Type: +000000a: 0160 0000 .`.. + +Contents of section Function: +0000010: 0100 .. + +Contents of section Memory: +0000014: 0101 0101 .... + +Contents of section DataCount: +000001a: 01 . + +Contents of section Code: +000001d: 0105 00fc 0900 0b ....... + +Contents of section Data: +0000026: 0100 4100 0b00 ..A... +``` + +``` +; target/debug/twiggy top twiggy/tests/all/fixtures/threads.wasm + + Shallow Bytes │ Shallow % │ Item +───────────────┼───────────┼─────────────────────── + 8 ┊ 18.18% ┊ wasm magic bytes + 7 ┊ 15.91% ┊ code[0] + 6 ┊ 13.64% ┊ code section headers + 5 ┊ 11.36% ┊ data[0] + 3 ┊ 6.82% ┊ type[0]: () -> nil + 3 ┊ 6.82% ┊ type section headers + 3 ┊ 6.82% ┊ memory[0] + 3 ┊ 6.82% ┊ memory section headers + 3 ┊ 6.82% ┊ "data count" section + 3 ┊ 6.82% ┊ data section headers + 44 ┊ 100.00% ┊ Σ [10 Total Rows] +``` + +``` +; exa -l --header twiggy/tests/all/fixtures/threads.wasm + +Permissions Size User Date Modified Name +.rw-rw-r-- 44 katelyn 21 Jun 23:07 twiggy/tests/all/fixtures/threads.wasm +```