Skip to content

Commit 06e68ea

Browse files
authored
Simplify create_sending function. NFC (#17189)
Rather than mangling all symbols and then trying to unmangle them again, just mangle the ones that actually need mangling. This allows the complete removal of the unmangling function.
1 parent 75f1731 commit 06e68ea

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

emscripten.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -753,29 +753,24 @@ def add_standard_wasm_imports(send_items_map):
753753

754754

755755
def create_sending(invoke_funcs, metadata):
756-
em_js_funcs = set(metadata['emJsFuncs'].keys())
757-
declares = [asmjs_mangle(d) for d in metadata['declares']]
758-
externs = [asmjs_mangle(e) for e in metadata['globalImports']]
759-
send_items = set(invoke_funcs + declares + externs)
760-
send_items.update(em_js_funcs)
761-
762-
def fix_import_name(g):
763-
# Unlike fastcomp the wasm backend doesn't use the '_' prefix for native
764-
# symbols. Emscripten currently expects symbols to start with '_' so we
765-
# artificially add them to the output of emscripten-wasm-finalize and them
766-
# strip them again here.
767-
# note that we don't do this for EM_JS functions (which, rarely, may have
768-
# a '_' prefix)
769-
if g.startswith('_') and g not in em_js_funcs:
770-
return g[1:]
771-
return g
772-
756+
# Map of wasm imports to mangled/external/JS names
773757
send_items_map = OrderedDict()
774-
for name in send_items:
775-
internal_name = fix_import_name(name)
776-
if internal_name in send_items_map:
777-
exit_with_error('duplicate symbol in exports to wasm: %s', name)
778-
send_items_map[internal_name] = name
758+
759+
def add_send_items(name, mangled_name, ignore_dups=False):
760+
# Sanity check that the names of emJsFuncs, declares, and globalImports don't overlap
761+
if not ignore_dups and name in send_items_map:
762+
assert name not in send_items_map, 'duplicate symbol in exports: %s' % name
763+
send_items_map[name] = mangled_name
764+
765+
for name in metadata['emJsFuncs']:
766+
add_send_items(name, name)
767+
for name in invoke_funcs:
768+
add_send_items(name, name)
769+
for name in metadata['declares']:
770+
add_send_items(name, asmjs_mangle(name))
771+
for name in metadata['globalImports']:
772+
# globalImports can currently overlap with declares, in the case of dynamic linking
773+
add_send_items(name, asmjs_mangle(name), ignore_dups=settings.RELOCATABLE)
779774

780775
add_standard_wasm_imports(send_items_map)
781776

0 commit comments

Comments
 (0)