From patchwork Tue Dec 17 10:41:45 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: 103256 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 DFCC93858C48 for ; Tue, 17 Dec 2024 10:42:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFCC93858C48 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=CPX+f+/Y X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id D51F33858D26 for ; Tue, 17 Dec 2024 10:41:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D51F33858D26 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 D51F33858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734432112; cv=none; b=Wehdwb1qq6VNAAZ0r+r2EKq2RTPsj6xwowVRuBar/8XxqZ24Gq695vgQdPwbcJWtni4rI80NPn08s719hWqSIvw99xbPX4OvKPx5hU+S2Yi2gC0qWGT73XcqiY1UAsVbXFsjE/GJ4NhjtspKq6XAAezCYFrkAN84UfzZNYcRkZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734432112; c=relaxed/simple; bh=yvNT8QN33FIHxjIJsaXncmfTqhhEnfkWWYM3wGKotFY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NU/1A+vHVoh2yIngfrfLL9qsx/bdUVI9jVtMZ2myAdKX9H+fVY612ZvrxrC92YJcr/v5MPyyxgdOPH5xW4w9rYvHJ/XWE9xfChiE2vIqM1Umrx6pB9y1pUq8N9mNCI0rvMj4nnLU+A/T9ZelDc9tF3hrp/Jh+oVR3jKgLRsaPZ0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D51F33858D26 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3ad272538e8so17057645ab.1 for ; Tue, 17 Dec 2024 02:41:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734432111; x=1735036911; 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=Ypq+ZKEzcdNHK4oRtuRHX2Nbk11JcJ6dT9+EUF92ZQ8=; b=CPX+f+/YC9yZCKjWtsbfrv7xAvrl03U4xK47jafyQFyyzdRM7VOqnfBbtOHEDobq9G eonkW2IFny3PMaVHCLdABcfKRsRLHdG22JbpvKMeUm3nbkrmosKpmDzytFN1NwsRpWAI Px9oRA7AuVCZjJ4L1diQtoARpgVYCvhsfKUONRRvE61G7j/x1m4vZeZZiNjj4j7JMOhg GE/4KyonU45jE1QXjgD7BXbbKQLM3+oqNMNoDEkk1cGe+YPnUoAXtTzdRdbAEHaDdnaL lL5kGxEJXS7Pew+/k42mBM7uxu3etRGPmFGoJwVGt5cKA6w4imp+GfVGHEohaC12z4mA SNGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734432111; x=1735036911; 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=Ypq+ZKEzcdNHK4oRtuRHX2Nbk11JcJ6dT9+EUF92ZQ8=; b=G8FU9/jhbp7BXGfwW2KsfS5P58bvxsmpCl41R5yM4WxERJKn/zsJOBftAjbXmyjqPa +MrYCGYrPjWFu2u3+4/4i97ThfspZvAMTjiuXIbXQ2dKXV1qmK29Vhp8aDCvF7E7jeVI dcWls86xQLogT+Y9a98mK6H0H5SatavjqixBQAQ6yx1nIrqq4dkeFY8Q1gi3ymRP7e5K /z7rxPWIMrAsjAoKbiZC4qZdoIBUlBLx3oBEKXuObAtiw+tuPQrpqGhnLASuybTSqk6v mLdgOWkcRQmBfttqLjlrzxDFjtOHjK2CgpqNgkHH5LPpLRuGQQZHUZuWP7Dut76KfvXr PRpg== X-Gm-Message-State: AOJu0Yw+sub3n6Qh5WBBTRBUJuBjHgfAGuItefnnmpgPiVHcl5yqFU4/ uX2BLL1caMUeu20pTrjNX8GCnU8/KQquqC4cx/BvoP+e6qSkqPsm X-Gm-Gg: ASbGnctGmaD2Gg4PLmMF8k4OUZMycUdfyo9r8RY+7slmsqWpGDFg8ifBoCM2iwO02YZ HDZNbWMmAygY7CUISFrNpo9KneQJy5a5aLOVjRm/V0neG/1cRX/561zb5LTrUeGTQdzq4HFe7d8 ECIyGVIe0hae55GHDs/ykbRPLXSK4s7bIcFY+idj8YgMf2uLgBv/6QoVSAVGHqAVrr0Pwltaz8s SNQHMtb0Vqa6EkWHL27zgOoSZ7SNTafhLo9fbMLFmGcyjaxLsoPmOtw4yqKsPog6Wr+0FWt0op4 Zr4od+0pTtMxp0bzcv/4RyfoOqIEIhewIas0PQYjMS9O X-Google-Smtp-Source: AGHT+IFcfpJaf3wokaz1YeFvm6A8o7nOKcck6dHiUKiNNiuEaoBw9OvhtrTS2TXdmf4SaM5nJ4UGKA== X-Received: by 2002:a05:6e02:18ca:b0:3a9:d0e6:abf2 with SMTP id e9e14a558f8ab-3bb0ac12780mr31900985ab.10.1734432110994; Tue, 17 Dec 2024 02:41:50 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.160.47]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e5e03685cdsm1606626173.4.2024.12.17.02.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 02:41:50 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 329F7C0231; Tue, 17 Dec 2024 18:41:45 +0800 (CST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: sam@gentoo.org, eggert@cs.ucla.edu, fweimer@redhat.com Subject: [PATCH v3] Hide all malloc functions from compiler [BZ #32366] Date: Tue, 17 Dec 2024 18:41:45 +0800 Message-ID: <20241217104145.3385106-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