From patchwork Mon Dec 1 17:04:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 791 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=1764608929; bh=ZOZiRnfIZ0HStV73r5IflpYj0ocZPcRn4hLqrVTdhSY=; 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=QWzR+QcSKU/ymo3P1Nw5zp0+fs99lir7zITVl0es3sbbHqoY0NO6EJthzqbhgadVd 8BkqvrIx+TBJ/dlRMtqFufJ1CvKNtkclRgWBsRETh/Dp7KMIpTMu97Mk8ogx7GJI4L QJu7D4ZvWlaOBKYLYdR7U/BV6XQaxJSujXA+yAmZgYhy9QTwXA3xjfi12lfGyTaw9N ZjlfBVkMxzC14Y1jJxCG/QBC+WR0ReX6VadyenL4xd93KOETr5HPkGuNgS54DuN2SO XAX7SfMavesYRinLa8gZWOnRLJRhNWqW1hm4k9Uc98nElFRFePJx4TVBe1gbGGg0+c Iw/CLK7tZMQ6A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 556E7688D6 for ; Mon, 1 Dec 2025 10:08:49 -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 PN3R3rNzcBkd for ; Mon, 1 Dec 2025 10:08:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608929; bh=ZOZiRnfIZ0HStV73r5IflpYj0ocZPcRn4hLqrVTdhSY=; 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=QWzR+QcSKU/ymo3P1Nw5zp0+fs99lir7zITVl0es3sbbHqoY0NO6EJthzqbhgadVd 8BkqvrIx+TBJ/dlRMtqFufJ1CvKNtkclRgWBsRETh/Dp7KMIpTMu97Mk8ogx7GJI4L QJu7D4ZvWlaOBKYLYdR7U/BV6XQaxJSujXA+yAmZgYhy9QTwXA3xjfi12lfGyTaw9N ZjlfBVkMxzC14Y1jJxCG/QBC+WR0ReX6VadyenL4xd93KOETr5HPkGuNgS54DuN2SO XAX7SfMavesYRinLa8gZWOnRLJRhNWqW1hm4k9Uc98nElFRFePJx4TVBe1gbGGg0+c Iw/CLK7tZMQ6A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 44B91688A7 for ; Mon, 1 Dec 2025 10:08:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608926; bh=+b1qn01nwRDVTwmubso/nefKcf2f7KfyytDYZH1hnBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vEbR3YI1JAAEPer43u4qiyMxhhDnA05ATcwYd5AKH0BYcWAhx4W+4o03H4GF6apBM SMIkxyw7/DhXtpwG5x3hF0uAbOo10qOdudad7v2iNX7CixMvUku2/jVrwF8jWgpglZ A83WiavZBdS/1EViuXqBZtVo3SUkqITaaYMEMmim6Yhdhyl72q/wpVZDp4QnlYqjx6 +one25G31EDmlcn4KXawnNCUoRLitFE8dRXJVHV7AMjCbMs03frnsz0m5DDqMhL0cu YrItcBFyrjj1mYEuSyvMRbrXHpzmhDvw5fU1nEAVRWYIaeMm012khjyNkN1em3aUeK PJI/g7lUBo+Qw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A886C6888B; Mon, 1 Dec 2025 10:08:46 -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 HnGGme_aJqCv; Mon, 1 Dec 2025 10:08:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608926; bh=7pdNk/YM+ShtGkhu7pabouR14uNJ7EUtopiAzlTKpjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e0juvUcL3+KT2L5WmTLRk7BpDjtQO5G3tNipI3uxq3/heov8EVKDCIf+o9SS0Mfsg oYPKoCpoGiLoQRV2K4UL9fkMIBU/Z8gL5BgSnr9aEgf08OIXqScj5h599xZZrNMGWT uDpFN7m3pZo55AufwLZcmRbaon3LsdEhW5sQzMuDUjs9J50u/h4j0xVW4lC3yVRoTA vX7tynRVHeOgwdJqL8LEXmA5BVo/gbwaal7nr1zEM4PQho37GNi4fvTJ1bnhJKWey6 HHh4uurpXpu/GBiAafJZVjKDwGBTeJ8QIx1NsvKjX4i3Z90UJOUamQHzlgMI0O/MF6 gmwH4TXNdlSNA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id CB1925E439; Mon, 1 Dec 2025 10:08:45 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 1 Dec 2025 10:04:55 -0700 Message-ID: <20251201170529.3237986-17-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: I7EGZ3IO4SBZVC7MTF5E6YQW6IN352Y3 X-Message-ID-Hash: I7EGZ3IO4SBZVC7MTF5E6YQW6IN352Y3 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 , Simon Glass , Rabin Vincent , Stephen Warren , Tom Rini , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 16/37] malloc: use hidden visibility 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 When running sandbox, U-Boot's malloc symbols can be hooked into the GOT before U-Boot code runs. This causes issues because the dynamic linker may call malloc/free before gd is initialized. Use hidden visibility for malloc symbols to prevent them from being hooked into the GOT, so only code in the U-Boot binary itself calls them; any other code calls the standard C library malloc(). Changes from original commit: - Use DLMALLOC_EXPORT mechanism instead of #pragma in malloc.h Cc: Rabin Vincent Signed-off-by: Stephen Warren Reviewed-by: Tom Rini Reviewed-by: Simon Glass Co-developed-by: Claude Signed-off-by: Simon Glass (cherry picked from commit 2f0bcd4de1a5b990e58d12cd0c7f9d7e9248fec4) --- common/dlmalloc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 5a8e463671c..d53cbf2f2e1 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -538,6 +538,15 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP #define DLMALLOC_VERSION 20806 #endif /* DLMALLOC_VERSION */ +/* + * For U-Boot, use hidden visibility to prevent malloc symbols from being + * hooked into the GOT, avoiding issues during early initialization before + * gd is set up. + */ +#ifdef __UBOOT__ +#define DLMALLOC_EXPORT extern __attribute__((visibility("hidden"))) +#endif + #ifndef DLMALLOC_EXPORT #define DLMALLOC_EXPORT extern #endif