Skip to content

Commit c175235

Browse files
authored
[wasm64] Fix (or skip) all core tests in wasm64l mode (#16922)
This change contains a lot of fixes for wasm64 as well as a lot of disabling of classes of tests. Most significant changes have been split out and landed previously.
1 parent ba67d7d commit c175235

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+692
-127
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 wasm64l.test_getopt wasm64l.test_em_asm* wasm64l.test_minimal_runtime_utf8_invalid wasm64l.test_strftime wasm64l.test_utime"
384+
test_targets: "wasm64.test_hello_world wasm64.test_ccall wasm64l"
385385
test-other:
386386
executor: bionic
387387
steps:

cmake/Modules/Platform/Emscripten.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ set(EMSCRIPTEN_SYSROOT "${_emcache_output}/sysroot")
232232
list(APPEND CMAKE_FIND_ROOT_PATH "${EMSCRIPTEN_SYSROOT}")
233233
list(APPEND CMAKE_SYSTEM_PREFIX_PATH /)
234234

235-
set(CMAKE_LIBRARY_ARCHITECTURE "wasm32-emscripten")
235+
if ($ENV{CFLAGS} MATCHES "MEMORY64")
236+
set(CMAKE_LIBRARY_ARCHITECTURE "wasm64-emscripten")
237+
else()
238+
set(CMAKE_LIBRARY_ARCHITECTURE "wasm32-emscripten")
239+
endif()
236240

237241
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
238242
set(CMAKE_INSTALL_PREFIX "${EMSCRIPTEN_SYSROOT}" CACHE PATH

embuilder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
'libal',
4242
'libdlmalloc',
4343
'libdlmalloc-noerrno',
44+
'libdlmalloc-tracing',
4445
'libdlmalloc-debug',
4546
'libemmalloc',
4647
'libemmalloc-debug',

emcc.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,11 @@ def phase_setup(options, state, newargs, user_settings):
14511451
if settings.DISABLE_EXCEPTION_THROWING and not settings.DISABLE_EXCEPTION_CATCHING:
14521452
exit_with_error("DISABLE_EXCEPTION_THROWING was set (probably from -fno-exceptions) but is not compatible with enabling exception catching (DISABLE_EXCEPTION_CATCHING=0). If you don't want exceptions, set DISABLE_EXCEPTION_CATCHING to 1; if you do want exceptions, don't link with -fno-exceptions")
14531453

1454+
if settings.MEMORY64:
1455+
default_setting(user_settings, 'SUPPORT_LONGJMP', 0)
1456+
if settings.SUPPORT_LONGJMP:
1457+
exit_with_error('MEMORY64 is not compatible with SUPPORT_LONGJMP')
1458+
14541459
# SUPPORT_LONGJMP=1 means the default SjLj handling mechanism, currently
14551460
# 'emscripten'
14561461
if settings.SUPPORT_LONGJMP == 1:
@@ -2252,6 +2257,17 @@ def check_memory_setting(setting):
22522257
if settings.SHARED_MEMORY or settings.RELOCATABLE or settings.ASYNCIFY_LAZY_LOAD_CODE or settings.WASM2JS:
22532258
settings.IMPORTED_MEMORY = 1
22542259

2260+
# Any "pointers" passed to JS will now be i64's, in both modes.
2261+
# Also turn off minifying, which clashes with instrumented functions in preamble.js
2262+
if settings.MEMORY64:
2263+
if settings.RELOCATABLE:
2264+
exit_with_error('MEMORY64 is not compatible with dynamic linking')
2265+
if not settings.DISABLE_EXCEPTION_CATCHING:
2266+
exit_with_error('MEMORY64 is not compatible with DISABLE_EXCEPTION_CATCHING=0')
2267+
settings.WASM_BIGINT = 1
2268+
settings.MINIFY_WASM_IMPORTS_AND_EXPORTS = 0
2269+
settings.MINIFY_WASM_IMPORTED_MODULES = 0
2270+
22552271
if settings.WASM_BIGINT:
22562272
settings.LEGALIZE_JS_FFI = 0
22572273

@@ -2523,15 +2539,6 @@ def get_full_import_name(name):
25232539
'emscripten_stack_get_base',
25242540
'emscripten_stack_get_end']
25252541

2526-
# Any "pointers" passed to JS will now be i64's, in both modes.
2527-
# Also turn off minifying, which clashes with instrumented functions in preamble.js
2528-
if settings.MEMORY64:
2529-
if user_settings.get('WASM_BIGINT') == '0':
2530-
exit_with_error('MEMORY64 is not compatible with WASM_BIGINT=0')
2531-
settings.WASM_BIGINT = 1
2532-
settings.MINIFY_WASM_IMPORTS_AND_EXPORTS = 0
2533-
settings.MINIFY_WASM_IMPORTED_MODULES = 0
2534-
25352542
# check if we can address the 2GB mark and higher: either if we start at
25362543
# 2GB, or if we allow growth to either any amount or to 2GB or more.
25372544
if settings.INITIAL_MEMORY > 2 * 1024 * 1024 * 1024 or \

src/library.js

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ mergeInto(LibraryManager.library, {
8888
#endif
8989

9090
// Returns a pointer ('p'), which means an i32 on wasm32 and an i64 wasm64
91+
// We have a separate JS version `getHeapMax()` which can be called directly
92+
// avoiding any wrapper added for wasm64.
9193
emscripten_get_heap_max__sig: 'p',
94+
emscripten_get_heap_max__deps: ['$getHeapMax'],
9295
emscripten_get_heap_max: function() {
96+
return getHeapMax();
97+
},
98+
99+
$getHeapMax: function() {
93100
#if ALLOW_MEMORY_GROWTH
94101
// Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
95102
// full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
@@ -147,8 +154,9 @@ mergeInto(LibraryManager.library, {
147154
},
148155
#endif // ~TEST_MEMORY_GROWTH_FAILS
149156

157+
emscripten_resize_heap__sig: 'ip',
150158
emscripten_resize_heap__deps: [
151-
'emscripten_get_heap_max',
159+
'$getHeapMax',
152160
#if ASSERTIONS == 2
153161
'emscripten_get_now',
154162
#endif
@@ -203,7 +211,7 @@ mergeInto(LibraryManager.library, {
203211

204212
// A limit is set for how much we can grow. We should not exceed that
205213
// (the wasm binary specifies it, so if we tried, we'd fail anyhow).
206-
var maxHeapSize = _emscripten_get_heap_max();
214+
var maxHeapSize = getHeapMax();
207215
if (requestedSize > maxHeapSize) {
208216
#if ASSERTIONS
209217
err('Cannot enlarge memory, asked to go up to ' + requestedSize + ' bytes, but the limit is ' + maxHeapSize + ' bytes!');
@@ -342,6 +350,7 @@ mergeInto(LibraryManager.library, {
342350
// the initial values of the environment accessible by getenv.
343351
$ENV: {},
344352

353+
getloadavg__sig: 'ipi',
345354
getloadavg: function(loadavg, nelem) {
346355
// int getloadavg(double loadavg[], int nelem);
347356
// http://linux.die.net/man/3/getloadavg
@@ -389,7 +398,7 @@ mergeInto(LibraryManager.library, {
389398
// assert.h
390399
// ==========================================================================
391400

392-
__assert_fail__sig: 'viiii',
401+
__assert_fail__sig: 'vppip',
393402
__assert_fail: function(condition, filename, line, func) {
394403
abort('Assertion failed: ' + UTF8ToString(condition) + ', at: ' + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
395404
},
@@ -403,7 +412,7 @@ mergeInto(LibraryManager.library, {
403412
return Date.now();
404413
},
405414

406-
_mktime_js__sig: 'ii',
415+
_mktime_js__sig: 'ip',
407416
_mktime_js: function(tmPtr) {
408417
var date = new Date({{{ makeGetValue('tmPtr', C_STRUCTS.tm.tm_year, 'i32') }}} + 1900,
409418
{{{ makeGetValue('tmPtr', C_STRUCTS.tm.tm_mon, 'i32') }}},
@@ -503,7 +512,7 @@ mergeInto(LibraryManager.library, {
503512
},
504513

505514
// musl-internal function used to implement both `asctime` and `asctime_r`
506-
__asctime_r__sig: 'iii',
515+
__asctime_r__sig: 'ppp',
507516
__asctime_r: function(tmPtr, buf) {
508517
var date = {
509518
tm_sec: {{{ makeGetValue('tmPtr', C_STRUCTS.tm.tm_sec, 'i32') }}},
@@ -953,6 +962,7 @@ mergeInto(LibraryManager.library, {
953962
, '$intArrayFromString'
954963
#endif
955964
],
965+
strptime__sig: 'pppp',
956966
strptime: function(buf, format, tm) {
957967
// char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tm);
958968
// http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html
@@ -1193,6 +1203,7 @@ mergeInto(LibraryManager.library, {
11931203

11941204
return 0;
11951205
},
1206+
strptime_l__sig: 'pppp',
11961207
strptime_l__deps: ['strptime'],
11971208
strptime_l: function(buf, format, tm) {
11981209
return _strptime(buf, format, tm); // no locale support yet
@@ -2217,6 +2228,7 @@ mergeInto(LibraryManager.library, {
22172228
},
22182229

22192230
getentropy__deps: ['$getRandomDevice'],
2231+
getentropy__sig: 'ipp',
22202232
getentropy: function(buffer, size) {
22212233
if (!_getentropy.randomDevice) {
22222234
_getentropy.randomDevice = getRandomDevice();
@@ -2248,12 +2260,12 @@ mergeInto(LibraryManager.library, {
22482260
// emscripten.h
22492261
// ==========================================================================
22502262

2251-
emscripten_run_script__sig: 'vi',
2263+
emscripten_run_script__sig: 'vp',
22522264
emscripten_run_script: function(ptr) {
22532265
{{{ makeEval('eval(UTF8ToString(ptr));') }}}
22542266
},
22552267

2256-
emscripten_run_script_int__sig: 'ii',
2268+
emscripten_run_script_int__sig: 'ip',
22572269
emscripten_run_script_int__docs: '/** @suppress{checkTypes} */',
22582270
emscripten_run_script_int: function(ptr) {
22592271
{{{ makeEval('return eval(UTF8ToString(ptr))|0;') }}}
@@ -2262,7 +2274,7 @@ mergeInto(LibraryManager.library, {
22622274
// We use builtin_malloc and builtin_free here because otherwise lsan will
22632275
// report the last returned string as a leak.
22642276
emscripten_run_script_string__deps: ['emscripten_builtin_malloc', 'emscripten_builtin_free'],
2265-
emscripten_run_script_string__sig: 'ii',
2277+
emscripten_run_script_string__sig: 'pp',
22662278
emscripten_run_script_string: function(ptr) {
22672279
{{{ makeEval("var s = eval(UTF8ToString(ptr));") }}}
22682280
if (s == null) {
@@ -2524,6 +2536,10 @@ mergeInto(LibraryManager.library, {
25242536

25252537
emscripten_get_callstack__deps: ['emscripten_get_callstack_js'],
25262538
emscripten_get_callstack: function(flags, str, maxbytes) {
2539+
// Use explicit calls to from64 rather then using the __sig
2540+
// magic here. This is because the __sig wrapper uses arrow function
2541+
// notation which causes the inner call to traverseStack to fail.
2542+
{{{ from64('str') }}};
25272543
var callstack = _emscripten_get_callstack_js(flags);
25282544
// User can query the required amount of bytes to hold the callstack.
25292545
if (!str || maxbytes <= 0) {
@@ -2562,6 +2578,7 @@ mergeInto(LibraryManager.library, {
25622578
}
25632579
},
25642580

2581+
emscripten_log__sig: 'vipp',
25652582
emscripten_log__deps: ['$formatString', 'emscripten_log_js'],
25662583
emscripten_log: function(flags, format, varargs) {
25672584
var result = formatString(format, varargs);
@@ -2600,6 +2617,7 @@ mergeInto(LibraryManager.library, {
26002617
debugger;
26012618
},
26022619

2620+
emscripten_print_double__sig: 'iipi',
26032621
emscripten_print_double: function(x, to, max) {
26042622
var str = x + '';
26052623
if (to) return stringToUTF8(str, to, max);
@@ -2642,14 +2660,22 @@ mergeInto(LibraryManager.library, {
26422660
// Returns a representation of a call site of the caller of this function, in a manner
26432661
// similar to __builtin_return_address. If level is 0, we return the call site of the
26442662
// caller of this function.
2663+
emscripten_return_address__sig: 'pi',
26452664
emscripten_return_address__deps: ['$convertFrameToPC', '$jsStackTrace'],
26462665
emscripten_return_address: function(level) {
26472666
var callstack = jsStackTrace().split('\n');
26482667
if (callstack[0] == 'Error') {
26492668
callstack.shift();
26502669
}
26512670
// skip this function and the caller to get caller's return address
2652-
return convertFrameToPC(callstack[level + 3]);
2671+
#if MEMORY64
2672+
// MEMORY64 injects and extra wrapper within emscripten_return_address
2673+
// to handle BigInt convertions.
2674+
var caller = callstack[level + 4];
2675+
#else
2676+
var caller = callstack[level + 3];
2677+
#endif
2678+
return convertFrameToPC(caller);
26532679
},
26542680

26552681
$UNWIND_CACHE: {},
@@ -2692,6 +2718,7 @@ mergeInto(LibraryManager.library, {
26922718
// must be able to unwind from a PC value that may no longer be on the
26932719
// execution stack, and so we are forced to cache the entire call stack.
26942720
emscripten_stack_snapshot__deps: ['$convertFrameToPC', '$UNWIND_CACHE', '$saveInUnwindCache', '$jsStackTrace'],
2721+
emscripten_stack_snapshot__sig: 'p',
26952722
emscripten_stack_snapshot: function () {
26962723
var callstack = jsStackTrace().split('\n');
26972724
if (callstack[0] == 'Error') {
@@ -2722,6 +2749,7 @@ mergeInto(LibraryManager.library, {
27222749
// emscripten_stack_snapshot, or this function will instead use the current
27232750
// call stack.
27242751
emscripten_stack_unwind_buffer__deps: ['$UNWIND_CACHE', '$saveInUnwindCache', '$convertFrameToPC', '$jsStackTrace'],
2752+
emscripten_stack_unwind_buffer__sig: 'ippi',
27252753
emscripten_stack_unwind_buffer: function (addr, buffer, count) {
27262754
var stack;
27272755
if (UNWIND_CACHE.last_addr == addr) {
@@ -2756,6 +2784,7 @@ mergeInto(LibraryManager.library, {
27562784
],
27572785
// Don't treat allocation of _emscripten_pc_get_function.ret as a leak
27582786
emscripten_pc_get_function__noleakcheck: true,
2787+
emscripten_pc_get_function__sig: 'pp',
27592788
#endif
27602789
emscripten_pc_get_function: function (pc) {
27612790
#if !USE_OFFSET_CONVERTER
@@ -2820,6 +2849,7 @@ mergeInto(LibraryManager.library, {
28202849
],
28212850
// Don't treat allocation of _emscripten_pc_get_file.ret as a leak
28222851
emscripten_pc_get_file__noleakcheck: true,
2852+
emscripten_pc_get_file__sig: 'pp',
28232853
emscripten_pc_get_file: function (pc) {
28242854
var result = convertPCtoSourceLocation(pc);
28252855
if (!result) return 0;
@@ -2831,13 +2861,15 @@ mergeInto(LibraryManager.library, {
28312861

28322862
// Look up the line number from our stack frame cache with our PC representation.
28332863
emscripten_pc_get_line__deps: ['$convertPCtoSourceLocation'],
2864+
emscripten_pc_get_line__sig: 'pp',
28342865
emscripten_pc_get_line: function (pc) {
28352866
var result = convertPCtoSourceLocation(pc);
28362867
return result ? result.line : 0;
28372868
},
28382869

28392870
// Look up the column number from our stack frame cache with our PC representation.
28402871
emscripten_pc_get_column__deps: ['$convertPCtoSourceLocation'],
2872+
emscripten_pc_get_column__sig: 'pp',
28412873
emscripten_pc_get_column: function (pc) {
28422874
var result = convertPCtoSourceLocation(pc);
28432875
return result ? result.column || 0 : 0;
@@ -2882,7 +2914,6 @@ mergeInto(LibraryManager.library, {
28822914
#endif
28832915
],
28842916
$readAsmConstArgs: function(sigPtr, buf) {
2885-
{{{ from64(['sigPtr', 'buf']) }}};
28862917
#if ASSERTIONS
28872918
// Nobody should have mutated _readAsmConstArgsArray underneath us to be something else than an array.
28882919
assert(Array.isArray(readAsmConstArgsArray));
@@ -2960,6 +2991,7 @@ mergeInto(LibraryManager.library, {
29602991
#endif
29612992

29622993
$mainThreadEM_ASM__deps: ['$readAsmConstArgs'],
2994+
$mainThreadEM_ASM__sig: 'iippi',
29632995
$mainThreadEM_ASM: function(code, sigPtr, argbuf, sync) {
29642996
#if RELOCATABLE
29652997
code -= {{{ GLOBAL_BASE }}};
@@ -3095,6 +3127,7 @@ mergeInto(LibraryManager.library, {
30953127

30963128
#if STACK_OVERFLOW_CHECK
30973129
// Used by wasm-emscripten-finalize to implement STACK_OVERFLOW_CHECK
3130+
__handle_stack_overflow__sig: 'vp',
30983131
__handle_stack_overflow__deps: ['emscripten_stack_get_base'],
30993132
__handle_stack_overflow: function(requested) {
31003133
requested = requested >>> 0;

src/library_bootstrap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ mergeInto(LibraryManager.library, {
2323

2424
// printf/puts implementations for when musl is not pulled in - very
2525
// partial, but enough for bootstrapping structInfo
26-
2726
printf__deps: ['$formatString'],
27+
printf__sig: 'ipp',
2828
printf: function(format, varargs) {
2929
// int printf(const char *restrict format, ...);
3030
// http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
@@ -36,6 +36,7 @@ mergeInto(LibraryManager.library, {
3636
return result.length;
3737
},
3838

39+
puts__sig: 'ip',
3940
puts: function(s) {
4041
// extra effort to support puts, even without a filesystem. very partial, very hackish
4142
var result = UTF8ToString(s);

src/library_browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,11 +1162,11 @@ var LibraryBrowser = {
11621162
},
11631163

11641164
// Runs natively in pthread, no __proxy needed.
1165-
emscripten_async_call__sig: 'viii',
1165+
emscripten_async_call__sig: 'vppi',
11661166
emscripten_async_call__deps: ['$safeSetTimeout'],
11671167
emscripten_async_call: function(func, arg, millis) {
11681168
function wrapper() {
1169-
{{{ makeDynCall('vi', 'func') }}}(arg);
1169+
{{{ makeDynCall('vp', 'func') }}}(arg);
11701170
}
11711171

11721172
if (millis >= 0

0 commit comments

Comments
 (0)