Skip to content

Commit c288cfa

Browse files
committed
Add EXPORT_KEEPALIVE to export symbols even in MINIMAL_RUNTIME
1 parent 8c2a8a1 commit c288cfa

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

emcc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,8 @@ def phase_linker_setup(options, state, newargs):
19591959
default_setting('SUPPORT_ERRNO', 0)
19601960
# Require explicit -lfoo.js flags to link with JS libraries.
19611961
default_setting('AUTO_JS_LIBRARIES', 0)
1962+
# When using MINIMAL_RUNTIME, symbols should only be exported if requested.
1963+
default_setting('EXPORT_KEEPALIVE', 0)
19621964

19631965
if settings.STRICT_JS and (settings.MODULARIZE or settings.EXPORT_ES6):
19641966
exit_with_error("STRICT_JS doesn't work with MODULARIZE or EXPORT_ES6")

emscripten.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def install_wrapper(sym):
740740
wrapper = '/** @type {function(...*):?} */\nvar %s = ' % mangled
741741

742742
# TODO(sbc): Can we avoid exporting the dynCall_ functions on the module.
743-
if mangled in settings.EXPORTED_FUNCTIONS or name.startswith('dynCall_'):
743+
if name.startswith('dynCall_') or (settings.EXPORT_KEEPALIVE and mangled in settings.EXPORTED_FUNCTIONS):
744744
exported = 'Module["%s"] = ' % mangled
745745
else:
746746
exported = ''
@@ -793,8 +793,9 @@ def create_receiving(exports):
793793
mangled = asmjs_mangle(s)
794794
dynCallAssignment = ('dynCalls["' + s.replace('dynCall_', '') + '"] = ') if generate_dyncall_assignment and mangled.startswith('dynCall_') else ''
795795
export_assignment = ''
796-
if settings.MODULARIZE and settings.EXPORT_ALL:
797-
export_assignment = f'Module["{mangled}"] = '
796+
if settings.MODULARIZE:
797+
if settings.EXPORT_ALL or (settings.EXPORT_KEEPALIVE and mangled in settings.EXPORTED_FUNCTIONS):
798+
export_assignment = f'Module["{mangled}"] = '
798799
receiving += [f'{export_assignment}{dynCallAssignment}{mangled} = asm["{s}"]']
799800
else:
800801
receiving += make_export_wrappers(exports, delay_assignment)

src/settings.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,14 @@ var EXPORTED_FUNCTIONS = [];
994994
// [link]
995995
var EXPORT_ALL = false;
996996

997+
// If true, we export the symbols that are present in JS onto the Module
998+
// object.
999+
// It only does Module['X'] = X;
1000+
//
1001+
// This only applies to MINIMAL_RUNTIME, where symbols aren't exported by
1002+
// default.
1003+
var EXPORT_KEEPALIVE = true;
1004+
9971005
// Remembers the values of these settings, and makes them accessible
9981006
// through getCompilerSetting and emscripten_get_compiler_setting.
9991007
// To see what is retained, look for compilerSettings in the generated code.

0 commit comments

Comments
 (0)