Skip to content

Support --trap-mode argument in s2wasm #5620

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
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
8 changes: 2 additions & 6 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2229,12 +2229,8 @@ def do_binaryen(final, target, asm_target, options, memfile, wasm_binary_target,
# save the asm.js input
shared.safe_copy(asm_target, os.path.join(shared.get_emscripten_temp_dir(), os.path.basename(asm_target)))
cmd = [os.path.join(binaryen_bin, 'asm2wasm'), asm_target, '--total-memory=' + str(shared.Settings.TOTAL_MEMORY)]
if shared.Settings.BINARYEN_TRAP_MODE == 'js':
cmd += ['--emit-jsified-potential-traps']
elif shared.Settings.BINARYEN_TRAP_MODE == 'clamp':
cmd += ['--emit-clamped-potential-traps']
elif shared.Settings.BINARYEN_TRAP_MODE == 'allow':
cmd += ['--emit-potential-traps']
if shared.Settings.BINARYEN_TRAP_MODE in ('js', 'clamp', 'allow'):
cmd += ['--trap-mode=' + shared.Settings.BINARYEN_TRAP_MODE]
else:
logging.error('invalid BINARYEN_TRAP_MODE value: ' + shared.Settings.BINARYEN_TRAP_MODE + ' (should be js/clamp/allow)')
sys.exit(1)
Expand Down
3 changes: 3 additions & 0 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,9 @@ def wrapped():
args += ['--allow-memory-growth'] if shared.Settings.ALLOW_MEMORY_GROWTH else []
args += ['-l', libc_rt_lib]
args += ['-l', compiler_rt_lib]

if shared.Settings.BINARYEN_TRAP_MODE:
args += ['--trap-mode=' + shared.Settings.BINARYEN_TRAP_MODE]
return args


Expand Down
4 changes: 3 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7368,13 +7368,15 @@ def test_binaryen(self):
self.emcc_args += ['-s', 'BINARYEN=1', '-s', 'BINARYEN_METHOD="interpret-binary"']
self.do_run(open(path_from_root('tests', 'hello_world.c')).read(), 'hello, world!')

@no_wasm_backend("trap mode support")
def test_binaryen_trap_mode(self):
if not self.is_wasm(): return self.skip('wasm test')
TRAP_OUTPUTS = ('trap', 'RuntimeError')
default = Settings.BINARYEN_TRAP_MODE
print 'default is', default
for mode in ['js', 'clamp', 'allow', '']:
if mode == 'js' and self.is_wasm_backend():
# wasm backend does not use asm2wasm imports, which js trap mode requires
continue
print 'mode:', mode
Settings.BINARYEN_TRAP_MODE = mode or default
if not mode: mode = default
Expand Down
2 changes: 1 addition & 1 deletion tools/ports/binaryen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, shutil, logging

TAG = 'version_37'
TAG = 'version_38'

def needed(settings, shared, ports):
if not settings.BINARYEN: return False
Expand Down