Skip to content
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

[wasm64] Error on -fsanitize=address + wasm64 #21180

Merged
merged 1 commit into from
Jan 26, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ u64 MonotonicNanoTime() {
return (u64)ts.tv_sec * (1000ULL * 1000 * 1000) + ts.tv_nsec;
}

void GetMemoryProfile(fill_profile_f cb, uptr *stats) {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is needed for wasm64 but not wasm32 because its referenced by compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h but not by compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h


} // namespace __sanitizer

#endif
4 changes: 4 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -14421,3 +14421,7 @@ def test_uuid(self):
# "window.crypto.getRandomValues"
self.assertContained(").randomBytes", js_out)
self.assertContained("window.crypto.getRandomValues", js_out)

def test_wasm64_no_asan(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sMEMORY64', '-fsanitize=address'])
self.assertContained('error: MEMORY64 does not yet work with ASAN', err)
17 changes: 17 additions & 0 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@

logger = logging.getLogger('emscripten')

# helper functions for JS to call into C to do memory operations. these
# let us sanitize memory access from the JS side, by calling into C where
# it has been instrumented.
ASAN_C_HELPERS = [
'_asan_c_load_1', '_asan_c_load_1u',
'_asan_c_load_2', '_asan_c_load_2u',
'_asan_c_load_4', '_asan_c_load_4u',
'_asan_c_load_f', '_asan_c_load_d',
'_asan_c_store_1', '_asan_c_store_1u',
'_asan_c_store_2', '_asan_c_store_2u',
'_asan_c_store_4', '_asan_c_store_4u',
'_asan_c_store_f', '_asan_c_store_d',
]


def compute_minimal_runtime_initializer_and_exports(post, exports, receiving):
# Declare all exports out to global JS scope so that JS library functions can access them in a
Expand Down Expand Up @@ -955,6 +969,9 @@ def create_pointer_conversion_wrappers(metadata):
sym, sig = function.split(':')
mapping[sym] = sig

for f in ASAN_C_HELPERS:
mapping[f] = '_p'

wrappers = '''
// Argument name here must shadow the `wasmExports` global so
// that it is recognised by metadce and minify-import-export-names
Expand Down
21 changes: 5 additions & 16 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,21 +1546,7 @@ def check_memory_setting(setting):
if not settings.UBSAN_RUNTIME:
settings.UBSAN_RUNTIME = 2

# helper functions for JS to call into C to do memory operations. these
# let us sanitize memory access from the JS side, by calling into C where
# it has been instrumented.
ASAN_C_HELPERS = [
'_asan_c_load_1', '_asan_c_load_1u',
'_asan_c_load_2', '_asan_c_load_2u',
'_asan_c_load_4', '_asan_c_load_4u',
'_asan_c_load_f', '_asan_c_load_d',
'_asan_c_store_1', '_asan_c_store_1u',
'_asan_c_store_2', '_asan_c_store_2u',
'_asan_c_store_4', '_asan_c_store_4u',
'_asan_c_store_f', '_asan_c_store_d',
]

settings.REQUIRED_EXPORTS += ASAN_C_HELPERS
settings.REQUIRED_EXPORTS += emscripten.ASAN_C_HELPERS

if settings.ASYNCIFY and not settings.ASYNCIFY_ONLY:
# we do not want asyncify to instrument these helpers - they just access
Expand All @@ -1572,7 +1558,7 @@ def check_memory_setting(setting):
# do anything (as the user's list won't contain these functions), and if
# we did add them, the pass would assert on incompatible lists, hence the
# condition in the above if.
settings.ASYNCIFY_REMOVE += ASAN_C_HELPERS
settings.ASYNCIFY_REMOVE += emscripten.ASAN_C_HELPERS

if settings.ASAN_SHADOW_SIZE != -1:
diagnostics.warning('emcc', 'ASAN_SHADOW_SIZE is ignored and will be removed in a future release')
Expand Down Expand Up @@ -1620,6 +1606,9 @@ def check_memory_setting(setting):
# by SAFE_HEAP as a null pointer dereference.
exit_with_error('ASan does not work with SAFE_HEAP')

if settings.MEMORY64:
exit_with_error('MEMORY64 does not yet work with ASAN')

if settings.USE_ASAN or settings.SAFE_HEAP:
# ASan and SAFE_HEAP check address 0 themselves
settings.CHECK_NULL_WRITES = 0
Expand Down
Loading