Skip to content

Commit 8a2f1ab

Browse files
committed
[Wasm64] Fix argv handling for >4GB memories
1 parent dee7d9a commit 8a2f1ab

File tree

9 files changed

+30
-7
lines changed

9 files changed

+30
-7
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ jobs:
618618
wasm64
619619
wasm64_4gb.test_hello_world
620620
wasm64_4gb.test_em_asm
621+
wasm64_4gb.test_async_main
621622
core_2gb.test_em_asm
622623
wasm64l.test_bigswitch
623624
other.test_memory64_proxies

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ def phase_linker_setup(options, state, newargs):
24212421
settings.EXPORT_IF_DEFINED.append('__wasm_apply_data_relocs')
24222422

24232423
if settings.SIDE_MODULE and 'GLOBAL_BASE' in user_settings:
2424-
exit_with_error('GLOBAL_BASE is not compatible with SIDE_MODULE')
2424+
diagnostics.warning('unused-command-line-argument', 'GLOBAL_BASE is not compatible with SIDE_MODULE')
24252425

24262426
if settings.PROXY_TO_WORKER or options.use_preload_plugins:
24272427
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$Browser']

src/postamble.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ function callMain() {
7474

7575
var argc = args.length;
7676
var argv = stackAlloc((argc + 1) * {{{ POINTER_SIZE }}});
77-
var argv_ptr = argv >> {{{ POINTER_SHIFT }}};
77+
var argv_ptr = argv;
7878
args.forEach((arg) => {
79-
{{{ POINTER_HEAP }}}[argv_ptr++] = {{{ to64('stringToUTF8OnStack(arg)') }}};
79+
{{{ makeSetValue('argv_ptr', 0, 'stringToUTF8OnStack(arg)', '*') }}};
80+
argv_ptr += {{{ POINTER_SIZE }}};
8081
});
81-
{{{ POINTER_HEAP }}}[argv_ptr] = {{{ to64('0') }}};
82+
{{{ makeSetValue('argv_ptr', 0, 0, '*') }}};
8283
#else
8384
var argc = 0;
8485
var argv = 0;

test/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ def check_dylink(self):
575575
self.skipTest('no dynamic linking support in wasm2js yet')
576576
if '-fsanitize=undefined' in self.emcc_args:
577577
self.skipTest('no dynamic linking support in UBSan yet')
578+
# Dynamic linking requires IMPORTED_MEMORY which depends on the JS API
579+
# for creating 64-bit memories.
580+
if self.get_setting('GLOBAL_BASE') == '4gb':
581+
self.skipTest('no support for IMPORTED_MEMORY over 4gb yet')
578582

579583
def require_v8(self):
580584
if not config.V8_ENGINE or config.V8_ENGINE not in config.JS_ENGINES:
@@ -705,6 +709,10 @@ def setup_node_pthreads(self):
705709
self.emcc_args += ['-Wno-pthreads-mem-growth', '-pthread']
706710
if self.get_setting('MINIMAL_RUNTIME'):
707711
self.skipTest('node pthreads not yet supported with MINIMAL_RUNTIME')
712+
# Pthread support requires IMPORTED_MEMORY which depends on the JS API
713+
# for creating 64-bit memories.
714+
if self.get_setting('GLOBAL_BASE') == '4gb':
715+
self.skipTest('no support for IMPORTED_MEMORY over 4gb yet')
708716
self.js_engines = [config.NODE_JS]
709717
self.node_args += shared.node_pthread_flags()
710718

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14822
1+
14820
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5774
1+
5780
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6094
1+
6100

test/runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
'ubsan',
7070
'wasm64',
7171
'wasm64_v8',
72+
'wasm64_4gb',
7273
]
7374

7475
# The default core test mode, used when none is specified

test/test_core.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,8 @@ def test_memorygrowth_3_force_fail_reallocBuffer(self):
23782378
@no_asan('requires more memory when growing')
23792379
@no_lsan('requires more memory when growing')
23802380
def test_aborting_new(self, args):
2381+
if self.get_setting('INITIAL_MEMORY'):
2382+
self.skipTest('test depends on default INITIAL_MEMORY')
23812383
# test that C++ new properly errors if we fail to malloc when growth is
23822384
# enabled, with or without growth
23832385
self.emcc_args += args
@@ -6517,6 +6519,9 @@ def test_whets(self):
65176519
@no_asan('depends on the specifics of memory size, which for asan we are forced to increase')
65186520
@no_lsan('depends on the specifics of memory size, which for lsan we are forced to increase')
65196521
def test_dlmalloc_inline(self):
6522+
if self.get_setting('INITIAL_MEMORY'):
6523+
self.skipTest('test depends on default INITIAL_MEMORY')
6524+
65206525
# needed with typed arrays
65216526
self.set_setting('INITIAL_MEMORY', '128mb')
65226527

@@ -6530,6 +6535,9 @@ def test_dlmalloc_inline(self):
65306535
@no_lsan('depends on the specifics of memory size, which for lsan we are forced to increase')
65316536
@no_wasmfs('wasmfs does some malloc/free during startup, fragmenting the heap, leading to differences later')
65326537
def test_dlmalloc(self):
6538+
if self.get_setting('INITIAL_MEMORY'):
6539+
self.skipTest('test depends on default INITIAL_MEMORY')
6540+
65336541
# needed with typed arrays
65346542
self.set_setting('INITIAL_MEMORY', '128mb')
65356543

@@ -6562,6 +6570,9 @@ def test_dlmalloc(self):
65626570
@no_asan('the memory size limit here is too small for asan')
65636571
@no_lsan('the memory size limit here is too small for lsan')
65646572
def test_dlmalloc_large(self):
6573+
if self.get_setting('INITIAL_MEMORY'):
6574+
self.skipTest('test depends on default INITIAL_MEMORY')
6575+
65656576
self.emcc_args += ['-sABORTING_MALLOC=0', '-sALLOW_MEMORY_GROWTH=1', '-sMAXIMUM_MEMORY=128MB']
65666577
self.do_runf(test_file('dlmalloc_test_large.c'), '0 0 0 1')
65676578

@@ -8396,6 +8407,7 @@ def test_asyncify_during_exit(self):
83968407
@no_lsan('undefined symbol __global_base')
83978408
@no_wasm2js('dynamic linking support in wasm2js')
83988409
@with_asyncify_and_jspi
8410+
@needs_dylink
83998411
def test_asyncify_main_module(self):
84008412
self.set_setting('MAIN_MODULE', 2)
84018413
self.do_core_test('test_hello_world.c')

0 commit comments

Comments
 (0)