From 24c7157c58b95900be7def1e94ea86fe93f08c3d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 19 Dec 2019 10:20:33 -0800 Subject: [PATCH 01/16] EXPORT_ALL for MAIN_MODULES in the wasm backend. fixes #9793 --- emcc.py | 7 +++++++ tests/test_other.py | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/emcc.py b/emcc.py index 8da9c9fb87f69..eeded54b239cc 100755 --- a/emcc.py +++ b/emcc.py @@ -1153,6 +1153,13 @@ def check(input_file): assert not shared.Settings.SIDE_MODULE if shared.Settings.MAIN_MODULE != 2: shared.Settings.INCLUDE_FULL_LIBRARY = 1 + # fastcomp adds all the JS library to the asmLibraryArg object which is + # provided as "env" to wasm modules, which lets them access those methods. + # in the wasm backend we use a more straightforward method of flipping + # the EXPORT_ALL flag, which provides those methods on Module, which is + # used to look up imports as necessary. + if shared.Settings.WASM_BACKEND: + shared.Settings.EXPORT_ALL = 1 elif shared.Settings.SIDE_MODULE: assert not shared.Settings.MAIN_MODULE options.memory_init_file = False # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) diff --git a/tests/test_other.py b/tests/test_other.py index efba3f4407697..6b9484bade74d 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -6631,6 +6631,8 @@ def test_dlopen_rtld_global(self): 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. + # This happens to also check that main modules have EXPORT_ALL enabled, + # in order to make their JS library code available to side modules. create_test_file('side.cpp', r''' #include #include @@ -6668,7 +6670,7 @@ def test_main_module_without_exceptions_message(self): 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', + run_process([PYTHON, EMCC, 'main.cpp', '-s', 'MAIN_MODULE=1', '--embed-file', 'libside.wasm'] + args) build_main([]) From 7132b9fb43a7d2f4e8d21c938104fdf8c7ef391b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 19 Dec 2019 11:01:44 -0800 Subject: [PATCH 02/16] Fixes. also fixes metadce here, turns out --- tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports | 4 ++++ tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports | 1 + tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent | 1 + tests/test_other.py | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports index e6487907aa0c3..bd9925f1fae21 100644 --- a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports +++ b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports @@ -1,7 +1,11 @@ __assign_got_enties __errno_location +__growWasmMemory __stdio_write __wasm_call_ctors +dynCall_ii +dynCall_jiji +free main malloc setThrew diff --git a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports index 4c11a9d043951..ad3c147cb8336 100644 --- a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports +++ b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports @@ -9,4 +9,5 @@ g$__THREW__ g$__threwValue g$stdout memory +setTempRet0 table diff --git a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent index 4c11a9d043951..ad3c147cb8336 100644 --- a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent +++ b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent @@ -9,4 +9,5 @@ g$__THREW__ g$__threwValue g$stdout memory +setTempRet0 table diff --git a/tests/test_other.py b/tests/test_other.py index 6d5dd6945639d..c9026c69a111e 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -8221,7 +8221,7 @@ def test_metadce_cxx_fastcomp(self, *args): # don't compare the # of functions in a main module, which changes a lot # TODO(sbc): Investivate why the number of exports is order of magnitude # larger for wasm backend. - 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 12, [], [], 10770, 12, 10, None), # noqa + 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 12648, 13, 14, None), # noqa }) @no_fastcomp() def test_metadce_hello(self, *args): From f4ed6e3c326430d79795d0f4c3eb291d5a818af0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 20 Dec 2019 15:45:31 -0800 Subject: [PATCH 03/16] wip yolo --- emcc.py | 8 +------- src/settings.js | 9 ++++++--- tests/test_core.py | 5 ----- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/emcc.py b/emcc.py index cee2ddc54c744..390d4398a17d7 100755 --- a/emcc.py +++ b/emcc.py @@ -1151,14 +1151,8 @@ def check(input_file): if shared.Settings.MAIN_MODULE: assert not shared.Settings.SIDE_MODULE - if shared.Settings.MAIN_MODULE != 2: + if shared.Settings.MAIN_MODULE == 1: shared.Settings.INCLUDE_FULL_LIBRARY = 1 - # fastcomp adds all the JS library to the asmLibraryArg object which is - # provided as "env" to wasm modules, which lets them access those methods. - # in the wasm backend we use a more straightforward method of flipping - # the EXPORT_ALL flag, which provides those methods on Module, which is - # used to look up imports as necessary. - if shared.Settings.WASM_BACKEND: shared.Settings.EXPORT_ALL = 1 elif shared.Settings.SIDE_MODULE: assert not shared.Settings.MAIN_MODULE diff --git a/src/settings.js b/src/settings.js index 939d9f23de8c3..19f0223296049 100644 --- a/src/settings.js +++ b/src/settings.js @@ -766,9 +766,12 @@ var NODE_CODE_CACHING = 0; // there, you are in effect removing it). var EXPORTED_FUNCTIONS = ['_main']; -// If true, we export all the symbols. Note that this does *not* affect LLVM, so -// it can still eliminate functions as dead. This just exports them on the -// Module object. +// If true, we export all the symbols that are present in JS onto the Module +// object. This does not affect which symbols will be present - it does not +// prevent DCE or cause anything to be included in linking. It only does +// Module['X'] = X; +// for all X that end up in the JS file. This is useful to export the JS +// library functions on Module, for things like dynamic linking. var EXPORT_ALL = 0; // Export all bindings generator functions (prefixed with emscripten_bind_). This diff --git a/tests/test_core.py b/tests/test_core.py index 9d44f7754ea72..da4584693c5e4 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2546,12 +2546,10 @@ def test_nestedstructs(self): def prep_dlfcn_lib(self): self.clear_setting('MAIN_MODULE') self.set_setting('SIDE_MODULE') - self.set_setting('EXPORT_ALL') def prep_dlfcn_main(self): self.set_setting('MAIN_MODULE') self.clear_setting('SIDE_MODULE') - self.set_setting('EXPORT_ALL') create_test_file('lib_so_pre.js', ''' if (!Module['preRun']) Module['preRun'] = []; @@ -3557,9 +3555,6 @@ def test_dlfcn_feature_in_lib(self, js_engines): self.do_run(src, 'float: 42.\n', js_engines=js_engines) def dylink_test(self, main, side, expected=None, header=None, main_emcc_args=[], force_c=False, need_reverse=True, auto_load=True, **kwargs): - # shared settings - self.set_setting('EXPORT_ALL', 1) - if header: create_test_file('header.h', header) From 94c4bc46ed9bac8a1311fdd28d0c0b1901e30a96 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 20 Dec 2019 16:37:00 -0800 Subject: [PATCH 04/16] fastcomp side modules need EXPORT_ALL --- emcc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/emcc.py b/emcc.py index 390d4398a17d7..c66682dfe4e33 100755 --- a/emcc.py +++ b/emcc.py @@ -1157,6 +1157,8 @@ def check(input_file): elif shared.Settings.SIDE_MODULE: assert not shared.Settings.MAIN_MODULE options.memory_init_file = False # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) + if not shared.Settings.WASM_BACKEND: + shared.Settings.EXPORT_ALL = 1 if shared.Settings.MAIN_MODULE or shared.Settings.SIDE_MODULE: assert shared.Settings.ASM_JS, 'module linking requires asm.js output (-s ASM_JS=1)' From 618de0156e5d1943c5916c59f85393bb91c63bdf Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 20 Dec 2019 16:39:28 -0800 Subject: [PATCH 05/16] update tests --- ...lo_world_fastcomp_O3_MAIN_MODULE_2.exports | 18 ++++++------- ...ello_world_fastcomp_O3_MAIN_MODULE_2.funcs | 1 + ...lo_world_fastcomp_O3_MAIN_MODULE_2.imports | 26 +++++++++---------- ...hello_world_fastcomp_O3_MAIN_MODULE_2.sent | 26 +++++++++---------- tests/test_other.py | 2 +- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.exports b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.exports index bd29f14588483..04da04db32933 100644 --- a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.exports +++ b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.exports @@ -1,9 +1,9 @@ -___errno_location -__apply_relocations -_main -_malloc -dynCall_X -dynCall_ii -dynCall_iiii -dynCall_iiiii -stackAlloc +___errno_location +__apply_relocations +_main +_malloc +dynCall_X +dynCall_ii +dynCall_iiii +dynCall_iiiii +stackAlloc diff --git a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs index c83a4f6d53f04..30bb2ba87aed2 100644 --- a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs +++ b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs @@ -6,6 +6,7 @@ $___overflow $___stdio_write $___towrite $__apply_relocations +$_fwrite $_main $_malloc $_memcpy diff --git a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.imports b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.imports index 5dbce77d5c11b..75fe6722988e0 100644 --- a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.imports +++ b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.imports @@ -1,13 +1,13 @@ -STACKTOP -___wasi_fd_write -__memory_base -__table_base -_emscripten_get_heap_size -_emscripten_memcpy_big -_emscripten_resize_heap -abort -fb -gb -memory -setTempRet0 -table +STACKTOP +___wasi_fd_write +__memory_base +__table_base +_emscripten_get_heap_size +_emscripten_memcpy_big +_emscripten_resize_heap +abort +fb +gb +memory +setTempRet0 +table diff --git a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.sent b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.sent index 5dbce77d5c11b..75fe6722988e0 100644 --- a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.sent +++ b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.sent @@ -1,13 +1,13 @@ -STACKTOP -___wasi_fd_write -__memory_base -__table_base -_emscripten_get_heap_size -_emscripten_memcpy_big -_emscripten_resize_heap -abort -fb -gb -memory -setTempRet0 -table +STACKTOP +___wasi_fd_write +__memory_base +__table_base +_emscripten_get_heap_size +_emscripten_memcpy_big +_emscripten_resize_heap +abort +fb +gb +memory +setTempRet0 +table diff --git a/tests/test_other.py b/tests/test_other.py index c9026c69a111e..5e7eb81ca849b 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -8240,7 +8240,7 @@ def test_metadce_hello(self, *args): 4, [], [], 8, 0, 0, 0), # noqa; totally empty! # we don't metadce with linkable code! other modules may want stuff # don't compare the # of functions in a main module, which changes a lot - 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 10017, 13, 9, 20), # noqa + 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 10017, 13, 9, 21), # noqa }) @no_wasm_backend() def test_metadce_hello_fastcomp(self, *args): From 10500e551a1e90bbd0260de89a773b26ed4f25ae Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 20 Dec 2019 16:40:55 -0800 Subject: [PATCH 06/16] update tests --- tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports | 4 ---- tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports | 1 - tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent | 1 - tests/test_other.py | 2 +- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports index bd9925f1fae21..e6487907aa0c3 100644 --- a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports +++ b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.exports @@ -1,11 +1,7 @@ __assign_got_enties __errno_location -__growWasmMemory __stdio_write __wasm_call_ctors -dynCall_ii -dynCall_jiji -free main malloc setThrew diff --git a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports index ad3c147cb8336..4c11a9d043951 100644 --- a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports +++ b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.imports @@ -9,5 +9,4 @@ g$__THREW__ g$__threwValue g$stdout memory -setTempRet0 table diff --git a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent index ad3c147cb8336..4c11a9d043951 100644 --- a/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent +++ b/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.sent @@ -9,5 +9,4 @@ g$__THREW__ g$__threwValue g$stdout memory -setTempRet0 table diff --git a/tests/test_other.py b/tests/test_other.py index 5e7eb81ca849b..0d5c29eba4aac 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -8221,7 +8221,7 @@ def test_metadce_cxx_fastcomp(self, *args): # don't compare the # of functions in a main module, which changes a lot # TODO(sbc): Investivate why the number of exports is order of magnitude # larger for wasm backend. - 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 12648, 13, 14, None), # noqa + 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 12, [], [], 10652, 12, 10, None), # noqa }) @no_fastcomp() def test_metadce_hello(self, *args): From 97b0f5afb4b6d5e65d16ed8fe2e3547b039cf758 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 20 Dec 2019 16:41:57 -0800 Subject: [PATCH 07/16] comment fix --- tests/test_other.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_other.py b/tests/test_other.py index 0d5c29eba4aac..91468c1fe90ff 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -6629,8 +6629,6 @@ def test_dlopen_rtld_global(self): 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. - # This happens to also check that main modules have EXPORT_ALL enabled, - # in order to make their JS library code available to side modules. create_test_file('side.cpp', r''' #include #include From 7e398fffd610c9ee2eb079a7ed266b43e6f5bbbe Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 20 Dec 2019 17:19:19 -0800 Subject: [PATCH 08/16] update tests --- tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs | 1 - tests/test_other.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs index 30bb2ba87aed2..c83a4f6d53f04 100644 --- a/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs +++ b/tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.funcs @@ -6,7 +6,6 @@ $___overflow $___stdio_write $___towrite $__apply_relocations -$_fwrite $_main $_malloc $_memcpy diff --git a/tests/test_other.py b/tests/test_other.py index 91468c1fe90ff..4d73543274782 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -8238,7 +8238,7 @@ def test_metadce_hello(self, *args): 4, [], [], 8, 0, 0, 0), # noqa; totally empty! # we don't metadce with linkable code! other modules may want stuff # don't compare the # of functions in a main module, which changes a lot - 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 10017, 13, 9, 21), # noqa + 'main_module_2': (['-O3', '-s', 'MAIN_MODULE=2'], 13, [], [], 10017, 13, 9, 20), # noqa }) @no_wasm_backend() def test_metadce_hello_fastcomp(self, *args): From 637e25ebd5cf41db302ef1e643fe05b3f76ff789 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 6 Jan 2020 15:16:11 -0800 Subject: [PATCH 09/16] try --- emcc.py | 3 --- emscripten.py | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/emcc.py b/emcc.py index be0462f4fe4ba..9dec4dafb39c2 100755 --- a/emcc.py +++ b/emcc.py @@ -1153,12 +1153,9 @@ def check(input_file): assert not shared.Settings.SIDE_MODULE if shared.Settings.MAIN_MODULE == 1: shared.Settings.INCLUDE_FULL_LIBRARY = 1 - shared.Settings.EXPORT_ALL = 1 elif shared.Settings.SIDE_MODULE: assert not shared.Settings.MAIN_MODULE options.memory_init_file = False # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) - if not shared.Settings.WASM_BACKEND: - shared.Settings.EXPORT_ALL = 1 if shared.Settings.MAIN_MODULE or shared.Settings.SIDE_MODULE: assert shared.Settings.ASM_JS, 'module linking requires asm.js output (-s ASM_JS=1)' diff --git a/emscripten.py b/emscripten.py index a287354dcbb8b..f12f3758bc00d 100644 --- a/emscripten.py +++ b/emscripten.py @@ -2609,6 +2609,13 @@ def create_sending_wasm(invoke_funcs, forwarded_json, metadata): declared_items = ['_' + item for item in metadata['declares']] send_items = set(basic_funcs + invoke_funcs + em_asm_funcs + em_js_funcs + declared_items) + if shared.Settings.MAIN_MODULE == 1: + # Main modules must provide all JS library functions to side modules, as they + # may require them (in main module mode 2, the user must specify which + # using the normal EXPORTED_RUNTIME_METHODS method). + js_library_funcs = set(key for key, value in forwarded_json['Functions']['libraryFunctions'].items() if value != 2) + send_items = send_items.union(js_library_funcs) + def fix_import_name(g): if g.startswith('Math_'): return g.split('_')[1] From 460f2476969b889066588a4e14cbcc4014eef215 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 6 Jan 2020 15:19:23 -0800 Subject: [PATCH 10/16] more --- tests/other/metadce/hello_libcxx_O2_fexceptions.imports | 4 ++++ .../hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports | 4 ++++ tests/test_other.py | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/other/metadce/hello_libcxx_O2_fexceptions.imports b/tests/other/metadce/hello_libcxx_O2_fexceptions.imports index 181d2c604c444..caabaad975a02 100644 --- a/tests/other/metadce/hello_libcxx_O2_fexceptions.imports +++ b/tests/other/metadce/hello_libcxx_O2_fexceptions.imports @@ -29,9 +29,12 @@ invoke_ii invoke_iii invoke_iiii invoke_iiiii +invoke_iiiiii invoke_iiiiiii invoke_iiiiiiii +invoke_iiiiiiiiiii invoke_iiiiiiiiiiii +invoke_iiiiiiiiiiiii invoke_jiiii invoke_v invoke_vi @@ -40,6 +43,7 @@ invoke_viii invoke_viiii invoke_viiiiiii invoke_viiiiiiiiii +invoke_viiiiiiiiiiiiiii memory setTempRet0 strftime_l diff --git a/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports b/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports index 181d2c604c444..caabaad975a02 100644 --- a/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports +++ b/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports @@ -29,9 +29,12 @@ invoke_ii invoke_iii invoke_iiii invoke_iiiii +invoke_iiiiii invoke_iiiiiii invoke_iiiiiiii +invoke_iiiiiiiiiii invoke_iiiiiiiiiiii +invoke_iiiiiiiiiiiii invoke_jiiii invoke_v invoke_vi @@ -40,6 +43,7 @@ invoke_viii invoke_viiii invoke_viiiiiii invoke_viiiiiiiiii +invoke_viiiiiiiiiiiiiii memory setTempRet0 strftime_l diff --git a/tests/test_other.py b/tests/test_other.py index c07d7fe4b12ab..97b125ae555f1 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -8184,10 +8184,10 @@ def test_metadce_minimal_fastcomp(self, *args): @parameterized({ 'noexcept': (['-O2'], 19, [], ['waka'], 218988, 17, 33, None), # noqa # exceptions increases code size significantly - 'except': (['-O2', '-fexceptions'], 52, [], ['waka'], 279827, 46, 46, None), # noqa + 'except': (['-O2', '-fexceptions'], 52, [], ['waka'], 279827, 50, 46, None), # noqa # exceptions does not pull in demangling by default, which increases code size 'mangle': (['-O2', '-fexceptions', - '-s', 'DEMANGLE_SUPPORT'], 52, [], ['waka'], 408028, 46, 47, None), # noqa + '-s', 'DEMANGLE_SUPPORT'], 52, [], ['waka'], 408028, 50, 47, None), # noqa }) @no_fastcomp() def test_metadce_cxx(self, *args): From 6b5d0eaa47b8f2c3897e3c4c0c3653bf35cf8159 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 6 Jan 2020 15:28:35 -0800 Subject: [PATCH 11/16] wip --- emcc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/emcc.py b/emcc.py index 9dec4dafb39c2..0c207771fb80b 100755 --- a/emcc.py +++ b/emcc.py @@ -1153,9 +1153,13 @@ def check(input_file): assert not shared.Settings.SIDE_MODULE if shared.Settings.MAIN_MODULE == 1: shared.Settings.INCLUDE_FULL_LIBRARY = 1 + if not shared.Settings.WASM_BACKEND: + shared.Settings.EXPORT_ALL = 1 elif shared.Settings.SIDE_MODULE: assert not shared.Settings.MAIN_MODULE options.memory_init_file = False # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) + if not shared.Settings.WASM_BACKEND: + shared.Settings.EXPORT_ALL = 1 if shared.Settings.MAIN_MODULE or shared.Settings.SIDE_MODULE: assert shared.Settings.ASM_JS, 'module linking requires asm.js output (-s ASM_JS=1)' From 8ea0c49416bee98cb43ec5005acd41fe70844a93 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 6 Jan 2020 15:46:18 -0800 Subject: [PATCH 12/16] fix --- emcc.py | 4 +++- emscripten.py | 7 ------- src/support.js | 5 +++++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/emcc.py b/emcc.py index 0c207771fb80b..76209f9f37716 100755 --- a/emcc.py +++ b/emcc.py @@ -1152,8 +1152,10 @@ def check(input_file): if shared.Settings.MAIN_MODULE: assert not shared.Settings.SIDE_MODULE if shared.Settings.MAIN_MODULE == 1: + # Main modules must provide all JS library functions to side modules, as they + # may require them (in main module mode 2, the user must specify which + # using the normal exporting method). shared.Settings.INCLUDE_FULL_LIBRARY = 1 - if not shared.Settings.WASM_BACKEND: shared.Settings.EXPORT_ALL = 1 elif shared.Settings.SIDE_MODULE: assert not shared.Settings.MAIN_MODULE diff --git a/emscripten.py b/emscripten.py index f12f3758bc00d..a287354dcbb8b 100644 --- a/emscripten.py +++ b/emscripten.py @@ -2609,13 +2609,6 @@ def create_sending_wasm(invoke_funcs, forwarded_json, metadata): declared_items = ['_' + item for item in metadata['declares']] send_items = set(basic_funcs + invoke_funcs + em_asm_funcs + em_js_funcs + declared_items) - if shared.Settings.MAIN_MODULE == 1: - # Main modules must provide all JS library functions to side modules, as they - # may require them (in main module mode 2, the user must specify which - # using the normal EXPORTED_RUNTIME_METHODS method). - js_library_funcs = set(key for key, value in forwarded_json['Functions']['libraryFunctions'].items() if value != 2) - send_items = send_items.union(js_library_funcs) - def fix_import_name(g): if g.startswith('Math_'): return g.split('_')[1] diff --git a/src/support.js b/src/support.js index f7e795b943c49..88526a5c51a95 100644 --- a/src/support.js +++ b/src/support.js @@ -508,6 +508,11 @@ function loadWebAssemblyModule(binary, flags) { return obj[prop] = function() { if (!fp) { var f = resolveSymbol(name, 'function', legalized); +#if ASSERTIONS + // this resolved symbol must exist, as we are about to try to + // add it to the table; error clearly here instead of there. + assert(f, 'could not resolve: ' + name); +#endif fp = addFunction(f, sig); } return fp; From cbd59655029d3439a08013d9de79b274ecde9946 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 6 Jan 2020 15:56:27 -0800 Subject: [PATCH 13/16] better --- emcc.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/emcc.py b/emcc.py index 76209f9f37716..16ccf30bc6f57 100755 --- a/emcc.py +++ b/emcc.py @@ -1159,8 +1159,11 @@ def check(input_file): shared.Settings.EXPORT_ALL = 1 elif shared.Settings.SIDE_MODULE: assert not shared.Settings.MAIN_MODULE - options.memory_init_file = False # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) - if not shared.Settings.WASM_BACKEND: + # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) + options.memory_init_file = False + # fastcomp dynamic linking is a little odd in that EXPORT_ALL matters + # even for side modules. + if not shared.Settings.WASM_BACKEND and shared.Settings.SIDE_MODULE == 1: shared.Settings.EXPORT_ALL = 1 if shared.Settings.MAIN_MODULE or shared.Settings.SIDE_MODULE: From a09b98c8218db62f6725a201eb7433be4ab9aeb7 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 6 Jan 2020 16:51:47 -0800 Subject: [PATCH 14/16] update tests --- tests/other/metadce/hello_libcxx_O2_fexceptions.imports | 4 ---- .../hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports | 4 ---- tests/test_other.py | 4 ++-- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/other/metadce/hello_libcxx_O2_fexceptions.imports b/tests/other/metadce/hello_libcxx_O2_fexceptions.imports index caabaad975a02..181d2c604c444 100644 --- a/tests/other/metadce/hello_libcxx_O2_fexceptions.imports +++ b/tests/other/metadce/hello_libcxx_O2_fexceptions.imports @@ -29,12 +29,9 @@ invoke_ii invoke_iii invoke_iiii invoke_iiiii -invoke_iiiiii invoke_iiiiiii invoke_iiiiiiii -invoke_iiiiiiiiiii invoke_iiiiiiiiiiii -invoke_iiiiiiiiiiiii invoke_jiiii invoke_v invoke_vi @@ -43,7 +40,6 @@ invoke_viii invoke_viiii invoke_viiiiiii invoke_viiiiiiiiii -invoke_viiiiiiiiiiiiiii memory setTempRet0 strftime_l diff --git a/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports b/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports index caabaad975a02..181d2c604c444 100644 --- a/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports +++ b/tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.imports @@ -29,12 +29,9 @@ invoke_ii invoke_iii invoke_iiii invoke_iiiii -invoke_iiiiii invoke_iiiiiii invoke_iiiiiiii -invoke_iiiiiiiiiii invoke_iiiiiiiiiiii -invoke_iiiiiiiiiiiii invoke_jiiii invoke_v invoke_vi @@ -43,7 +40,6 @@ invoke_viii invoke_viiii invoke_viiiiiii invoke_viiiiiiiiii -invoke_viiiiiiiiiiiiiii memory setTempRet0 strftime_l diff --git a/tests/test_other.py b/tests/test_other.py index 97b125ae555f1..c07d7fe4b12ab 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -8184,10 +8184,10 @@ def test_metadce_minimal_fastcomp(self, *args): @parameterized({ 'noexcept': (['-O2'], 19, [], ['waka'], 218988, 17, 33, None), # noqa # exceptions increases code size significantly - 'except': (['-O2', '-fexceptions'], 52, [], ['waka'], 279827, 50, 46, None), # noqa + 'except': (['-O2', '-fexceptions'], 52, [], ['waka'], 279827, 46, 46, None), # noqa # exceptions does not pull in demangling by default, which increases code size 'mangle': (['-O2', '-fexceptions', - '-s', 'DEMANGLE_SUPPORT'], 52, [], ['waka'], 408028, 50, 47, None), # noqa + '-s', 'DEMANGLE_SUPPORT'], 52, [], ['waka'], 408028, 46, 47, None), # noqa }) @no_fastcomp() def test_metadce_cxx(self, *args): From a5bc0811597e35fc18186381ab97c11b4d55593d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 8 Jan 2020 12:16:50 -0800 Subject: [PATCH 15/16] feedback --- src/support.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/support.js b/src/support.js index 88526a5c51a95..f7e795b943c49 100644 --- a/src/support.js +++ b/src/support.js @@ -508,11 +508,6 @@ function loadWebAssemblyModule(binary, flags) { return obj[prop] = function() { if (!fp) { var f = resolveSymbol(name, 'function', legalized); -#if ASSERTIONS - // this resolved symbol must exist, as we are about to try to - // add it to the table; error clearly here instead of there. - assert(f, 'could not resolve: ' + name); -#endif fp = addFunction(f, sig); } return fp; From 7f0c7a5fe7b95f4066940359ec839d964146018c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 8 Jan 2020 12:20:31 -0800 Subject: [PATCH 16/16] fix --- emcc.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/emcc.py b/emcc.py index 7efe589d4c7d1..bf6a6bcad9889 100755 --- a/emcc.py +++ b/emcc.py @@ -1155,24 +1155,17 @@ def check(input_file): if shared.Settings.MAIN_MODULE: assert not shared.Settings.SIDE_MODULE if shared.Settings.MAIN_MODULE == 1: - # Main modules must provide all JS library functions to side modules, as they - # may require them (in main module mode 2, the user must specify which - # using the normal exporting method). shared.Settings.INCLUDE_FULL_LIBRARY = 1 - shared.Settings.EXPORT_ALL = 1 elif shared.Settings.SIDE_MODULE: assert not shared.Settings.MAIN_MODULE # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) options.memory_init_file = False - # fastcomp dynamic linking is a little odd in that EXPORT_ALL matters - # even for side modules. - if not shared.Settings.WASM_BACKEND and shared.Settings.SIDE_MODULE == 1: - shared.Settings.EXPORT_ALL = 1 if shared.Settings.MAIN_MODULE or shared.Settings.SIDE_MODULE: assert shared.Settings.ASM_JS, 'module linking requires asm.js output (-s ASM_JS=1)' - if shared.Settings.MAIN_MODULE != 2 and shared.Settings.SIDE_MODULE != 2: + if shared.Settings.MAIN_MODULE == 1 or shared.Settings.SIDE_MODULE == 1: shared.Settings.LINKABLE = 1 + shared.Settings.EXPORT_ALL = 1 shared.Settings.RELOCATABLE = 1 assert not options.use_closure_compiler, 'cannot use closure compiler on shared modules' # shared modules need memory utilities to allocate their memory