Skip to content

Commit 94ce461

Browse files
authored
Revert "Unify legacy dyncall mechanisms" (#24378)
Reverts #24371 Turns out this was failing the core3.test_dyncall_pointers_legacy test. Will need to revist.
1 parent 5db08eb commit 94ce461

File tree

5 files changed

+47
-37
lines changed

5 files changed

+47
-37
lines changed

site/source/docs/compiling/Modularized-Output.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ fix in future releses. Current limitations include:
126126
* :ref:`abort_on_wasm_exceptions` is not supported (requires wrapping wasm
127127
exports).
128128

129+
* :ref:`dyncalls` is not supported (depends on the ``Module`` global)
130+
131+
* :ref:`asyncify` is not supported (depends on :ref:`dyncalls`)
132+
129133
* :ref:`asyncify_lazy_load_code` is not supported (depends on ``wasmExports``
130134
global)
131135

@@ -168,10 +172,6 @@ Some additional limitations are:
168172

169173
- ``-pthread`` / :ref:`wasm_workers` are not yet supported.
170174

171-
* :ref:`dyncalls` is not supported (depends on the ``Module`` global)
172-
173-
* :ref:`asyncify` is not supported (depends on :ref:`dyncalls`)
174-
175175
- Setting :ref:`wasm` to ``0`` is not supported.
176176

177177
- Setting :ref:`wasm_async_compilation` to ``0`` is not supported.

src/lib/libcore.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,13 +1729,25 @@ addToLibrary({
17291729
},
17301730

17311731
#if DYNCALLS || !WASM_BIGINT
1732-
$dynCalls__internal: true,
1733-
$dynCalls: {},
1734-
$dynCallLegacy__deps: ['$dynCalls'],
1732+
#if MINIMAL_RUNTIME
1733+
$dynCalls: '{}',
1734+
#endif
1735+
$dynCallLegacy__deps: [
1736+
#if MINIMAL_RUNTIME
1737+
'$dynCalls',
1738+
#endif
1739+
#if MODULARIZE == 'instance'
1740+
() => error('dynCallLegacy is not yet compatible with MODULARIZE=instance'),
1741+
#endif
1742+
],
17351743
$dynCallLegacy: (sig, ptr, args) => {
17361744
sig = sig.replace(/p/g, {{{ MEMORY64 ? "'j'" : "'i'" }}})
17371745
#if ASSERTIONS
1746+
#if MINIMAL_RUNTIME
17381747
assert(sig in dynCalls, `bad function pointer type - sig is not in dynCalls: '${sig}'`);
1748+
#else
1749+
assert(('dynCall_' + sig) in Module, `bad function pointer type - dynCall function not found for sig '${sig}'`);
1750+
#endif
17391751
if (args?.length) {
17401752
#if WASM_BIGINT
17411753
// j (64-bit integer) is fine, and is implemented as a BigInt. Without
@@ -1750,7 +1762,11 @@ addToLibrary({
17501762
assert(sig.length == 1);
17511763
}
17521764
#endif
1765+
#if MINIMAL_RUNTIME
17531766
var f = dynCalls[sig];
1767+
#else
1768+
var f = Module['dynCall_' + sig];
1769+
#endif
17541770
return f(ptr, ...args);
17551771
},
17561772
#if DYNCALLS

test/test_core.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ def metafunc(self, jspi, *args, **kwargs):
212212
self.require_jspi()
213213
else:
214214
self.set_setting('ASYNCIFY')
215+
if self.get_setting('MODULARIZE') == 'instance':
216+
self.skipTest('MODULARIZE=instance is not compatible with ASYNCIFY=1')
215217
f(self, *args, **kwargs)
216218

217219
parameterize(metafunc, {'': (False,),
@@ -231,6 +233,8 @@ def metafunc(self, asyncify, *args, **kwargs):
231233
self.require_jspi()
232234
elif asyncify == 1:
233235
self.set_setting('ASYNCIFY')
236+
if self.get_setting('MODULARIZE') == 'instance':
237+
self.skipTest('MODULARIZE=instance is not compatible with ASYNCIFY=1')
234238
else:
235239
assert asyncify == 0
236240
f(self, *args, **kwargs)
@@ -1881,7 +1885,7 @@ def test_emscripten_get_compiler_setting(self):
18811885
self.set_setting('RETAIN_COMPILER_SETTINGS')
18821886
self.do_runf(src, read_file(output).replace('waka', utils.EMSCRIPTEN_VERSION))
18831887

1884-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
1888+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
18851889
def test_emscripten_has_asyncify(self):
18861890
src = r'''
18871891
#include <stdio.h>
@@ -7020,7 +7024,7 @@ def test_EXPORTED_RUNTIME_METHODS(self):
70207024
self.do_core_test('EXPORTED_RUNTIME_METHODS.c')
70217025

70227026
@also_with_minimal_runtime
7023-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with DYNCALLS')
7027+
@no_modularize_instance('uses dynCallLegacy')
70247028
def test_dyncall_specific(self):
70257029
if self.get_setting('WASM_BIGINT') != 0 and not self.is_wasm2js():
70267030
# define DYNCALLS because this test does test calling them directly, and
@@ -7047,8 +7051,8 @@ def test_dyncall_specific(self):
70477051
'legacy': (['-sDYNCALLS'],),
70487052
})
70497053
def test_dyncall_pointers(self, args):
7050-
if args and self.get_setting('WASM_ESM_INTEGRATION'):
7051-
self.skipTest('WASM_ESM_INTEGRATION is not compatible with DYNCALLS')
7054+
if args:
7055+
self.skipTest('dynCallLegacy is not yet compatible with WASM_ESM_INTEGRATION')
70527056
self.do_core_test('test_dyncall_pointers.c', emcc_args=args)
70537057

70547058
@also_with_wasm_bigint
@@ -8064,7 +8068,7 @@ def test_vswprintf_utf8(self):
80648068

80658069
# Test async sleeps in the presence of invoke_* calls, which can happen with
80668070
# longjmp or exceptions.
8067-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8071+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
80688072
def test_asyncify_longjmp(self):
80698073
self.set_setting('ASYNCIFY')
80708074
self.set_setting('STRICT')
@@ -8124,7 +8128,7 @@ def test_async_loop(self):
81248128
self.do_runf('main.c', 'hello 0\nhello 1\nhello 2\nhello 3\nhello 4\n')
81258129

81268130
@requires_v8
8127-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8131+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
81288132
def test_async_hello_v8(self):
81298133
self.test_async_hello()
81308134

@@ -8229,7 +8233,7 @@ def test_async_ccall_promise(self, exit_runtime):
82298233
self.emcc_args += ['--pre-js', 'pre.js']
82308234
self.do_runf('main.c', 'stringf: first\nsecond\n6.4')
82318235

8232-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8236+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
82338237
def test_fibers_asyncify(self):
82348238
self.set_setting('ASYNCIFY')
82358239
self.maybe_closure()
@@ -8240,7 +8244,7 @@ def test_asyncify_unused(self):
82408244
# test a program not using asyncify, but the pref is set
82418245
self.do_core_test('test_hello_world.c')
82428246

8243-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8247+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
82448248
@parameterized({
82458249
'normal': ([], True),
82468250
'removelist_a': (['-sASYNCIFY_REMOVE=["foo(int, double)"]'], False),
@@ -8288,7 +8292,7 @@ def test_asyncify_lists(self, args, should_pass, response=None):
82888292
# virt() manually, rather than have them inferred automatically.
82898293
'add_no_prop': (['-sASYNCIFY_IGNORE_INDIRECT', '-sASYNCIFY_ADD=["__original_main","main","virt()"]', '-sASYNCIFY_PROPAGATE_ADD=0'], True),
82908294
})
8291-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8295+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
82928296
def test_asyncify_indirect_lists(self, args, should_pass):
82938297
self.set_setting('ASYNCIFY')
82948298
self.emcc_args += args
@@ -8306,7 +8310,7 @@ def test_asyncify_indirect_lists(self, args, should_pass):
83068310
raise
83078311

83088312
@with_dylink_reversed
8309-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8313+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
83108314
def test_asyncify_side_module(self):
83118315
self.set_setting('ASYNCIFY')
83128316
self.set_setting('ASYNCIFY_IMPORTS', ['my_sleep'])
@@ -8336,12 +8340,12 @@ def test_asyncify_side_module(self):
83368340
''', 'before sleep\n42\n42\nafter sleep\n', header='void my_sleep(int);', force_c=True)
83378341

83388342
@no_asan('asyncify stack operations confuse asan')
8339-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8343+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
83408344
def test_emscripten_scan_registers(self):
83418345
self.set_setting('ASYNCIFY')
83428346
self.do_core_test('test_emscripten_scan_registers.cpp')
83438347

8344-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8348+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
83458349
def test_asyncify_assertions(self):
83468350
self.set_setting('ASYNCIFY')
83478351
self.set_setting('ASYNCIFY_IMPORTS', ['suspend'])
@@ -8350,7 +8354,7 @@ def test_asyncify_assertions(self):
83508354

83518355
@no_lsan('leaks asyncify stack during exit')
83528356
@no_asan('leaks asyncify stack during exit')
8353-
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1')
8357+
@no_modularize_instance('MODULARIZE=instance is not compatible with ASYNCIFY=1')
83548358
def test_asyncify_during_exit(self):
83558359
self.set_setting('ASYNCIFY')
83568360
self.set_setting('ASSERTIONS')

tools/emscripten.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -907,15 +907,6 @@ def can_use_await():
907907
return settings.MODULARIZE
908908

909909

910-
def make_dyncall_assignment(sym):
911-
if not sym.startswith('dynCall_'):
912-
return ''
913-
if not settings.DYNCALLS or '$dynCall' not in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE:
914-
return ''
915-
sig = sym.replace('dynCall_', '')
916-
return f"dynCalls['{sig}'] = "
917-
918-
919910
def make_export_wrappers(function_exports):
920911
assert not settings.MINIMAL_RUNTIME
921912

@@ -955,8 +946,6 @@ def install_wrapper(sym):
955946
exported = "Module['%s'] = " % mangled
956947
wrapper += exported
957948

958-
wrapper += make_dyncall_assignment(name)
959-
960949
if settings.ASSERTIONS and install_wrapper(name):
961950
# With assertions enabled we create a wrapper that are calls get routed through, for
962951
# the lifetime of the program.
@@ -1006,16 +995,17 @@ def create_receiving(function_exports, tag_exports):
1006995
# var _main;
1007996
# function assignWasmExports(wasmExport) {
1008997
# _main = wasmExports["_main"];
998+
generate_dyncall_assignment = settings.DYNCALLS and '$dynCall' in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE
1009999
exports = [x for x in function_exports if x != building.WASM_CALL_CTORS]
10101000
receiving.append('function assignWasmExports(wasmExports) {')
10111001
for s in exports:
10121002
mangled = asmjs_mangle(s)
1013-
dyncall_assignment = make_dyncall_assignment(s)
1003+
dynCallAssignment = ('dynCalls["' + s.replace('dynCall_', '') + '"] = ') if generate_dyncall_assignment and mangled.startswith('dynCall_') else ''
10141004
should_export = settings.EXPORT_ALL or (settings.EXPORT_KEEPALIVE and mangled in settings.EXPORTED_FUNCTIONS)
10151005
export_assignment = ''
10161006
if settings.MODULARIZE and should_export:
10171007
export_assignment = f"Module['{mangled}'] = "
1018-
receiving.append(f" {export_assignment}{dyncall_assignment}{mangled} = wasmExports['{s}'];")
1008+
receiving.append(f" {export_assignment}{dynCallAssignment}{mangled} = wasmExports['{s}'];")
10191009
receiving.append('}')
10201010
sep = ',\n '
10211011
mangled = [asmjs_mangle(s) for s in exports]

tools/link.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,6 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915
800800
exit_with_error('WASM_ESM_INTEGRATION requires MODULARIZE=instance')
801801
if settings.RELOCATABLE:
802802
exit_with_error('WASM_ESM_INTEGRATION is not compatible with dynamic linking')
803-
if settings.ASYNCIFY == 1:
804-
exit_with_error('WASM_ESM_INTEGRATION is not compatible with -sASYNCIFY=1')
805-
if settings.DYNCALLS:
806-
exit_with_error('WASM_ESM_INTEGRATION is not compatible with DYNCALLS')
807803
if settings.WASM_WORKERS or settings.PTHREADS:
808804
exit_with_error('WASM_ESM_INTEGRATION is not compatible with multi-threading')
809805
if settings.USE_OFFSET_CONVERTER:
@@ -836,6 +832,10 @@ def limit_incoming_module_api():
836832
exit_with_error('MODULARIZE=instance requires EXPORT_ES6')
837833
if settings.ABORT_ON_WASM_EXCEPTIONS:
838834
exit_with_error('MODULARIZE=instance is not compatible with ABORT_ON_WASM_EXCEPTIONS')
835+
if settings.ASYNCIFY == 1:
836+
exit_with_error('MODULARIZE=instance is not compatible with -sASYNCIFY=1')
837+
if settings.DYNCALLS:
838+
exit_with_error('MODULARIZE=instance is not compatible with -sDYNCALLS')
839839
if settings.ASYNCIFY_LAZY_LOAD_CODE:
840840
exit_with_error('MODULARIZE=instance is not compatible with -sASYNCIFY_LAZY_LOAD_CODE')
841841
if settings.MINIMAL_RUNTIME:

0 commit comments

Comments
 (0)