diff --git a/emcc.py b/emcc.py index fb6595ba293f1..bf6a6bcad9889 100755 --- a/emcc.py +++ b/emcc.py @@ -1154,16 +1154,18 @@ 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 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) + # memory init file is not supported with asm.js side modules, must be executable synchronously (for dlopen) + options.memory_init_file = False 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 diff --git a/src/settings.js b/src/settings.js index 731d6fbcbf6e1..0eb7650f6a539 100644 --- a/src/settings.js +++ b/src/settings.js @@ -785,9 +785,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/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.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_core.py b/tests/test_core.py index 7827524b9c93b..17e12c2154eb0 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2555,12 +2555,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'] = []; @@ -3566,9 +3564,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) diff --git a/tests/test_other.py b/tests/test_other.py index 1705d813997b0..19e8424dce464 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -6685,7 +6685,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([]) @@ -8238,7 +8238,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'], 12, [], [], 10652, 12, 10, None), # noqa }) @no_fastcomp() def test_metadce_hello(self, *args):