Skip to content

Commit b45172c

Browse files
committed
Fix wasm2s (SAFE_HEAP) test suite
This change fixes all the failing tests in the wasm2s suite. Depends on WebAssembly/binaryen#4439.
1 parent 2885620 commit b45172c

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

emcc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,9 @@ def default_setting(name, new_default):
14381438
if name not in settings_map:
14391439
setattr(settings, name, new_default)
14401440

1441-
if settings.OPT_LEVEL >= 1:
1441+
if settings.SAFE_HEAP >= 1:
1442+
default_setting('ASSERTIONS', 1)
1443+
elif settings.OPT_LEVEL >= 1:
14421444
default_setting('ASSERTIONS', 0)
14431445
if settings.SHRINK_LEVEL >= 2:
14441446
default_setting('EVAL_CTORS', 1)
@@ -1954,6 +1956,8 @@ def default_setting(name, new_default):
19541956
# SAFE_HEAP check includes calling emscripten_get_sbrk_ptr() from wasm
19551957
settings.REQUIRED_EXPORTS += ['emscripten_get_sbrk_ptr', 'emscripten_stack_get_base']
19561958
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$unSign']
1959+
if not settings.ASSERTIONS:
1960+
exit_with_error('SAFE_HEAP requires ASSERTIONS to be enabled')
19571961

19581962
if not settings.DECLARE_ASM_MODULE_EXPORTS:
19591963
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$exportAsmFunctions']

src/runtime_safe_heap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function SAFE_HEAP_STORE(dest, value, bytes, isFloat) {
110110
#else
111111
if (dest % bytes !== 0) warnOnce('alignment error in a memory store operation, alignment was a multiple of ' + (((dest ^ (dest-1)) >> 1) + 1) + ', but was was expected to be aligned to a multiple of ' + bytes);
112112
#endif
113-
if (runtimeInitialized) {
113+
if (runtimeInitialized && !runtimeExited) {
114114
var brk = _sbrk() >>> 0;
115115
if (dest + bytes > brk) abort('segmentation fault, exceeded the top of the available dynamic heap when storing ' + bytes + ' bytes to address ' + dest + '. DYNAMICTOP=' + brk);
116116
assert(brk >= _emscripten_stack_get_base()); // sbrk-managed memory must be above the stack
@@ -134,7 +134,7 @@ function SAFE_HEAP_LOAD(dest, bytes, unsigned, isFloat) {
134134
#else
135135
if (dest % bytes !== 0) warnOnce('alignment error in a memory load operation, alignment was a multiple of ' + (((dest ^ (dest-1)) >> 1) + 1) + ', but was was expected to be aligned to a multiple of ' + bytes);
136136
#endif
137-
if (runtimeInitialized) {
137+
if (runtimeInitialized && !runtimeExited) {
138138
var brk = _sbrk() >>> 0;
139139
if (dest + bytes > brk) abort('segmentation fault, exceeded the top of the available dynamic heap when loading ' + bytes + ' bytes from address ' + dest + '. DYNAMICTOP=' + brk);
140140
assert(brk >= _emscripten_stack_get_base()); // sbrk-managed memory must be above the stack

src/shell.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ assert(typeof Module['TOTAL_MEMORY'] === 'undefined', 'Module.TOTAL_MEMORY has b
450450
{{{ makeRemovedFSAssert('IDBFS') }}}
451451
{{{ makeRemovedFSAssert('PROXYFS') }}}
452452
{{{ makeRemovedFSAssert('WORKERFS') }}}
453+
#if !NODERAWFS
453454
{{{ makeRemovedFSAssert('NODEFS') }}}
455+
#endif
454456
{{{ makeRemovedRuntimeFunction('alignMemory') }}}
455457

456458
#if USE_PTHREADS

system/lib/sbrk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ void *sbrk(intptr_t increment_) {
9696
#endif // __EMSCRIPTEN_PTHREADS__
9797

9898
#ifdef __EMSCRIPTEN_TRACING__
99-
EM_ASM({if (typeof emscriptenMemoryProfiler !== 'undefined') emscriptenMemoryProfiler.onSbrkGrow($0, $1)}, old_brk, old_brk + increment );
99+
if (increment) {
100+
EM_ASM({if (typeof emscriptenMemoryProfiler !== 'undefined') emscriptenMemoryProfiler.onSbrkGrow($0, $1)}, old_brk, old_brk + increment );
101+
}
100102
#endif
101103
return (void*)old_brk;
102104

tests/test_core.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,6 +2297,7 @@ def test_varargs_byval(self):
22972297
The current type of b is: 9
22982298
''')
22992299

2300+
@no_safe_heap('musls fcntl seems to contain an invalid read')
23002301
def test_functionpointer_libfunc_varargs(self):
23012302
self.do_core_test('test_functionpointer_libfunc_varargs.c')
23022303

@@ -6512,6 +6513,7 @@ def test_dyncall_specific(self, *args):
65126513
print(str(args) + ' ' + which)
65136514
self.do_core_test('dyncall_specific.c', emcc_args=['-D' + which] + list(args) + extra_args)
65146515

6516+
@no_safe_heap('SAFE_HEAP is not compatible with ASSERTIONS=0')
65156517
def test_getValue_setValue(self):
65166518
# these used to be exported, but no longer are by default
65176519
def test(output_prefix='', args=[], assert_returncode=0):
@@ -6535,6 +6537,7 @@ def test(output_prefix='', args=[], assert_returncode=0):
65356537
'': ([],),
65366538
'_files': (['-DUSE_FILES'],)
65376539
})
6540+
@no_safe_heap('SAFE_HEAP is not compatible with ASSERTIONS=0')
65386541
def test_FS_exports(self, extra_args):
65396542
# these used to be exported, but no longer are by default
65406543
def test(output_prefix='', args=[], assert_returncode=0):
@@ -6557,6 +6560,7 @@ def test(output_prefix='', args=[], assert_returncode=0):
65576560
self.set_setting('EXPORTED_RUNTIME_METHODS', ['FS_createDataFile'])
65586561
test(args=['-s', 'FORCE_FILESYSTEM'])
65596562

6563+
@no_safe_heap('SAFE_HEAP is not compatible with ASSERTIONS=0')
65606564
def test_legacy_exported_runtime_numbers(self):
65616565
# these used to be exported, but no longer are by default
65626566
def test(output_prefix='', args=[], assert_returncode=0):
@@ -6717,6 +6721,7 @@ def test_emulate_function_pointer_casts(self):
67176721
self.do_core_test('test_emulate_function_pointer_casts.cpp')
67186722

67196723
@no_wasm2js('TODO: nicely printed names in wasm2js')
6724+
@no_safe_heap('SAFE_HEAP is not compatible with ASSERTIONS=0')
67206725
@parameterized({
67216726
'normal': ([],),
67226727
'noexcept': (['-fno-exceptions'],)
@@ -7881,13 +7886,11 @@ def test_memprof_requirements(self):
78817886
# This test checks for the global variables required to run the memory
78827887
# profiler. It would fail if these variables were made no longer global
78837888
# or if their identifiers were changed.
7884-
create_file('main.cpp', '''
7885-
extern "C" {
7886-
void check_memprof_requirements();
7887-
}
7889+
create_file('main.c', '''
7890+
int check_memprof_requirements();
7891+
78887892
int main() {
7889-
check_memprof_requirements();
7890-
return 0;
7893+
return check_memprof_requirements();
78917894
}
78927895
''')
78937896
create_file('lib.js', '''
@@ -7898,14 +7901,16 @@ def test_memprof_requirements(self):
78987901
typeof _emscripten_stack_get_current === 'function' &&
78997902
typeof Module['___heap_base'] === 'number') {
79007903
out('able to run memprof');
7904+
return 0;
79017905
} else {
79027906
out('missing the required variables to run memprof');
7907+
return 1;
79037908
}
79047909
}
79057910
});
79067911
''')
79077912
self.emcc_args += ['--memoryprofiler', '--js-library', 'lib.js']
7908-
self.do_runf('main.cpp', 'able to run memprof')
7913+
self.do_runf('main.c', 'able to run memprof')
79097914

79107915
def test_fs_dict(self):
79117916
self.set_setting('FORCE_FILESYSTEM')

0 commit comments

Comments
 (0)