Skip to content

Commit ad9fef3

Browse files
committed
[wasm64] Enable table64 lowering
This change prepares for the LLVM change which actually enables the use of table64 in the output: llvm/llvm-project#92042
1 parent ba5a64d commit ad9fef3

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

tools/emscripten.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
328328
else:
329329
# Skip finalize and only extract the metadata.
330330
if in_wasm != out_wasm:
331-
shutil.copy(in_wasm, out_wasm)
331+
if settings.MEMORY64:
332+
building.run_wasm_opt(in_wasm, out_wasm, ['--table64-lowering'])
333+
else:
334+
shutil.copy(in_wasm, out_wasm)
332335
metadata = get_metadata(in_wasm, out_wasm, False, [])
333336

334337
if settings.RELOCATABLE and settings.MEMORY64 == 2:
@@ -662,18 +665,18 @@ def create_tsd(metadata, embind_tsd):
662665
out += create_tsd_exported_runtime_methods(metadata)
663666
# Manually generate defintions for any Wasm function exports.
664667
out += 'interface WasmModule {\n'
665-
for name, types in metadata.function_exports.items():
668+
for name, functype in metadata.function_exports.items():
666669
mangled = asmjs_mangle(name)
667670
should_export = settings.EXPORT_KEEPALIVE and mangled in settings.EXPORTED_FUNCTIONS
668671
if not should_export:
669672
continue
670673
arguments = []
671-
for index, type in enumerate(types.params):
674+
for index, type in enumerate(functype.params):
672675
arguments.append(f"_{index}: {type_to_ts_type(type)}")
673676
out += f' {mangled}({", ".join(arguments)}): '
674-
assert len(types.returns) <= 1, 'One return type only supported'
675-
if types.returns:
676-
out += f'{type_to_ts_type(types.returns[0])}'
677+
assert len(functype.returns) <= 1, 'One return type only supported'
678+
if functype.returns:
679+
out += f'{type_to_ts_type(functype.returns[0])}'
677680
else:
678681
out += 'void'
679682
out += ';\n'
@@ -791,6 +794,8 @@ def add_standard_wasm_imports(send_items_map):
791794

792795
if settings.RELOCATABLE:
793796
send_items_map['__indirect_function_table'] = 'wasmTable'
797+
if settings.MEMORY64:
798+
send_items_map['__table_base32'] = '___table_base32'
794799

795800
if settings.AUTODEBUG:
796801
extra_sent_items += [
@@ -1100,7 +1105,17 @@ def create_pointer_conversion_wrappers(metadata):
11001105

11011106
sigs_seen = set()
11021107
wrap_functions = []
1103-
for symbol in metadata.function_exports:
1108+
for symbol, functype in metadata.function_exports.items():
1109+
# dynCall_ functions are generated by binaryen. They all take a
1110+
# function pointer as their first argument.
1111+
# The second part of this check can be removed once the table64
1112+
# llvm changs lands.
1113+
if symbol.startswith('dynCall_') and functype.params[0] == webassembly.Type.I64:
1114+
sig = symbol.split('_')[-1]
1115+
sig = ['p' if t == 'p' else '_' for t in sig]
1116+
sig.insert(1, 'p')
1117+
sig = ''.join(sig)
1118+
mapping[symbol] = sig
11041119
sig = mapping.get(symbol)
11051120
if sig:
11061121
if settings.MEMORY64:

tools/link.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,9 @@ def phase_linker_setup(options, state, newargs):
13361336
# Any "pointers" passed to JS will now be i64's, in both modes.
13371337
settings.WASM_BIGINT = 1
13381338

1339+
if settings.MEMORY64 and settings.RELOCATABLE:
1340+
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('__table_base32')
1341+
13391342
if settings.WASM_WORKERS:
13401343
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$_wasmWorkerInitializeRuntime']
13411344
# set location of Wasm Worker bootstrap JS file
@@ -1957,7 +1960,7 @@ def run_embind_gen(wasm_target, js_syms, extra_settings):
19571960
outfile_js = in_temp('tsgen_a.out.js')
19581961
# The Wasm outfile may be modified by emscripten.emscript, so use a temporary file.
19591962
outfile_wasm = in_temp('tsgen_a.out.wasm')
1960-
emscripten.emscript(wasm_target, outfile_wasm, outfile_js, js_syms, False)
1963+
emscripten.emscript(wasm_target, outfile_wasm, outfile_js, js_syms, finalize=False)
19611964
# Build the flags needed by Node.js to properly run the output file.
19621965
node_args = []
19631966
if settings.MEMORY64:

0 commit comments

Comments
 (0)