Skip to content

Simplify create_sending function. NFC #17189

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 1 commit into from
Jun 9, 2022
Merged
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
39 changes: 17 additions & 22 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,29 +753,24 @@ def add_standard_wasm_imports(send_items_map):


def create_sending(invoke_funcs, metadata):
em_js_funcs = set(metadata['emJsFuncs'].keys())
declares = [asmjs_mangle(d) for d in metadata['declares']]
externs = [asmjs_mangle(e) for e in metadata['globalImports']]
send_items = set(invoke_funcs + declares + externs)
send_items.update(em_js_funcs)

def fix_import_name(g):
# Unlike fastcomp the wasm backend doesn't use the '_' prefix for native
# symbols. Emscripten currently expects symbols to start with '_' so we
# artificially add them to the output of emscripten-wasm-finalize and them
# strip them again here.
# note that we don't do this for EM_JS functions (which, rarely, may have
# a '_' prefix)
if g.startswith('_') and g not in em_js_funcs:
return g[1:]
return g

# Map of wasm imports to mangled/external/JS names
send_items_map = OrderedDict()
for name in send_items:
internal_name = fix_import_name(name)
if internal_name in send_items_map:
exit_with_error('duplicate symbol in exports to wasm: %s', name)
send_items_map[internal_name] = name

def add_send_items(name, mangled_name, ignore_dups=False):
# Sanity check that the names of emJsFuncs, declares, and globalImports don't overlap
if not ignore_dups and name in send_items_map:
assert name not in send_items_map, 'duplicate symbol in exports: %s' % name
send_items_map[name] = mangled_name

for name in metadata['emJsFuncs']:
add_send_items(name, name)
for name in invoke_funcs:
add_send_items(name, name)
for name in metadata['declares']:
add_send_items(name, asmjs_mangle(name))
for name in metadata['globalImports']:
# globalImports can currently overlap with declares, in the case of dynamic linking
add_send_items(name, asmjs_mangle(name), ignore_dups=settings.RELOCATABLE)
Copy link
Member

Choose a reason for hiding this comment

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

Before this PR we didn't have this check on RELOCATABLE, why is it needed now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Before this PR we were allowing duplication of the mangled names because we were doing send_items = set(invoke_funcs + declares + externs)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So this change actually increases the strictness a little

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure if we even need this check TBH

Copy link
Member

Choose a reason for hiding this comment

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

I see, makes sense.


add_standard_wasm_imports(send_items_map)

Expand Down