Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use debug version of malloc when ASSERTIONS=1. NFC #23330

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jan 7, 2025

Previously we were only using it with ASSERTIONS=2.

The debug version dlmalloc has many very useful checks, including checking for double-free. This is something that is done by glibc malloc even in release builds. It seems reasonable that we should do this basic checking in our debug builds at least.

Required fixing two genuine bugs: One double-free in test code and one invalid free in embind.

Fixes: #23360

@sbc100 sbc100 marked this pull request as draft January 7, 2025 19:19
@sbc100 sbc100 requested review from kripken and dschuff January 8, 2025 20:16
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but please add a changelog mention. some people may be using ASSERTIONS builds in production, and would like to know about this.

@sbc100 sbc100 mentioned this pull request Jan 8, 2025
@sbc100 sbc100 marked this pull request as ready for review January 8, 2025 23:26
@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 8, 2025

Changelog updated.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@sbc100 sbc100 force-pushed the malloc_debug branch 3 times, most recently from 94ef6a9 to c0bf5c9 Compare January 9, 2025 22:13
@sbc100 sbc100 enabled auto-merge (squash) January 9, 2025 22:14
@sbc100 sbc100 disabled auto-merge January 9, 2025 22:27
@sbc100 sbc100 enabled auto-merge (squash) January 9, 2025 22:27
@sbc100 sbc100 force-pushed the malloc_debug branch 2 times, most recently from 79f1dd0 to f940575 Compare January 10, 2025 18:47
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jan 10, 2025
For some reason emscrpiten was overriding MALLINFO_FIELD_TYPE to be int
even though this defaults size_t and size_t is the document type in the
man page, and size_t allows for correct reporting of numbers larger than
2^32.

What is worse the `MALLINFO_FIELD_TYPE` override was only place when
`DLMALLOC_DEBUG` was defined which meant that `MALLINFO_FIELD_TYPE`
varied between `-sASSERTIONS=1` and `-sASSERTIONS=2` builds of dlmalloc.

This means that `-sMEMORY64 + -sASSERTIONS=2` builds of dlmalloc were
simply broken WRT `mallinfo` since the public definition of mallinfo
disagreed with the dlmalloc-internal version.

I verified that the follow tests fails without this change:

EMCC_CFLAGS=-sASSERTIONS=2 ./test/runner wasm64.test_mallinfo

I'm not updating the actual test code here since test coverage will be
coming in emscripten-core#23330.

This change was spit out from emscripten-core#23330.
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jan 10, 2025
For some reason emscrpiten was overriding MALLINFO_FIELD_TYPE to be int
even though this defaults size_t and size_t is the document type in the
man page, and size_t allows for correct reporting of numbers larger than
2^32.

What is worse the `MALLINFO_FIELD_TYPE` override was only place when
`DLMALLOC_DEBUG` was defined which meant that `MALLINFO_FIELD_TYPE`
varied between `-sASSERTIONS=1` and `-sASSERTIONS=2` builds of dlmalloc.

This means that `-sMEMORY64 + -sASSERTIONS=2` builds of dlmalloc were
simply broken WRT `mallinfo` since the public definition of mallinfo
disagreed with the dlmalloc-internal version.

I verified that the follow tests fails without this change:

EMCC_CFLAGS=-sASSERTIONS=2 ./test/runner wasm64.test_mallinfo

I'm not updating the actual test code here since test coverage will be
coming in emscripten-core#23330.

This change was spit out from emscripten-core#23330.
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jan 10, 2025
For some reason emscrpiten was overriding MALLINFO_FIELD_TYPE to be int
even though this defaults size_t and size_t is the document type in the
man page, and size_t allows for correct reporting of numbers larger than
2^32.

What is worse the `MALLINFO_FIELD_TYPE` override was only place when
`DLMALLOC_DEBUG` was defined which meant that `MALLINFO_FIELD_TYPE`
varied between `-sASSERTIONS=1` and `-sASSERTIONS=2` builds of dlmalloc.

This means that `-sMEMORY64 + -sASSERTIONS=2` builds of dlmalloc were
simply broken WRT `mallinfo` since the public definition of mallinfo
disagreed with the dlmalloc-internal version.

I verified that the follow tests fails without this change:

EMCC_CFLAGS=-sASSERTIONS=2 ./test/runner wasm64.test_mallinfo

I'm not updating the actual test code here since test coverage will be
coming in emscripten-core#23330.

This change was spit out from emscripten-core#23330.
sbc100 added a commit to sbc100/emscripten that referenced this pull request Jan 10, 2025
For some reason emscrpiten was overriding MALLINFO_FIELD_TYPE to be int
even though this defaults size_t and size_t is the document type in the
man page, and size_t allows for correct reporting of numbers larger than
2^32.

What is worse the `MALLINFO_FIELD_TYPE` override was only place when
`DLMALLOC_DEBUG` was defined which meant that `MALLINFO_FIELD_TYPE`
varied between `-sASSERTIONS=1` and `-sASSERTIONS=2` builds of dlmalloc.

This means that `-sMEMORY64 + -sASSERTIONS=2` builds of dlmalloc were
simply broken WRT `mallinfo` since the public definition of mallinfo
disagreed with the dlmalloc-internal version.

I verified that the follow tests fails without this change:

EMCC_CFLAGS=-sASSERTIONS=2 ./test/runner wasm64.test_mallinfo

I'm not updating the actual test code here since test coverage will be
coming in emscripten-core#23330.

This change was spit out from emscripten-core#23330.
sbc100 added a commit that referenced this pull request Jan 10, 2025
For some reason emscripten was overriding `MALLINFO_FIELD_TYPE` to be
`int` even though this defaults `size_t` and `size_t` is what linux
uses, and `size_t` allows for correct reporting of numbers larger than
2^32.

What is worse, the `MALLINFO_FIELD_TYPE` override was only applied when
`DLMALLOC_DEBUG` was defined which meant that `MALLINFO_FIELD_TYPE`
varied between `-sASSERTIONS=1` and `-sASSERTIONS=2` builds of dlmalloc!

This means that `-sMEMORY64 + -sASSERTIONS=2` builds of dlmalloc were
simply broken WRT `mallinfo` since the public definition of mallinfo
disagreed with the dlmalloc-internal version.

I verified that the follow tests fails without this change:
`EMCC_CFLAGS=-sASSERTIONS=2 ./test/runner wasm64.test_mallinfo`

I'm not updating the actual test code here since test coverage will be
coming in #23330.

This change was spit out from #23330.
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.

Fixes: emscripten-core#23360
@sbc100 sbc100 merged commit 0265d84 into emscripten-core:main Jan 10, 2025
29 checks passed
@sbc100 sbc100 deleted the malloc_debug branch January 10, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Abort in free in test_embind_strict_js_no_utf8
2 participants