From 9d5d9d7d7fe33719d6788315e4eb6645642d3350 Mon Sep 17 00:00:00 2001 From: Andrew Evstyukhin Date: Sat, 25 Sep 2021 09:40:40 +0300 Subject: [PATCH 1/3] Skip all validation when 'no-validation' pass is specified https://github.com/WebAssembly/binaryen/issues/4167 --- tools/building.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/building.py b/tools/building.py index 523f6a3b26186..d903b23f83ba5 100644 --- a/tools/building.py +++ b/tools/building.py @@ -1443,6 +1443,13 @@ def run_binaryen_command(tool, infile, outfile=None, args=[], debug=False, stdou if settings.GENERATE_SOURCE_MAP and outfile: cmd += [f'--input-source-map={infile}.map'] cmd += [f'--output-source-map={outfile}.map'] + # we should skip all validation when 'no-validation' pass is specified + if settings.BINARYEN_EXTRA_PASSES: + # BINARYEN_EXTRA_PASSES is comma-separated + extras = settings.BINARYEN_EXTRA_PASSES.split(',') + # we support both '-'-prefixed and unprefixed pass names + if '--no-validation' in extras or 'no-validation' in extras: + cmd += ['--no-validation'] ret = check_call(cmd, stdout=stdout).stdout if outfile: save_intermediate(outfile, '%s.wasm' % tool) From 5cbd497c98d675895926a4aa7cb43100d1b8d1b9 Mon Sep 17 00:00:00 2001 From: Andrew Evstyukhin Date: Sat, 25 Sep 2021 11:16:45 +0300 Subject: [PATCH 2/3] Add test: tests/runner other.test_binaryen_passes_no_validation --- tests/test_other.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_other.py b/tests/test_other.py index 464645ebb1a59..0b37ba3367c23 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -7028,6 +7028,23 @@ def build(args=[]): # adding --metrics should not affect code size self.assertEqual(base_size, os.path.getsize('a.out.wasm')) + def test_binaryen_passes_no_validation(self): + def build(args=[]): + return self.run_process([EMXX, test_file('hello_world.cpp'), '-O3'] + args, stdout=PIPE).stdout + + with env_modify({'BINARYEN_PASS_DEBUG': '1'}): + out = build() + self.assertContained('(validating)', out) + self.assertContained('(final validation)', out) + base_size = os.path.getsize('a.out.wasm') + + out = build(['-s', 'BINARYEN_EXTRA_PASSES="--no-validation"']) + # (validating) and (final validation) should not appear + self.assertNotContained('(validating)', out) + self.assertNotContained('(final validation)', out) + # adding --no-validation should not affect code size + self.assertEqual(base_size, os.path.getsize('a.out.wasm')) + def assertFileContents(self, filename, contents): contents = contents.replace('\r', '') From 99b9377f34f827a456c2b07b2f445523d802da2a Mon Sep 17 00:00:00 2001 From: Andrew Evstyukhin Date: Sat, 9 Oct 2021 10:03:11 +0300 Subject: [PATCH 3/3] Analyze stderr. Avoid 'wasm-metadce'. --- tests/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_other.py b/tests/test_other.py index 0b37ba3367c23..d2a9c5e29be8b 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -7030,7 +7030,7 @@ def build(args=[]): def test_binaryen_passes_no_validation(self): def build(args=[]): - return self.run_process([EMXX, test_file('hello_world.cpp'), '-O3'] + args, stdout=PIPE).stdout + return self.run_process([EMXX, test_file('hello_world.cpp'), '-O3', '-g3'] + args, stderr=PIPE).stderr with env_modify({'BINARYEN_PASS_DEBUG': '1'}): out = build()