Skip to content

Test for incompatible HEAP transforms in acorn-optimizer #24309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a single test with all 3 features enabled is enough?

Copy link
Collaborator Author

@RReverser RReverser May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be enough to reproduce the issue, but I found that having separate tests helps to narrow down which particular transform is at fault. Just really putting "unit" into the "unit tests".


@node_pthreads
def test_proxy_to_pthread_stack(self):
# Check that the proxied main gets run with STACK_SIZE setting and not
Expand Down
8 changes: 4 additions & 4 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down