Skip to content

Commit

Permalink
Use debug version of malloc when ASSERTIONS=1. NFC
Browse files Browse the repository at this point in the history
Previously we were only using it with `ASSERTIONS=2`.  The debug version
dlmalloc has a lot very useful checks.  Enabling this found a few real
issues in our test code.
  • Loading branch information
sbc100 committed Jan 9, 2025
1 parent f8f9611 commit 94ef6a9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ See docs/process.md for more on how version tagging works.
- JavaScript libraries can now be specified via `-lfoo.js`. This works like the
existing `--js-library` flag but will search the library path (all paths
specified with `-L`) for `libfoo.js`. (#23338)
- Emscripten now uses the debug version of malloc (i.e. assertions enabled)
when linking in debug mode (`-O0` and/or `-sASSERTIONS`). This means that
things like double-free will be detected in these builds. Previously this was
only true with `-sASSERTIONS=2`. (#23330)

3.1.74 - 12/14/24
-----------------
Expand Down
2 changes: 2 additions & 0 deletions embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'libdlmalloc-tracing',
'libdlmalloc-debug',
'libdlmalloc-ww',
'libdlmalloc-ww-debug',
'libembind',
'libembind-rtti',
'libemmalloc',
Expand Down Expand Up @@ -101,6 +102,7 @@
'libc++-mt',
'libc++-mt-noexcept',
'libdlmalloc-mt',
'libdlmalloc-mt-debug',
'libGL-emu',
'libGL-emu-webgl2-getprocaddr',
'libGL-mt-getprocaddr',
Expand Down
8 changes: 6 additions & 2 deletions test/other/test_tsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ static void action(const void *nodep, VISIT which, int depth) {
}
}

static void free_node(void* nodep) {
// no-op since we didn't allocate any per-node data
}

int main(void) {
int ptr[12];
void *val = NULL;
Expand All @@ -51,6 +55,6 @@ int main(void) {
assert(val);
}
twalk(root, action);
tdestroy(root, free);
tdestroy(root, free_node);
return 0;
}
}
6 changes: 3 additions & 3 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8019,10 +8019,10 @@ def test_dlmalloc_modes(self):
printf("double-freed\n");
}
''')
self.run_process([EMCC, 'src.c'])
self.run_process([EMCC, 'src.c', '-O2'])
self.assertContained('double-freed', self.run_js('a.out.js'))
# in debug mode, the double-free is caught
self.run_process([EMCC, 'src.c', '-sASSERTIONS=2'])
self.run_process([EMCC, 'src.c', '-O0'])
out = self.run_js('a.out.js', assert_returncode=NON_ZERO)
self.assertContained('native code called abort()', out)

Expand Down Expand Up @@ -13403,7 +13403,7 @@ def test_standard_library_mapping(self):

# Check that the linker was run with `-mt` variants because `-pthread` was passed.
self.assertContained(' -lc-mt-debug ', err)
self.assertContained(' -ldlmalloc-mt ', err)
self.assertContained(' -ldlmalloc-mt-debug ', err)
self.assertContained(' -lcompiler_rt-mt ', err)

def test_explicit_gl_linking(self):
Expand Down
2 changes: 1 addition & 1 deletion tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ def vary_on(cls):
def get_default_variation(cls, **kwargs):
return super().get_default_variation(
malloc=settings.MALLOC,
is_debug=settings.ASSERTIONS >= 2,
is_debug=settings.ASSERTIONS,
is_tracing=settings.EMSCRIPTEN_TRACING,
memvalidate='memvalidate' in settings.MALLOC,
verbose='verbose' in settings.MALLOC,
Expand Down

0 comments on commit 94ef6a9

Please sign in to comment.