Skip to content

Commit 56d885f

Browse files
authored
[wasm64] Fix argv setup code for wasm64 (#16943)
Use makeGetValue/makeSetValue over direct heap manipulation in order to make the code compatible with both wasm64 and wasm32.
1 parent 085cd2f commit 56d885f

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ jobs:
381381
executor: bionic
382382
steps:
383383
- run-tests-linux:
384-
test_targets: "wasm64.test_hello_world wasm64.test_ccall wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file wasm64l.test_ccall wasm64l.test_signals wasm64l.test_emscripten_get_compiler_setting wasm64l.test_float_builtins"
384+
test_targets: "wasm64.test_hello_world wasm64.test_ccall wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file wasm64l.test_ccall wasm64l.test_signals wasm64l.test_emscripten_get_compiler_setting wasm64l.test_float_builtins wasm64l.test_getopt"
385385
test-other:
386386
executor: bionic
387387
steps:

src/parseTools.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,12 @@ function needsQuoting(ident) {
177177
const POINTER_SIZE = MEMORY64 ? 8 : 4;
178178
const POINTER_BITS = POINTER_SIZE * 8;
179179
const POINTER_TYPE = 'u' + POINTER_BITS;
180+
const POINTER_SHIFT = MEMORY64 ? '3' : '2';
181+
const POINTER_HEAP = MEMORY64 ? 'HEAP64' : 'HEAP32';
182+
180183
const SIZE_TYPE = POINTER_TYPE;
181184

185+
182186
// Similar to POINTER_TYPE, but this is the actual wasm type that is
183187
// used in practice, while POINTER_TYPE is the more refined internal
184188
// type (that is unsigned, where as core wasm does not have unsigned

src/postamble.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,15 @@ function callMain(args) {
147147
mainArgs = [thisProgram].concat(args)
148148
#elif MAIN_READS_PARAMS
149149
args = args || [];
150+
args.unshift(thisProgram);
150151

151-
var argc = args.length+1;
152+
var argc = args.length;
152153
var argv = stackAlloc((argc + 1) * {{{ Runtime.POINTER_SIZE }}});
153-
HEAP32[argv >> 2] = allocateUTF8OnStack(thisProgram);
154-
for (var i = 1; i < argc; i++) {
155-
HEAP32[(argv >> 2) + i] = allocateUTF8OnStack(args[i - 1]);
156-
}
157-
HEAP32[(argv >> 2) + argc] = 0;
154+
var argv_ptr = argv >> {{{ POINTER_SHIFT }}};
155+
args.forEach((arg) => {
156+
{{{ POINTER_HEAP }}}[argv_ptr++] = {{{ to64('allocateUTF8OnStack(arg)') }}};
157+
});
158+
{{{ POINTER_HEAP }}}[argv_ptr] = {{{ to64('0') }}};
158159
#else
159160
var argc = 0;
160161
var argv = 0;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
27065
1+
27005
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
27394
1+
27385
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6371
1+
6386
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6701
1+
6717

0 commit comments

Comments
 (0)