From patchwork Wed Oct 23 11:05:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99407 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 12ED9385841E for ; Wed, 23 Oct 2024 11:06:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 7F6193858C60; Wed, 23 Oct 2024 11:05:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F6193858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7F6193858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681558; cv=none; b=UqpoWJq56+NdFIOrHHJJgla3wxu1K8EoDfCZMLrD9VaV/F+sYqf+fgs+miOu6PREZAexS4xKkV1xVf6G90rgjnxSUA5lHcM6589U+EnGG0kYYmp7wY9uR+H6kgY1MXC0gxtGLddgqjowW8NnHhxHoGUgOpA3hhXQ7FaMY7q8VVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681558; c=relaxed/simple; bh=3CkA5JCk1rUfx/Snm6yLEioXnDKhP6wvtcFewp4crB4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=J9Kw1+WOpnfGNNDp8ucJtMMARsHrPDakxk28pkWJTBlegVYgbILBMunOko3kcCI7Ml6ign+W+Lbw+h8YSzPO6SVPxHWucoaPv5qAMJR00HhNZ7LQFGjtPFw6l1j0RhYdD4+poXsKxZWJ2w/fZftLCTGKauDWJbmSA6YKLCyg76A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F13B0339; Wed, 23 Oct 2024 04:06:22 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 957A93F528; Wed, 23 Oct 2024 04:05:52 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 01/22] aarch64: Add -mbranch-protection=gcs option Date: Wed, 23 Oct 2024 12:05:07 +0100 Message-Id: <20241023110528.487830-2-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy This enables Guarded Control Stack (GCS) compatible code generation. The "standard" branch-protection type enables it, and the default depends on the compiler default. gcc/ChangeLog: * config/aarch64/aarch64-protos.h (aarch_gcs_enabled): Declare. * config/aarch64/aarch64.cc (aarch_gcs_enabled): Define. (aarch_handle_no_branch_protection): Handle gcs. (aarch_handle_standard_branch_protection): Handle gcs. (aarch_handle_gcs_protection): New. * config/aarch64/aarch64.opt: Add aarch_enable_gcs. * configure: Regenerate. * configure.ac: Handle gcs in --enable-standard-branch-protection. * doc/invoke.texi: Document -mbranch-protection=gcs. --- gcc/config/aarch64/aarch64-protos.h | 2 ++ gcc/config/aarch64/aarch64.cc | 24 ++++++++++++++++++++++++ gcc/config/aarch64/aarch64.opt | 3 +++ gcc/configure | 2 +- gcc/configure.ac | 6 +++--- gcc/doc/invoke.texi | 5 +++-- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h index d03c1fe798b..b8ec8a58c4e 100644 --- a/gcc/config/aarch64/aarch64-protos.h +++ b/gcc/config/aarch64/aarch64-protos.h @@ -1125,4 +1125,6 @@ extern void aarch64_adjust_reg_alloc_order (); bool aarch64_optimize_mode_switching (aarch64_mode_entity); void aarch64_restore_za (rtx); +extern bool aarch64_gcs_enabled (); + #endif /* GCC_AARCH64_PROTOS_H */ diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 3ab550acc7c..33f97d42d55 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -8502,6 +8502,13 @@ aarch_bti_j_insn_p (rtx_insn *insn) return GET_CODE (pat) == UNSPEC_VOLATILE && XINT (pat, 1) == UNSPECV_BTI_J; } +/* Return TRUE if Guarded Control Stack is enabled. */ +bool +aarch64_gcs_enabled (void) +{ + return (aarch64_enable_gcs == 1); +} + /* Check if X (or any sub-rtx of X) is a PACIASP/PACIBSP instruction. */ bool aarch_pac_insn_p (rtx x) @@ -18885,6 +18892,7 @@ aarch64_handle_no_branch_protection (void) { aarch_ra_sign_scope = AARCH_FUNCTION_NONE; aarch_enable_bti = 0; + aarch64_enable_gcs = 0; } static void @@ -18893,6 +18901,7 @@ aarch64_handle_standard_branch_protection (void) aarch_ra_sign_scope = AARCH_FUNCTION_NON_LEAF; aarch64_ra_sign_key = AARCH64_KEY_A; aarch_enable_bti = 1; + aarch64_enable_gcs = 1; } static void @@ -18919,6 +18928,11 @@ aarch64_handle_bti_protection (void) { aarch_enable_bti = 1; } +static void +aarch64_handle_gcs_protection (void) +{ + aarch64_enable_gcs = 1; +} static const struct aarch_branch_protect_type aarch64_pac_ret_subtypes[] = { { "leaf", false, aarch64_handle_pac_ret_leaf, NULL, 0 }, @@ -18933,6 +18947,7 @@ static const struct aarch_branch_protect_type aarch64_branch_protect_types[] = { "pac-ret", false, aarch64_handle_pac_ret_protection, aarch64_pac_ret_subtypes, ARRAY_SIZE (aarch64_pac_ret_subtypes) }, { "bti", false, aarch64_handle_bti_protection, NULL, 0 }, + { "gcs", false, aarch64_handle_gcs_protection, NULL, 0 }, { NULL, false, NULL, NULL, 0 } }; @@ -19032,6 +19047,15 @@ aarch64_override_options (void) #endif } + if (aarch64_enable_gcs == 2) + { +#ifdef TARGET_ENABLE_GCS + aarch64_enable_gcs = 1; +#else + aarch64_enable_gcs = 0; +#endif + } + /* Return address signing is currently not supported for ILP32 targets. For LP64 targets use the configured option in the absence of a command-line option for -mbranch-protection. */ diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt index c2c9965b062..36bc719b822 100644 --- a/gcc/config/aarch64/aarch64.opt +++ b/gcc/config/aarch64/aarch64.opt @@ -45,6 +45,9 @@ uint64_t aarch64_isa_flags_1 = 0 TargetVariable unsigned aarch_enable_bti = 2 +TargetVariable +unsigned aarch64_enable_gcs = 2 + TargetVariable enum aarch64_key_type aarch64_ra_sign_key = AARCH64_KEY_A diff --git a/gcc/configure b/gcc/configure index 5acc42c1e4d..8ed47b4dadb 100755 --- a/gcc/configure +++ b/gcc/configure @@ -28044,7 +28044,7 @@ if test "${enable_standard_branch_protection+set}" = set; then : enableval=$enable_standard_branch_protection; case $enableval in yes) - tm_defines="${tm_defines} TARGET_ENABLE_BTI=1 TARGET_ENABLE_PAC_RET=1" + tm_defines="${tm_defines} TARGET_ENABLE_BTI=1 TARGET_ENABLE_PAC_RET=1 TARGET_ENABLE_GCS=1" ;; no) ;; diff --git a/gcc/configure.ac b/gcc/configure.ac index 23f4884eff9..8048c4550aa 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -4392,14 +4392,14 @@ case "$target" in AC_ARG_ENABLE(standard-branch-protection, [ AS_HELP_STRING([--enable-standard-branch-protection], - [enable Branch Target Identification Mechanism and Return Address Signing by default for AArch64]) + [enable Branch Target Identification Mechanism, Return Address Signing, and Guarded Control Stack by default for AArch64]) AS_HELP_STRING([--disable-standard-branch-protection], - [disable Branch Target Identification Mechanism and Return Address Signing by default for AArch64]) + [disable Branch Target Identification Mechanism, Return Address Signing, and Guarded Control Stack by default for AArch64]) ], [ case $enableval in yes) - tm_defines="${tm_defines} TARGET_ENABLE_BTI=1 TARGET_ENABLE_PAC_RET=1" + tm_defines="${tm_defines} TARGET_ENABLE_BTI=1 TARGET_ENABLE_PAC_RET=1 TARGET_ENABLE_GCS=1" ;; no) ;; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 8437b2029ed..e66d5da2aee 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -811,7 +811,7 @@ Objective-C and Objective-C++ Dialects}. -mpc-relative-literal-loads -msign-return-address=@var{scope} -mbranch-protection=@var{none}|@var{standard}|@var{pac-ret}[+@var{leaf} -+@var{b-key}]|@var{bti} ++@var{b-key}]|@var{bti}|@var{gcs} -mharden-sls=@var{opts} -march=@var{name} -mcpu=@var{name} -mtune=@var{name} -moverride=@var{string} -mverbose-cost-dump @@ -21467,7 +21467,7 @@ default value is @samp{none}. This option has been deprecated by -mbranch-protection. @opindex mbranch-protection -@item -mbranch-protection=@var{none}|@var{standard}|@var{pac-ret}[+@var{leaf}+@var{b-key}]|@var{bti} +@item -mbranch-protection=@var{none}|@var{standard}|@var{pac-ret}[+@var{leaf}+@var{b-key}]|@var{bti}|@var{gcs} Select the branch protection features to use. @samp{none} is the default and turns off all types of branch protection. @samp{standard} turns on all types of branch protection features. If a feature @@ -21480,6 +21480,7 @@ argument @samp{leaf} can be used to extend the signing to include leaf functions. The optional argument @samp{b-key} can be used to sign the functions with the B-key instead of the A-key. @samp{bti} turns on branch target identification mechanism. +@samp{gcs} turns on guarded control stack compatible code generation. @opindex mharden-sls @item -mharden-sls=@var{opts} From patchwork Wed Oct 23 11:05:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99408 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 21BA23858D21 for ; Wed, 23 Oct 2024 11:06:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 8F4B63858C2B; Wed, 23 Oct 2024 11:06:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F4B63858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8F4B63858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681569; cv=none; b=sJaWbK2N4Thm5nkFcZPTTMtCPmIdKxGEVUts5sZereR9xIdazr5jJpBRpag536XgRbL9+NpIuk1J0UVCvJpkobC8JDzULI385RSiubG+HfHWwHrd9rdMHH/ueUVEb3cLVhkvQe9EbxWTwPKh3QKek7dDf/t0jIWoSmTKZtXmwc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681569; c=relaxed/simple; bh=Pu6dRTAbY4mzSa9qXnjO5CszA+dRCmV+a6a37/oHEHU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=cg5GpTsQp6S14iYZyXQMEkiw8C8qE/TlQrTqKxW1AKsTwjnrnqzV6xRASOW/rQ53nFeWnoeGANgOjvkuN7WADrG2mO5Hm37MlhISJa0oKJiN1RReYlFxhOR0eUXtgQ69ONcQdTXvEIU1Q7XmVnArCQUCmdsicgUz49vIwIoaqeU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 099E0339; Wed, 23 Oct 2024 04:06:30 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A20863F528; Wed, 23 Oct 2024 04:05:59 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 02/22] aarch64: Add branch-protection target pragma tests Date: Wed, 23 Oct 2024 12:05:08 +0100 Message-Id: <20241023110528.487830-3-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Szabolcs Nagy gcc/testsuite/ChangeLog: * gcc.target/aarch64/pragma_cpp_predefs_4.c: Add branch-protection tests. --- .../gcc.target/aarch64/pragma_cpp_predefs_4.c | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_4.c b/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_4.c index 23ebe5e4f50..8e707630774 100644 --- a/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_4.c +++ b/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_4.c @@ -83,3 +83,53 @@ #ifndef __ARM_FEATURE_SME_F64F64 #error Foo #endif + +#pragma GCC target "branch-protection=standard" +#ifndef __ARM_FEATURE_BTI_DEFAULT +#error Foo +#endif +#if __ARM_FEATURE_PAC_DEFAULT != 1 +#error Foo +#endif + +#pragma GCC target ("branch-protection=none") +#ifdef __ARM_FEATURE_BTI_DEFAULT +#error Foo +#endif +#ifdef __ARM_FEATURE_PAC_DEFAULT +#error Foo +#endif + +#pragma GCC push_options +#pragma GCC target "branch-protection=bti+pac-ret" +#ifndef __ARM_FEATURE_BTI_DEFAULT +#error Foo +#endif +#pragma GCC pop_options +#ifdef __ARM_FEATURE_BTI_DEFAULT +#error Foo +#endif + +#pragma GCC target "branch-protection=bti" +#ifndef __ARM_FEATURE_BTI_DEFAULT +#error Foo +#endif +#ifdef __ARM_FEATURE_PAC_DEFAULT +#error Foo +#endif + +#pragma GCC target "branch-protection=pac-ret" +#ifdef __ARM_FEATURE_BTI_DEFAULT +#error Foo +#endif +#if __ARM_FEATURE_PAC_DEFAULT != 1 +#error Foo +#endif + +#pragma GCC target "branch-protection=pac-ret+leaf+b-key" +#ifdef __ARM_FEATURE_BTI_DEFAULT +#error Foo +#endif +#if __ARM_FEATURE_PAC_DEFAULT != 6 +#error Foo +#endif From patchwork Wed Oct 23 11:05:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99410 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 04876385843F for ; Wed, 23 Oct 2024 11:07:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 9313B3858D33; Wed, 23 Oct 2024 11:06:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9313B3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9313B3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681585; cv=none; b=aJMhryLKj03XctsBuZS8qD256skkzgCd9z3q/aoxY+/DKC5ZbSmIoVxVb0aSsNUpTXHExxR34WwfrGdkWCI2LaWFJF37vSE04zxAftrefP6ij8UfLF22YMDEjnAl78kuY17tISyLYaocqnRNgfxub7xerTk3I13aH5ooATzXhto= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681585; c=relaxed/simple; bh=V6DTLbXLpIIAvmOfXgaDfJ5Ei4VhsNcFmgcdv95BFK8=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=t1spWY0ax4adPynmgvp+KWYjXQEyJgwG6kjdNY4S6YuiWdlx3fvH/EmLsFUYFyM3CMvToNlIrcTzBU8gW0IbQlcSB85S5GSzBXQOrh2od+YAKTNVJQSjFEq5SBM0ihiQI6pLn/0JawK0N1bBh6rbXIzs8MMKxtBAXXIxoHw4WyA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 17B67339; Wed, 23 Oct 2024 04:06:52 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B16D83F528; Wed, 23 Oct 2024 04:06:21 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 03/22] aarch64: Add support for chkfeat insn Date: Wed, 23 Oct 2024 12:05:09 +0100 Message-Id: <20241023110528.487830-4-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy This is a hint space instruction to check for enabled HW features and update the x16 register accordingly. Use unspec_volatile to prevent reordering it around calls since calls can enable or disable HW features. gcc/ChangeLog: * config/aarch64/aarch64.md (aarch64_chkfeat): New. --- gcc/config/aarch64/aarch64.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index c54b29cd64b..43bed0ce10f 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -381,6 +381,7 @@ (define_c_enum "unspecv" [ UNSPECV_BTI_C ; Represent BTI c. UNSPECV_BTI_J ; Represent BTI j. UNSPECV_BTI_JC ; Represent BTI jc. + UNSPECV_CHKFEAT ; Represent CHKFEAT X16. UNSPECV_TSTART ; Represent transaction start. UNSPECV_TCOMMIT ; Represent transaction commit. UNSPECV_TCANCEL ; Represent transaction cancel. @@ -8312,6 +8313,14 @@ (define_insn "aarch64_restore_nzcv" "msr\tnzcv, %0" ) +;; CHKFEAT instruction +(define_insn "aarch64_chkfeat" + [(set (reg:DI R16_REGNUM) + (unspec_volatile:DI [(reg:DI R16_REGNUM)] UNSPECV_CHKFEAT))] + "" + "hint\\t40 // chkfeat x16" +) + ;; AdvSIMD Stuff (include "aarch64-simd.md") From patchwork Wed Oct 23 11:05:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99414 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 231983858023 for ; Wed, 23 Oct 2024 11:09:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 041143858C2B; Wed, 23 Oct 2024 11:06:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 041143858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 041143858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681598; cv=none; b=c/g/8UKGRegwDvAj2yI8XvObd7StgjgEfyc+55HItfIYvtFfGKcu8e38GMy+xyqvHWLrLcZmjgdyMkZ8lPv/6Q0HxeXlBxIw4H/V9reUhBvvU4lQWx8IszhE2orh2TRbPoxRMMtxR8FbVmBwLFVqVeuKx13D2oiimfy+eLMIgvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681598; c=relaxed/simple; bh=4xiTZl16vhM4bPlG0FipmruqTuk3J8p1JAusX+i30fw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=BNGQtn1I0xlG8QKY++9wbr1Wc08DsoudXdSXie8BM2qlrhLD2ABaAMo4sKeb+JYthIRgQBZMQTEtTWGoGEJM3e79MoYvTMprd4YBwKQ8b02zpApk5dQE6QaHN/Emd3f1kOP2zLKyXlGYlLF5yftPS9Mzx48doDfUQpXjs9FPFqc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 71C61339; Wed, 23 Oct 2024 04:06:58 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 16E6B3F528; Wed, 23 Oct 2024 04:06:27 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 04/22] aarch64: Add __builtin_aarch64_chkfeat Date: Wed, 23 Oct 2024 12:05:10 +0100 Message-Id: <20241023110528.487830-5-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy Builtin for chkfeat: the input argument is used to initialize x16 then execute chkfeat and return the updated x16. Note: ACLE __chkfeat(x) plans to flip the bits to be more intuitive (xor the input to output), but for the builtin that seems unnecessary complication. gcc/ChangeLog: * config/aarch64/aarch64-builtins.cc (enum aarch64_builtins): Define AARCH64_BUILTIN_CHKFEAT. (aarch64_general_init_builtins): Handle chkfeat. (aarch64_general_expand_builtin): Handle chkfeat. --- gcc/config/aarch64/aarch64-builtins.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc index 7d737877e0b..765f2091504 100644 --- a/gcc/config/aarch64/aarch64-builtins.cc +++ b/gcc/config/aarch64/aarch64-builtins.cc @@ -875,6 +875,8 @@ enum aarch64_builtins AARCH64_PLDX, AARCH64_PLI, AARCH64_PLIX, + /* Armv8.9-A / Armv9.4-A builtins. */ + AARCH64_BUILTIN_CHKFEAT, AARCH64_BUILTIN_MAX }; @@ -2280,6 +2282,12 @@ aarch64_general_init_builtins (void) if (!TARGET_ILP32) aarch64_init_pauth_hint_builtins (); + tree ftype_chkfeat + = build_function_type_list (uint64_type_node, uint64_type_node, NULL); + aarch64_builtin_decls[AARCH64_BUILTIN_CHKFEAT] + = aarch64_general_add_builtin ("__builtin_aarch64_chkfeat", ftype_chkfeat, + AARCH64_BUILTIN_CHKFEAT); + if (in_lto_p) handle_arm_acle_h (); } @@ -3484,6 +3492,16 @@ aarch64_general_expand_builtin (unsigned int fcode, tree exp, rtx target, case AARCH64_PLIX: aarch64_expand_prefetch_builtin (exp, fcode); return target; + + case AARCH64_BUILTIN_CHKFEAT: + { + rtx x16_reg = gen_rtx_REG (DImode, R16_REGNUM); + op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); + emit_move_insn (x16_reg, op0); + expand_insn (CODE_FOR_aarch64_chkfeat, 0, 0); + emit_move_insn (target, x16_reg); + return target; + } } if (fcode >= AARCH64_SIMD_BUILTIN_BASE && fcode <= AARCH64_SIMD_BUILTIN_MAX) From patchwork Wed Oct 23 11:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99409 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 CEE943858C5F for ; Wed, 23 Oct 2024 11:07:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 40C1D3858C60; Wed, 23 Oct 2024 11:06:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40C1D3858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 40C1D3858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681599; cv=none; b=B7JAYZzTg87gV57n03bdGSqoL5aOUjcqbCTlkD4DRAmA5+d3WaEJ4bJTnlXi2g9PPjdZaO4/jO/UOJC8L2gxtnFceNZJjV1rs0Vu6oK/i9B9dvWe5FzdC9gweVXCReTaAFZcXhAz55cZfVnK/qXQ1z8n3unEEjhovbVUBxEKxOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681599; c=relaxed/simple; bh=DNuLmAOi/4EKo1F/6sMQSkyDg1ZZQhnGQKKYmnmuRHo=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=a+XoyPI3ySr5leTRiTx44Az7ebRBi8RFwhTC2b5kufG3DLNNMl3HoCwwVtxCBV7qNmqJgtpjKggzrrQK8Dnh/kByLN57X5jBgp5/GwAZkpmANvH42o36XuAPZTQhB5gOCoQCrq5cKR75EQwPxytY59sixXhNHOfNUxI6veQpUkk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B9B88497; Wed, 23 Oct 2024 04:07:05 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 503773F528; Wed, 23 Oct 2024 04:06:35 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 05/22] aarch64: Add __builtin_aarch64_chkfeat tests Date: Wed, 23 Oct 2024 12:05:11 +0100 Message-Id: <20241023110528.487830-6-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Szabolcs Nagy gcc/testsuite/ChangeLog: * gcc.target/aarch64/chkfeat-1.c: New test. * gcc.target/aarch64/chkfeat-2.c: New test. --- gcc/testsuite/gcc.target/aarch64/chkfeat-1.c | 75 ++++++++++++++++++++ gcc/testsuite/gcc.target/aarch64/chkfeat-2.c | 15 ++++ 2 files changed, 90 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/chkfeat-1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/chkfeat-2.c diff --git a/gcc/testsuite/gcc.target/aarch64/chkfeat-1.c b/gcc/testsuite/gcc.target/aarch64/chkfeat-1.c new file mode 100644 index 00000000000..2fae81e740f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/chkfeat-1.c @@ -0,0 +1,75 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mbranch-protection=none" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +/* +**foo1: +** mov x16, 1 +** hint 40 // chkfeat x16 +** mov x0, x16 +** ret +*/ +unsigned long long +foo1 (void) +{ + return __builtin_aarch64_chkfeat (1); +} + +/* +**foo2: +** mov x16, 1 +** movk x16, 0x5678, lsl 32 +** movk x16, 0x1234, lsl 48 +** hint 40 // chkfeat x16 +** mov x0, x16 +** ret +*/ +unsigned long long +foo2 (void) +{ + return __builtin_aarch64_chkfeat (0x1234567800000001); +} + +/* +**foo3: +** mov x16, x0 +** hint 40 // chkfeat x16 +** mov x0, x16 +** ret +*/ +unsigned long long +foo3 (unsigned long long x) +{ + return __builtin_aarch64_chkfeat (x); +} + +/* +**foo4: +** ldr x16, \[x0\] +** hint 40 // chkfeat x16 +** str x16, \[x0\] +** ret +*/ +void +foo4 (unsigned long long *p) +{ + *p = __builtin_aarch64_chkfeat (*p); +} + +/* +**foo5: +** mov x16, 1 +** hint 40 // chkfeat x16 +** cmp x16, 0 +**( +** csel w0, w1, w0, eq +**| +** csel w0, w0, w1, ne +**) +** ret +*/ +int +foo5 (int x, int y) +{ + return __builtin_aarch64_chkfeat (1) ? x : y; +} diff --git a/gcc/testsuite/gcc.target/aarch64/chkfeat-2.c b/gcc/testsuite/gcc.target/aarch64/chkfeat-2.c new file mode 100644 index 00000000000..682524e244f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/chkfeat-2.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times {hint\t40 // chkfeat x16} 2 } } */ + +void bar (void); + +/* Extern call may change enabled HW features. */ +unsigned long long +foo (void) +{ + unsigned long long a = __builtin_aarch64_chkfeat (1); + bar (); + unsigned long long b = __builtin_aarch64_chkfeat (1); + return a + b; +} From patchwork Wed Oct 23 11:05:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99412 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 AD9413857C78 for ; Wed, 23 Oct 2024 11:07:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 770503858D33; Wed, 23 Oct 2024 11:06:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 770503858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 770503858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681617; cv=none; b=LNY0wm3JAFPiBh/jkrTadRXp7hWI1IvyXDOFen5/4qrnEHdTnJIMjXnjU++/hFM/4ovcVeBcMW1yfU1IUnIdPABdoLBIoC4IH2dvM5VXMDOSUjm8dUYCOkESmAzsPiWWXQWRqMxKB5/i6LmBnMJEHpuBYhsoRg0wNHTVfkuQ9aM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681617; c=relaxed/simple; bh=YUL3wKVxrccZMaqu9dDuNPNSFY3xN9a2BiyUpf6v/zU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Hx29+fTeaj9v52tbOQcXeTMxS5ylDTqgt4kFs1yGDbT03hi2uyEzPQQ58CcDAvfpiAkCDV/yrisUbvMCVss2yjM3ACAh0JwubHRm9quYCYTWnDOV1zbfAD5z4z7Fs6v0ej0IkYLdinVx/gfJrzt0h7JHiNAqnGSpdbLRCcisj2s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EA9D8339; Wed, 23 Oct 2024 04:07:22 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 906E83F528; Wed, 23 Oct 2024 04:06:52 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 06/22] aarch64: Add GCS instructions Date: Wed, 23 Oct 2024 12:05:12 +0100 Message-Id: <20241023110528.487830-7-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy Add instructions for the Guarded Control Stack extension. GCSSS1 and GCSSS2 are modelled as a single GCSSS unspec, because they are always used together in the compiler. Before GCSPOPM and GCSSS2 an extra "mov xn, 0" is added to clear the output register, this is needed to get reasonable result when GCS is disabled, when the instructions are NOPs. Since the instructions are expected to be used behind runtime feature checks, this is mainly relevant if GCS can be disabled asynchronously. The output of GCSPOPM is usually not needed, so a separate gcspopm_xzr was added to model that. Did not do the same for GCSSS as it is a less common operation. The used mnemonics do not depend on updated assembler since these instructions can be used without new -march setting behind a runtime check. Reading the GCSPR is modelled as unspec_volatile so it does not get reordered wrt the other instructions changing the GCSPR. gcc/ChangeLog: * config/aarch64/aarch64.md (aarch64_load_gcspr): New. (aarch64_gcspopm): New. (aarch64_gcspopm_xzr): New. (aarch64_gcsss): New. --- gcc/config/aarch64/aarch64.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 43bed0ce10f..e4e11e35b5b 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -382,6 +382,9 @@ (define_c_enum "unspecv" [ UNSPECV_BTI_J ; Represent BTI j. UNSPECV_BTI_JC ; Represent BTI jc. UNSPECV_CHKFEAT ; Represent CHKFEAT X16. + UNSPECV_GCSPR ; Represent MRS Xn, GCSPR_EL0 + UNSPECV_GCSPOPM ; Represent GCSPOPM. + UNSPECV_GCSSS ; Represent GCSSS1 and GCSSS2. UNSPECV_TSTART ; Represent transaction start. UNSPECV_TCOMMIT ; Represent transaction commit. UNSPECV_TCANCEL ; Represent transaction cancel. @@ -8321,6 +8324,38 @@ (define_insn "aarch64_chkfeat" "hint\\t40 // chkfeat x16" ) +;; Guarded Control Stack (GCS) instructions +(define_insn "aarch64_load_gcspr" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec_volatile:DI [(const_int 0)] UNSPECV_GCSPR))] + "" + "mrs\\t%0, s3_3_c2_c5_1 // gcspr_el0" + [(set_attr "type" "mrs")] +) + +(define_insn "aarch64_gcspopm" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec_volatile:DI [(const_int 0)] UNSPECV_GCSPOPM))] + "" + "mov\\t%0, 0\;sysl\\t%0, #3, c7, c7, #1 // gcspopm" + [(set_attr "length" "8")] +) + +(define_insn "aarch64_gcspopm_xzr" + [(unspec_volatile [(const_int 0)] UNSPECV_GCSPOPM)] + "" + "sysl\\txzr, #3, c7, c7, #1 // gcspopm" +) + +(define_insn "aarch64_gcsss" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec_volatile:DI [(match_operand:DI 1 "register_operand" "r")] + UNSPECV_GCSSS))] + "" + "sys\\t#3, c7, c7, #2, %1 // gcsss1\;mov\\t%0, 0\;sysl\\t%0, #3, c7, c7, #3 // gcsss2" + [(set_attr "length" "12")] +) + ;; AdvSIMD Stuff (include "aarch64-simd.md") From patchwork Wed Oct 23 11:05:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99421 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 5DBD23857C58 for ; Wed, 23 Oct 2024 11:10:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id D035B3858D21; Wed, 23 Oct 2024 11:06:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D035B3858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D035B3858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681625; cv=none; b=eECkFWrvZ4QBFdg/XKYVtGQvkDP4rae28yfINOBzMRgT7681GVIVHuQyUnaE4amK1x2boO0IqfhO5XW2jlgeYRcc5SlQUYqAstv2x5K2X6kbiygJLXrKr7xqZQNDytppCMrKmnQpXdAI08JBXAMQ0QE8PbVAi3mIsvmkRwAOr8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681625; c=relaxed/simple; bh=NF09LIM+neKFp5cMAD/fQVvnDFIy7W7D3gtMCTFTnsE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=k3ITk/4B8072HZ2xjEl0J5DqE1bX2Mo0KSZp1pp3OgPeLnU2AMVPKpOPWv91OGrhbMHxVzbWLckwPoNRpLNzNNaPj9AAVJqij5HJ8vP6S4q9xUlxuaMHTFAAEh5miqM64hsZoiJXFGa+FEUJdzgcB3XBqpnwhwY5+kHCPZMwiQI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 58472339; Wed, 23 Oct 2024 04:07:29 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F15133F528; Wed, 23 Oct 2024 04:06:58 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 07/22] aarch64: Add GCS builtins Date: Wed, 23 Oct 2024 12:05:13 +0100 Message-Id: <20241023110528.487830-8-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy Add new builtins for GCS: void *__builtin_aarch64_gcspr (void) uint64_t __builtin_aarch64_gcspopm (void) void *__builtin_aarch64_gcsss (void *) The builtins are always enabled, but should be used behind runtime checks in case the target does not support GCS. They are thin wrappers around the corresponding instructions. The GCS pointer is modelled with void * type (normal stores do not work on GCS memory, but it is writable via the gcsss operation or via GCSSTR if enabled so not const) and an entry on the GCS is modelled with uint64_t (since it has fixed size and can be a token that's not a pointer). gcc/ChangeLog: * config/aarch64/aarch64-builtins.cc (enum aarch64_builtins): Add AARCH64_BUILTIN_GCSPR, AARCH64_BUILTIN_GCSPOPM, AARCH64_BUILTIN_GCSSS. (aarch64_init_gcs_builtins): New. (aarch64_general_init_builtins): Call aarch64_init_gcs_builtins. (aarch64_expand_gcs_builtin): New. (aarch64_general_expand_builtin): Call aarch64_expand_gcs_builtin. --- gcc/config/aarch64/aarch64-builtins.cc | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc index 765f2091504..a42a2b9e67f 100644 --- a/gcc/config/aarch64/aarch64-builtins.cc +++ b/gcc/config/aarch64/aarch64-builtins.cc @@ -877,6 +877,9 @@ enum aarch64_builtins AARCH64_PLIX, /* Armv8.9-A / Armv9.4-A builtins. */ AARCH64_BUILTIN_CHKFEAT, + AARCH64_BUILTIN_GCSPR, + AARCH64_BUILTIN_GCSPOPM, + AARCH64_BUILTIN_GCSSS, AARCH64_BUILTIN_MAX }; @@ -2241,6 +2244,29 @@ aarch64_init_fpsr_fpcr_builtins (void) AARCH64_BUILTIN_SET_FPSR64); } +/* Add builtins for Guarded Control Stack instructions. */ + +static void +aarch64_init_gcs_builtins (void) +{ + tree ftype; + + ftype = build_function_type_list (ptr_type_node, NULL); + aarch64_builtin_decls[AARCH64_BUILTIN_GCSPR] + = aarch64_general_add_builtin ("__builtin_aarch64_gcspr", ftype, + AARCH64_BUILTIN_GCSPR); + + ftype = build_function_type_list (uint64_type_node, NULL); + aarch64_builtin_decls[AARCH64_BUILTIN_GCSPOPM] + = aarch64_general_add_builtin ("__builtin_aarch64_gcspopm", ftype, + AARCH64_BUILTIN_GCSPOPM); + + ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL); + aarch64_builtin_decls[AARCH64_BUILTIN_GCSSS] + = aarch64_general_add_builtin ("__builtin_aarch64_gcsss", ftype, + AARCH64_BUILTIN_GCSSS); +} + /* Initialize all builtins in the AARCH64_BUILTIN_GENERAL group. */ void @@ -2288,6 +2314,8 @@ aarch64_general_init_builtins (void) = aarch64_general_add_builtin ("__builtin_aarch64_chkfeat", ftype_chkfeat, AARCH64_BUILTIN_CHKFEAT); + aarch64_init_gcs_builtins (); + if (in_lto_p) handle_arm_acle_h (); } @@ -3367,6 +3395,43 @@ aarch64_expand_fpsr_fpcr_getter (enum insn_code icode, machine_mode mode, return op.value; } +/* Expand GCS builtin EXP with code FCODE, putting the result + int TARGET. If IGNORE is true the return value is ignored. */ + +rtx +aarch64_expand_gcs_builtin (tree exp, rtx target, int fcode, int ignore) +{ + if (fcode == AARCH64_BUILTIN_GCSPR) + { + expand_operand op; + create_output_operand (&op, target, DImode); + expand_insn (CODE_FOR_aarch64_load_gcspr, 1, &op); + return op.value; + } + if (fcode == AARCH64_BUILTIN_GCSPOPM && ignore) + { + expand_insn (CODE_FOR_aarch64_gcspopm_xzr, 0, 0); + return target; + } + if (fcode == AARCH64_BUILTIN_GCSPOPM) + { + expand_operand op; + create_output_operand (&op, target, Pmode); + expand_insn (CODE_FOR_aarch64_gcspopm, 1, &op); + return op.value; + } + if (fcode == AARCH64_BUILTIN_GCSSS) + { + expand_operand ops[2]; + rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 0)); + create_output_operand (&ops[0], target, Pmode); + create_input_operand (&ops[1], op1, Pmode); + expand_insn (CODE_FOR_aarch64_gcsss, 2, ops); + return ops[0].value; + } + gcc_unreachable (); +} + /* Expand an expression EXP that calls built-in function FCODE, with result going to TARGET if that's convenient. IGNORE is true if the result of the builtin is ignored. */ @@ -3502,6 +3567,11 @@ aarch64_general_expand_builtin (unsigned int fcode, tree exp, rtx target, emit_move_insn (target, x16_reg); return target; } + + case AARCH64_BUILTIN_GCSPR: + case AARCH64_BUILTIN_GCSPOPM: + case AARCH64_BUILTIN_GCSSS: + return aarch64_expand_gcs_builtin (exp, target, fcode, ignore); } if (fcode >= AARCH64_SIMD_BUILTIN_BASE && fcode <= AARCH64_SIMD_BUILTIN_MAX) From patchwork Wed Oct 23 11:05:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99411 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 C0C23385841F for ; Wed, 23 Oct 2024 11:07:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 5A8CF3858431; Wed, 23 Oct 2024 11:07:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A8CF3858431 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5A8CF3858431 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681630; cv=none; b=VlTBpmr+2svDOErvOJ6+R8mHUrlQ8ifCbPwbhwS4B83sKLTPbTkz/HPn6BbqAGMAEGZ/LtZrGharK6AEwkMPIFJYkHOzjqV6R6Nl2LfrjfquTAv8fx2gS71EOaK3c1kjs6WTew8q80EZd+uDWdzrMn/fJARBLeNE7dWaPiqqT50= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681630; c=relaxed/simple; bh=s9zhTVLHr7vPQhsGahDX1CqmffeM7rI+ixgWLjRdDhE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=BU2MPxYEYJjQqOozhetHsYwBfhzLru5dShBF1NDd0rLAvwex4vAMPBY/RTfMRU5e1iHYILQXq6/cwX8dP25Atp6Q3czAEPKHPFM4lvR+fVwVkhbhFb9RSrGPQQVqMKoveucFRHSCYdhdv3myfd2BVchOO4jJk2J31AUCEKd004M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CDD69339; Wed, 23 Oct 2024 04:07:35 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 739393F528; Wed, 23 Oct 2024 04:07:05 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 08/22] aarch64: Add __builtin_aarch64_gcs* tests Date: Wed, 23 Oct 2024 12:05:14 +0100 Message-Id: <20241023110528.487830-9-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Szabolcs Nagy gcc/testsuite/ChangeLog: * gcc.target/aarch64/gcspopm-1.c: New test. * gcc.target/aarch64/gcspr-1.c: New test. * gcc.target/aarch64/gcsss-1.c: New test. --- gcc/testsuite/gcc.target/aarch64/gcspopm-1.c | 69 ++++++++++++++++++++ gcc/testsuite/gcc.target/aarch64/gcspr-1.c | 31 +++++++++ gcc/testsuite/gcc.target/aarch64/gcsss-1.c | 49 ++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/gcspopm-1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/gcspr-1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/gcsss-1.c diff --git a/gcc/testsuite/gcc.target/aarch64/gcspopm-1.c b/gcc/testsuite/gcc.target/aarch64/gcspopm-1.c new file mode 100644 index 00000000000..6e6add39cf7 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gcspopm-1.c @@ -0,0 +1,69 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mbranch-protection=none" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +/* +**foo1: +** sysl xzr, #3, c7, c7, #1 // gcspopm +** ret +*/ +void +foo1 (void) +{ + __builtin_aarch64_gcspopm (); +} + +/* +**foo2: +** mov x0, 0 +** sysl x0, #3, c7, c7, #1 // gcspopm +** ret +*/ +unsigned long long +foo2 (void) +{ + return __builtin_aarch64_gcspopm (); +} + +/* +**foo3: +** mov x16, 1 +** ( +** mov x0, 0 +** hint 40 // chkfeat x16 +** | +** hint 40 // chkfeat x16 +** mov x0, 0 +** ) +** cbz x16, .* +** ret +** mov x0, 0 +** sysl x0, #3, c7, c7, #1 // gcspopm +** ret +*/ +unsigned long long +foo3 (void) +{ + if (__builtin_aarch64_chkfeat (1) == 0) + return __builtin_aarch64_gcspopm (); + return 0; +} + +/* +**foo4: +** sysl xzr, #3, c7, c7, #1 // gcspopm +** mov x0, 0 +** sysl x0, #3, c7, c7, #1 // gcspopm +** sysl xzr, #3, c7, c7, #1 // gcspopm +** ret +*/ +unsigned long long +foo4 (void) +{ + unsigned long long a = __builtin_aarch64_gcspopm (); + unsigned long long b = __builtin_aarch64_gcspopm (); + unsigned long long c = __builtin_aarch64_gcspopm (); + (void) a; + (void) c; + return b; +} diff --git a/gcc/testsuite/gcc.target/aarch64/gcspr-1.c b/gcc/testsuite/gcc.target/aarch64/gcspr-1.c new file mode 100644 index 00000000000..0e651979551 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gcspr-1.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mbranch-protection=none" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +/* +**foo1: +** mrs x0, s3_3_c2_c5_1 // gcspr_el0 +** ret +*/ +void * +foo1 (void) +{ + return __builtin_aarch64_gcspr (); +} + +/* +**foo2: +** mrs x[0-9]*, s3_3_c2_c5_1 // gcspr_el0 +** sysl xzr, #3, c7, c7, #1 // gcspopm +** mrs x[0-9]*, s3_3_c2_c5_1 // gcspr_el0 +** sub x0, x[0-9]*, x[0-9]* +** ret +*/ +long +foo2 (void) +{ + const char *p = __builtin_aarch64_gcspr (); + __builtin_aarch64_gcspopm (); + const char *q = __builtin_aarch64_gcspr (); + return p - q; +} diff --git a/gcc/testsuite/gcc.target/aarch64/gcsss-1.c b/gcc/testsuite/gcc.target/aarch64/gcsss-1.c new file mode 100644 index 00000000000..025c7fee647 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gcsss-1.c @@ -0,0 +1,49 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mbranch-protection=none" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +/* +**foo1: +** sys #3, c7, c7, #2, x0 // gcsss1 +** mov x[0-9]*, 0 +** sysl x[0-9]*, #3, c7, c7, #3 // gcsss2 +** ret +*/ +void +foo1 (void *p) +{ + __builtin_aarch64_gcsss (p); +} + +/* +**foo2: +** sys #3, c7, c7, #2, x0 // gcsss1 +** mov x0, 0 +** sysl x0, #3, c7, c7, #3 // gcsss2 +** ret +*/ +void * +foo2 (void *p) +{ + return __builtin_aarch64_gcsss (p); +} + +/* +**foo3: +** mov x16, 1 +** hint 40 // chkfeat x16 +** cbnz x16, .* +** sys #3, c7, c7, #2, x0 // gcsss1 +** mov x0, 0 +** sysl x0, #3, c7, c7, #3 // gcsss2 +** ret +** mov x0, 0 +** ret +*/ +void * +foo3 (void *p) +{ + if (__builtin_aarch64_chkfeat (1) == 0) + return __builtin_aarch64_gcsss (p); + return 0; +} From patchwork Wed Oct 23 11:05:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99416 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 D2EBE3858282 for ; Wed, 23 Oct 2024 11:09:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 92E5B3858D33; Wed, 23 Oct 2024 11:07:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92E5B3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 92E5B3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681641; cv=none; b=aV5kioZi2SdDXKN5G+t4jCJJUArCHbqk+KdMetuz877birLP6/q/xA2E3m3ApgJsHxyiBoASipK7roYjtcgoCR6/pYDKBtfX89Qz9Ap8XJqlj6TfiHP94/d+K3EkJkCLjS9iW1J4DyYRGyt+Q2T4lGIT/FTDmpjrQZEUTxNWYgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681641; c=relaxed/simple; bh=OCiBHmHvntEPD+6cQ8r6LiDKE7vqj8o6Pm/rjBtq4J4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=nsbGqgjdwktkM3YmPqp7DZFe1tqn3g3rh8iIJle0ZEUkyco5YVliryOGZTxtXO34FHQEX6Pq/IYaF69UlIbgDq9jW8Aq3bJLBiK9xMFtPT/mFiXM5i7IY8I4I2Eu9lLNKfap1gUIZ56wxe7IH27Jp6m+QwIg/f3SHUbxDiZu59o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1B158339; Wed, 23 Oct 2024 04:07:42 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B510C3F528; Wed, 23 Oct 2024 04:07:11 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 09/22] aarch64: Add GCS support for nonlocal stack save Date: Wed, 23 Oct 2024 12:05:15 +0100 Message-Id: <20241023110528.487830-10-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy Nonlocal stack save and restore has to also save and restore the GCS pointer. This is used in __builtin_setjmp/longjmp and nonlocal goto. The GCS specific code is only emitted if GCS branch-protection is enabled and the code always checks at runtime if GCS is enabled. The new -mbranch-protection=gcs and old -mbranch-protection=none code are ABI compatible: jmpbuf for __builtin_setjmp has space for 5 pointers, the layout is old layout: fp, pc, sp, unused, unused new layout: fp, pc, sp, gcsp, unused Note: the ILP32 code generation is wrong as it saves the pointers with Pmode (i.e. 8 bytes per pointer), but the user supplied buffer size is for 5 pointers (4 bytes per pointer), this is not fixed. The nonlocal goto has no ABI compatibility issues as the goto and its destination are in the same translation unit. gcc/ChangeLog: * config/aarch64/aarch64.h (STACK_SAVEAREA_MODE): Make space for gcs. * config/aarch64/aarch64.md (save_stack_nonlocal): New. (restore_stack_nonlocal): New. --- gcc/config/aarch64/aarch64.h | 7 +++ gcc/config/aarch64/aarch64.md | 82 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h index 593319fd472..43a92e85780 100644 --- a/gcc/config/aarch64/aarch64.h +++ b/gcc/config/aarch64/aarch64.h @@ -1297,6 +1297,13 @@ typedef struct #define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \ ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2) +/* Have space for both SP and GCSPR in the NONLOCAL case in + emit_stack_save as well as in __builtin_setjmp, __builtin_longjmp + and __builtin_nonlocal_goto. + Note: On ILP32 the documented buf size is not enough PR84150. */ +#define STACK_SAVEAREA_MODE(LEVEL) \ + ((LEVEL) == SAVE_NONLOCAL ? TImode : Pmode) + #define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, LR_REGNUM) #define RETURN_ADDR_RTX aarch64_return_addr diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index e4e11e35b5b..6e1646387d8 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -1200,6 +1200,88 @@ (define_insn "*cb1" (const_int 1)))] ) +(define_expand "save_stack_nonlocal" + [(set (match_operand 0 "memory_operand") + (match_operand 1 "register_operand"))] + "" +{ + rtx stack_slot = adjust_address (operands[0], Pmode, 0); + emit_move_insn (stack_slot, operands[1]); + + if (aarch64_gcs_enabled ()) + { + /* Save GCS with code like + mov x16, 1 + chkfeat x16 + tbnz x16, 0, .L_done + mrs tmp, gcspr_el0 + str tmp, [%0, 8] + .L_done: */ + + rtx done_label = gen_label_rtx (); + rtx r16 = gen_rtx_REG (DImode, R16_REGNUM); + emit_move_insn (r16, const1_rtx); + emit_insn (gen_aarch64_chkfeat ()); + emit_insn (gen_tbranch_neqi3 (r16, const0_rtx, done_label)); + rtx gcs_slot = adjust_address (operands[0], Pmode, GET_MODE_SIZE (Pmode)); + rtx gcs = force_reg (Pmode, const0_rtx); + emit_insn (gen_aarch64_load_gcspr (gcs)); + emit_move_insn (gcs_slot, gcs); + emit_label (done_label); + } + DONE; +}) + +(define_expand "restore_stack_nonlocal" + [(set (match_operand 0 "register_operand" "") + (match_operand 1 "memory_operand" ""))] + "" +{ + rtx stack_slot = adjust_address (operands[1], Pmode, 0); + emit_move_insn (operands[0], stack_slot); + + if (aarch64_gcs_enabled ()) + { + /* Restore GCS with code like + mov x16, 1 + chkfeat x16 + tbnz x16, 0, .L_done + ldr tmp1, [%1, 8] + mrs tmp2, gcspr_el0 + subs tmp2, tmp1, tmp2 + b.eq .L_done + .L_loop: + gcspopm + subs tmp2, tmp2, 8 + b.ne .L_loop + .L_done: */ + + rtx loop_label = gen_label_rtx (); + rtx done_label = gen_label_rtx (); + rtx r16 = gen_rtx_REG (DImode, R16_REGNUM); + emit_move_insn (r16, const1_rtx); + emit_insn (gen_aarch64_chkfeat ()); + emit_insn (gen_tbranch_neqi3 (r16, const0_rtx, done_label)); + rtx gcs_slot = adjust_address (operands[1], Pmode, GET_MODE_SIZE (Pmode)); + rtx gcs_old = force_reg (Pmode, const0_rtx); + emit_move_insn (gcs_old, gcs_slot); + rtx gcs_now = force_reg (Pmode, const0_rtx); + emit_insn (gen_aarch64_load_gcspr (gcs_now)); + emit_insn (gen_subdi3_compare1 (gcs_now, gcs_old, gcs_now)); + rtx cc_reg = gen_rtx_REG (CC_NZmode, CC_REGNUM); + rtx cmp_rtx = gen_rtx_fmt_ee (EQ, DImode, cc_reg, const0_rtx); + emit_jump_insn (gen_condjump (cmp_rtx, cc_reg, done_label)); + emit_label (loop_label); + emit_insn (gen_aarch64_gcspopm_xzr ()); + emit_insn (gen_adddi3_compare0 (gcs_now, gcs_now, GEN_INT (-8))); + cc_reg = gen_rtx_REG (CC_NZmode, CC_REGNUM); + cmp_rtx = gen_rtx_fmt_ee (NE, DImode, cc_reg, const0_rtx); + emit_jump_insn (gen_condjump (cmp_rtx, cc_reg, loop_label)); + emit_label (done_label); + } + DONE; +}) + ;; ------------------------------------------------------------------- ;; Subroutine calls and sibcalls ;; ------------------------------------------------------------------- From patchwork Wed Oct 23 11:05:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99420 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 AB27B3857C6E for ; Wed, 23 Oct 2024 11:10:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 2547F3858D3C; Wed, 23 Oct 2024 11:07:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2547F3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2547F3858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681649; cv=none; b=XSGPmCBG58JCySjDnK3PgEsLSwlbDhXKpc4w8cuBSpz8RzNW3pyGhJQF7tgwfVwtRGaJnmIeBM01kAh5upgCziEm3i9pGLb3ef98aQW6YotwJDqJBsJGwnTcVufLm8x+jifYT+BAlQ2TCvggfO7tiIbKq12AWzVstREB9z4j+6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681649; c=relaxed/simple; bh=CxFKRKeKnmtsakSSXBG7UO619XKVpq7nm9DKi72v+SQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=EDTURUbHf7sVcuDkVx41Cfec2VdMEptsdM9NdlFhS5PVmD5/0wHhBUQBzE263hn4XEhXgC4Wdd5EYBlqQ6fKWsUEAwQq2tOZgoWgryoZDqoOVebd71g/qYkVdSUamwQurjbAv8gjyU6W5bNHXEGhcpFQCUNluQ7H0Qm/83eUJtE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9553B497; Wed, 23 Oct 2024 04:07:49 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3A80B3F528; Wed, 23 Oct 2024 04:07:19 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 10/22] aarch64: Add non-local goto and jump tests for GCS Date: Wed, 23 Oct 2024 12:05:16 +0100 Message-Id: <20241023110528.487830-11-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Szabolcs Nagy These are scan asm tests only, relying on existing execution tests for runtime coverage. gcc/testsuite/ChangeLog: * gcc.target/aarch64/gcs-nonlocal-1.c: New test. * gcc.target/aarch64/gcs-nonlocal-2.c: New test. --- .../gcc.target/aarch64/gcs-nonlocal-1.c | 25 +++++++++++++++++++ .../gcc.target/aarch64/gcs-nonlocal-2.c | 21 ++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-2.c diff --git a/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-1.c b/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-1.c new file mode 100644 index 00000000000..821fab816f9 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-1.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mbranch-protection=gcs" } */ +/* { dg-final { scan-assembler-times "hint\\t40 // chkfeat x16" 2 } } */ +/* { dg-final { scan-assembler-times "mrs\\tx\[0-9\]+, s3_3_c2_c5_1 // gcspr_el0" 2 } } */ +/* { dg-final { scan-assembler-times "sysl\\txzr, #3, c7, c7, #1 // gcspopm" 1 } } */ + +int bar1 (int); +int bar2 (int); + +void foo (int cmd) +{ + __label__ start; + int x = 0; + + void nonlocal_goto (void) + { + x++; + goto start; + } + +start: + while (bar1 (x)) + if (bar2 (x)) + nonlocal_goto (); +} diff --git a/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-2.c b/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-2.c new file mode 100644 index 00000000000..63dbce36e1e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-2.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mbranch-protection=gcs" } */ +/* { dg-final { scan-assembler-times "hint\\t40 // chkfeat x16" 2 } } */ +/* { dg-final { scan-assembler-times "mrs\\tx\[0-9\]+, s3_3_c2_c5_1 // gcspr_el0" 2 } } */ +/* { dg-final { scan-assembler-times "sysl\\txzr, #3, c7, c7, #1 // gcspopm" 1 } } */ + +void longj (void *buf) +{ + __builtin_longjmp (buf, 1); +} + +void foo (void); +void bar (void); + +void setj (void *buf) +{ + if (__builtin_setjmp (buf)) + foo (); + else + bar (); +} From patchwork Wed Oct 23 11:05:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99413 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 D4B523858416 for ; Wed, 23 Oct 2024 11:08:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id EEC633858D39; Wed, 23 Oct 2024 11:07:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EEC633858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EEC633858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681656; cv=none; b=nyL3aFhfvFJvQ9IUoZd/Wd6Mpy3/Hgm2kAf2Po0owGkm5LMSXrSfx5AcT2LYAGaSww52o3T0pZtp6sSI7vA2kdrPmYgHrtURvUUbrWFRYLJ7d8goIjjRuvU2Bmlslih3HaIo3hpADOP8IpjAn/73wh2BatIIaB1OsSYKf0XSbPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681656; c=relaxed/simple; bh=qzrU0x0BBWGN4Pg01cBJOD6H+hQkmi21DE47SIRifqI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=H5NjC8prGMaX+ScvoQChIOhsaTv3IXJa1AR6t+oyU2WgouR/8ebERPaNk1TeJuvm3jVVFIsZaLtU4iJUeipr0sT/EeLN1ksyaTSUJrTlZ/fgcQi9tp3piPoet5qHHHRxNbhm7ksNeBehpa6jqUESfltxxLi2HyDmzYjgjLc4MPg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 49AC9339; Wed, 23 Oct 2024 04:08:04 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E3EF83F528; Wed, 23 Oct 2024 04:07:33 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 11/22] aarch64: Add ACLE feature macros for GCS Date: Wed, 23 Oct 2024 12:05:17 +0100 Message-Id: <20241023110528.487830-12-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy gcc/ChangeLog: * config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins): Define macros for GCS. --- gcc/config/aarch64/aarch64-c.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc index f9b9e379375..bdc1c0da584 100644 --- a/gcc/config/aarch64/aarch64-c.cc +++ b/gcc/config/aarch64/aarch64-c.cc @@ -247,6 +247,9 @@ aarch64_update_cpp_builtins (cpp_reader *pfile) aarch64_def_or_undef (TARGET_PAUTH, "__ARM_FEATURE_PAUTH", pfile); aarch64_def_or_undef (TARGET_BTI, "__ARM_FEATURE_BTI", pfile); + aarch64_def_or_undef (aarch64_gcs_enabled (), + "__ARM_FEATURE_GCS_DEFAULT", pfile); + aarch64_def_or_undef (TARGET_GCS, "__ARM_FEATURE_GCS", pfile); aarch64_def_or_undef (TARGET_I8MM, "__ARM_FEATURE_MATMUL_INT8", pfile); aarch64_def_or_undef (TARGET_BF16_SIMD, "__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", pfile); From patchwork Wed Oct 23 11:05:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99424 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 32C07385842D for ; Wed, 23 Oct 2024 11:11:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 7954A3858C41; Wed, 23 Oct 2024 11:07:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7954A3858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7954A3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681668; cv=none; b=AthLM/V9BEYnu2SAP2+yTrENLWDcIpyjnwcf5fKSSgiEs0jpWk/8XunzSKj0k6RvlReCaN3x+J6pljKEpyqhzx6IMNJizeedJm/n3JaJOAkDCMHPHXb5fEdCZAlOU2PM8wu0H42ccsfBFoPQF0zuWQMkSwCOarF8jjvZ5pMl1mM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681668; c=relaxed/simple; bh=4TQqSEl7FfAei1qlHhf0OV1ZJDEUYbJMAohvIiHYbAg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=LwPQY/ampACZOx8YmgSfCAMC+1p7GEIP10dfB/CNi5tvFNuq2wLXj0MoTWcgwEk5TKhlZTPBViKidALUjy+75dCYAFGbetgDXKPlHJohrt251bOkz5DvRjthw+EYCxq0+ZU58Kd3qkxLCj+C8PrC8V+9YOafrsokFMdhywo8EAg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F36FF339; Wed, 23 Oct 2024 04:08:10 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9B7CC3F528; Wed, 23 Oct 2024 04:07:40 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 12/22] aarch64: Add test for GCS ACLE defs Date: Wed, 23 Oct 2024 12:05:18 +0100 Message-Id: <20241023110528.487830-13-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Szabolcs Nagy gcc/testsuite/ChangeLog: * gcc.target/aarch64/pragma_cpp_predefs_1.c: GCS test. --- .../gcc.target/aarch64/pragma_cpp_predefs_1.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_1.c b/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_1.c index 307fa3d67da..6122cd55d66 100644 --- a/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_1.c +++ b/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_1.c @@ -268,6 +268,36 @@ #error "__ARM_FEATURE_RCPC is not defined but should be!" #endif +#pragma GCC target ("arch=armv8.8-a+gcs") +#ifndef __ARM_FEATURE_GCS +#error "__ARM_FEATURE_GCS is not defined but should be!" +#endif + +#pragma GCC target ("arch=armv8.8-a+nogcs") +#ifdef __ARM_FEATURE_GCS +#error "__ARM_FEATURE_GCS is defined but should not be!" +#endif + +#pragma GCC target ("arch=armv8.8-a") +#ifdef __ARM_FEATURE_GCS +#error "__ARM_FEATURE_GCS is defined but should not be!" +#endif + +#pragma GCC target ("branch-protection=gcs") +#ifndef __ARM_FEATURE_GCS_DEFAULT +#error "__ARM_FEATURE_GCS_DEFAULT is not defined but should be!" +#endif + +#pragma GCC target ("branch-protection=none") +#ifdef __ARM_FEATURE_GCS_DEFAULT +#error "__ARM_FEATURE_GCS_DEFAULT is defined but should not be!" +#endif + +#pragma GCC target ("branch-protection=standard") +#ifndef __ARM_FEATURE_GCS_DEFAULT +#error "__ARM_FEATURE_GCS_DEFAULT is not defined but should be!" +#endif + int foo (int a) { From patchwork Wed Oct 23 11:05:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99417 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 17CD63858430 for ; Wed, 23 Oct 2024 11:09:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id D44D83858D21; Wed, 23 Oct 2024 11:07:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D44D83858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D44D83858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681678; cv=none; b=YH2ceR9xduOg9Jkc/2Qkb0gRLsS4isV7Bozbph2GQb/dJR1KewGeys5p0/OesRR0/G0pKuquOfdeswpYVdJDPfZDoLpoahlyPmQUZzIEr7sCHh9UPOIqlauECzjgGtVHSISjXf110wEmg7eA1iql48ZD9+IwxZt4LYLyfkDCcOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681678; c=relaxed/simple; bh=lY69+S7SQwIN6hGXEjiB3vlrJN14VG8/7uGhg/reZTs=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=o6+EtSONcmMr7nZfCP52MqtNLqhGtaJOd6LKPTssrRrSlmK5SaN7JEFoCxhCnMgJ00K8YpTBis/4u/NF+43FXOGBmDDgPV14eHBfymePBnY71hyZxqLtgxspc0rTZWM1FKi8/u/+ECaKGcAr9sEUwjzACw6MNTxw4fk9L4N9/SI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5CD74497; Wed, 23 Oct 2024 04:08:17 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 02BAB3F7A6; Wed, 23 Oct 2024 04:07:46 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 13/22] aarch64: Add target pragma tests for gcs Date: Wed, 23 Oct 2024 12:05:19 +0100 Message-Id: <20241023110528.487830-14-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Szabolcs Nagy gcc/testsuite/ChangeLog: * gcc.target/aarch64/pragma_cpp_predefs_4.c: Add gcs specific tests. --- .../gcc.target/aarch64/pragma_cpp_predefs_4.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_4.c b/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_4.c index 8e707630774..417293d4d5a 100644 --- a/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_4.c +++ b/gcc/testsuite/gcc.target/aarch64/pragma_cpp_predefs_4.c @@ -91,6 +91,9 @@ #if __ARM_FEATURE_PAC_DEFAULT != 1 #error Foo #endif +#ifndef __ARM_FEATURE_GCS_DEFAULT +#error Foo +#endif #pragma GCC target ("branch-protection=none") #ifdef __ARM_FEATURE_BTI_DEFAULT @@ -99,6 +102,9 @@ #ifdef __ARM_FEATURE_PAC_DEFAULT #error Foo #endif +#ifdef __ARM_FEATURE_GCS_DEFAULT +#error Foo +#endif #pragma GCC push_options #pragma GCC target "branch-protection=bti+pac-ret" @@ -117,6 +123,9 @@ #ifdef __ARM_FEATURE_PAC_DEFAULT #error Foo #endif +#ifdef __ARM_FEATURE_GCS_DEFAULT +#error Foo +#endif #pragma GCC target "branch-protection=pac-ret" #ifdef __ARM_FEATURE_BTI_DEFAULT @@ -133,3 +142,29 @@ #if __ARM_FEATURE_PAC_DEFAULT != 6 #error Foo #endif + +#pragma GCC target "branch-protection=gcs" +#ifdef __ARM_FEATURE_BTI_DEFAULT +#error Foo +#endif +#ifdef __ARM_FEATURE_PAC_DEFAULT +#error Foo +#endif +#ifndef __ARM_FEATURE_GCS_DEFAULT +#error Foo +#endif + +#pragma GCC target "arch=armv8.8-a+gcs" +#ifndef __ARM_FEATURE_GCS +#error Foo +#endif + +#pragma GCC target "arch=armv8.8-a+nogcs" +#ifdef __ARM_FEATURE_GCS +#error Foo +#endif + +#pragma GCC target "arch=armv8.8-a" +#ifdef __ARM_FEATURE_GCS +#error Foo +#endif From patchwork Wed Oct 23 11:05:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99427 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 B01F6385841D for ; Wed, 23 Oct 2024 11:12:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 9EA983858D28; Wed, 23 Oct 2024 11:08:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EA983858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9EA983858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681704; cv=none; b=IKXnY+rLAfwUoqF9IOf4PjPGC8kzqP8x6qV++2ayTESiPTUpR0nXZ6+feI8xptyUt2wRYF8ZzyRQ/1hK92WuTBEt+GYr9Bi0DOLWhfxvjJBsCLltDWj8pt/Ey1C4oxRaG+HNNa6Z3ItIfZ3xMz1jLrDk+jQ/b86jU5V93Q9JyWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681704; c=relaxed/simple; bh=ansGdE7IrYTT3POMNLnk6XU7LOoBRS41ualRlBrVjPg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=uCNCu/0euBe1N6MY8zNe5DBcSvYxvjrL6c5SQ601oKecYtBkRKIYfqZkdPJfaKLOFu84LD77E5pLbLDOAmFPdoGORnESOvkg+Fa+IiH7h5sks7vqbHP3IP47TX5KsyeNwm9pkbk/6Cs1A82GXw1xXOsFLfsIZdad0xNwXb9fCYU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 266A8339; Wed, 23 Oct 2024 04:08:42 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BF83E3F528; Wed, 23 Oct 2024 04:08:11 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 14/22] aarch64: Add GCS support to the unwinder Date: Wed, 23 Oct 2024 12:05:20 +0100 Message-Id: <20241023110528.487830-15-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Szabolcs Nagy Follows the current linux ABI that uses single signal entry token and shared shadow stack between thread and alt stack. Could be behind __ARM_FEATURE_GCS_DEFAULT ifdef (only do anything special with gcs compat codegen) but there is a runtime check anyway. Change affected tests to be compatible with -mbranch-protection=standard gcc/testsuite/ChangeLog: * g++.target/aarch64/pr94515-1.C (f1_no_pac_ret): Update. (main): Update. Co-authored-by: Matthieu Longo * gcc.target/aarch64/pr104689.c (unwind): Update. Co-authored-by: Matthieu Longo libgcc/ChangeLog: * config/aarch64/aarch64-unwind.h (_Unwind_Frames_Extra): Update. (_Unwind_Frames_Increment): Define. Co-authored-by: Matthieu Longo --- gcc/testsuite/g++.target/aarch64/pr94515-1.C | 6 +- gcc/testsuite/gcc.target/aarch64/pr104689.c | 3 +- libgcc/config/aarch64/aarch64-unwind.h | 59 +++++++++++++++++++- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/g++.target/aarch64/pr94515-1.C b/gcc/testsuite/g++.target/aarch64/pr94515-1.C index 359039e1753..8175ea50c32 100644 --- a/gcc/testsuite/g++.target/aarch64/pr94515-1.C +++ b/gcc/testsuite/g++.target/aarch64/pr94515-1.C @@ -5,7 +5,7 @@ volatile int zero = 0; -__attribute__((noinline, target("branch-protection=none"))) +__attribute__((noinline, target("branch-protection=bti"))) void unwind (void) { if (zero == 0) @@ -22,7 +22,7 @@ int test (int z) // autiasp -> cfi_negate_ra_state: RA_signing_SP -> RA_no_signing return 1; } else { - // 2nd cfi_negate_ra_state because the CFI directives are processed linearily. + // 2nd cfi_negate_ra_state because the CFI directives are processed linearly. // At this point, the unwinder would believe that the address is not signed // due to the previous return. That's why the compiler has to emit second // cfi_negate_ra_state to mean that the return address is still signed. @@ -33,7 +33,7 @@ int test (int z) } } -__attribute__((target("branch-protection=none"))) +__attribute__((target("branch-protection=bti"))) int main () { try { diff --git a/gcc/testsuite/gcc.target/aarch64/pr104689.c b/gcc/testsuite/gcc.target/aarch64/pr104689.c index 3b7adbdfe7d..9688ecc85f9 100644 --- a/gcc/testsuite/gcc.target/aarch64/pr104689.c +++ b/gcc/testsuite/gcc.target/aarch64/pr104689.c @@ -98,6 +98,7 @@ asm("" "unusual_no_pac_ret:\n" " .cfi_startproc\n" " " SET_RA_STATE_0 "\n" +" bti c\n" " stp x29, x30, [sp, -16]!\n" " .cfi_def_cfa_offset 16\n" " .cfi_offset 29, -16\n" @@ -121,7 +122,7 @@ static void f2_pac_ret (void) die (); } -__attribute__((target("branch-protection=none"))) +__attribute__((target("branch-protection=bti"))) static void f1_no_pac_ret (void) { unusual_pac_ret (f2_pac_ret); diff --git a/libgcc/config/aarch64/aarch64-unwind.h b/libgcc/config/aarch64/aarch64-unwind.h index 4d36f0b26f7..cf4ec749c05 100644 --- a/libgcc/config/aarch64/aarch64-unwind.h +++ b/libgcc/config/aarch64/aarch64-unwind.h @@ -178,6 +178,9 @@ aarch64_demangle_return_addr (struct _Unwind_Context *context, return addr; } +/* GCS enable flag for chkfeat instruction. */ +#define CHKFEAT_GCS 1 + /* SME runtime function local to libgcc, streaming compatible and preserves more registers than the base PCS requires, but we don't rely on that here. */ @@ -185,12 +188,66 @@ __attribute__ ((visibility ("hidden"))) void __libgcc_arm_za_disable (void); /* Disable the SME ZA state in case an unwound frame used the ZA - lazy saving scheme. */ + lazy saving scheme. And unwind the GCS for EH. */ #undef _Unwind_Frames_Extra #define _Unwind_Frames_Extra(x) \ do \ { \ __libgcc_arm_za_disable (); \ + if (__builtin_aarch64_chkfeat (CHKFEAT_GCS) == 0) \ + { \ + for (_Unwind_Word n = (x); n != 0; n--) \ + __builtin_aarch64_gcspopm (); \ + } \ + } \ + while (0) + +/* On signal entry the OS places a token on the GCS that can be used to + verify the integrity of the GCS pointer on signal return. It also + places the signal handler return address (the restorer that calls the + signal return syscall) on the GCS so the handler can return. + Because of this token, each stack frame visited during unwinding has + exactly one corresponding entry on the GCS, so the frame count is + the number of entries that will have to be popped at EH return time. + + Note: This depends on the GCS signal ABI of the OS. + + When unwinding across a stack frame for each frame the corresponding + entry is checked on the GCS against the computed return address from + the normal stack. If they don't match then _URC_FATAL_PHASE2_ERROR + is returned. This check is omitted if + + 1. GCS is disabled. Note: asynchronous GCS disable is supported here + if GCSPR and the GCS remains readable. + 2. Non-catchable exception where exception_class == 0. Note: the + pthread cancellation implementation in glibc sets exception_class + to 0 when the unwinder is used for cancellation cleanup handling, + so this allows the GCS to get out of sync during cancellation. + This weakens security but avoids an ABI break in glibc. + 3. Zero return address which marks the outermost stack frame. + 4. Signal stack frame, the GCS entry is an OS specific token then + with the top bit set. + */ +#undef _Unwind_Frames_Increment +#define _Unwind_Frames_Increment(exc, context, frames) \ + do \ + { \ + frames++; \ + if (__builtin_aarch64_chkfeat (CHKFEAT_GCS) != 0 \ + || exc->exception_class == 0 \ + || _Unwind_GetIP (context) == 0) \ + break; \ + const _Unwind_Word *gcs = __builtin_aarch64_gcspr (); \ + if (_Unwind_IsSignalFrame (context)) \ + { \ + if (gcs[frames] >> 63 == 0) \ + return _URC_FATAL_PHASE2_ERROR; \ + } \ + else \ + { \ + if (gcs[frames] != _Unwind_GetIP (context)) \ + return _URC_FATAL_PHASE2_ERROR; \ + } \ } \ while (0) From patchwork Wed Oct 23 11:05:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99415 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 B1A533858C56 for ; Wed, 23 Oct 2024 11:09:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 8819C3858D33; Wed, 23 Oct 2024 11:08:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8819C3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8819C3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681711; cv=none; b=Y9hAILMARoGMeGOeq0SUUwSMItiDk7pvttjg/W/S6RTLPNFCIAUSpdrFGtLLP8sV2ByvRkh9dDzlvYN+MzzrOmgdcWIABdUs6kmLT1H4r9cUA+2wdnJLLrLygo6OmXdJjcAyW58RrpBQBeRXHj+BvBJM1dePPoXHn/W5OpYfIvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681711; c=relaxed/simple; bh=LH0Iq/BEySAQs7NIF3ggj8u5y43IX0osXFmmxcdxnI8=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=kJegsk+buB9oNGq8yKBFP9hVbfLjTejidYg+uJGVrrywiLhSwX79o0MTVqMS1CdFowsZKUqR8nuYx3NNonyHremDgsLsyYW1hu9lfZycX+Iyr8xY0b79sgdJO3Ww3Fe9f8t/kZGznzC4jn3hkvqKD1M+osQzY+0Fx6KufHe6YcE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0FCC9497; Wed, 23 Oct 2024 04:08:49 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A99673F528; Wed, 23 Oct 2024 04:08:18 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 15/22] aarch64: Emit GNU property NOTE for GCS Date: Wed, 23 Oct 2024 12:05:21 +0100 Message-Id: <20241023110528.487830-16-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy gcc/ChangeLog: * config/aarch64/aarch64.cc (GNU_PROPERTY_AARCH64_FEATURE_1_GCS): Define. (aarch64_file_end_indicate_exec_stack): Set GCS property bit. --- gcc/config/aarch64/aarch64.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 33f97d42d55..a89a30113b9 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -29242,6 +29242,7 @@ aarch64_can_tag_addresses () #define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) #define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1) +#define GNU_PROPERTY_AARCH64_FEATURE_1_GCS (1U << 2) void aarch64_file_end_indicate_exec_stack () { @@ -29254,6 +29255,9 @@ aarch64_file_end_indicate_exec_stack () if (aarch_ra_sign_scope != AARCH_FUNCTION_NONE) feature_1_and |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC; + if (aarch64_gcs_enabled ()) + feature_1_and |= GNU_PROPERTY_AARCH64_FEATURE_1_GCS; + if (feature_1_and) { /* Generate .note.gnu.property section. */ @@ -29285,6 +29289,7 @@ aarch64_file_end_indicate_exec_stack () assemble_align (POINTER_SIZE); } } +#undef GNU_PROPERTY_AARCH64_FEATURE_1_GCS #undef GNU_PROPERTY_AARCH64_FEATURE_1_PAC #undef GNU_PROPERTY_AARCH64_FEATURE_1_BTI #undef GNU_PROPERTY_AARCH64_FEATURE_1_AND From patchwork Wed Oct 23 11:05:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99422 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 E17D73858294 for ; Wed, 23 Oct 2024 11:10:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id C5CA8385842D; Wed, 23 Oct 2024 11:08:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5CA8385842D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C5CA8385842D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681724; cv=none; b=w6op3hLcXWs1fsShE32KmDz5nKMrmDY9z8CKEOWArKQrFmVuj79xjLx7aVl9ORMoSezzuKdfHeQqIUouWHD6M6SaLRPYrRlaxWhB/g4hPuxxPn916TUBz7tBwcl2PaqU5+9MjhCBsJzAzCe/hlmMhOU4WKP1d8yLC/L93HZ9a8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681724; c=relaxed/simple; bh=6SmsPnsLBaRuYUm/xz72s0PjLDVpUSvCZVMXTowHFVg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=pmH8VvXGfjfTIP246tNWC3NX+JfXUXEwd0kjNFQs0p7+xaC15JRaGOK/EWdsBaXL0S2NSHPqgw/gZcmuyJzBfGJTZrn1hjqTBLfQ4n9idr8fZM2cg0U95FB4DT3m9W0xVOQceZQa+O4J72AfFVVwIyVyG2nofuG7r7SprsIz9CY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3225E339; Wed, 23 Oct 2024 04:09:06 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CC9923F528; Wed, 23 Oct 2024 04:08:35 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 16/22] aarch64: libgcc: add GCS marking to asm Date: Wed, 23 Oct 2024 12:05:22 +0100 Message-Id: <20241023110528.487830-17-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, KAM_STOCKGEN, 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 From: Szabolcs Nagy libgcc/ChangeLog: * config/aarch64/aarch64-asm.h (FEATURE_1_GCS): Define. (GCS_FLAG): Define if GCS is enabled. (GNU_PROPERTY): Add GCS_FLAG. --- libgcc/config/aarch64/aarch64-asm.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libgcc/config/aarch64/aarch64-asm.h b/libgcc/config/aarch64/aarch64-asm.h index d8ab91d52f1..f7bd225f7a4 100644 --- a/libgcc/config/aarch64/aarch64-asm.h +++ b/libgcc/config/aarch64/aarch64-asm.h @@ -22,6 +22,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +#ifndef AARCH64_ASM_H +#define AARCH64_ASM_H + #include "auto-target.h" #define L(label) .L ## label @@ -38,6 +41,7 @@ #define FEATURE_1_AND 0xc0000000 #define FEATURE_1_BTI 1 #define FEATURE_1_PAC 2 +#define FEATURE_1_GCS 4 /* Supported features based on the code generation options. */ #if defined(__ARM_FEATURE_BTI_DEFAULT) @@ -58,6 +62,12 @@ # define AUTIASP #endif +#if __ARM_FEATURE_GCS_DEFAULT +# define GCS_FLAG FEATURE_1_GCS +#else +# define GCS_FLAG 0 +#endif + #ifdef __ELF__ #define HIDDEN(name) .hidden name #define SYMBOL_SIZE(name) .size name, .-name @@ -88,8 +98,8 @@ .previous /* Add GNU property note if built with branch protection. */ -# if (BTI_FLAG|PAC_FLAG) != 0 -GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG) +# if (BTI_FLAG|PAC_FLAG|GCS_FLAG) != 0 +GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG|GCS_FLAG) # endif #endif @@ -106,3 +116,5 @@ GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG) #define END(name) \ .cfi_endproc; \ SYMBOL_SIZE(name) + +#endif From patchwork Wed Oct 23 11:05:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99419 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 7E9FB385802C for ; Wed, 23 Oct 2024 11:10:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 2EE323858C51; Wed, 23 Oct 2024 11:08:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EE323858C51 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2EE323858C51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681730; cv=none; b=ALqXqeQ6/UeQ9Bx0ioxAlvEiGDC2StD29X/eVWdUFyjf7O/AcvBy+ZcKT0O4LzTKXI6QXS6IcXoV7rn17cXZY4/Ceouj5KI0bl+4BP06l4CJZvj+VEqfqlhKjfKEGRrvrM4t4FqtrhKvlW27Pf8gei5DnnVqFdoqypKt4qNuVEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681730; c=relaxed/simple; bh=+9B4Bf6lEsocpTKk6tRcOgLk91iuoRD7u7ihLBuovXM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=aYCoKKEtHfbLNaq0Q7l7z+zWzWFfgcVn+2r8Zrdcjqeq+w+CKLH9SSsQaDHWFQ2TMNsMnqCfhWcu+4qCPHp/BOYnErV6Ofbo6iZpFU2NDQY+zUVlgEHxVdfnEJzo5a39OtSgDyJkO1ANOsNs2QPfCefc6vcU2t0Fd3vPhMyBrqI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A44BB497; Wed, 23 Oct 2024 04:09:13 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4A0A03F528; Wed, 23 Oct 2024 04:08:43 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 17/22] aarch64: libatomic: add GCS marking to asm Date: Wed, 23 Oct 2024 12:05:23 +0100 Message-Id: <20241023110528.487830-18-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy libatomic/ChangeLog: * config/linux/aarch64/atomic_16.S (FEATURE_1_GCS): Define. (GCS_FLAG): Define if GCS is enabled. (GNU_PROPERTY): Add GCS_FLAG. --- libatomic/config/linux/aarch64/atomic_16.S | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libatomic/config/linux/aarch64/atomic_16.S b/libatomic/config/linux/aarch64/atomic_16.S index 5767fba5c03..685db776382 100644 --- a/libatomic/config/linux/aarch64/atomic_16.S +++ b/libatomic/config/linux/aarch64/atomic_16.S @@ -775,6 +775,7 @@ END_FEAT (compare_exchange_16, LSE) #define FEATURE_1_AND 0xc0000000 #define FEATURE_1_BTI 1 #define FEATURE_1_PAC 2 +#define FEATURE_1_GCS 4 /* Supported features based on the code generation options. */ #if defined(__ARM_FEATURE_BTI_DEFAULT) @@ -789,6 +790,12 @@ END_FEAT (compare_exchange_16, LSE) # define PAC_FLAG 0 #endif +#if __ARM_FEATURE_GCS_DEFAULT +# define GCS_FLAG FEATURE_1_GCS +#else +# define GCS_FLAG 0 +#endif + /* Add a NT_GNU_PROPERTY_TYPE_0 note. */ #define GNU_PROPERTY(type, value) \ .section .note.gnu.property, "a"; \ @@ -806,7 +813,7 @@ END_FEAT (compare_exchange_16, LSE) .section .note.GNU-stack, "", %progbits /* Add GNU property note if built with branch protection. */ -# if (BTI_FLAG|PAC_FLAG) != 0 -GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG) +# if (BTI_FLAG|PAC_FLAG|GCS_FLAG) != 0 +GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG|GCS_FLAG) # endif #endif From patchwork Wed Oct 23 11:05:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99425 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 380653857C5F for ; Wed, 23 Oct 2024 11:11:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 5CA273858D21; Wed, 23 Oct 2024 11:08:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CA273858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5CA273858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681734; cv=none; b=iGq+O5k8woGjwMeqqTUKA7R6WG9x8ykCy5uEyqMyvY52XOjSohwir+Uhtvez9goVv8v/GdOiJI6/r6zBiFwNCunF+7CpqT6nftNYBLVnKVN9SmiBfA9Lh+0UD45fG2gl0uVyUAsQFw1d/pIAkOReQReymDrhIlv5zf4+WK9PsyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681734; c=relaxed/simple; bh=/oDS8HC92DJw62fg1qMSs/toY9WOG+APO4PcVDIgKfg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=EpELAUY3QnRF4nWh7L61F8nL62KO2vgllZKn0STt3OOpLX8tukXKUEuXsvW4a1GfrotlLZslyHc7+U2rrkhvZFa4u87stPmwppkD9m0liZE6VV9ijATj2TbOk4FDfg0VJ8ephsMGAxBXXCbbJDAMklB7NOMwUyQyi1bnGavok6c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CFD8D339; Wed, 23 Oct 2024 04:09:19 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 745993F528; Wed, 23 Oct 2024 04:08:49 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 18/22] aarch64: libitm: Add GCS support Date: Wed, 23 Oct 2024 12:05:24 +0100 Message-Id: <20241023110528.487830-19-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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 From: Szabolcs Nagy Transaction begin and abort use setjmp/longjmp like operations that need to be updated for GCS compatibility. We use similar logic to libc setjmp/longjmp that support switching stack and thus switching GCS (e.g. due to longjmp out of a makecontext stack), this is kept even though it is likely not required for transaction aborts. The gtm_jmpbuf is internal to libitm so we can change its layout without breaking ABI. libitm/ChangeLog: * config/aarch64/sjlj.S: Add GCS support and mark GCS compatible. * config/aarch64/target.h: Add gcs field to gtm_jmpbuf. --- libitm/config/aarch64/sjlj.S | 60 ++++++++++++++++++++++++++++++++-- libitm/config/aarch64/target.h | 1 + 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/libitm/config/aarch64/sjlj.S b/libitm/config/aarch64/sjlj.S index aeffd4d1070..cf1d8af2c96 100644 --- a/libitm/config/aarch64/sjlj.S +++ b/libitm/config/aarch64/sjlj.S @@ -29,6 +29,13 @@ #define AUTIASP hint 29 #define PACIBSP hint 27 #define AUTIBSP hint 31 +#define CHKFEAT_X16 hint 40 +#define MRS_GCSPR(x) mrs x, s3_3_c2_c5_1 +#define GCSPOPM(x) sysl x, #3, c7, c7, #1 +#define GCSSS1(x) sys #3, c7, c7, #2, x +#define GCSSS2(x) sysl x, #3, c7, c7, #3 + +#define L(name) .L##name #if defined(HAVE_AS_CFI_PSEUDO_OP) && defined(__GCC_HAVE_DWARF2_CFI_ASM) # define cfi_negate_ra_state .cfi_negate_ra_state @@ -80,7 +87,16 @@ _ITM_beginTransaction: stp d10, d11, [sp, 7*16] stp d12, d13, [sp, 8*16] stp d14, d15, [sp, 9*16] - str x1, [sp, 10*16] + + /* GCS support. */ + mov x2, 0 + mov x16, 1 + CHKFEAT_X16 + tbnz x16, 0, L(gcs_done_sj) + MRS_GCSPR (x2) + add x2, x2, 8 /* GCS after _ITM_beginTransaction returns. */ +L(gcs_done_sj): + stp x2, x1, [sp, 10*16] /* Invoke GTM_begin_transaction with the struct we just built. */ mov x1, sp @@ -117,7 +133,38 @@ GTM_longjmp: ldp d10, d11, [x1, 7*16] ldp d12, d13, [x1, 8*16] ldp d14, d15, [x1, 9*16] + + /* GCS support. */ + mov x16, 1 + CHKFEAT_X16 + tbnz x16, 0, L(gcs_done_lj) + MRS_GCSPR (x7) ldr x3, [x1, 10*16] + mov x4, x3 + /* x7: GCSPR now. x3, x4: target GCSPR. x5, x6: tmp regs. */ +L(gcs_scan): + cmp x7, x4 + b.eq L(gcs_pop) + sub x4, x4, 8 + /* Check for a cap token. */ + ldr x5, [x4] + and x6, x4, 0xfffffffffffff000 + orr x6, x6, 1 + cmp x5, x6 + b.ne L(gcs_scan) +L(gcs_switch): + add x7, x4, 8 + GCSSS1 (x4) + GCSSS2 (xzr) +L(gcs_pop): + cmp x7, x3 + b.eq L(gcs_done_lj) + GCSPOPM (xzr) + add x7, x7, 8 + b L(gcs_pop) +L(gcs_done_lj): + + ldr x3, [x1, 10*16 + 8] ldp x29, x30, [x1] cfi_def_cfa(x1, 0) CFI_PAC_TOGGLE @@ -132,6 +179,7 @@ GTM_longjmp: #define FEATURE_1_AND 0xc0000000 #define FEATURE_1_BTI 1 #define FEATURE_1_PAC 2 +#define FEATURE_1_GCS 4 /* Supported features based on the code generation options. */ #if defined(__ARM_FEATURE_BTI_DEFAULT) @@ -146,6 +194,12 @@ GTM_longjmp: # define PAC_FLAG 0 #endif +#if __ARM_FEATURE_GCS_DEFAULT +# define GCS_FLAG FEATURE_1_GCS +#else +# define GCS_FLAG 0 +#endif + /* Add a NT_GNU_PROPERTY_TYPE_0 note. */ #define GNU_PROPERTY(type, value) \ .section .note.gnu.property, "a"; \ @@ -163,7 +217,7 @@ GTM_longjmp: .section .note.GNU-stack, "", %progbits /* Add GNU property note if built with branch protection. */ -# if (BTI_FLAG|PAC_FLAG) != 0 -GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG) +# if (BTI_FLAG|PAC_FLAG|GCS_FLAG) != 0 +GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG|GCS_FLAG) # endif #endif diff --git a/libitm/config/aarch64/target.h b/libitm/config/aarch64/target.h index 3d99197bfab..a1f39b4bf7a 100644 --- a/libitm/config/aarch64/target.h +++ b/libitm/config/aarch64/target.h @@ -30,6 +30,7 @@ typedef struct gtm_jmpbuf unsigned long long pc; /* x30 */ unsigned long long gr[10]; /* x19-x28 */ unsigned long long vr[8]; /* d8-d15 */ + void *gcs; /* GCSPR_EL0 */ void *cfa; } gtm_jmpbuf; From patchwork Wed Oct 23 11:05:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99428 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 3A3A53858C50 for ; Wed, 23 Oct 2024 11:13:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 34A933858C52; Wed, 23 Oct 2024 11:08:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 34A933858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 34A933858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681741; cv=none; b=YsXIlSRZ2nugw+PrMPLYSGvjfLMAXtJ0mTzd1L2wTfTEgqrl/bPaqJ/WxhtBYc67HLO6649uSH8hyI7/XwQ6ObIR4vcrqD9Kn/Urpnzo1C/vzKePro7StiPHR+8/XZUVgNxLCjKLciRScpSd0gRyi/yjgMpFoVN6U6F7GvJVgGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681741; c=relaxed/simple; bh=x8Rs2pOxCkSaPfQjaJ4Lt2UppedOMJZlFWeNPLZflls=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=hfmkFjLiFy2393685lT07hEZGOCLPQK093vSSjv6Z4udI1mDErnrthCaF1dZp5ypIcQEobLEXOsCx5JUErd3kL+zccOrjvMg+1/BTfZK5f24G1Z8HR63o/SG14oXyU6AKapi6oThuEq9FzPqtH9HmqrctdH056bm9YHpQhR6f6I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B14AB339; Wed, 23 Oct 2024 04:09:26 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 57A573F528; Wed, 23 Oct 2024 04:08:56 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 19/22] aarch64: Introduce indirect_return attribute Date: Wed, 23 Oct 2024 12:05:25 +0100 Message-Id: <20241023110528.487830-20-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_STOCKGEN, 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 From: Szabolcs Nagy Tail calls of indirect_return functions from non-indirect_return functions are disallowed even if BTI is disabled, since the call site may have BTI enabled. Following x86, mismatching attribute on function pointers is not a type error even though this can lead to bugs. Needed for swapcontext within the same function when GCS is enabled. gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_gnu_attributes): Add indirect_return. (aarch64_function_ok_for_sibcall): Disallow tail calls if caller is non-indirect_return but callee is indirect_return. (aarch64_comp_type_attributes): Check indirect_return attribute. * config/arm/aarch-bti-insert.cc (call_needs_bti_j): New. (rest_of_insert_bti): Use call_needs_bti_j. --- gcc/config/aarch64/aarch64.cc | 11 +++++++++ gcc/config/arm/aarch-bti-insert.cc | 36 ++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index a89a30113b9..9bfc9a1dbba 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -853,6 +853,7 @@ static const attribute_spec aarch64_gnu_attributes[] = affects_type_identity, handler, exclude } */ { "aarch64_vector_pcs", 0, 0, false, true, true, true, handle_aarch64_vector_pcs_attribute, NULL }, + { "indirect_return", 0, 0, false, true, true, false, NULL, NULL }, { "arm_sve_vector_bits", 1, 1, false, true, false, true, aarch64_sve::handle_arm_sve_vector_bits_attribute, NULL }, @@ -6429,6 +6430,14 @@ aarch64_function_ok_for_sibcall (tree, tree exp) if (bool (aarch64_cfun_shared_flags (state)) != bool (aarch64_fntype_shared_flags (fntype, state))) return false; + + /* BTI J is needed where indirect_return functions may return + if bti is enabled there. */ + if (lookup_attribute ("indirect_return", TYPE_ATTRIBUTES (fntype)) + && !lookup_attribute ("indirect_return", + TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))) + return false; + return true; } @@ -29118,6 +29127,8 @@ aarch64_comp_type_attributes (const_tree type1, const_tree type2) if (!check_attr ("gnu", "aarch64_vector_pcs")) return 0; + if (!check_attr ("gnu", "indirect_return")) + return 0; if (!check_attr ("gnu", "Advanced SIMD type")) return 0; if (!check_attr ("gnu", "SVE type")) diff --git a/gcc/config/arm/aarch-bti-insert.cc b/gcc/config/arm/aarch-bti-insert.cc index 14d36971cd4..403afff9120 100644 --- a/gcc/config/arm/aarch-bti-insert.cc +++ b/gcc/config/arm/aarch-bti-insert.cc @@ -92,6 +92,35 @@ const pass_data pass_data_insert_bti = 0, /* todo_flags_finish. */ }; +/* Decide if BTI J is needed after a call instruction. */ +static bool +call_needs_bti_j (rtx_insn *insn) +{ + /* Call returns twice, one of which may be indirect. */ + if (find_reg_note (insn, REG_SETJMP, NULL)) + return true; + + /* Tail call does not return. */ + if (SIBLING_CALL_P (insn)) + return false; + + /* Check if the function is marked to return indirectly. */ + rtx call = get_call_rtx_from (insn); + rtx fnaddr = XEXP (call, 0); + tree fndecl = NULL_TREE; + if (GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF) + fndecl = SYMBOL_REF_DECL (XEXP (fnaddr, 0)); + if (fndecl == NULL_TREE) + fndecl = MEM_EXPR (fnaddr); + if (!fndecl) + return false; + if (TREE_CODE (TREE_TYPE (fndecl)) != FUNCTION_TYPE + && TREE_CODE (TREE_TYPE (fndecl)) != METHOD_TYPE) + return false; + tree fntype = TREE_TYPE (fndecl); + return lookup_attribute ("indirect_return", TYPE_ATTRIBUTES (fntype)); +} + /* Insert the BTI instruction. */ /* This is implemented as a late RTL pass that runs before branch shortening and does the following. */ @@ -147,10 +176,9 @@ rest_of_insert_bti (void) } } - /* Also look for calls to setjmp () which would be marked with - REG_SETJMP note and put a BTI J after. This is where longjump () - will return. */ - if (CALL_P (insn) && (find_reg_note (insn, REG_SETJMP, NULL))) + /* Also look for calls that may return indirectly, such as setjmp, + and put a BTI J after them. */ + if (CALL_P (insn) && call_needs_bti_j (insn)) { bti_insn = aarch_gen_bti_j (); emit_insn_after (bti_insn, insn); From patchwork Wed Oct 23 11:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99418 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 1BAE53857BBA for ; Wed, 23 Oct 2024 11:09:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 53D243858416; Wed, 23 Oct 2024 11:09:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53D243858416 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 53D243858416 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681753; cv=none; b=nT1kB2HD88XTuYlhoTEPna3nV5+iO8KAdXQODR76CUBfr8jK5GmiUQrrphpjUlDLeJSzPPJ8intqQzULnOO/0f9wOA4q75b+R6swhIi3eyGkTpzQouBsv/FkND6i6FrYOXBUEBxljss1t9KSYQb8rE1uzoQvyOKQDzp42JGRj3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681753; c=relaxed/simple; bh=Nx2DvICM9Qfl4rhmNEerZRWrLldE3WPyDvHo9iEVUgE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=G1Jf1+GLXTfo7r/Zlpw3ejHuKYtb24OEEqTnAyVb+0Ct4UXjGaeCrtfCc0Ow3kLD9A4X1Oq3tvv7qVP013tqVuOGhK+Q0dt5DwgYlJYySO9YjIXKZszJWr8BMjTtAPDVSVOCs4Czvqjk4a9knBG5/mj30A+RFmGw0xWw2mK4sr4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CFE7B339; Wed, 23 Oct 2024 04:09:32 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 762953F528; Wed, 23 Oct 2024 04:09:02 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 20/22] aarch64: Add tests and docs for indirect_return attribute Date: Wed, 23 Oct 2024 12:05:26 +0100 Message-Id: <20241023110528.487830-21-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Richard Ball This patch adds a new testcase and docs for the indirect_return attribute. gcc/ChangeLog: * doc/extend.texi: Add AArch64 docs for indirect_return attribute. gcc/testsuite/ChangeLog: * gcc.target/aarch64/indirect_return.c: New test. Co-authored-by: Yury Khrustalev --- gcc/doc/extend.texi | 5 ++++ .../gcc.target/aarch64/indirect_return.c | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/indirect_return.c diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 42bd567119d..45e2b3ec569 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -4760,6 +4760,11 @@ Enable or disable calls to out-of-line helpers to implement atomic operations. This corresponds to the behavior of the command-line options @option{-moutline-atomics} and @option{-mno-outline-atomics}. +@cindex @code{indirect_return} function attribute, AArch64 +@item indirect_return +Used to inform the compiler that a function may return via +an indirect return. Adds a BTI J instruction under @option{mbranch-protection=} bti. + @end table The above target attributes can be specified as follows: diff --git a/gcc/testsuite/gcc.target/aarch64/indirect_return.c b/gcc/testsuite/gcc.target/aarch64/indirect_return.c new file mode 100644 index 00000000000..f1ef56d5557 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/indirect_return.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-mbranch-protection=bti" } */ + +int __attribute((indirect_return)) +foo (int a) +{ + return a; +} + +/* +**func1: +** hint 34 // bti c +** ... +** bl foo +** hint 36 // bti j +** ... +** ret +*/ +int +func1 (int a, int b) +{ + return foo (a + b); +} + +/* { dg-final { check-function-bodies "**" "" "" } } */ From patchwork Wed Oct 23 11:05:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99426 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 90F583857BA5 for ; Wed, 23 Oct 2024 11:11:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id AF4C23857C6A; Wed, 23 Oct 2024 11:09:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF4C23857C6A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AF4C23857C6A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681755; cv=none; b=ZM5fzc1ygCT98iS7fCmyD5XE4DumtBo3U2UbQJnXuxhK9HvJR+XK2/5dAMA6k83t5pFitD9wMPDsvvutk8p6SHQCpMuL3k9Paom0p1Rj3FtqGP5qraBfM/5E7D7O/zUBKtJbiMyk4jJM79ZDIAk0tZzHi/gS4NxiAJOy1WfKqGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681755; c=relaxed/simple; bh=+MmeyNrxOyE2Vp+k+iVYy41VmM8wxZFbSIXownj0CUY=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=xZz+QHUYpyW7Y7CP/i9fvpRnOxNDK8fdlXMD4FF9FTudjlivX6+KnufbkD73Iz4CQbcoY/moVX0C06aGHRxXSOk+OpAKN+Iu2KSIPdKA1KcZ+1ZctfUVZe0JyuRlwrNaA9crGud0CRdptgWrAZ5wYPY5VP0FLIkTClQzg7Yc3z8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 37DF0497; Wed, 23 Oct 2024 04:09:39 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D1BE23F528; Wed, 23 Oct 2024 04:09:08 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 21/22] aarch64: Fix tests incompatible with GCS Date: Wed, 23 Oct 2024 12:05:27 +0100 Message-Id: <20241023110528.487830-22-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 From: Matthieu Longo gcc/testsuite/ChangeLog: * g++.target/aarch64/return_address_sign_ab_exception.C: Update. * gcc.target/aarch64/eh_return.c: Update. --- .../return_address_sign_ab_exception.C | 19 +++++++++++++------ gcc/testsuite/gcc.target/aarch64/eh_return.c | 13 +++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C b/gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C index ead11de7b15..6c79ebf03eb 100644 --- a/gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C +++ b/gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C @@ -1,16 +1,28 @@ /* { dg-do run } */ /* { dg-options "--save-temps" } */ /* { dg-require-effective-target arm_v8_3a_bkey_directive } */ +/* { dg-final { check-function-bodies "**" "" } } */ +/* +** _Z5foo_av: +** hint 25 // paciasp +** ... +*/ __attribute__((target("branch-protection=pac-ret+leaf"))) int foo_a () { throw 22; } +/* +** _Z5foo_bv: +** hint 27 // pacibsp +** ... +*/ __attribute__((target("branch-protection=pac-ret+leaf+b-key"))) int foo_b () { throw 22; } +/* { dg-final { scan-assembler-times ".cfi_b_key_frame" 1 } } */ int main (int argc, char** argv) { try { @@ -23,9 +35,4 @@ int main (int argc, char** argv) { } } return 1; -} - -/* { dg-final { scan-assembler-times "paciasp" 1 } } */ -/* { dg-final { scan-assembler-times "pacibsp" 1 } } */ -/* { dg-final { scan-assembler-times ".cfi_b_key_frame" 1 } } */ - +} \ No newline at end of file diff --git a/gcc/testsuite/gcc.target/aarch64/eh_return.c b/gcc/testsuite/gcc.target/aarch64/eh_return.c index 32179488085..51b20f784b3 100644 --- a/gcc/testsuite/gcc.target/aarch64/eh_return.c +++ b/gcc/testsuite/gcc.target/aarch64/eh_return.c @@ -1,6 +1,19 @@ /* { dg-do run } */ /* { dg-options "-O2 -fno-inline" } */ +/* With BTI enabled, this test would crash with SIGILL, Illegal instruction. + The 2nd argument of __builtin_eh_return is expected to be an EH handler + within a function, rather than a separate function. + The current implementation of __builtin_eh_return in AArch64 backend emits a + jump instead of branching with LR. + The prologue of the handler (i.e. continuation) starts with "bti c" (vs. + "bti jc") which is a landing pad type prohibiting jumps, hence the exception + at runtime. + The current behavior of __builtin_eh_return is considered correct. + Consequently, the default option -mbranch-protection=standard needs to be + overridden to remove BTI. */ +/* { dg-additional-options "-mbranch-protection=pac-ret+leaf+gcs" { target { default_branch_protection } } } */ + #include #include From patchwork Wed Oct 23 11:05:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 99429 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 0BFC5385840E for ; Wed, 23 Oct 2024 11:14:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 113EA3858403; Wed, 23 Oct 2024 11:09:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 113EA3858403 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 113EA3858403 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681767; cv=none; b=dOuYN72bx57h4RK7i+q01TPbh5Lt94oo5C0ksdwP0K/HBeqoUHgSz/xvoPtekAtwssosHZE8ytKr0PRC47zqJjPD4vXaGY0ZCa0Y7WG+BIywZ247j/fLa1bNOThlKyuYvUkjQjkV/0kxnbsVHsJAxQhJ3rqOwisR2vvanpL3KuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729681767; c=relaxed/simple; bh=jsqjuziZXeFgwGMqzp+a7vEn5aSsTU4yG+1citL8NsQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=w1tZZZc0PeROVHIT0Io/wVJGDMEKurqBFTaDIg9Rc0xRt/wCk2QclCkRQKEkUMwoBUUyNwRBUHzuhGXKKAV36SMTGAEq9KMSbm9buHXzuMwPxKksUPOnfrNglS6jdFy2ZYPWUo6eAsWfAM5mlnzWRXstjSrYSYxFwkQrdD4OWG0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8A890339; Wed, 23 Oct 2024 04:09:45 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.39.30]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 314A93F528; Wed, 23 Oct 2024 04:09:15 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com Subject: [PATCH 22/22] aarch64: Fix nonlocal goto tests incompatible with GCS Date: Wed, 23 Oct 2024 12:05:28 +0100 Message-Id: <20241023110528.487830-23-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023110528.487830-1-yury.khrustalev@arm.com> References: <20241023110528.487830-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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 gcc/testsuite/ChangeLog: * gcc.target/aarch64/gcs-nonlocal-3.c: New test. * gcc.target/aarch64/sme/nonlocal_goto_4.c: Update. * gcc.target/aarch64/sme/nonlocal_goto_5.c: Update. * gcc.target/aarch64/sme/nonlocal_goto_6.c: Update. --- .../gcc.target/aarch64/gcs-nonlocal-3.c | 33 +++++++++++++++++++ .../gcc.target/aarch64/sme/nonlocal_goto_4.c | 2 +- .../gcc.target/aarch64/sme/nonlocal_goto_5.c | 2 +- .../gcc.target/aarch64/sme/nonlocal_goto_6.c | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-3.c diff --git a/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-3.c b/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-3.c new file mode 100644 index 00000000000..8511f66f66e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gcs-nonlocal-3.c @@ -0,0 +1,33 @@ +/* { dg-options "-O2 -fno-schedule-insns -fno-schedule-insns2 -mbranch-protection=gcs" } */ +/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {\.L[0-9]+\:} } } */ + +void run(void (*)()); + +/* +** bar.0: +** ... +** hint 40 // chkfeat x16 +** tbnz w16, 0, (\.L[0-9]+) +** ... +** mrs x1, s3_3_c2_c5_1 // gcspr_el0 +** subs x1, x3, x1 +** bne (\.L[0-9]+)\n\1\: +** ... +** br x[0-9]+\n\2\: +** ... +** sysl xzr, #3, c7, c7, #1 // gcspopm +** ... +** b \1 +*/ +int +foo (int *ptr) +{ + __label__ failure; + + void bar () { *ptr += 1; goto failure; } + run (bar); + return 1; + +failure: + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_4.c b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_4.c index 0446076286b..aed04bb495c 100644 --- a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_4.c +++ b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_4.c @@ -1,4 +1,4 @@ -/* { dg-options "-O2 -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-options "-O2 -fno-schedule-insns -fno-schedule-insns2 -mbranch-protection=none" } */ /* { dg-final { check-function-bodies "**" "" } } */ void run(void (*)()); diff --git a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_5.c b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_5.c index 4246aec8b2f..e4a31c5c600 100644 --- a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_5.c +++ b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_5.c @@ -1,4 +1,4 @@ -/* { dg-options "-O2 -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-options "-O2 -fno-schedule-insns -fno-schedule-insns2 -mbranch-protection=none" } */ /* { dg-final { check-function-bodies "**" "" } } */ void run(void (*)() __arm_streaming); diff --git a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_6.c b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_6.c index 151e2f22dc7..38f6c139f6d 100644 --- a/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_6.c +++ b/gcc/testsuite/gcc.target/aarch64/sme/nonlocal_goto_6.c @@ -1,4 +1,4 @@ -/* { dg-options "-O2 -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-options "-O2 -fno-schedule-insns -fno-schedule-insns2 -mbranch-protection=none" } */ /* { dg-final { check-function-bodies "**" "" } } */ void run(void (*)() __arm_streaming_compatible);