From e57881a98f10dc10672eadbb32e7a7720d3795f6 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 23 Apr 2024 15:10:19 -0700 Subject: [PATCH] Move code in `metadce` to avoid handling mangling twice. NFC (#21812) The stripping of the initial leading underscore can be done first to avoid having to do when mapping the wasi function names. --- tools/building.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/building.py b/tools/building.py index 863444d473f6..6a3895c424f2 100644 --- a/tools/building.py +++ b/tools/building.py @@ -762,6 +762,13 @@ def metadce(js_file, wasm_file, debug_info): export = asmjs_mangle(item['export']) if settings.EXPORT_ALL or export in required_symbols: item['root'] = True + + # fixup wasm backend prefixing + for item in graph: + if 'import' in item: + if item['import'][1][0] == '_': + item['import'][1] = item['import'][1][1:] + # fix wasi imports TODO: support wasm stable with an option? WASI_IMPORTS = { 'environ_get', @@ -782,13 +789,9 @@ def metadce(js_file, wasm_file, debug_info): 'path_open', } for item in graph: - if 'import' in item and item['import'][1][1:] in WASI_IMPORTS: + if 'import' in item and item['import'][1] in WASI_IMPORTS: item['import'][0] = settings.WASI_MODULE_NAME - # fixup wasm backend prefixing - for item in graph: - if 'import' in item: - if item['import'][1][0] == '_': - item['import'][1] = item['import'][1][1:] + # map import names from wasm to JS, using the actual name the wasm uses for the import import_name_map = {} for item in graph: