From patchwork Tue Dec 17 09:58:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 103250 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77FBE3858D20 for ; Tue, 17 Dec 2024 10:00:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77FBE3858D20 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Pawtem8W X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 5F76B3858D1E for ; Tue, 17 Dec 2024 09:58:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F76B3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F76B3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734429513; cv=none; b=tzzRRIiP38I7om5ZrIGXy6EDIL1m+u/4xuQqP63shdfb+xI7jOpUhZCWSdTOkGix9pm51EiLICOHvVB88S1Sd+hEXT9/PZw0+0yU5Ln6X4JSo/2rfuXeud8Dhan4EIpeErrcy0n/d8ZcicKLyJg568QdYPD41e8/iPQH3ohdqvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734429513; c=relaxed/simple; bh=GdaGRcPAbtjAixyapce2wpsqh9MFKJltnRMvMyfawGs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MvpB78MMhYbil34aQttbg9E7TkbnVEy5/B5HI0XqT/WME7eAi7/JMSDsNML3d1UX9RitE56uc2fC53n1UdiQNhdh5wPMEScWiA0lMn+ukSeKKTfZj76H07PH2mRDD8A7WXwGxbHGdGf11SyKIDJL+IoTUa0wweg4G62LWwbwx2U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F76B3858D1E Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-3ab37d98dd4so17095995ab.3 for ; Tue, 17 Dec 2024 01:58:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734429512; x=1735034312; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qrBuIyspCRHX11etRHveDanNAT55Rl2dEjuocsUimv8=; b=Pawtem8W/+G0L4dOETlYrfCgp1ekYkWi240jpl/9s2qoArsaqmGyAs7npzBeALz2/C dUEAHurnE23N8+D+hCg/SfM5Mc54rchmpXz+rd3lsBqfuE96mXo3U4P5YiZX60Whr2Zw TD5HSRP9os1Okoo8vvERI1d3V3DekYYZ5QBqsPy8zySo4ZRXs65T1MiYhMSTdigKP7kK WPPxxsu9HKtIuHEqgi/MbHxPs0Ua+5HvQFz3GdVnwTVS1XfmZ+Xqp6sDH9UBaWt6QyKq SCJj2ozO3n4Qzd/8W9QXNj+qQGxL/ENQj7W1btNSfA/Hp8/muIh4ZN2eRzOS1VSq6I1g NR5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734429512; x=1735034312; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qrBuIyspCRHX11etRHveDanNAT55Rl2dEjuocsUimv8=; b=kA35n08LbLo+k762vD7pnBwyxdxYtBW4KllrUeTIHKvSaTiuqmCWoe7aUxQVx6SDvw DDOdKO3dbIUg+k+5UkHd1Q106W++slOA0nOYze8yXZiHCLKVtqSAR53P5jyNk/R1DFAM Ebb8OF9KII1yqPuzIJuWn/O5s4eCGZP7u/vrB2EoP9ykwQ8rTyREHRQLDNxI7eFfse3G a33Dr24dTIoB/XWqbHisxyIo/7Bfga+euRQMq9Dy5ITvSaIQZcTmjXQXsHS2g13zGZaV v/VqYeGbEZ3snEoXr5KzTe7bc29HmfqjirmTGNszl/pENdcU1r/+hWEcTOHBQ4fmBBhI TKvQ== X-Gm-Message-State: AOJu0YzjX06b77qbTRuljy1QGCvBn4J4Fs90FydECIs5hzL1JATQoE6c XKkeUqxlJAHYil5I9fYJklb+KbAv5qfGx2Io70bJbnVjoHKTbSRD X-Gm-Gg: ASbGncs3WsXmK/9xtdfOW23MTjYKmKJHAxFPPLinuOkcXdb9MMLxdRZhInxn2TmREHo OErxPj50E0V/LhMCbjbe023Wua7QAujeV0KTKn2srxSZLuyyVhiZtxSQ91JOhD/WVDIJMNdeZUf k7xBp27G/hGl4tKY7kGxLKyQZGI8D27uVfUfLWL9ScGaiSgIi0hk/WMUEmTL9Drbu0f6jo6pQC6 mlipgfpfzGV954Y8t3IhEBfcMAWROm7dO/st0t+ee3yNwPAc4ON5IgGdDm90jm2vup3VURJ/nc9 xIvwdx1EizqrN2C2wj7/VA+j+9GpRcU9juW8kKb6za6+ X-Google-Smtp-Source: AGHT+IHLcvHwLliIDLdpPAi5P5DjoYoYeFdI8aRHnShvEsNbd/OeMSpZgRcepg2b7VgkAMbqsmWOCA== X-Received: by 2002:a05:6e02:188f:b0:3a7:783d:93d7 with SMTP id e9e14a558f8ab-3afee9a6acfmr143359845ab.4.1734429512553; Tue, 17 Dec 2024 01:58:32 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.160.47]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3b24cf3a711sm20586725ab.63.2024.12.17.01.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 01:58:32 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 63EE3C0188; Tue, 17 Dec 2024 17:58:27 +0800 (CST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: sam@gentoo.org, eggert@cs.ucla.edu, fweimer@redhat.com Subject: [PATCH] Hide all malloc functions from compiler [BZ #32366] Date: Tue, 17 Dec 2024 17:58:26 +0800 Message-ID: <20241217095827.3098710-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3019.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Since -1 isn't a power of two, compiler may reject it, hide memalign from Clang 19 which issues an error: tst-memalign.c:86:31: error: requested alignment is not a power of 2 [-Werror,-Wnon-power-of-two-alignment] 86 | p = memalign (-1, pagesize); | ~~^~~ tst-memalign.c:86:31: error: requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed [-Werror,-Wbuiltin-assume-aligned-alignment] 86 | p = memalign (-1, pagesize); Update tst-malloc-aux.h to hide all malloc functions and include it in all malloc tests to prevent compiler from optimizing out any malloc functions. Tested with Clang 19.1.5 and GCC 15 20241206 for BZ #32366. Signed-off-by: H.J. Lu --- malloc/tst-mallinfo2.c | 2 ++ malloc/tst-malloc-aux.h | 25 ++++++++++++++++++++----- malloc/tst-malloc-backtrace.c | 2 ++ malloc/tst-memalign.c | 2 ++ malloc/tst-safe-linking.c | 2 ++ malloc/tst-valloc.c | 2 ++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/malloc/tst-mallinfo2.c b/malloc/tst-mallinfo2.c index 2c02f5f700..f072b9f24b 100644 --- a/malloc/tst-mallinfo2.c +++ b/malloc/tst-mallinfo2.c @@ -23,6 +23,8 @@ #include #include +#include "tst-malloc-aux.h" + /* This is not specifically needed for the test, but (1) does something to the data so gcc doesn't optimize it away, and (2) may help when developing future tests. */ diff --git a/malloc/tst-malloc-aux.h b/malloc/tst-malloc-aux.h index 54908b4a24..3e1b61ce34 100644 --- a/malloc/tst-malloc-aux.h +++ b/malloc/tst-malloc-aux.h @@ -22,20 +22,35 @@ #include #include - -static void *(*volatile aligned_alloc_indirect)(size_t, size_t) = aligned_alloc; -static void *(*volatile calloc_indirect)(size_t, size_t) = calloc; -static void *(*volatile malloc_indirect)(size_t) = malloc; -static void *(*volatile realloc_indirect)(void*, size_t) = realloc; +#include + +static __typeof (aligned_alloc) * volatile aligned_alloc_indirect + = aligned_alloc; +static __typeof (calloc) * volatile calloc_indirect = calloc; +static __typeof (malloc) * volatile malloc_indirect = malloc; +static __typeof (memalign) * volatile memalign_indirect = memalign; +static __typeof (posix_memalign) * volatile posix_memalign_indirect + = posix_memalign; +static __typeof (pvalloc) * volatile pvalloc_indirect = pvalloc; +static __typeof (realloc) * volatile realloc_indirect = realloc; +static __typeof (valloc) * volatile valloc_indirect = valloc; #undef aligned_alloc #undef calloc #undef malloc +#undef memalign +#undef posix_memalign +#undef pvalloc #undef realloc +#undef valloc #define aligned_alloc aligned_alloc_indirect #define calloc calloc_indirect #define malloc malloc_indirect +#define memalign memalign_indirect +#define posix_memalign posix_memalign_indirect +#define pvalloc pvalloc_indirect #define realloc realloc_indirect +#define valloc valloc_indirect #endif /* TST_MALLOC_AUX_H */ diff --git a/malloc/tst-malloc-backtrace.c b/malloc/tst-malloc-backtrace.c index c7b1d65e5c..65fa91f6fd 100644 --- a/malloc/tst-malloc-backtrace.c +++ b/malloc/tst-malloc-backtrace.c @@ -22,6 +22,8 @@ #include #include +#include "tst-malloc-aux.h" + #define SIZE 4096 /* Wrap free with a function to prevent gcc from optimizing it out. */ diff --git a/malloc/tst-memalign.c b/malloc/tst-memalign.c index 563f6413d2..ac9770d3f9 100644 --- a/malloc/tst-memalign.c +++ b/malloc/tst-memalign.c @@ -23,6 +23,8 @@ #include #include +#include "tst-malloc-aux.h" + static int errors = 0; static void diff --git a/malloc/tst-safe-linking.c b/malloc/tst-safe-linking.c index 5302575ad1..59d45d0da5 100644 --- a/malloc/tst-safe-linking.c +++ b/malloc/tst-safe-linking.c @@ -26,6 +26,8 @@ #include #include +#include "tst-malloc-aux.h" + /* Run CALLBACK and check that the data on standard error equals EXPECTED. */ static void diff --git a/malloc/tst-valloc.c b/malloc/tst-valloc.c index 9bab8c6470..0243d3dfd4 100644 --- a/malloc/tst-valloc.c +++ b/malloc/tst-valloc.c @@ -23,6 +23,8 @@ #include #include +#include "tst-malloc-aux.h" + static int errors = 0; static void