Skip to content

Commit 5f56dba

Browse files
authored
Strip the wasm producers section by default (#7967)
Update binaryen to get the pass. Also use --strip-debug for debug (the old --strip means the same, but is less specific). See WebAssembly/binaryen#1875 This lets us re-enable part of the metadce test (where the producers section was skewing the size of a tiny binary).
1 parent 217ef19 commit 5f56dba

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

emcc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,9 @@ def check(input_file):
13621362
if shared.Settings.GLOBAL_BASE >= 1024: # hardcoded value in the binaryen pass
13631363
passes += ['--post-emscripten']
13641364
if options.debug_level < 3:
1365-
passes += ['--strip']
1365+
passes += ['--strip-debug']
1366+
if not shared.Settings.EMIT_PRODUCERS_SECTION:
1367+
passes += ['--strip-producers']
13661368
if passes:
13671369
shared.Settings.BINARYEN_PASSES = ','.join(passes)
13681370

src/settings.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,16 @@ var BINARYEN_ASYNC_COMPILATION = 1;
10641064
// you can set it to override if you are a Binaryen developer.
10651065
var BINARYEN_ROOT = "";
10661066

1067+
// WebAssembly defines a "producers section" which compilers and tools can
1068+
// annotate themselves in. Emscripten does not emit this by default, as it
1069+
// increases code size, and some users may not want information about their tools
1070+
// to be included in their builds for privacy or security reasons, see
1071+
// https://github.com/WebAssembly/tool-conventions/issues/93.
1072+
// TODO: currently this flag just controls whether we run the binaryen pass
1073+
// to strip it out from the wasm (where the LLVM wasm backend may have
1074+
// created it)
1075+
var EMIT_PRODUCERS_SECTION = 0;
1076+
10671077
// Whether to legalize the JS FFI interfaces (imports/exports) by wrapping them
10681078
// to automatically demote i64 to i32 and promote f32 to f64. This is necessary
10691079
// in order to interface with JavaScript, both for asm.js and wasm. For

tests/test_other.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7909,7 +7909,7 @@ def test(filename, expectations, size_slack):
79097909
(['-Oz'], 5, [], [], 3309, 7, 2, 14), # noqa
79107910
# finally, check what happens when we export nothing. wasm should be almost empty
79117911
(['-Os', '-s', 'EXPORTED_FUNCTIONS=[]'],
7912-
0, [], [], None, 0, 1, 1), # noqa; FIXME: should be almost totally empty! see https://github.com/WebAssembly/binaryen/pull/1875
7912+
0, [], [], 61, 0, 1, 1), # noqa
79137913
], size_slack) # noqa
79147914

79157915
print('test on a minimal pure computational thing')
@@ -8395,6 +8395,19 @@ def test_wasm_sourcemap_dead(self):
83958395
# has only two entries
83968396
self.assertRegexpMatches(output, r'"mappings":\s*"[A-Za-z0-9+/]+,[A-Za-z0-9+/]+"')
83978397

8398+
def test_wasm_producers_section(self):
8399+
# no producers section by default
8400+
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c')])
8401+
with open('a.out.wasm', 'rb') as f:
8402+
self.assertNotIn('clang', str(f.read()))
8403+
size = os.path.getsize('a.out.wasm')
8404+
if self.is_wasm_backend():
8405+
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'EMIT_PRODUCERS_SECTION=1'])
8406+
with open('a.out.wasm', 'rb') as f:
8407+
self.assertIn('clang', str(f.read()))
8408+
size_with_section = os.path.getsize('a.out.wasm')
8409+
self.assertLess(size, size_with_section)
8410+
83988411
def test_html_preprocess(self):
83998412
test_file = path_from_root('tests', 'module', 'test_stdin.c')
84008413
output_file = path_from_root('tests', 'module', 'test_stdin.html')

tools/ports/binaryen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import os, shutil, logging
77

8-
TAG = 'version_66'
8+
TAG = 'version_67'
99

1010
def needed(settings, shared, ports):
1111
if not settings.WASM:

0 commit comments

Comments
 (0)