From 7cf0f4b75e5ac5d5f4e6cab0662cd74de07addb5 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 10 Jan 2025 10:47:59 -0800 Subject: [PATCH] Always use `size_t` in dlmalloc's mallinfo 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 #23330. This change was spit out from #23330. --- system/include/compat/malloc.h | 20 ++++++++++---------- system/lib/dlmalloc.c | 1 - 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/system/include/compat/malloc.h b/system/include/compat/malloc.h index 279bec3f1d2dc..80563d0debc1e 100644 --- a/system/include/compat/malloc.h +++ b/system/include/compat/malloc.h @@ -11,16 +11,16 @@ extern "C" { system/lib/dlmalloc.c. */ struct mallinfo { - int arena; /* total space allocated from system */ - int ordblks; /* number of non-inuse chunks */ - int smblks; /* unused -- always zero */ - int hblks; /* number of mmapped regions */ - int hblkhd; /* total space in mmapped regions */ - int usmblks; /* unused -- always zero */ - int fsmblks; /* unused -- always zero */ - int uordblks; /* total allocated space */ - int fordblks; /* total non-inuse space */ - int keepcost; /* top-most, releasable (via malloc_trim) space */ + size_t arena; /* total space allocated from system */ + size_t ordblks; /* number of non-inuse chunks */ + size_t smblks; /* unused -- always zero */ + size_t hblks; /* number of mmapped regions */ + size_t hblkhd; /* total space in mmapped regions */ + size_t usmblks; /* unused -- always zero */ + size_t fsmblks; /* unused -- always zero */ + size_t uordblks; /* total allocated space */ + size_t fordblks; /* total non-inuse space */ + size_t keepcost; /* top-most, releasable (via malloc_trim) space */ }; /* The routines. */ diff --git a/system/lib/dlmalloc.c b/system/lib/dlmalloc.c index 5c4de3fe03c89..7dc91503f1bec 100644 --- a/system/lib/dlmalloc.c +++ b/system/lib/dlmalloc.c @@ -16,7 +16,6 @@ #define ABORT __builtin_unreachable() /* allow malloc stats only in debug builds, which brings in stdio code. */ #define NO_MALLOC_STATS 1 -#define MALLINFO_FIELD_TYPE int #endif /* XXX Emscripten Tracing API. This defines away the code if tracing is disabled. */ #include