From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1816) id 7200B385F3C1; Mon, 12 Dec 2022 11:22:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7200B385F3C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670844158; bh=EsQv0+tnCaekRCy5JxL6PW0FbNeQKCQCJjA1NA3a3XA=; h=From:To:Subject:Date:From; b=uqZlJWqgvqAuli0mhd1ZeTKyISyfHolFFmCj6U4XG/XTJcM03KBtCm9/ILEHNvsJd PBfLbXC37pmVlR8xSCPYU8fyJDRUao/n7ESqUi4Nx9Ep3/E3Pmjpc9wfmiZ+7DYa/g YDUj1XxpqYDisPXZPtdpv64WaEcXN/3kIMuXZjlo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kyrylo Tkachov To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4609] aarch64: Add __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI ACLE defines X-Act-Checkin: gcc X-Git-Author: Kyrylo Tkachov X-Git-Refname: refs/heads/master X-Git-Oldrev: 49bf49bb6174734879adcba7fb340c1c8f5dd253 X-Git-Newrev: 688f4eb28186daf333f7a7f5b1bdc1df43bb6c47 Message-Id: <20221212112238.7200B385F3C1@sourceware.org> Date: Mon, 12 Dec 2022 11:22:38 +0000 (GMT) List-Id: https://gcc.gnu.org/g:688f4eb28186daf333f7a7f5b1bdc1df43bb6c47 commit r13-4609-g688f4eb28186daf333f7a7f5b1bdc1df43bb6c47 Author: Kyrylo Tkachov Date: Mon Dec 12 11:07:45 2022 +0000 aarch64: Add __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI ACLE defines Recent ACLE additions specified the __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI macros [1] that the compiler should define when the pointer authentication and BTI instructions are available (and don't act as NOPs). We've received requests to enable them in GCC for aarch64, similar to clang [2]. It's a fairly simple patch and should be non-intrusive at this stage. Pointer authentication has its own "pauth" feature flag, whereas BTI depends on an architecture level of Armv8.5-a or later. Bootstrapped and tested on aarch64-none-linux-gnu. [1] https://github.com/ARM-software/acle/blob/main/main/acle.md#pointer-authentication [2] https://reviews.llvm.org/rG7d40baa82b1f272f68de63f3c4f68d970bdcd6ed gcc/ChangeLog: * config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins): Define __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI when appropriate. * config/aarch64/aarch64.h (TARGET_BTI): Define. gcc/testsuite/ChangeLog: * gcc.target/aarch64/acle/bti_def.c: New test. * gcc.target/aarch64/acle/pauth_def.c: New test. Diff: --- gcc/config/aarch64/aarch64-c.cc | 2 ++ gcc/config/aarch64/aarch64.h | 5 +++++ gcc/testsuite/gcc.target/aarch64/acle/bti_def.c | 10 ++++++++++ gcc/testsuite/gcc.target/aarch64/acle/pauth_def.c | 10 ++++++++++ 4 files changed, 27 insertions(+) diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc index e296c73350f..e47b6a870e2 100644 --- a/gcc/config/aarch64/aarch64-c.cc +++ b/gcc/config/aarch64/aarch64-c.cc @@ -195,6 +195,8 @@ aarch64_update_cpp_builtins (cpp_reader *pfile) builtin_define_with_int_value ("__ARM_FEATURE_PAC_DEFAULT", v); } + aarch64_def_or_undef (TARGET_PAUTH, "__ARM_FEATURE_PAUTH", pfile); + aarch64_def_or_undef (TARGET_BTI, "__ARM_FEATURE_BTI", 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); diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h index dcb1ecef71a..db6ec5c48d8 100644 --- a/gcc/config/aarch64/aarch64.h +++ b/gcc/config/aarch64/aarch64.h @@ -312,6 +312,11 @@ enum class aarch64_feature : unsigned char { /* PAUTH instructions are enabled through +pauth. */ #define TARGET_PAUTH (AARCH64_ISA_PAUTH) +/* BTI instructions exist from Armv8.5-a onwards. Their automatic use is + enabled through -mbranch-protection by using NOP-space instructions, + but this TARGET_ is used for defining BTI-related ACLE things. */ +#define TARGET_BTI (AARCH64_ISA_V8_5A) + /* MOPS instructions are enabled through +mops. */ #define TARGET_MOPS (AARCH64_ISA_MOPS) diff --git a/gcc/testsuite/gcc.target/aarch64/acle/bti_def.c b/gcc/testsuite/gcc.target/aarch64/acle/bti_def.c new file mode 100644 index 00000000000..db94769ec8b --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/acle/bti_def.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ + +#pragma GCC target "arch=armv8.5-a" +#ifndef __ARM_FEATURE_BTI +#error "__ARM_FEATURE_BTI is not defined but should be!" +#endif + +void +foo (void) {} + diff --git a/gcc/testsuite/gcc.target/aarch64/acle/pauth_def.c b/gcc/testsuite/gcc.target/aarch64/acle/pauth_def.c new file mode 100644 index 00000000000..400a0f61deb --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/acle/pauth_def.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ + +#pragma GCC target "+pauth" +#ifndef __ARM_FEATURE_PAUTH +#error "__ARM_FEATURE_PAUTH is not defined but should be!" +#endif + +void +foo (void) {} +