From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 16A75387089F for ; Thu, 14 Jan 2021 14:05:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 16A75387089F Received: by mail-pf1-x434.google.com with SMTP id c12so3387901pfo.10 for ; Thu, 14 Jan 2021 06:05:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/OQTP/wWHde8oiiJPbz/mFs4znlDkMrut7X1fdbbeUs=; b=RfS3ffIujdEeTYLSAL89L7kla8GIEjqT2EO4NJHP4FCie4xrAG7ygSb0WYm+InHSPY CdXL6n0t1cnHT2FCdGNw0OHbsM2zmJJFcUgDxJyEMocV2dN/kJzVF3zj7Q/1//Ki7VBX 9mJQzKTZt+i2Ei1Of35k2q2JbMf+8o1gX5w4ypCnk72sbQYTz+T5+EwpQ2SeSPW6rbFt +VXXhwMwFb2Hu9sV/5kyI0+25j+//Pzgw7FneUeq6f3Vdjl8DWhQyFkBhF5T5YfE0PD6 Rv4znSFXmL48iWs5B30MP68FMrZ5hrOGGieD0WEmnqG10Q0hARS+mrWuIgFoWpsa9e7M laLg== X-Gm-Message-State: AOAM5338ESB2+8L2/20iMtehkFDzoknh9mebakzNh0vKiljAZR4DlkCM 03x99cqH9hNoxnXKIBIEpsLRE7LPcPk= X-Google-Smtp-Source: ABdhPJxuBvvlLv5MilGr/SzwFYuzrHPM9XdOPcnPToZ4XyHYf/USC6lPgnKIGVM6EtfK6Ige49sLsg== X-Received: by 2002:a63:3184:: with SMTP id x126mr7704206pgx.354.1610633117806; Thu, 14 Jan 2021 06:05:17 -0800 (PST) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id y21sm6078830pfr.90.2021.01.14.06.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jan 2021 06:05:17 -0800 (PST) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id EB22F1A013C; Thu, 14 Jan 2021 06:05:15 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: Uros Bizjak Subject: [PATCH] x86: Error on -fcf-protection with incompatible target Date: Thu, 14 Jan 2021 06:05:14 -0800 Message-Id: <20210114140514.2760199-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3039.6 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jan 2021 14:05:21 -0000 -fcf-protection with CF_BRANCH inserts ENDBR32 at function entries. ENDBR32 is NOP only on 64-bit processors and 32-bit TARGET_CMOVE processors. Issue an error for -fcf-protection with CF_BRANCH when compiling for 32-bit non-TARGET_CMOVE targets. gcc/ PR target/98667 * config/i386/i386-options.c (ix86_option_override_internal): Issue an error for -fcf-protection with CF_BRANCH when compiling for 32-bit non-TARGET_CMOVE targets. gcc/testsuite/ PR target/98667 * gcc.target/i386/pr98667-1.c: New file. * gcc.target/i386/pr98667-2.c: Likewise. * gcc.target/i386/pr98667-3.c: Likewise. --- gcc/config/i386/i386-options.c | 9 ++++++++- gcc/testsuite/gcc.target/i386/pr98667-1.c | 9 +++++++++ gcc/testsuite/gcc.target/i386/pr98667-2.c | 9 +++++++++ gcc/testsuite/gcc.target/i386/pr98667-3.c | 7 +++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr98667-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr98667-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr98667-3.c diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c index 4e0165ff32c..1489871b36f 100644 --- a/gcc/config/i386/i386-options.c +++ b/gcc/config/i386/i386-options.c @@ -3016,8 +3016,15 @@ ix86_option_override_internal (bool main_args_p, } if (opts->x_flag_cf_protection != CF_NONE) - opts->x_flag_cf_protection + { + if ((opts->x_flag_cf_protection & CF_BRANCH) == CF_BRANCH + && !TARGET_64BIT + && !TARGET_CMOVE) + error ("%<-fcf-protection%> is not compatible with this target"); + + opts->x_flag_cf_protection = (cf_protection_level) (opts->x_flag_cf_protection | CF_SET); + } if (ix86_tune_features [X86_TUNE_AVOID_256FMA_CHAINS]) SET_OPTION_IF_UNSET (opts, opts_set, param_avoid_fma_max_bits, 256); diff --git a/gcc/testsuite/gcc.target/i386/pr98667-1.c b/gcc/testsuite/gcc.target/i386/pr98667-1.c new file mode 100644 index 00000000000..5bf0c9285a8 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98667-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target ia32 } } */ +/* { dg-options "-O2 -fcf-protection -march=i486" } */ + +void +test (void) +{ +} + +/* { dg-error "'-fcf-protection' is not compatible with this target" "" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.target/i386/pr98667-2.c b/gcc/testsuite/gcc.target/i386/pr98667-2.c new file mode 100644 index 00000000000..bc3a78c9641 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98667-2.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target ia32 } } */ +/* { dg-options "-O2 -fcf-protection=branch -march=i486" } */ + +void +test (void) +{ +} + +/* { dg-error "'-fcf-protection' is not compatible with this target" "" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.target/i386/pr98667-3.c b/gcc/testsuite/gcc.target/i386/pr98667-3.c new file mode 100644 index 00000000000..a6ea6d04331 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98667-3.c @@ -0,0 +1,7 @@ +/* { dg-do compile { target ia32 } } */ +/* { dg-options "-O2 -fcf-protection=return -march=i486" } */ + +void +test (void) +{ +} -- 2.29.2