Skip to content

Enable EXPORT_ALL in main modules with the wasm backend #10079

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 20 commits into from
Jan 8, 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
8 changes: 5 additions & 3 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

If WASM_BACKEND?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there is no harm to do it in fastcomp too, and it makes the two paths more similar. Also, I'm not sure that there isn't a fastcomp bug that isn't fixed by this, but I didn't investigate. But maybe I'm forgetting something?

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
Expand Down
9 changes: 6 additions & 3 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
26 changes: 13 additions & 13 deletions tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.imports
Original file line number Diff line number Diff line change
@@ -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
26 changes: 13 additions & 13 deletions tests/other/metadce/hello_world_fastcomp_O3_MAIN_MODULE_2.sent
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = [];
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand Down Expand Up @@ -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):
Expand Down