From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 144723858D34 for ; Fri, 5 Apr 2024 18:37:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 144723858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 144723858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712342234; cv=none; b=juGp/DG64joxTEFIRH1+RxGvBh8WA1fGsaNpH/lDfwv6LadXfWJwyHVgKPXUIM5pqtTFfiG6lEKKHHyfRUhRd5s7wONOh4DKbyTQBaoKYQvduL6IwhwY+dUMFTPavV5YYS/LxVBerQ/3KiOEceugaVI+euBwjbWpAJnm2lp43Qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712342234; c=relaxed/simple; bh=9gbinTtiSKbbVokYfjuFvtrOsIj+w30nBwMM5c2JFdU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=pkllt01g7SGcSGzH0qzQp9ESaUHlvERKzsD3yR+eFc+RSJV40+ncpKUsoIIhDzMxpVgkj6xIXlEGE7UjMLqbRyCQ+MMKf+uiC69Oskoy6DXVWe+sHwt0JhoE/sTX6v3/fYDr+iSM/ix/StHoxJYCeJKslE5qf/pnIGGinBXsXA0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712342232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Gxzz7EA8u3bfqodH1z7DDlsdDxY2LeP2ErRUEouoN0E=; b=TTCsKJzR7SFXnN1QrmflPvrl44r+enmxOC6+QE+VH0HvLZ7t7BG+1lUsnPC4zFo0pgoH/R XeB00MZ7mLGd3WgCWQMHtdahy/aHN93Ado+YBXAhQAvnN/crb0VjDy9p+fdYxDi8b15VMo CI3YiXnUT2FHQc62mqeYTEzJlhg69ak= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-ixh0psrCPSywe_dTqBajww-1; Fri, 05 Apr 2024 14:37:11 -0400 X-MC-Unique: ixh0psrCPSywe_dTqBajww-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-430b327e703so22110431cf.3 for ; Fri, 05 Apr 2024 11:37:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712342230; x=1712947030; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gxzz7EA8u3bfqodH1z7DDlsdDxY2LeP2ErRUEouoN0E=; b=bllQvuZ0xjN/NlVfSrxmh6V4PNxRtEyVndAf2nONpr2OoGK83RY7ZfbXt/CTmpWqjz N/FQUU5SEO6aF5Ty6AbkQ18xYF74dnrm5npdEDvorBmUQlGBYQlqr9RTdmODlXz+kXJk PS9dEJ9H2lUcv2jjmIl2rtF0CmmNf0+PuDhhyn4d0dQk2pEwmPv8PpoSzvJoJlWW+7px MBtCs8iWZwX490sCvcLDa60DpENDcnv7YqWvu6ArWkd7Weu9CzO0FqtmyJEBiTeRuDaD IadggTrTZR6kjRzUWf5NYcKApH0A3ndb6S5k2SO66alfmOErj2+tPQuEj0Ov0pK6ys76 1fqQ== X-Gm-Message-State: AOJu0YwVddBi/MV3reZ8zvIamZwEKH/M8qcokHzqybUzVgryi273WEHJ rxZaNyytAkr/iySOi0tTGaP8l7osKLm/TrClwD7fxwWuJ/qRs+jZohlGx8HhlU28SP1HKZwoUel /ZEgVgduJUtHmmafYmA5ewLwDVglfeifsfSliVW/ZHWibhUAr/mX1ff0= X-Received: by 2002:a05:622a:15ca:b0:434:66fe:f4ff with SMTP id d10-20020a05622a15ca00b0043466fef4ffmr1767759qty.49.1712342230616; Fri, 05 Apr 2024 11:37:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7NLyKwChSp+bRI7DO6M/3+FRnemwSzLBRrSfLkd5ieOCOrFGvGKCm49SOsBrfuevpHn7I0w== X-Received: by 2002:a05:622a:15ca:b0:434:66fe:f4ff with SMTP id d10-20020a05622a15ca00b0043466fef4ffmr1767739qty.49.1712342230255; Fri, 05 Apr 2024 11:37:10 -0700 (PDT) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id ev7-20020a05622a510700b00434518af495sm984380qtb.8.2024.04.05.11.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 11:37:09 -0700 (PDT) Date: Fri, 5 Apr 2024 14:37:08 -0400 From: Marek Polacek To: Jakub Jelinek Cc: GCC Patches Subject: [PATCH v2] target: missing -Whardened with -fcf-protection=none [PR114606] Message-ID: References: <20240405182218.55288-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Fri, Apr 05, 2024 at 08:28:08PM +0200, Jakub Jelinek wrote: > On Fri, Apr 05, 2024 at 02:22:18PM -0400, Marek Polacek wrote: > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > -- >8 -- > > -Whardened warns when -fhardened couldn't enable a hardening option > > because that option was disabled on the command line, e.g.: > > > > $ ./cc1plus -quiet g.C -fhardened -O2 -fstack-protector > > cc1plus: warning: '-fstack-protector-strong' is not enabled by '-fhardened' because it was specified on the command line [-Whardened] > > > > but it doesn't work as expected with -fcf-protection=none: > > > > $ ./cc1plus -quiet g.C -fhardened -O2 -fcf-protection=none > > > > because we're checking == CF_NONE which doesn't distinguish between nothing > > and -fcf-protection=none. I should have used OPTION_SET_P, like below. > > > > PR target/114606 > > > > gcc/ChangeLog: > > > > * config/i386/i386-options.cc (ix86_option_override_internal): Use > > OPTION_SET_P rather than checking == CF_NONE. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.target/i386/fhardened-1.c: New test. > > * gcc.target/i386/fhardened-2.c: New test. > > --- > > gcc/config/i386/i386-options.cc | 2 +- > > gcc/testsuite/gcc.target/i386/fhardened-1.c | 8 ++++++++ > > gcc/testsuite/gcc.target/i386/fhardened-2.c | 8 ++++++++ > > 3 files changed, 17 insertions(+), 1 deletion(-) > > create mode 100644 gcc/testsuite/gcc.target/i386/fhardened-1.c > > create mode 100644 gcc/testsuite/gcc.target/i386/fhardened-2.c > > > > diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc > > index 7896d576977..20c6dc48090 100644 > > --- a/gcc/config/i386/i386-options.cc > > +++ b/gcc/config/i386/i386-options.cc > > @@ -3242,7 +3242,7 @@ ix86_option_override_internal (bool main_args_p, > > on the command line. */ > > if (opts->x_flag_hardened && cf_okay_p) > > { > > - if (opts->x_flag_cf_protection == CF_NONE) > > + if (!OPTION_SET_P (flag_cf_protection)) > > This function is passed explicit opts and opts_set arguments, so it > shouldn't be using flag_something macros nor OPTION_SET_P, as the former > use global_options.x_flag_something rather than opts->x_flag_something > and the latter uses global_options_set.x_flag_something. Ah right, so the other uses of OPTION_SET_P in ix86_option_override_internal are also wrong? > So, I think you want to use if (!opts_set->x_flag_cf_protection) > instead. Fixed below, thanks. New tests passed on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- -Whardened warns when -fhardened couldn't enable a hardening option because that option was disabled on the command line, e.g.: $ ./cc1plus -quiet g.C -fhardened -O2 -fstack-protector cc1plus: warning: '-fstack-protector-strong' is not enabled by '-fhardened' because it was specified on the command line [-Whardened] but it doesn't work as expected with -fcf-protection=none: $ ./cc1plus -quiet g.C -fhardened -O2 -fcf-protection=none because we're checking == CF_NONE which doesn't distinguish between nothing and -fcf-protection=none. I should have used opts_set, like below. PR target/114606 gcc/ChangeLog: * config/i386/i386-options.cc (ix86_option_override_internal): Use opts_set rather than checking == CF_NONE. gcc/testsuite/ChangeLog: * gcc.target/i386/fhardened-1.c: New test. * gcc.target/i386/fhardened-2.c: New test. --- gcc/config/i386/i386-options.cc | 2 +- gcc/testsuite/gcc.target/i386/fhardened-1.c | 8 ++++++++ gcc/testsuite/gcc.target/i386/fhardened-2.c | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/fhardened-1.c create mode 100644 gcc/testsuite/gcc.target/i386/fhardened-2.c diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index 7896d576977..68a2e1c6910 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -3242,7 +3242,7 @@ ix86_option_override_internal (bool main_args_p, on the command line. */ if (opts->x_flag_hardened && cf_okay_p) { - if (opts->x_flag_cf_protection == CF_NONE) + if (!opts_set->x_flag_cf_protection) opts->x_flag_cf_protection = CF_FULL; else if (opts->x_flag_cf_protection != CF_FULL) warning_at (UNKNOWN_LOCATION, OPT_Whardened, diff --git a/gcc/testsuite/gcc.target/i386/fhardened-1.c b/gcc/testsuite/gcc.target/i386/fhardened-1.c new file mode 100644 index 00000000000..55d1718ff55 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/fhardened-1.c @@ -0,0 +1,8 @@ +/* PR target/114606 */ +/* { dg-options "-fhardened -O2 -fcf-protection=none" } */ + +#ifdef __CET__ +# error "-fcf-protection enabled when it should not be" +#endif + +/* { dg-warning ".-fcf-protection=full. is not enabled by .-fhardened. because it was specified" "" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.target/i386/fhardened-2.c b/gcc/testsuite/gcc.target/i386/fhardened-2.c new file mode 100644 index 00000000000..9b8c1381c19 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/fhardened-2.c @@ -0,0 +1,8 @@ +/* PR target/114606 */ +/* { dg-options "-fhardened -O2" } */ + +#if __CET__ != 3 +# error "-fcf-protection not enabled" +#endif + +/* { dg-bogus ".-fcf-protection=full. is not enabled by .-fhardened. because it was specified" "" { target *-*-* } 0 } */ base-commit: 75b49c0e9012f5ecef0d32f3f6a0d8da66517576 -- 2.44.0