Skip to content

Commit d98572b

Browse files
committed
If building with -s SUPPORT_ERRNO=0, make sure that dlmalloc does not reference __errno_location so that it can be optimized out by Closure
1 parent 6c634b1 commit d98572b

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

embuilder.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
dlmalloc_debug
4343
dlmalloc_threadsafe
4444
dlmalloc_threadsafe_debug
45+
dlmalloc_noerrno
46+
dlmalloc_debug_noerrno
47+
dlmalloc_threadsafe_noerrno
48+
dlmalloc_threadsafe_debug_noerrno
4549
pthreads
4650
libc++
4751
libc++_noexcept
@@ -108,6 +112,8 @@
108112
'al', 'compiler-rt', 'gl', 'gl-mt', 'libc', 'libc-mt', 'libc-extras',
109113
'emmalloc', 'emmalloc_debug', 'dlmalloc', 'dlmalloc_threadsafe', 'pthreads',
110114
'dlmalloc_debug', 'dlmalloc_threadsafe_debug', 'libc++', 'libc++_noexcept',
115+
'dlmalloc_debug_noerrno', 'dlmalloc_threadsafe_debug_noerrno',
116+
'dlmalloc_noerrno', 'dlmalloc_threadsafe_noerrno',
111117
'libc++abi', 'html5'
112118
]
113119
USER_TASKS = [
@@ -201,6 +207,14 @@ def main():
201207
build(C_WITH_MALLOC, ['libdlmalloc_threadsafe_debug.bc'], ['-g', '-s', 'USE_PTHREADS=1', '-s', 'MALLOC="dlmalloc"'])
202208
elif what in ('dlmalloc_threadsafe', 'libc-mt', 'pthreads'):
203209
build(C_WITH_MALLOC, ['libc-mt.bc', 'libdlmalloc_threadsafe.bc', 'libpthreads.bc'], ['-s', 'USE_PTHREADS=1', '-s', 'MALLOC="dlmalloc"'])
210+
elif what == 'dlmalloc_noerrno':
211+
build(C_WITH_MALLOC, ['libdlmalloc_noerrno.bc'], ['-s', 'MALLOC="dlmalloc"', '-s', 'SUPPORT_ERRNO=0'])
212+
elif what == 'dlmalloc_debug_noerrno':
213+
build(C_WITH_MALLOC, ['libdlmalloc_debug_noerrno.bc'], ['-g', '-s', 'MALLOC="dlmalloc"', '-s', 'SUPPORT_ERRNO=0'])
214+
elif what == 'dlmalloc_threadsafe_debug_noerrno':
215+
build(C_WITH_MALLOC, ['libdlmalloc_threadsafe_debug_noerrno.bc'], ['-g', '-s', 'USE_PTHREADS=1', '-s', 'MALLOC="dlmalloc"', '-s', 'SUPPORT_ERRNO=0'])
216+
elif what == 'dlmalloc_threadsafe_noerrno':
217+
build(C_WITH_MALLOC, ['libdlmalloc_threadsafe_noerrno.bc'], ['-s', 'USE_PTHREADS=1', '-s', 'MALLOC="dlmalloc"', '-s', 'SUPPORT_ERRNO=0'])
204218
elif what == 'libc-wasm':
205219
build(C_WITH_STDLIB, ['libc-wasm.bc'], ['-s', 'WASM=1'])
206220
elif what == 'libc++':

tests/test_sanity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,10 @@ def test_embuilder(self):
723723
([PYTHON, EMBUILDER, 'build', 'dlmalloc_debug'], ['building and verifying dlmalloc', 'success'], True, ['libdlmalloc_debug.bc']),
724724
([PYTHON, EMBUILDER, 'build', 'dlmalloc_threadsafe'], ['building and verifying dlmalloc_threadsafe', 'success'], True, ['libdlmalloc_threadsafe.bc']),
725725
([PYTHON, EMBUILDER, 'build', 'dlmalloc_threadsafe_debug'], ['building and verifying dlmalloc', 'success'], True, ['libdlmalloc_threadsafe_debug.bc']),
726+
([PYTHON, EMBUILDER, 'build', 'dlmalloc_noerrno'], ['building and verifying dlmalloc', 'success'], True, ['libdlmalloc_noerrno.bc']),
727+
([PYTHON, EMBUILDER, 'build', 'dlmalloc_debug_noerrno'], ['building and verifying dlmalloc', 'success'], True, ['libdlmalloc_debug_noerrno.bc']),
728+
([PYTHON, EMBUILDER, 'build', 'dlmalloc_threadsafe_noerrno'], ['building and verifying dlmalloc_threadsafe', 'success'], True, ['libdlmalloc_threadsafe_noerrno.bc']),
729+
([PYTHON, EMBUILDER, 'build', 'dlmalloc_threadsafe_debug_noerrno'], ['building and verifying dlmalloc', 'success'], True, ['libdlmalloc_threadsafe_debug_noerrno.bc']),
726730
([PYTHON, EMBUILDER, 'build', 'emmalloc'], ['building and verifying emmalloc', 'success'], True, ['libemmalloc.bc']),
727731
([PYTHON, EMBUILDER, 'build', 'emmalloc_debug'], ['building and verifying emmalloc', 'success'], True, ['libemmalloc_debug.bc']),
728732
([PYTHON, EMBUILDER, 'build', 'pthreads'], ['building and verifying pthreads', 'success'], True, ['libpthreads.bc']),

tools/system_libs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ def require_dlmalloc(what):
431431
extra += '_debug'
432432
if base == 'dlmalloc':
433433
source = 'dlmalloc.c'
434+
435+
# Only dlmalloc interacts with errno, emmalloc does not
436+
if not shared.Settings.SUPPORT_ERRNO:
437+
extra += '_noerrno'
434438
elif base == 'emmalloc':
435439
source = 'emmalloc.cpp'
436440
return (source, 'lib' + base + extra)
@@ -453,6 +457,8 @@ def create_malloc(out_name):
453457
# TODO: consider adding -DEMMALLOC_DEBUG, but that is quite slow
454458
else:
455459
cflags += ['-DNDEBUG']
460+
if not shared.Settings.SUPPORT_ERRNO:
461+
cflags += ['-DMALLOC_FAILURE_ACTION=']
456462
check_call([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', malloc_source()), '-o', o] + cflags + get_cflags())
457463
return o
458464

0 commit comments

Comments
 (0)