Skip to content

Commit ef5dbde

Browse files
authored
Don't treat internal globals as expected user exports. NFC (#24280)
This change renames `treat_as_user_export` to `is_user_export` and inverts the relationship between this function and `is_internal_global`. Internal globals is a subset of all non-user symbols, not the other way around. This change is split of from a larger ESM integration change I'm working on.
1 parent 862812a commit ef5dbde

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

tools/building.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -750,15 +750,6 @@ def minify_wasm_js(js_file, wasm_file, expensive_optimizations, debug_info):
750750
return js_file
751751

752752

753-
def is_internal_global(name):
754-
internal_start_stop_symbols = {'__start_em_asm', '__stop_em_asm',
755-
'__start_em_js', '__stop_em_js',
756-
'__start_em_lib_deps', '__stop_em_lib_deps',
757-
'__em_lib_deps'}
758-
internal_prefixes = ('__em_js__', '__em_lib_deps')
759-
return not shared.treat_as_user_export(name) or name in internal_start_stop_symbols or any(name.startswith(p) for p in internal_prefixes)
760-
761-
762753
# get the flags to pass into the very last binaryen tool invocation, that runs
763754
# the final set of optimizations
764755
def get_last_binaryen_opts():
@@ -864,7 +855,7 @@ def metadce(js_file, wasm_file, debug_info, last):
864855
unused_imports.append(native_name)
865856
elif name.startswith('emcc$export$') and settings.DECLARE_ASM_MODULE_EXPORTS:
866857
native_name = export_name_map[name]
867-
if not is_internal_global(native_name):
858+
if shared.is_user_export(native_name):
868859
unused_exports.append(native_name)
869860
if not unused_exports and not unused_imports:
870861
# nothing found to be unused, so we have nothing to remove

tools/emscripten.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from tools import extract_metadata
3131
from tools.utils import exit_with_error, path_from_root, removeprefix
3232
from tools.shared import DEBUG, asmjs_mangle, in_temp
33-
from tools.shared import treat_as_user_export
3433
from tools.settings import settings, user_settings
3534

3635
sys.path.append(path_from_root('third_party'))
@@ -282,7 +281,7 @@ def trim_asm_const_body(body):
282281
def create_global_exports(global_exports):
283282
lines = []
284283
for k, v in global_exports.items():
285-
if building.is_internal_global(k):
284+
if shared.is_internal_global(k):
286285
continue
287286

288287
v = int(v)
@@ -571,7 +570,7 @@ def finalize_wasm(infile, outfile, js_syms):
571570
# EMSCRIPTEN_KEEPALIVE (llvm.used).
572571
# These are any exports that were not requested on the command line and are
573572
# not known auto-generated system functions.
574-
unexpected_exports = [e for e in metadata.all_exports if treat_as_user_export(e)]
573+
unexpected_exports = [e for e in metadata.all_exports if shared.is_user_export(e)]
575574
for n in unexpected_exports:
576575
if not n.isidentifier():
577576
exit_with_error(f'invalid export name: {n}')

tools/shared.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,18 @@ def is_c_symbol(name):
636636
return name.startswith('_')
637637

638638

639-
def treat_as_user_export(name):
639+
def is_internal_global(name):
640+
internal_start_stop_symbols = {'__start_em_asm', '__stop_em_asm',
641+
'__start_em_js', '__stop_em_js',
642+
'__start_em_lib_deps', '__stop_em_lib_deps',
643+
'__em_lib_deps'}
644+
internal_prefixes = ('__em_js__', '__em_lib_deps')
645+
return name in internal_start_stop_symbols or any(name.startswith(p) for p in internal_prefixes)
646+
647+
648+
def is_user_export(name):
649+
if is_internal_global(name):
650+
return False
640651
return name not in ['__indirect_function_table', 'memory'] and not name.startswith(('dynCall_', 'orig$'))
641652

642653

@@ -650,7 +661,7 @@ def asmjs_mangle(name):
650661
# to simply `main` which is expected by the emscripten JS glue code.
651662
if name == '__main_argc_argv':
652663
name = 'main'
653-
if treat_as_user_export(name):
664+
if is_user_export(name):
654665
return '_' + name
655666
return name
656667

0 commit comments

Comments
 (0)