Skip to content

Better message when a side module needs exceptions #9698

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 7 commits into from
Nov 6, 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
10 changes: 6 additions & 4 deletions src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,11 +1320,13 @@ function makeStructuralReturn(values, inAsm) {
}

function makeThrow(what) {
if (ASSERTIONS) {
return 'throw ' + what + (DISABLE_EXCEPTION_CATCHING == 1 ? ' + " - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch."' : '') + ';';
} else {
return 'throw ' + what + ';';
if (ASSERTIONS && DISABLE_EXCEPTION_CATCHING == 1) {
what += ' + " - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch."';
if (MAIN_MODULE) {
what += ' + " (note: in dynamic linking, if a side module wants exceptions, the main module must be built with that support)"';
}
}
return 'throw ' + what + ';';
}

function makeSignOp(value, type, op, force, ignore) {
Expand Down
63 changes: 58 additions & 5 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6497,11 +6497,11 @@ def test_ld_library_path(self):
self.assertContained('Ok', out)

def test_dlopen_rtld_global(self):
# TODO: wasm support. this test checks RTLD_GLOBAL where a module is loaded
# before the module providing a global it needs is. in asm.js we use JS
# to create a redirection function. In wasm we just have wasm, so we
# need to introspect the wasm module. Browsers may add that eventually,
# or we could ship a little library that does it.
# This test checks RTLD_GLOBAL where a module is loaded
# before the module providing a global it needs is. in asm.js we use JS
# to create a redirection function. In wasm we just have wasm, so we
# need to introspect the wasm module. Browsers may add that eventually,
# or we could ship a little library that does it.
create_test_file('hello1.c', r'''
#include <stdio.h>

Expand Down Expand Up @@ -6565,6 +6565,59 @@ def test_dlopen_rtld_global(self):
self.assertContained('hello1_val by hello1:3', out)
self.assertContained('hello1_val by hello2:3', out)

@no_fastcomp()
def test_main_module_without_exceptions_message(self):
# A side module that needs exceptions needs a main module with that
# support enabled; show a clear message in that case.
create_test_file('side.cpp', r'''
#include <exception>
#include <stdio.h>

extern "C" void test_throw() {
try {
throw 42;
} catch(int x) {
printf("catch %d.\n", x);
return;
}
puts("bad location");
}
''')
create_test_file('main.cpp', r'''
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>

typedef void (*voidf)();

int main() {
void* h = dlopen ("libside.wasm", RTLD_NOW|RTLD_GLOBAL);
assert(h);
voidf f = (voidf)dlsym(h, "test_throw");
assert(f);
f();
return 0;
}
''')
run_process([PYTHON, EMCC, '-o', 'libside.wasm', 'side.cpp', '-s', 'SIDE_MODULE=1', '-fexceptions'])

def build_main(args):
print(args)
with env_modify({'EMCC_FORCE_STDLIBS': 'libc++abi'}):
run_process([PYTHON, EMCC, 'main.cpp', '-s', 'MAIN_MODULE=1', '-s', 'EXPORT_ALL',
'--embed-file', 'libside.wasm'] + args)

build_main([])
out = run_js('a.out.js', assert_returncode=None, stderr=STDOUT)
self.assertContained('Exception catching is disabled, this exception cannot be caught.', out)
self.assertContained('note: in dynamic linking, if a side module wants exceptions, the main module must be built with that support', out)

build_main(['-fexceptions'])
out = run_js('a.out.js')
self.assertContained('catch 42', out)

def test_debug_asmLastOpts(self):
create_test_file('src.c', r'''
#include <stdio.h>
Expand Down