| Message ID | 20251201170529.3237986-28-sjg@u-boot.org |
|---|---|
| State | New |
| Headers |
Return-Path: <concept-bounces+u-boot-concept=u-boot.org@u-boot.org> X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608967; bh=za2AztBM4P+VoZ5S35IkM4NqMANyQzpspXMPE7tCt30=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=nKsX5Xv8up+8GP8Cpp8w5YBMCRyhxVspCRgOED5kOMQaeELcfs0kZ2sOOvJE96Bbf PMnVqJz5uajotp10E6NhhV8U3WWi7fQS+PtVfHBqJBV4sPCZkzqGrdR3i9+bSPfC3+ uVNK3zEcL1y3sTl9GMP/1Sno/1n5BL5QYWnncEBEpMmMD7DFsA3Vy2OS+7mln/2svR 9Z2CuaB6Xmo0ySE7JAcle/CEZmKfp4JeFU+rXXI9GQJw5//Y/m/2zgc65AUIUUlnyO w6tMQQ9z+fSXK6TnwMKzvJWdHjh6Tt1XwN06cSP7bwS24EfxYhPYM7zwvrpmOWoJ8r WxjwJJ99cYTDw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8D9966888B for <u-boot-concept@u-boot.org>; Mon, 1 Dec 2025 10:09:27 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id rxAf95pVnojk for <u-boot-concept@u-boot.org>; Mon, 1 Dec 2025 10:09:27 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608967; bh=za2AztBM4P+VoZ5S35IkM4NqMANyQzpspXMPE7tCt30=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=nKsX5Xv8up+8GP8Cpp8w5YBMCRyhxVspCRgOED5kOMQaeELcfs0kZ2sOOvJE96Bbf PMnVqJz5uajotp10E6NhhV8U3WWi7fQS+PtVfHBqJBV4sPCZkzqGrdR3i9+bSPfC3+ uVNK3zEcL1y3sTl9GMP/1Sno/1n5BL5QYWnncEBEpMmMD7DFsA3Vy2OS+7mln/2svR 9Z2CuaB6Xmo0ySE7JAcle/CEZmKfp4JeFU+rXXI9GQJw5//Y/m/2zgc65AUIUUlnyO w6tMQQ9z+fSXK6TnwMKzvJWdHjh6Tt1XwN06cSP7bwS24EfxYhPYM7zwvrpmOWoJ8r WxjwJJ99cYTDw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7CD0A688AE for <u-boot-concept@u-boot.org>; Mon, 1 Dec 2025 10:09:27 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608966; bh=UqEKmVMzV6+k06xedV5KaylljB/43yuNiBBm9vgD2/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qGVbQ876QEbdXF0o0wwHl2Da8j3FEehu6vpyAOxtY26lXEAbMfZpVWcZjKao3/xSL 2R1M2cXaAbkEu8u+2JBUnAnmLSDljriiKFB+mZlFcFrfIm1RtDMcorDSDsMubkZ6nA tswzBM/YWni3SWx0FIx8c3aPG/Qb+IdCbvuT44yqVMUM6+DrAIdQcM61kThy24k6dx pLPOJveHu+idlq8hT9Vt6GtRvOXzi4bVA/DwXdDTEepEpPFv3Ro6KaHTWym5FoG9wg hdbBmmbEUATZB8QIc6poW29l1RGOJ1qupQ4jKxPxR7QFB8YWy9uobdTI/ubsWnwY1F uU77gYg83nm/A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4C7CF687F3; Mon, 1 Dec 2025 10:09:26 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id nXsZIqkb8__h; Mon, 1 Dec 2025 10:09:26 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608959; bh=5cEwtQnj/+SW/L5Z9sEk6aeLNuePHmvfVkJVB9xydGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G6ZOb2VoV9RRX1KW7CMnjbF1nNjqNnITPi9mxW0dRVJNXOw5dslH+SLWy7/QMT1dI VQYjOW4FHa70oJ7JKFduZJPIvagY6kOGctMiiMLpkAz+vG8pkXpi3kdXKWXkMBJKpl BaXPswoUvXvOoN/j4MQJz0cK4pdcZamnk7HWPDFhBTkC22KKvNpCT55Z4s78A+iEEi 9CK9ZQTB6lMmckaTRrSaUlsAkSXSbE75FMukwsgp/FFf1ynQJhALj8ShehixZ+olLF /kyW1UwEfEnYu+R3PWL5lNXK6yKYg8Q+TC4HX8F7etYcvWSrgtWmRbgc+yTm9xczBI 3pWqxkWyJMhxw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4A5346888B; Mon, 1 Dec 2025 10:09:19 -0700 (MST) From: Simon Glass <sjg@u-boot.org> To: U-Boot Concept <concept@u-boot.org> Date: Mon, 1 Dec 2025 10:05:06 -0700 Message-ID: <20251201170529.3237986-28-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251201170529.3237986-1-sjg@u-boot.org> References: <20251201170529.3237986-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: P7YRUJTEI7ODKLCUPBHVRAOFOVKNV2TW X-Message-ID-Hash: P7YRUJTEI7ODKLCUPBHVRAOFOVKNV2TW X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt <xypron.glpk@gmx.de>, Simon Glass <simon.glass@canonical.com>, Simon Glass <sjg@chromium.org>, Claude <noreply@anthropic.com> X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 27/37] malloc: Avoid defining calloc() List-Id: Discussion and patches related to U-Boot Concept <concept.u-boot.org> Archived-At: <https://lists.u-boot.org/archives/list/concept@u-boot.org/message/P7YRUJTEI7ODKLCUPBHVRAOFOVKNV2TW/> List-Archive: <https://lists.u-boot.org/archives/list/concept@u-boot.org/> List-Help: <mailto:concept-request@u-boot.org?subject=help> List-Owner: <mailto:concept-owner@u-boot.org> List-Post: <mailto:concept@u-boot.org> List-Subscribe: <mailto:concept-join@u-boot.org> List-Unsubscribe: <mailto:concept-leave@u-boot.org> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit |
| Series |
malloc: Import dlmalloc 2.8.6
|
|
Commit Message
Simon Glass
Dec. 1, 2025, 5:05 p.m. UTC
From: Simon Glass <simon.glass@canonical.com> The C runtime calls malloc() before starting main(), e.g. to get some memory to use for dynamic linking. If CONFIG_TPL_SYS_MALLOC_SIMPLE is enabled, the calloc() symbol is defined within U-Boot. The C runtime may call that too. Add the SYS_MALLOC_SIMPLE section to the new malloc.h header to redirect malloc, realloc, calloc, and memalign to their simple implementations when SYS_MALLOC_SIMPLE is enabled. Add a COMPILING_DLMALLOC guard so that dlmalloc.c can include malloc.h without hitting the SYS_MALLOC_SIMPLE redirects, which would otherwise cause conflicts with the dlfree/free macro definitions. Changes from original commit: - Applied to new dlmalloc 2.8.6 malloc.h header structure Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> (cherry picked from commit 22f87ef53045c19df9a770c4101ed3ba744c1b35) --- include/malloc.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/include/malloc.h b/include/malloc.h index 72db7fdb507..f8f0dbb9b70 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -68,6 +68,24 @@ extern "C" { #define USE_DL_PREFIX #endif +/* + * When using simple malloc (SPL/TPL), redirect to simple implementations. + * Skip this when compiling dlmalloc.c itself to avoid conflicts. + */ +#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE) +#define malloc malloc_simple +#define realloc realloc_simple +#define calloc calloc_simple +#define memalign memalign_simple +#if IS_ENABLED(CONFIG_VALGRIND) +#define free free_simple +#else +static inline void free(void *ptr) {} +#endif +void *calloc(size_t nmemb, size_t size); +void *realloc_simple(void *ptr, size_t size); +#else /* !SYS_MALLOC_SIMPLE || COMPILING_DLMALLOC */ + #ifndef USE_DL_PREFIX #define dlcalloc calloc #define dlfree free @@ -106,6 +124,7 @@ extern "C" { #define malloc_stats() dlmalloc_stats() #define malloc_usable_size(p) dlmalloc_usable_size(p) #endif /* USE_DL_PREFIX */ +#endif /* !SYS_MALLOC_SIMPLE || COMPILING_DLMALLOC */ #if !NO_MALLINFO #ifndef HAVE_USR_INCLUDE_MALLOC_H