Skip to content

Commit 50e0b07

Browse files
authored
Revert "Prefer calloc over of malloc+zeroMemory. NFC" (emscripten-core#22568)
Reverts emscripten-core#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.
1 parent d0d9966 commit 50e0b07

11 files changed

+18
-16
lines changed

src/library_dylink.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ var LibraryDylink = {
363363
// Allocate memory even if malloc isn't ready yet. The allocated memory here
364364
// must be zero initialized since its used for all static data, including bss.
365365
$getMemory__noleakcheck: true,
366-
$getMemory__deps: ['$GOT', '__heap_base', '$alignMemory', 'calloc'],
366+
$getMemory__deps: ['$GOT', '__heap_base', '$zeroMemory', '$alignMemory', 'malloc'],
367367
$getMemory: (size) => {
368368
// After the runtime is initialized, we must only use sbrk() normally.
369369
#if DYLINK_DEBUG
@@ -373,7 +373,7 @@ var LibraryDylink = {
373373
// Currently we don't support freeing of static data when modules are
374374
// unloaded via dlclose. This function is tagged as `noleakcheck` to
375375
// avoid having this reported as leak.
376-
return _calloc(size, 1);
376+
return zeroMemory(_malloc(size), size);
377377
}
378378
var ret = ___heap_base;
379379
// Keep __heap_base stack aligned.
@@ -599,7 +599,7 @@ var LibraryDylink = {
599599
$loadWebAssemblyModule__deps: [
600600
'$loadDynamicLibrary', '$getMemory',
601601
'$relocateExports', '$resolveGlobalSymbol', '$GOTHandler',
602-
'$getDylinkMetadata', '$alignMemory',
602+
'$getDylinkMetadata', '$alignMemory', '$zeroMemory',
603603
'$currentModuleWeakSymbols',
604604
'$updateTableMap',
605605
'$wasmTable',

src/library_pthread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var LibraryPThread = {
3535
$PThread__postset: 'PThread.init();',
3636
$PThread__deps: ['_emscripten_thread_init',
3737
'$terminateWorker',
38-
'$cleanupThread',
38+
'$cleanupThread', '$zeroMemory',
3939
#if MAIN_MODULE
4040
'$markAsFinished',
4141
#endif

src/library_sdl.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ var LibrarySDL = {
13571357
return SDL.version;
13581358
},
13591359

1360-
SDL_Init__deps: ['calloc', 'memcpy'],
1360+
SDL_Init__deps: ['$zeroMemory', 'memcpy'],
13611361
SDL_Init__proxy: 'sync',
13621362
SDL_Init__docs: '/** @param{number} initFlags */',
13631363
SDL_Init: (initFlags) => {
@@ -1376,7 +1376,8 @@ var LibrarySDL = {
13761376
}
13771377

13781378
window.addEventListener("unload", SDL.receiveEvent);
1379-
SDL.keyboardState = _calloc(0x10000, 1); // Our SDL needs 512, but 64K is safe for older SDLs
1379+
SDL.keyboardState = _malloc(0x10000); // Our SDL needs 512, but 64K is safe for older SDLs
1380+
zeroMemory(SDL.keyboardState, 0x10000);
13801381
// Initialize this structure carefully for closure
13811382
SDL.DOMEventToSDLEvent['keydown'] = 0x300 /* SDL_KEYDOWN */;
13821383
SDL.DOMEventToSDLEvent['keyup'] = 0x301 /* SDL_KEYUP */;
@@ -1412,10 +1413,11 @@ var LibrarySDL = {
14121413
return 1;
14131414
},
14141415

1415-
SDL_GetVideoInfo__deps: ['calloc'],
1416+
SDL_GetVideoInfo__deps: ['$zeroMemory'],
14161417
SDL_GetVideoInfo__proxy: 'sync',
14171418
SDL_GetVideoInfo: () => {
1418-
var ret = _calloc({{{ C_STRUCTS.SDL_VideoInfo.__size__ }}}, 1);
1419+
var ret = _malloc({{{ C_STRUCTS.SDL_VideoInfo.__size__ }}});
1420+
zeroMemory(ret, {{{ C_STRUCTS.SDL_version.__size__ }}});
14191421
{{{ makeSetValue('ret', C_STRUCTS.SDL_VideoInfo.current_w, 'Module["canvas"].width', 'i32') }}};
14201422
{{{ makeSetValue('ret', C_STRUCTS.SDL_VideoInfo.current_h, 'Module["canvas"].height', 'i32') }}};
14211423
return ret;

test/other/codesize/test_codesize_hello_dylink.exports

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ __wasm_apply_data_relocs
22
__wasm_call_ctors
33
_emscripten_stack_alloc
44
_emscripten_stack_restore
5-
calloc
65
dynCall_jiji
76
emscripten_stack_get_current
87
main
8+
malloc
99
setThrew

test/other/codesize/test_codesize_hello_dylink.funcs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $__wasm_apply_global_relocs
88
$__wasm_call_ctors
99
$_emscripten_stack_alloc
1010
$_emscripten_stack_restore
11-
$dlcalloc
11+
$dlmalloc
1212
$emscripten_stack_get_current
1313
$legalstub$dynCall_jiji
1414
$main
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6285
1+
6292
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13820
1+
13833
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9763
1+
9350

test/test_core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,9 @@ def test_em_asm_side_module(self):
19431943
def test_em_js(self, args, force_c):
19441944
if '-sMAIN_MODULE=2' in args:
19451945
self.check_dylink()
1946-
self.emcc_args += ['-sEXPORTED_FUNCTIONS=_main,_malloc'] + args
1946+
else:
1947+
self.emcc_args += ['-sEXPORTED_FUNCTIONS=_main,_malloc']
1948+
self.emcc_args += args
19471949
if '-pthread' in args:
19481950
self.setup_node_pthreads()
19491951

test/test_other.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,6 @@ def test_dylink_pthread_bigint_em_asm(self):
21892189
def test_dylink_pthread_bigint_em_js(self):
21902190
self.set_setting('MAIN_MODULE', 2)
21912191
self.set_setting('WASM_BIGINT')
2192-
self.set_setting('EXPORTED_FUNCTIONS', '_malloc,_main')
21932192
self.emcc_args += ['-Wno-experimental', '-pthread']
21942193
self.do_runf('core/test_em_js.cpp')
21952194

0 commit comments

Comments
 (0)