diff --git a/test/test_other.py b/test/test_other.py index ffc83109ff681..752556e9208e4 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -12226,6 +12226,28 @@ def test_asan_strncpy(self): # https://github.com/emscripten-core/emscripten/issues/14618 self.do_runf('other/test_asan_strncpy.c', emcc_args=['-fsanitize=address']) + @parameterized({ + 'asan': ['AddressSanitizer: null-pointer-dereference on address 0x00000000', '-fsanitize=address'], + 'safe_heap': ['Aborted(segmentation fault storing 4 bytes to address 0)', '-sSAFE_HEAP'], + }) + @parameterized({ + '': [], + 'memgrowth': ['-pthread', '-sALLOW_MEMORY_GROWTH', '-Wno-pthreads-mem-growth'], + }) + @parameterized({ + '': [], + 'bigendian': ['-sSUPPORT_BIG_ENDIAN'], + }) + def test_null_deref_via_js(self, expected_output, *args): + # Multiple JS transforms look for pattern like `HEAPxx[...]` and transform it. + # This test ensures that one of the transforms doesn't produce a pattern that + # another pass can't find anymore, that is that features can work in conjunction. + self.do_runf( + 'other/test_null_deref_via_js.c', + emcc_args=args, + assert_returncode=NON_ZERO, + expected_output=[expected_output]) + @node_pthreads def test_proxy_to_pthread_stack(self): # Check that the proxied main gets run with STACK_SIZE setting and not diff --git a/tools/link.py b/tools/link.py index 60874b5aa4041..9e75ce1c63210 100644 --- a/tools/link.py +++ b/tools/link.py @@ -2279,10 +2279,6 @@ def phase_binaryen(target, options, wasm_target): # after generating the wasm, do some final operations if final_js: - if settings.SUPPORT_BIG_ENDIAN: - with ToolchainProfiler.profile_block('little_endian_heap'): - final_js = building.little_endian_heap(final_js) - # >=2GB heap support requires pointers in JS to be unsigned. rather than # require all pointers to be unsigned by default, which increases code size # a little, keep them signed, and just unsign them here if we need that. @@ -2305,6 +2301,10 @@ def phase_binaryen(target, options, wasm_target): if settings.SAFE_HEAP: final_js = building.instrument_js_for_safe_heap(final_js) + if settings.SUPPORT_BIG_ENDIAN: + with ToolchainProfiler.profile_block('little_endian_heap'): + final_js = building.little_endian_heap(final_js) + if settings.OPT_LEVEL >= 2 and settings.DEBUG_LEVEL <= 2: # minify the JS. Do not minify whitespace if Closure is used, so that # Closure can print out readable error messages (Closure will then