From 50e0b0785ad5f9adc9bd082451d5cdbf5c4c5229 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 13 Sep 2024 14:58:30 -0700 Subject: [PATCH] Revert "Prefer `calloc` over of malloc+zeroMemory. NFC" (#22568) Reverts emscripten-core/emscripten#22460 It's causing ASan/LSan failures: https://ci.chromium.org/ui/p/emscripten-releases/builders/ci/linux-test-suites/b8737231127543572609/overview I'm going to revert rather than fixing forward because I'm preparing a release. --- src/library_dylink.js | 6 +++--- src/library_pthread.js | 2 +- src/library_sdl.js | 10 ++++++---- test/other/codesize/test_codesize_hello_dylink.exports | 2 +- test/other/codesize/test_codesize_hello_dylink.funcs | 2 +- test/other/codesize/test_codesize_hello_dylink.gzsize | 2 +- test/other/codesize/test_codesize_hello_dylink.jssize | 2 +- test/other/codesize/test_codesize_hello_dylink.size | 2 +- test/test_core.py | 4 +++- test/test_other.py | 1 - tools/emscripten.py | 1 - 11 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/library_dylink.js b/src/library_dylink.js index f9f088d5e379a..a450db61cc888 100644 --- a/src/library_dylink.js +++ b/src/library_dylink.js @@ -363,7 +363,7 @@ var LibraryDylink = { // Allocate memory even if malloc isn't ready yet. The allocated memory here // must be zero initialized since its used for all static data, including bss. $getMemory__noleakcheck: true, - $getMemory__deps: ['$GOT', '__heap_base', '$alignMemory', 'calloc'], + $getMemory__deps: ['$GOT', '__heap_base', '$zeroMemory', '$alignMemory', 'malloc'], $getMemory: (size) => { // After the runtime is initialized, we must only use sbrk() normally. #if DYLINK_DEBUG @@ -373,7 +373,7 @@ var LibraryDylink = { // Currently we don't support freeing of static data when modules are // unloaded via dlclose. This function is tagged as `noleakcheck` to // avoid having this reported as leak. - return _calloc(size, 1); + return zeroMemory(_malloc(size), size); } var ret = ___heap_base; // Keep __heap_base stack aligned. @@ -599,7 +599,7 @@ var LibraryDylink = { $loadWebAssemblyModule__deps: [ '$loadDynamicLibrary', '$getMemory', '$relocateExports', '$resolveGlobalSymbol', '$GOTHandler', - '$getDylinkMetadata', '$alignMemory', + '$getDylinkMetadata', '$alignMemory', '$zeroMemory', '$currentModuleWeakSymbols', '$updateTableMap', '$wasmTable', diff --git a/src/library_pthread.js b/src/library_pthread.js index 680a6ac9dd316..5ccb829dbc44c 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -35,7 +35,7 @@ var LibraryPThread = { $PThread__postset: 'PThread.init();', $PThread__deps: ['_emscripten_thread_init', '$terminateWorker', - '$cleanupThread', + '$cleanupThread', '$zeroMemory', #if MAIN_MODULE '$markAsFinished', #endif diff --git a/src/library_sdl.js b/src/library_sdl.js index 0d54f422b3ad7..160849a38bf17 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1357,7 +1357,7 @@ var LibrarySDL = { return SDL.version; }, - SDL_Init__deps: ['calloc', 'memcpy'], + SDL_Init__deps: ['$zeroMemory', 'memcpy'], SDL_Init__proxy: 'sync', SDL_Init__docs: '/** @param{number} initFlags */', SDL_Init: (initFlags) => { @@ -1376,7 +1376,8 @@ var LibrarySDL = { } window.addEventListener("unload", SDL.receiveEvent); - SDL.keyboardState = _calloc(0x10000, 1); // Our SDL needs 512, but 64K is safe for older SDLs + SDL.keyboardState = _malloc(0x10000); // Our SDL needs 512, but 64K is safe for older SDLs + zeroMemory(SDL.keyboardState, 0x10000); // Initialize this structure carefully for closure SDL.DOMEventToSDLEvent['keydown'] = 0x300 /* SDL_KEYDOWN */; SDL.DOMEventToSDLEvent['keyup'] = 0x301 /* SDL_KEYUP */; @@ -1412,10 +1413,11 @@ var LibrarySDL = { return 1; }, - SDL_GetVideoInfo__deps: ['calloc'], + SDL_GetVideoInfo__deps: ['$zeroMemory'], SDL_GetVideoInfo__proxy: 'sync', SDL_GetVideoInfo: () => { - var ret = _calloc({{{ C_STRUCTS.SDL_VideoInfo.__size__ }}}, 1); + var ret = _malloc({{{ C_STRUCTS.SDL_VideoInfo.__size__ }}}); + zeroMemory(ret, {{{ C_STRUCTS.SDL_version.__size__ }}}); {{{ makeSetValue('ret', C_STRUCTS.SDL_VideoInfo.current_w, 'Module["canvas"].width', 'i32') }}}; {{{ makeSetValue('ret', C_STRUCTS.SDL_VideoInfo.current_h, 'Module["canvas"].height', 'i32') }}}; return ret; diff --git a/test/other/codesize/test_codesize_hello_dylink.exports b/test/other/codesize/test_codesize_hello_dylink.exports index f1e9af5fcfbf2..9aa298858fd18 100644 --- a/test/other/codesize/test_codesize_hello_dylink.exports +++ b/test/other/codesize/test_codesize_hello_dylink.exports @@ -2,8 +2,8 @@ __wasm_apply_data_relocs __wasm_call_ctors _emscripten_stack_alloc _emscripten_stack_restore -calloc dynCall_jiji emscripten_stack_get_current main +malloc setThrew diff --git a/test/other/codesize/test_codesize_hello_dylink.funcs b/test/other/codesize/test_codesize_hello_dylink.funcs index 2c23b988a7191..4ec6c20d0ee6c 100644 --- a/test/other/codesize/test_codesize_hello_dylink.funcs +++ b/test/other/codesize/test_codesize_hello_dylink.funcs @@ -8,7 +8,7 @@ $__wasm_apply_global_relocs $__wasm_call_ctors $_emscripten_stack_alloc $_emscripten_stack_restore -$dlcalloc +$dlmalloc $emscripten_stack_get_current $legalstub$dynCall_jiji $main diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize index 190e05fb52d22..a38f2dcf3d560 100644 --- a/test/other/codesize/test_codesize_hello_dylink.gzsize +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -1 +1 @@ -6285 +6292 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize index 61d1af505618a..b252c4d4631e2 100644 --- a/test/other/codesize/test_codesize_hello_dylink.jssize +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -1 +1 @@ -13820 +13833 diff --git a/test/other/codesize/test_codesize_hello_dylink.size b/test/other/codesize/test_codesize_hello_dylink.size index 1b0fcc83b67b3..01ddd66476899 100644 --- a/test/other/codesize/test_codesize_hello_dylink.size +++ b/test/other/codesize/test_codesize_hello_dylink.size @@ -1 +1 @@ -9763 +9350 diff --git a/test/test_core.py b/test/test_core.py index 6c38e9fede6df..838bd906c21ce 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -1943,7 +1943,9 @@ def test_em_asm_side_module(self): def test_em_js(self, args, force_c): if '-sMAIN_MODULE=2' in args: self.check_dylink() - self.emcc_args += ['-sEXPORTED_FUNCTIONS=_main,_malloc'] + args + else: + self.emcc_args += ['-sEXPORTED_FUNCTIONS=_main,_malloc'] + self.emcc_args += args if '-pthread' in args: self.setup_node_pthreads() diff --git a/test/test_other.py b/test/test_other.py index 8ed5c4786f71b..bd69c2249833e 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2189,7 +2189,6 @@ def test_dylink_pthread_bigint_em_asm(self): def test_dylink_pthread_bigint_em_js(self): self.set_setting('MAIN_MODULE', 2) self.set_setting('WASM_BIGINT') - self.set_setting('EXPORTED_FUNCTIONS', '_malloc,_main') self.emcc_args += ['-Wno-experimental', '-pthread'] self.do_runf('core/test_em_js.cpp') diff --git a/tools/emscripten.py b/tools/emscripten.py index 502cc2dca7d04..8319bd9ac46dd 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -1023,7 +1023,6 @@ def create_pointer_conversion_wrappers(metadata): '_emscripten_stack_alloc': 'pp', 'emscripten_builtin_malloc': 'pp', 'malloc': 'pp', - 'calloc': 'ppp', 'webidl_malloc': 'pp', 'memalign': 'ppp', 'memcmp': '_ppp',