Skip to content

Commit fa80ed0

Browse files
authored
Fix wasm64.test_stack_safe. NFC (#25079)
This change fixes ptrToString to handle 64-bit pointers, as well as negative pointers. For wasm64 have to deal with potentially negative pointer values flowing out of WebAssembly. The `>>> 0` trick doesn't work since it would truncate the value to 32-bits. Fixes: #25075
1 parent 4803d1b commit fa80ed0

File tree

4 files changed

+15
-31
lines changed

4 files changed

+15
-31
lines changed

.circleci/config.yml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -659,27 +659,6 @@ jobs:
659659
steps:
660660
- run-tests-linux:
661661
test_targets: "wasm2js1"
662-
test-wasm64:
663-
# We don't use `bionic` here since its too old to run recent node versions:
664-
# `/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found`
665-
executor: linux-python
666-
steps:
667-
- prepare-for-tests
668-
# The linux-python image uses /home/circleci rather than /root and jsvu
669-
# hardcodes /root into its launcher scripts so we need to reinstall v8.
670-
- run: rm -rf $HOME/.jsvu
671-
- install-v8
672-
- install-node-canary
673-
# When running wasm64 tests we need to make sure we use the testing
674-
# version of node (node canary) when running the compiler output (e.g.
675-
# in configure tests.
676-
- run:
677-
name: configure compiler to use node-canary
678-
command: echo "NODE_JS = NODE_JS_TEST" >> ~/emsdk/.emscripten
679-
- run-tests:
680-
title: "wasm64"
681-
test_targets: "wasm64"
682-
- upload-test-results
683662
test-wasm64-4gb:
684663
environment:
685664
LANG: "C.UTF-8"
@@ -707,6 +686,7 @@ jobs:
707686
core_2gb.test_*em_asm*
708687
core_2gb.test_*embind*
709688
core_2gb.test_fs_js_api_wasmfs
689+
wasm64.test_safe_stack
710690
wasm64l.test_hello_world
711691
wasm64l.test_bigswitch
712692
wasm64l.test_module_wasm_memory

src/lib/libcore.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ addToLibrary({
4545
#if ASSERTIONS
4646
assert(typeof ptr === 'number');
4747
#endif
48-
#if !CAN_ADDRESS_2GB && !MEMORY64
49-
// With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
48+
#if MEMORY64
49+
// Convert to 64-bit unsigned value. We need to use BigInt here since
50+
// Number cannot represent the full 64-bit range.
51+
if (ptr < 0) ptr = 2n**64n + BigInt(ptr);
52+
#else
53+
// Convert to 32-bit unsigned value
5054
ptr >>>= 0;
5155
#endif
52-
return '0x' + ptr.toString(16).padStart(8, '0');
56+
return '0x' + ptr.toString(16).padStart({{{ POINTER_SIZE * 2 }}}, '0');
5357
},
5458

5559
$zeroMemory: (ptr, size) => HEAPU8.fill(0, ptr, ptr + size),
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"hello_world.js": 53809,
3-
"hello_world.js.gz": 17016,
2+
"hello_world.js": 53777,
3+
"hello_world.js.gz": 16996,
44
"hello_world.wasm": 15127,
55
"hello_world.wasm.gz": 7448,
66
"no_asserts.js": 26387,
77
"no_asserts.js.gz": 8797,
88
"no_asserts.wasm": 12227,
99
"no_asserts.wasm.gz": 6008,
10-
"strict.js": 51847,
11-
"strict.js.gz": 16341,
10+
"strict.js": 51815,
11+
"strict.js.gz": 16321,
1212
"strict.wasm": 15127,
1313
"strict.wasm.gz": 7445,
14-
"total": 174524,
15-
"total_gz": 63055
14+
"total": 174460,
15+
"total_gz": 63015
1616
}

test/other/codesize/test_codesize_minimal_O0.expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ async function createWasm() {
784784

785785
var ptrToString = (ptr) => {
786786
assert(typeof ptr === 'number');
787-
// With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
787+
// Convert to 32-bit unsigned value
788788
ptr >>>= 0;
789789
return '0x' + ptr.toString(16).padStart(8, '0');
790790
};

0 commit comments

Comments
 (0)