Skip to content

Commit 70e698d

Browse files
authored
[wasm64] Error on -fsanitize=address + wasm64 (#21180)
This chance also includes a couple of minor fixes to asan + memory64 that helped me to confirm that it really doesn't work yet. See #21177
1 parent 6ae900e commit 70e698d

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

system/lib/compiler-rt/lib/sanitizer_common/sanitizer_emscripten.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ u64 MonotonicNanoTime() {
127127
return (u64)ts.tv_sec * (1000ULL * 1000 * 1000) + ts.tv_nsec;
128128
}
129129

130+
void GetMemoryProfile(fill_profile_f cb, uptr *stats) {}
131+
130132
} // namespace __sanitizer
131133

132134
#endif

test/test_other.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14421,3 +14421,7 @@ def test_uuid(self):
1442114421
# "window.crypto.getRandomValues"
1442214422
self.assertContained(").randomBytes", js_out)
1442314423
self.assertContained("window.crypto.getRandomValues", js_out)
14424+
14425+
def test_wasm64_no_asan(self):
14426+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sMEMORY64', '-fsanitize=address'])
14427+
self.assertContained('error: MEMORY64 does not yet work with ASAN', err)

tools/emscripten.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@
3737

3838
logger = logging.getLogger('emscripten')
3939

40+
# helper functions for JS to call into C to do memory operations. these
41+
# let us sanitize memory access from the JS side, by calling into C where
42+
# it has been instrumented.
43+
ASAN_C_HELPERS = [
44+
'_asan_c_load_1', '_asan_c_load_1u',
45+
'_asan_c_load_2', '_asan_c_load_2u',
46+
'_asan_c_load_4', '_asan_c_load_4u',
47+
'_asan_c_load_f', '_asan_c_load_d',
48+
'_asan_c_store_1', '_asan_c_store_1u',
49+
'_asan_c_store_2', '_asan_c_store_2u',
50+
'_asan_c_store_4', '_asan_c_store_4u',
51+
'_asan_c_store_f', '_asan_c_store_d',
52+
]
53+
4054

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

972+
for f in ASAN_C_HELPERS:
973+
mapping[f] = '_p'
974+
958975
wrappers = '''
959976
// Argument name here must shadow the `wasmExports` global so
960977
// that it is recognised by metadce and minify-import-export-names

tools/link.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,21 +1546,7 @@ def check_memory_setting(setting):
15461546
if not settings.UBSAN_RUNTIME:
15471547
settings.UBSAN_RUNTIME = 2
15481548

1549-
# helper functions for JS to call into C to do memory operations. these
1550-
# let us sanitize memory access from the JS side, by calling into C where
1551-
# it has been instrumented.
1552-
ASAN_C_HELPERS = [
1553-
'_asan_c_load_1', '_asan_c_load_1u',
1554-
'_asan_c_load_2', '_asan_c_load_2u',
1555-
'_asan_c_load_4', '_asan_c_load_4u',
1556-
'_asan_c_load_f', '_asan_c_load_d',
1557-
'_asan_c_store_1', '_asan_c_store_1u',
1558-
'_asan_c_store_2', '_asan_c_store_2u',
1559-
'_asan_c_store_4', '_asan_c_store_4u',
1560-
'_asan_c_store_f', '_asan_c_store_d',
1561-
]
1562-
1563-
settings.REQUIRED_EXPORTS += ASAN_C_HELPERS
1549+
settings.REQUIRED_EXPORTS += emscripten.ASAN_C_HELPERS
15641550

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

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

1609+
if settings.MEMORY64:
1610+
exit_with_error('MEMORY64 does not yet work with ASAN')
1611+
16231612
if settings.USE_ASAN or settings.SAFE_HEAP:
16241613
# ASan and SAFE_HEAP check address 0 themselves
16251614
settings.CHECK_NULL_WRITES = 0

0 commit comments

Comments
 (0)