Skip to content

Strip the wasm producers section by default #7967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,9 @@ def check(input_file):
if shared.Settings.GLOBAL_BASE >= 1024: # hardcoded value in the binaryen pass
passes += ['--post-emscripten']
if options.debug_level < 3:
passes += ['--strip']
passes += ['--strip-debug']
if not shared.Settings.EMIT_PRODUCERS_SECTION:
passes += ['--strip-producers']
if passes:
shared.Settings.BINARYEN_PASSES = ','.join(passes)

Expand Down
10 changes: 10 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,16 @@ var BINARYEN_ASYNC_COMPILATION = 1;
// you can set it to override if you are a Binaryen developer.
var BINARYEN_ROOT = "";

// WebAssembly defines a "producers section" which compilers and tools can
// annotate themselves in. Emscripten does not emit this by default, as it
// increases code size, and some users may not want information about their tools
// to be included in their builds for privacy or security reasons, see
// https://github.com/WebAssembly/tool-conventions/issues/93.
// TODO: currently this flag just controls whether we run the binaryen pass
// to strip it out from the wasm (where the LLVM wasm backend may have
// created it)
var EMIT_PRODUCERS_SECTION = 0;

// Whether to legalize the JS FFI interfaces (imports/exports) by wrapping them
// to automatically demote i64 to i32 and promote f32 to f64. This is necessary
// in order to interface with JavaScript, both for asm.js and wasm. For
Expand Down
15 changes: 14 additions & 1 deletion tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7909,7 +7909,7 @@ def test(filename, expectations, size_slack):
(['-Oz'], 5, [], [], 3309, 7, 2, 14), # noqa
# finally, check what happens when we export nothing. wasm should be almost empty
(['-Os', '-s', 'EXPORTED_FUNCTIONS=[]'],
0, [], [], None, 0, 1, 1), # noqa; FIXME: should be almost totally empty! see https://github.com/WebAssembly/binaryen/pull/1875
0, [], [], 61, 0, 1, 1), # noqa
], size_slack) # noqa

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

def test_wasm_producers_section(self):
# no producers section by default
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c')])
with open('a.out.wasm', 'rb') as f:
self.assertNotIn('clang', str(f.read()))
size = os.path.getsize('a.out.wasm')
if self.is_wasm_backend():
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'EMIT_PRODUCERS_SECTION=1'])
with open('a.out.wasm', 'rb') as f:
self.assertIn('clang', str(f.read()))
size_with_section = os.path.getsize('a.out.wasm')
self.assertLess(size, size_with_section)

def test_html_preprocess(self):
test_file = path_from_root('tests', 'module', 'test_stdin.c')
output_file = path_from_root('tests', 'module', 'test_stdin.html')
Expand Down
2 changes: 1 addition & 1 deletion tools/ports/binaryen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os, shutil, logging

TAG = 'version_66'
TAG = 'version_67'

def needed(settings, shared, ports):
if not settings.WASM:
Expand Down