Skip to content

Don't run binaryen postprocessing for Emscripten EH/SjLj #12399

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 5 commits into from
Oct 11, 2020
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: 0 additions & 4 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ def finalize_wasm(infile, memfile, DEBUG):
# if we don't need to modify the wasm, don't tell finalize to emit a wasm file
modify_wasm = False

# C++ exceptions and longjmp require invoke processing,
# https://github.com/WebAssembly/binaryen/issues/3081
if shared.Settings.SUPPORT_LONGJMP or shared.Settings.DISABLE_EXCEPTION_CATCHING != 1:
modify_wasm = True
if shared.Settings.WASM2JS:
# wasm2js requires full legalization (and will do extra wasm binary
# later processing later anyhow)
Expand Down
1 change: 0 additions & 1 deletion src/deps_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
"longjmp": ["setThrew", "realloc", "testSetjmp", "saveSetjmp"],
"siglongjmp": ["setThrew", "realloc", "testSetjmp", "saveSetjmp"],
"emscripten_longjmp": ["setThrew", "realloc", "testSetjmp", "saveSetjmp"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be sure I understand, now the LLVM backend will never emit emscripten_longjmp_jmpbuf any more, but it does emit emscripten_longjmp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

"emscripten_longjmp_jmpbuf": ["setThrew", "realloc", "testSetjmp", "saveSetjmp"],
"emscripten_websocket_new": ["malloc", "free"],
"emscripten_websocket_set_onmessage_callback_on_thread": ["malloc", "free"],
"emscripten_websocket_set_onclose_callback_on_thread": ["malloc", "free"],
Expand Down
1 change: 0 additions & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,6 @@ LibraryManager.library = {
// they each have a different signature - it is only at the wasm level that
// they become identical).
emscripten_longjmp: 'longjmp',
emscripten_longjmp_jmpbuf: 'longjmp',

// ==========================================================================
// sys/wait.h
Expand Down
10 changes: 2 additions & 8 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9000,9 +9000,8 @@ def ok(args, filename='hello_world.cpp', expected='hello, world!'):
self.run_process([EMCC, path_from_root('tests', filename)] + args)
self.assertContained(expected, self.run_js('a.out.js'))

# -O0 with BigInt support (to avoid the need for legalization) and without
# longjmp
required_flags = ['-sWASM_BIGINT', '-sSUPPORT_LONGJMP=0']
# -O0 with BigInt support (to avoid the need for legalization)
required_flags = ['-sWASM_BIGINT']
ok(required_flags)
# Same with DWARF
ok(required_flags + ['-g'])
Expand All @@ -9021,16 +9020,11 @@ def fail(args, details):

# plain -O0
legalization_message = 'to disable int64 legalization (which requires changes after link) use -s WASM_BIGINT'
longjmp_message = 'to disable longjmp support (which requires changes after link) use -s SUPPORT_LONGJMP=0'
fail([], legalization_message)
fail(['-sWASM_BIGINT'], longjmp_message)
fail(['-sSUPPORT_LONGJMP=0'], legalization_message)
# optimized builds even without legalization
optimization_message = '-O2+ optimizations always require changes, build with -O0 or -O1 instead'
fail(required_flags + ['-O2'], optimization_message)
fail(required_flags + ['-O3'], optimization_message)
# exceptions fails until invokes are fixed
fail(required_flags + ['-fexceptions'], 'C++ exceptions always require changes')

def test_output_to_nowhere(self):
self.run_process([EMCC, path_from_root('tests', 'hello_world.cpp'), '-o', os.devnull, '-c'])
Expand Down
8 changes: 2 additions & 6 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,16 +1574,12 @@ def run_binaryen_command(tool, infile, outfile=None, args=[], debug=False, stdou
# emit some extra helpful text for common issues
extra = ''
# a plain -O0 build *almost* doesn't need post-link changes, except for
# legalization and longjmp. show a clear error for those (as the flags
# the user passed in are not enough to see what went wrong)
# legalization. show a clear error for those (as the flags the user passed
# in are not enough to see what went wrong)
if shared.Settings.LEGALIZE_JS_FFI:
extra += '\nnote: to disable int64 legalization (which requires changes after link) use -s WASM_BIGINT'
if shared.Settings.SUPPORT_LONGJMP:
extra += '\nnote: to disable longjmp support (which requires changes after link) use -s SUPPORT_LONGJMP=0'
if shared.Settings.OPT_LEVEL > 0:
extra += '\nnote: -O2+ optimizations always require changes, build with -O0 or -O1 instead'
if shared.Settings.DISABLE_EXCEPTION_CATCHING != 1:
extra += '\nnote: C++ exceptions always require changes'
exit_with_error('changes to the wasm are required after link, but disallowed by ERROR_ON_WASM_CHANGES_AFTER_LINK: ' + str(cmd) + extra)
if debug:
cmd += ['-g'] # preserve the debug info
Expand Down
4 changes: 0 additions & 4 deletions tools/wasm2c/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ IMPORT_IMPL(void, Z_envZ_emscripten_longjmpZ_vii, (u32 buf, u32 value), {
longjmp(setjmp_stack[next_setjmp - 1], 1);
});

IMPORT_IMPL(void, Z_envZ_emscripten_longjmp_jmpbufZ_vii, (u32 buf, u32 value), {
return Z_envZ_emscripten_longjmpZ_vii(buf, value);
});

IMPORT_IMPL(void, Z_envZ_emscripten_notify_memory_growthZ_vi, (u32 size), {});

static u32 tempRet0 = 0;
Expand Down