From patchwork Tue Aug 19 19:39:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 27 Return-Path: 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=1755632415; bh=xz3MFh7rDZKnDb8PrDzcz2p28GiFnPRtTtrntM4XeSo=; 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=mGzgO4WEkhvkRW+jYDPuM+WHAb3YwJ3N7KxoXviEcF/L4ypdrfH8UYbBQxIK0tcXl nnHl/Fmv/1ID3+BfnM5kUZ0ltb+xNg0Vf65Oy+LxTnD7FG/NCvWIKV8Wqp8D6ir5Ab LlYXt6BC3YaldyFviS7xMA8l6KZrCh/W7ge9B+QZzaLfexQjDz61Aqb3nmSANnKXsf JzS8TBePsCBscWzYdpX6k8HxnK04d+GJ7w6dLIj7lWA2gdDgmPj+t58b+Tdipm9usl 6PtYRFXQRm382CutnyKibHPiLB/dslKcxDZHUZdKtr7buv4H9HrPGdg3/f70wy3A2m Si/vuLYkdwifA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 88B9D67619 for ; Tue, 19 Aug 2025 13:40:15 -0600 (MDT) 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 g5fNoVg9u5l2 for ; Tue, 19 Aug 2025 13:40:15 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755632414; bh=xz3MFh7rDZKnDb8PrDzcz2p28GiFnPRtTtrntM4XeSo=; 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=OEnkC4jOZjIcYu1qem8LE7wl26cXV494ZTMtwf3i+0fTl484ee5He05M1qfMIt9fT rBfzOl8+3tJmtSIuvbGLWH+llP0yCdpd3TXN8viifdAbIJHy1owygUUKTEV+iQWLpn uEqCyAe/RRcCGWihp9Z67MIO99dGcXF0szOPgADQETQ+TkK8WtGsolrJEkaFS88vsX Mu+br36bkf+3n1+9ElBNHkjhLugPZr0iOXzAHpKj7Iv0OoheS0SAWvonpzIKh6WKiE PPvUz5GvJgZTKg+1JFbxgpBuJ3QZ1Ko7W64Ir1rmzJe68tbWQPz5N78zmO/za7s3Ga gfqJan5Bi9FUQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1C4D867624 for ; Tue, 19 Aug 2025 13:40:14 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755632412; bh=lL+WNpqJwRPZaWYO4kfnO6W2HOuf2xec2rNEdJmDHZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uM87/TJ0kmitM6h6MEwnp/9liyZgtsYSjUNVPGCc7zVoOObUnL4FH95kUAMev0An3 Gha3cvTH+10d/NQYUCQmJ6CvxYvTpc7BqKZXzXCylwJ3WmHH+jD3hBysvUi2772N+H stjpMeCJFoXXMQljA+1F8fEXdHdTj7f/4pB2L2z7fWKQVnli1mt6z8IR+1jHql2Xk8 G3wdNHhOxG1v8/scX53A7x3DiZz2xUmdhmqO6m+2Yq1M7GjK3qAFyCJiTZYAGU2qJg Pj/U9/+WcwyaMF9NPSeDneSNiFIzS6Nfx59BRpGUvkObc9mYipPw1E9J9qoopa2NQN BrpzGpFGd3UHQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A67155E436; Tue, 19 Aug 2025 13:40:12 -0600 (MDT) 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 JDniNUrntiUR; Tue, 19 Aug 2025 13:40:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755632412; bh=REFaWQNbZq5opRtvM5tRaifyIJ/XxvWkm0WeNTsCoXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Utd93spKsxFm1qNHx8jEZ7UWX3Nqc8/ljVyinaoRV8lzn2gaovVrPpp3hCviujQvK rkkNqHJG041mwpqeyOaUEQd5Oa3ZFqXIv2nfkp5NCSPDLQ8MvDtFAhY3s0fpK1HzQW M0qWu5BbOS9GmbhVK8fZJqV824MRGsIdruFJtrw5LQ/eCaKjxfzYoO9QWFZQgQnI8o NISlMQD4nzzz3UdgXgOztEPBCiBBll01V6GzWjmakCfV262ZGkvDAGN9rRgjAJFL0V SwnI54JsUZaG+mYvwbzYPjAHTgvbbrOBSM6qytRxZQxJH4hJ69CAdSnd35C1t274M+ ritxRPJXbWAIw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 28035675EE; Tue, 19 Aug 2025 13:40:12 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 19 Aug 2025 13:39:00 -0600 Message-ID: <20250819193918.874215-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250819193918.874215-1-sjg@u-boot.org> References: <20250819193918.874215-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: MLMGPUVX4FL3FLRZQYNF7ENAPYM3BEYB X-Message-ID-Hash: MLMGPUVX4FL3FLRZQYNF7ENAPYM3BEYB 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/15] malloc: Avoid defining calloc() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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. Use the same #define technique as for malloc_simple(), to fix a crash on my machine when running: /tmp/b/sandbox_vpl/tpl/u-boot-tpl -D This does not happen in CI, perhaps because the C runtime uses malloc() instead of calloc(). Signed-off-by: Simon Glass --- common/malloc_simple.c | 2 +- include/malloc.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common/malloc_simple.c b/common/malloc_simple.c index f0f90a095bd..d820ded68c3 100644 --- a/common/malloc_simple.c +++ b/common/malloc_simple.c @@ -65,7 +65,7 @@ void *memalign_simple(size_t align, size_t bytes) } #if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE) -void *calloc(size_t nmemb, size_t elem_size) +void *calloc_simple(size_t nmemb, size_t elem_size) { size_t size = nmemb * elem_size; void *ptr; diff --git a/include/malloc.h b/include/malloc.h index 9e0be482416..728451086aa 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -882,6 +882,7 @@ void malloc_disable_testing(void); #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