From patchwork Fri Apr 5 18:22:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 88114 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 E7A0A3858415 for ; Fri, 5 Apr 2024 18:22:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5C62C385840C for ; Fri, 5 Apr 2024 18:22:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C62C385840C 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 5C62C385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712341346; cv=none; b=PB2HoyrBbmdivV81OLi0Vh2m+7rt4Y2JIjjR2XKA+CiJKF4JRmmulfAkznAJcbijngwKXei4TAed+GHWcUEOOmaz0fyb3lPGzWK/ch2V2gbvja5ktJZa91L9hp9uhYezIwIR64dQvtwFeloWrR/M84Sz2GqlBTp1ytC3K2mxOkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712341346; c=relaxed/simple; bh=9XTGmfN+vXotVOfxsQqUa6ZhXm+pqbjE8E3PPeD5ajY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=h2ZT6LsPfzMv0UOid8j9FmFgoslZ/JrfMxaQvzXTY5ASZAVJwo5n+hemI3UAH3uj65pFgT6/OUiwXBUAHnk+cUq8Tqbm7gjBMwHW26PScSV278hWBo5jhqEw7XA9oQpbvCfxn60GAusX8G6W4SyABAiWodcMKkL1g6huMql9fgI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712341344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mA7LDGKg/xeRoXbXSvcD/Csr55GqlETVWKIx0c2Hvno=; b=Vcq3hHoStrA9Ct5pzxLaLo6iFW75RvqRzrT8JkDYpYb0G0ps/Qit01hrMGcG6TqnMNw/x6 THx8MSjkZb1eUwPHdihelTPy0e2qorxsLyZsT31zvTSFMCO1KZAessOwMOT7zF/Exc2muT +zm7uOZu+q+UgfUgg5pJm5rsXfrYppw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-qTf2jRfSOpOXB6aVyTaoQQ-1; Fri, 05 Apr 2024 14:22:22 -0400 X-MC-Unique: qTf2jRfSOpOXB6aVyTaoQQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67B82185A785 for ; Fri, 5 Apr 2024 18:22:22 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.33.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 516901C060D0 for ; Fri, 5 Apr 2024 18:22:22 +0000 (UTC) From: Marek Polacek To: GCC Patches Subject: [PATCH] target: missing -Whardened with -fcf-protection=none [PR114606] Date: Fri, 5 Apr 2024 14:22:18 -0400 Message-ID: <20240405182218.55288-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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, 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 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 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 base-commit: e7d015b2506a1d9e84d9f7182e42e097147527e1 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)) 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 } */