@@ -969,7 +969,7 @@ def should_export(sym):
969969 return settings .EXPORT_ALL or (settings .EXPORT_KEEPALIVE and sym in settings .EXPORTED_FUNCTIONS )
970970
971971
972- def create_receiving (function_exports , other_exports , library_symbols , aliases ):
972+ def create_receiving (function_exports , other_exports , library_symbols , aliases , wasm_imports ):
973973 generate_dyncall_assignment = 'dynCalls' in library_symbols
974974 receiving = ['\n // Imports from the Wasm binary.' ]
975975
@@ -1019,6 +1019,7 @@ def create_receiving(function_exports, other_exports, library_symbols, aliases):
10191019 # In debug builds we generate trapping functions in case
10201020 # folks try to call/use a reference that was taken before the
10211021 # wasm module is available.
1022+ wasm_imports_mangled = {asmjs_mangle (s ) for s in wasm_imports }
10221023 for sym in mangled :
10231024 module_export = (settings .MODULARIZE or not settings .MINIMAL_RUNTIME ) and should_export (sym ) and settings .MODULARIZE != 'instance'
10241025 if not js_manipulation .isidentifier (sym ) and not module_export :
@@ -1029,7 +1030,11 @@ def create_receiving(function_exports, other_exports, library_symbols, aliases):
10291030 assignment += f" = Module['{ sym } ']"
10301031 else :
10311032 assignment = f"Module['{ sym } ']"
1032- receiving .append (f"{ assignment } = makeInvalidEarlyAccess('{ sym } ');" )
1033+ # Don't generate early access traps for symbols that are also wasm imports.
1034+ if sym in wasm_imports_mangled :
1035+ receiving .append (f"{ assignment } ;" )
1036+ else :
1037+ receiving .append (f"{ assignment } = makeInvalidEarlyAccess('{ sym } ');" )
10331038 else :
10341039 # Declare all exports in a single var statement
10351040 sep = ',\n '
@@ -1100,7 +1105,7 @@ def create_receiving(function_exports, other_exports, library_symbols, aliases):
11001105
11011106def create_module (metadata , function_exports , other_exports , library_symbols , aliases ):
11021107 module = []
1103- module .append (create_receiving (function_exports , other_exports , library_symbols , aliases ))
1108+ module .append (create_receiving (function_exports , other_exports , library_symbols , aliases , metadata . imports ))
11041109
11051110 sending = create_sending (metadata , library_symbols )
11061111 if settings .WASM_ESM_INTEGRATION :
0 commit comments