From patchwork Wed May 6 13:07:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 134553 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45B004BA7981 for ; Wed, 6 May 2026 13:09:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45B004BA7981 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=JjoCcu61 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id E7B224BA23EB for ; Wed, 6 May 2026 13:08:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E7B224BA23EB 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 E7B224BA23EB Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2607:f8b0:4864:20::52c ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1778072912; cv=pass; b=fwSKIceJHkpSSz0llIhZy9bYC73YubA0b6Vnet3B3a9eP1m3zrUPxGfaXBcq7ZcFtRwXRIfNFbn3EtucRp2fUYGl7+6jotZw2UlqMVf46fky5z9rwdRywZ5EHsELpuQItp2Ia6xCMo4fF3kV8g+epoA0Iiy9yknzkTiXwICeceM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1778072912; c=relaxed/simple; bh=KEQ4BJSMnAljoeOmTbbQT3z2Jk4RRSg4VoWamZD3Ryc=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=sGSG/A3LBehCu5egv+MKIFQt7eVorlBoG7brsblvDFa7dokME1RwTNQfapWN9UpOnCtHcHFxGEidrjmjA/M1zkcVC812h4gQAsylFnINvAdAsNDU09u7Jg5wwmRU9A3ktkP4+YyxNuXMNYCn/qkIodXUCHP4Gtfi+CYC8DpIX+U= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=JjoCcu61 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E7B224BA23EB Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-c8173b2af32so2428151a12.0 for ; Wed, 06 May 2026 06:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778072906; cv=none; d=google.com; s=arc-20240605; b=GBP7IFKCEAok8kVtNyajzqLKonkDmJCJVh9eCoI9+2NpcOnpa4S5LCLJAedJF9C65k t4v2OHSqd/bbMdGFFIhT0OmFjWsMoBDldz6GeZN0hjwTCh3JCILNO18fWMR4w/10ElGE lhb6smR2Yt4m8xm/Ul8QmU6iauC+yUaMPxs/lIs0FK9n1YrY6BUQYO66C/ippyVYrYXg dtgf/TmlHFFfGCvgKW5gGI3ZvgiLNoGcTdM2negj099frWEzDSAnFBUV3sdv8UQJtAai y+CluYcMR3DqhNyAGGIWAjNxkiFp8bTNSxFj9P2nBDtMQszrRrnRl0qMqqwXo+P0Y36q vZQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=K2L1A5mlzueppaW5nfvVm1pVn5UsarC/gbR5revgVhI=; fh=LUDT81Bpby9izX7VDpMqAlHXFbdvQgwv/nCVd4r3QqQ=; b=irpt0LnJpeTijA01jmS77l8Q/h9bqjsj3zkogLUUrGCL5cWbe2dQgAkWasNyQ89+p4 29xaMA7ZoIKqV9ebduYBxRI4Ezic26DiofIZSCtc65R5gp2XXIHv6Rng2418t/KI0lns GMHjVXz5aBTnZKBGginql4ZDhCU3QkZvk4mVgXWEOFf2t1UPCnpabMxRP6AHq/HALgTt 6exZazgNhsXJBjflVoV3pyfm9MRw4HJmcj1vWdOvD+boNb26jOFjq1e6aej6JJYIPVWj aX6Yx73UEEpwU0VY6MxzSKs1U83Bo/GJ+UJ3LONhOKPr4gGUQmRjuaROepoWCV5v1kze FzJQ==; darn=gcc.gnu.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778072906; x=1778677706; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=K2L1A5mlzueppaW5nfvVm1pVn5UsarC/gbR5revgVhI=; b=JjoCcu61q9fVOmQ6XX7lEFx+Pt8IF7bORroE9zXKtyC63rm3nwJ9sMDYJ2/C2Hq2BG fHb1qSAI4DOZi31hjd4EeIl68PH+7JyUJ6gbm2ypYjfPt9pRT8+EdgEJ/a6CReJ+p8cL tSvyyftQrwCqrFIRbhHbF83f6kCU+zAQKtHZVK5BK1ogAGstiyIOQwciNwqWx84aRHPO qQU1Xf9Z+SZQZpoOsMLg/pULJRvIjbVN/ja5/E6tSJ0V4JzzUZSJCvLBhL+oPhDEajt9 SICS4BfL9qGTg5YMAj5ke5zUFTcpJQ0DteIKC1bc5qHwnKa2T1JFfXNtKSsixq5UJB0B jaGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778072906; x=1778677706; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=K2L1A5mlzueppaW5nfvVm1pVn5UsarC/gbR5revgVhI=; b=bUYjRaWbrgdYOoiihnVyi9NZHyDHgT28ZKkjB/jfVISfiy9S0aaTzc9Tt9oAzkAV1S 7arHDW0EwtR1MB7n2ycPOO88DNsXk+nYEZvJ+462TUnoBKccM3yRRESIc8Q8VgW0UW7u mrvGUUv7MSu0EYwQvP3ppMLaIu2kupXaAisUd96UMsxanMVJxWu2LDj/Y9vwazDTVL9y PP2Ohe9QL+IYfdil4GfpGIcjnSUkGyLQs2s95LRdnfpP3fWpYTsoBycP/KFFp2/MejpE Pz7XN5vvGn69At11TWT6U5uzP1kL64WACKrkhcCGNpXjLZdUUTsjzhFdqoBXe4669aJ1 aPdw== X-Forwarded-Encrypted: i=1; AFNElJ+zUZcU5HumLRANprXtVaV558g9RPFqYeEcjWmxqtjUgoffVybKEh9xbnWuH7KqvK/cZaiEKxYuSH4sTg==@gcc.gnu.org X-Gm-Message-State: AOJu0YzMOaXUcPn4pIsK5FFAepW3jgeB23tksbAwCWRd31hMuFw3ULCL huyPlL7RtAOAeOT2v8EjcsyepvexFZZQcYtLRGZCLigyEG+HDtqseiN9wgRBHgG7qEFb4PzqadU XjDISot1fDYItBvlTHD/YkfMDTg8ES0Q= X-Gm-Gg: AeBDievTa+1NMfjLir6VSU/auQS1w7RtUn4Mg7UsHIPgmlAjH0WD8IAmdfYCw2qS+1t ru1M+c/mgUou+GxxU1a7vPGtf7INOWJGREUSNk7fS0KaPIO3gR+Tj3iF40tgjn1z0Pq8pRwi8W+ +VHVkTLLHi4839uqwArLAs/36kwIIEqXjszgEPVXTuvzapCJWIodlNw7buUWcUipymNb6goaZmz n20jOCQbHtBnMmqvPMZilzL9OgYWNjfhv1J0VgHmx4Li7ge0Jxu8eRhf5m0XHi1pp62vExbTxdm ebuUnfcYrjNX58v/ X-Received: by 2002:a05:6a20:5493:b0:39b:d937:8010 with SMTP id adf61e73a8af0-3aa5ac011e5mr3588730637.45.1778072905764; Wed, 06 May 2026 06:08:25 -0700 (PDT) MIME-Version: 1.0 References: <276174b0-549b-4adb-a0d9-78254e4dd11f@redhat.com> <3b43cbac3ac8d0ceae2285edf1d498c208c83188.camel@klomp.org> <23f95ef2ce6aa018fa2cf5af4dd76a7be2640fec.camel@klomp.org> In-Reply-To: From: "H.J. Lu" Date: Wed, 6 May 2026 21:07:47 +0800 X-Gm-Features: AVHnY4Iz7zPy30LNXDA71GS4jImbnrliIIPYjGyd5W0UZl6tBAXnxwhhNvazINg Message-ID: Subject: [PATCH] c: Don't warn the builtin declaration of stack protection guard To: Iain Sandoe Cc: Jakub Jelinek , Andrew Pinski , Mark Wielaard , GCC Patches , Florian Weimer , Jason Merrill , Joseph Myers , Stefan Schulze Frielinghaus , Rainer Orth X-Spam-Status: No, score=-3010.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org On Wed, May 6, 2026 at 2:00 PM Iain Sandoe wrote: > > Hi H.J. > > How was your original patch actually tested? I tested it on Linux. Since -mstack-protector-guard=global isn't the default, gcc.dg/Wnested-externs-1.c doesn't fail on Linux. > It seems that it makes changes that affect all the sub-ports of X86. > > > On 6 May 2026, at 04:15, Rainer Orth wrote: > > > > Hi H.J., > >> On Wed, May 6, 2026 at 6:05 AM Jakub Jelinek wrote: > >>> > >>> On Tue, May 05, 2026 at 11:20:34PM +0200, Jakub Jelinek wrote: > >>>> On Tue, May 05, 2026 at 02:15:54PM -0700, Andrew Pinski wrote: > >>>>>> If __stack_chk_guard is user provided, it needs to be changed to uintptr_t. > >>>> > >>>>>> commit c05b5e5d8cb660ed43159d66fd669c20746d6bea > >>>>>> Author: H.J. Lu > >>>>>> Date: Fri Sep 12 18:52:39 2025 -0700 > >>>>>> > >>>>>> c/c++: Declare stack protection guard as a global symbol > >>>>>> > >>>>>> declared __stack_chk_guard as uintptr_t if it is an internal global > >>>>>> symbol. Change __stack_chk_guard in libssp to match the internal > >>>>>> symbol type. > >>>>>> > >>>>>> PR c/121911 > >>>>>> * ssp.c: Include . Change __stack_chk_guard to > >>>>>> uintptr_t. > >>>>> > >>>>> Ok. > >>>> > >>>> This looks wrong to me. > >>>> __stack_chk_guard is void * on all targets but x86 and on it only in case of > >>>> one command line option. > >>>> So, this change would break all targets but some x86 cases? > >>>> > >>>> if (targetm.stack_protect_guard_symbol_p ()) > >>>> t = lang_hooks.types.type_for_mode (ptr_mode, 1); > >>>> else > >>>> t = ptr_type_node; > >>>> t = build_decl (UNKNOWN_LOCATION, > >>>> VAR_DECL, get_identifier ("__stack_chk_guard"), t); > >>>> > >>>> Why was this even changed when GCC 15 always used void *? > >>> > >>> Not to mention that lang_hooks.types.type_for_mode (ptr_mode, 1) > >>> is not really uintptr_t. > >>> It is the first of unsigned int, unsigned char, unsigned short, unsigned > >>> long, unsigned long long, unsigned __intXX which has the same mode > >>> as pointer. > >>> While uintptr_t is whatever type the target/ABI decided to be that type, > >>> of course C mandates that it effectively has at least the precision of a > >>> pointer, but which of the types with the same precision it is or if it isn't > >>> some larger type can vary. > >>> > >> > >> Since __stack_chk_guard is defined in C, maybe C++, we only need > >> lang_hooks.types.type_for_mode to return uintptr_t in cc1 or cc1plus. > >> What should be passed to ang_hooks.types.type_for_mode to get > >> uintptr_t? > > > > while your patch fixes Solaris/x86 bootstrap, it introduces a new > > failures and two regressions: > > > > +FAIL: g++.target/i386/ssp-global-hidden-3.C -std=gnu++20 (test for excess errors) > > +UNRESOLVED: g++.target/i386/ssp-global-hidden-3.C -std=gnu++20 compilation failed to produce executable > > > > 32-bit only with Solaris ld (gld build still running), same with gnu++26 > > and gnu++98: > > > > Excess errors: > > Undefined first referenced > > symbol in file > > __stack_chk_fail_local ./ssp-global-hidden-3.o (symbol scope specifies local binding) > > > > +FAIL: gcc.target/i386/ssp-global-hidden-3.c (test for excess errors) > > +UNRESOLVED: gcc.target/i386/ssp-global-hidden-3.c compilation failed to produce executable > > > > Same. > > > > +FAIL: gcc.dg/Wnested-externs-1.c (test for excess errors) > > +FAIL: gcc.dg/Wnested-externs-2.c (test for excess errors) > > > > Excess errors: > > cc1: warning: nested extern declaration of '__stack_chk_guard' [-Wnested-externs] > > These also failed on my overnight test of r17-344-g2dde6c91d0f0 on x86_64-darwin (64b) with: > > FAIL: gcc.dg/Wnested-externs-1.c (test for excess errors) > Excess errors: > cc1: warning: nested extern declaration of '__stack_chk_guard' [-Wnested-externs] > __stack_chk_guard is the builtin declaration of stack protection guard. Since its DECL_CONTEXT is set to current_function_decl, -Wnested-externs warns: cc1: warning: nested extern declaration of '__stack_chk_guard' [-Wnested-externs] Update pushdecl not to warn it. gcc/ PR c/121911 * c/c-decl.cc (pushdecl): Don't warn the builtin declaration of stack protection guard. gcc/testsuite/ PR c/121911 * gcc.dg/Wnested-externs-1.c: Add -mstack-protector-guard=global for x86. From 33bf7d81b77f37e7681d280949f25d0c1e11c928 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 6 May 2026 20:58:47 +0800 Subject: [PATCH] c: Don't warn the builtin declaration of stack protection guard __stack_chk_guard is the builtin declaration of stack protection guard. Since its DECL_CONTEXT is set to current_function_decl, -Wnested-externs warns: cc1: warning: nested extern declaration of '__stack_chk_guard' [-Wnested-externs] Update pushdecl not to warn it. gcc/ PR c/121911 * c/c-decl.cc (pushdecl): Don't warn the builtin declaration of stack protection guard. gcc/testsuite/ PR c/121911 * gcc.dg/Wnested-externs-1.c: Add -mstack-protector-guard=global for x86. Signed-off-by: H.J. Lu --- gcc/c/c-decl.cc | 5 ++++- gcc/testsuite/gcc.dg/Wnested-externs-1.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index cc07e05e336..a4f13dd26fe 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -3551,8 +3551,11 @@ pushdecl (tree x) visdecl = b->decl; vistype = TREE_TYPE (visdecl); } + /* Don't warn the builtin declaration of stack protection guard. */ if (scope != file_scope - && !DECL_IN_SYSTEM_HEADER (x)) + && !DECL_IN_SYSTEM_HEADER (x) + && (!targetm.stack_protect_guard_symbol_p () + || x != targetm.stack_protect_guard ())) warning_at (locus, OPT_Wnested_externs, "nested extern declaration of %qD", x); diff --git a/gcc/testsuite/gcc.dg/Wnested-externs-1.c b/gcc/testsuite/gcc.dg/Wnested-externs-1.c index 5c4b5ddd8e2..a93c6f6006a 100644 --- a/gcc/testsuite/gcc.dg/Wnested-externs-1.c +++ b/gcc/testsuite/gcc.dg/Wnested-externs-1.c @@ -2,6 +2,7 @@ /* Origin: Joseph Myers */ /* { dg-do compile } */ /* { dg-options "-Wnested-externs" } */ +/* { dg-additional-options "-mstack-protector-guard=global" { target x86_64-*-* i?86-*-* } } */ int a; static int b; -- 2.54.0