Message ID | 20240911155009.1343113-1-srinath.parvathaneni@arm.com |
---|---|
State | New |
Headers | show |
Series | [v1] aarch64: Add GCS build attributes support. | expand |
Hi Srinath, Not a full review, just some things that popped out to me. > On 11 Sep 2024, at 17:50, Srinath Parvathaneni <srinath.parvathaneni@arm.com> wrote: > > External email: Use caution opening links or attachments > > > This patch adds support for aarch64 gcs build attributes. This support > includes generating two new assembler directives .aeabi_subsection and > .aeabi_attribute. These directives are generated as per the syntax > mentioned in spec "Build Attributes for the Arm® 64-bit > Architecture (AArch64)" available at [1]. > > To check whether the assembler being used to build the toolchain > supports these directives, a new gcc configure check is added in > gcc/configure.ac. > > If the assembler support these directives, .aeabi_subsection and > .aeabi_attribute directives are emitted in the generated assembly, > when -mbranch-protection=gcs is passed. > > If the assembler does not support these directives, > .note.gnu.property section will emit the relevant gcs information > in the generated assembly, when -mbranch-protection=gcs is passed. > > This patch needs to be applied on top of GCC gcs patch series [2]. > > Bootstrapped on aarch64-none-linux-gnu and regression tested on > aarch64-none-elf, no issues. > > Ok for master? > > Regards, > Srinath. > > [1]: https://github.com/ARM-software/abi-aa/pull/230 > [2]: https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/vendors/ARM/heads/gcs > > gcc/ChangeLog: > > 2024-09-11 Srinath Parvathaneni <srinath.parvathaneni@arm.com> > > * config.in: Regenerated > * config/aarch64/aarch64.cc (aarch64_emit_aeabi_attribute): New > function declaration. > (aarch64_emit_aeabi_subsection): Likewise. > (aarch64_start_file): Emit gcs build attributes. > (aarch64_file_end_indicate_exec_stack): Update gcs bit in > note.gnu.property section. > * configure: Regenerated. > * configure.ac: Add gcc configure check. > > gcc/testsuite/ChangeLog: > > 2024-09-11 Srinath Parvathaneni <srinath.parvathaneni@arm.com> > > * gcc.target/aarch64/build-attribute-gcs.c: New test. > --- > gcc/config.in | 6 +++ > gcc/config/aarch64/a.out | Bin 0 -> 656 bytes This binary artifact shouldn’t be in the patch. > gcc/config/aarch64/aarch64.cc | 43 ++++++++++++++++++ > gcc/configure | 35 ++++++++++++++ > gcc/configure.ac | 7 +++ > .../gcc.target/aarch64/build-attribute-gcs.c | 24 ++++++++++ > 6 files changed, 115 insertions(+) > create mode 100644 gcc/config/aarch64/a.out > create mode 100644 gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c diff --git a/gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c b/gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c new file mode 100644 index 00000000000..eb15772757e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c @@ -0,0 +1,24 @@ +/* { dg-do compile { target aarch64*-*-linux* } } */ + +int main() +{ + return 0; +} + +/* { dg-options "-mbranch-protection=gcs" } */ +/* { dg-final { scan-assembler-not "\.aeabi_subsection \.aeabi-feature-and-bits, 1, 0" } } */ +/* { dg-final { scan-assembler-not "\.aeabi_attribute 3, 1\t\/\/ Tag_Feature_GCS" } } */ +/* { dg-final { scan-assembler ".note.gnu.property" } } */ + +/* { dg-options "-mbranch-protection=bti" } */ +/* { dg-final { scan-assembler ".note.gnu.property" } } */ + + +/* { dg-options "-mbranch-protection=pac-ret" } */ +/* { dg-final { scan-assembler ".note.gnu.property" } } */ + + +/* { dg-options "-mbranch-protection=standard" } */ +/* { dg-final { scan-assembler-not "\.aeabi_subsection \.aeabi-feature-and-bits, 1, 0" } } */ +/* { dg-final { scan-assembler-not "\.aeabi_attribute 3, 1\t\/\/ Tag_Feature_GCS" } } */ +/* { dg-final { scan-assembler ".note.gnu.property" } } */ These scans should be in different tests compiled with different options. You can’t have multiple dg-options directives in a single test and scanning for “.note.gnu.property” multiple times in a single test is redundant too. Thanks, Kyrill
On Wed, Sep 11, 2024 at 11:51 AM Srinath Parvathaneni <srinath.parvathaneni@arm.com> wrote: > > This patch adds support for aarch64 gcs build attributes. Hi, just wondering if you could clarify what "GCS" stands for in this context? When I see it, my first thought is "GNU Coding Standards", but I don't think that's right... > This support includes generating two new assembler directives > .aeabi_subsection and .aeabi_attribute. These directives are > generated as per the syntax mentioned in spec > "Build Attributes for the Arm® 64-bit Architecture (AArch64)" > available at [1]. > > To check whether the assembler being used to build the toolchain > supports these directives, a new gcc configure check is added in > gcc/configure.ac. > > If the assembler support these directives, .aeabi_subsection and > .aeabi_attribute directives are emitted in the generated assembly, > when -mbranch-protection=gcs is passed. > > If the assembler does not support these directives, > .note.gnu.property section will emit the relevant gcs information > in the generated assembly, when -mbranch-protection=gcs is passed. > > This patch needs to be applied on top of GCC gcs patch series [2]. > > Bootstrapped on aarch64-none-linux-gnu and regression tested on > aarch64-none-elf, no issues. > > Ok for master? > > Regards, > Srinath. > > [1]: https://github.com/ARM-software/abi-aa/pull/230 > [2]: https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/vendors/ARM/heads/gcs > > gcc/ChangeLog: > > 2024-09-11 Srinath Parvathaneni <srinath.parvathaneni@arm.com> > > * config.in: Regenerated > * config/aarch64/aarch64.cc (aarch64_emit_aeabi_attribute): New > function declaration. > (aarch64_emit_aeabi_subsection): Likewise. > (aarch64_start_file): Emit gcs build attributes. > (aarch64_file_end_indicate_exec_stack): Update gcs bit in > note.gnu.property section. > * configure: Regenerated. > * configure.ac: Add gcc configure check. > > gcc/testsuite/ChangeLog: > > 2024-09-11 Srinath Parvathaneni <srinath.parvathaneni@arm.com> > > * gcc.target/aarch64/build-attribute-gcs.c: New test. > --- > gcc/config.in | 6 +++ > gcc/config/aarch64/a.out | Bin 0 -> 656 bytes > gcc/config/aarch64/aarch64.cc | 43 ++++++++++++++++++ > gcc/configure | 35 ++++++++++++++ > gcc/configure.ac | 7 +++ > .../gcc.target/aarch64/build-attribute-gcs.c | 24 ++++++++++ > 6 files changed, 115 insertions(+) > create mode 100644 gcc/config/aarch64/a.out > create mode 100644 gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c >
> On 12 Sep 2024, at 16:43, Eric Gallager <egall@gwmail.gwu.edu> wrote: > > > > On Wed, Sep 11, 2024 at 11:51 AM Srinath Parvathaneni > <srinath.parvathaneni@arm.com> wrote: >> >> This patch adds support for aarch64 gcs build attributes. > > Hi, just wondering if you could clarify what "GCS" stands for in this > context? When I see it, my first thought is "GNU Coding Standards", > but I don't think that's right... It’s the Guarded Control Stack feature of the Arm architecture: https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-a-profile-architecture-2022 Thanks, Kyrill > >> This support includes generating two new assembler directives >> .aeabi_subsection and .aeabi_attribute. These directives are >> generated as per the syntax mentioned in spec >> "Build Attributes for the Arm® 64-bit Architecture (AArch64)" >> available at [1]. >> >> To check whether the assembler being used to build the toolchain >> supports these directives, a new gcc configure check is added in >> gcc/configure.ac. >> >> If the assembler support these directives, .aeabi_subsection and >> .aeabi_attribute directives are emitted in the generated assembly, >> when -mbranch-protection=gcs is passed. >> >> If the assembler does not support these directives, >> .note.gnu.property section will emit the relevant gcs information >> in the generated assembly, when -mbranch-protection=gcs is passed. >> >> This patch needs to be applied on top of GCC gcs patch series [2]. >> >> Bootstrapped on aarch64-none-linux-gnu and regression tested on >> aarch64-none-elf, no issues. >> >> Ok for master? >> >> Regards, >> Srinath. >> >> [1]: https://github.com/ARM-software/abi-aa/pull/230 >> [2]: https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/vendors/ARM/heads/gcs >> >> gcc/ChangeLog: >> >> 2024-09-11 Srinath Parvathaneni <srinath.parvathaneni@arm.com> >> >> * config.in: Regenerated >> * config/aarch64/aarch64.cc (aarch64_emit_aeabi_attribute): New >> function declaration. >> (aarch64_emit_aeabi_subsection): Likewise. >> (aarch64_start_file): Emit gcs build attributes. >> (aarch64_file_end_indicate_exec_stack): Update gcs bit in >> note.gnu.property section. >> * configure: Regenerated. >> * configure.ac: Add gcc configure check. >> >> gcc/testsuite/ChangeLog: >> >> 2024-09-11 Srinath Parvathaneni <srinath.parvathaneni@arm.com> >> >> * gcc.target/aarch64/build-attribute-gcs.c: New test. >> --- >> gcc/config.in | 6 +++ >> gcc/config/aarch64/a.out | Bin 0 -> 656 bytes >> gcc/config/aarch64/aarch64.cc | 43 ++++++++++++++++++ >> gcc/configure | 35 ++++++++++++++ >> gcc/configure.ac | 7 +++ >> .../gcc.target/aarch64/build-attribute-gcs.c | 24 ++++++++++ >> 6 files changed, 115 insertions(+) >> create mode 100644 gcc/config/aarch64/a.out >> create mode 100644 gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c >>
diff --git a/gcc/config.in b/gcc/config.in index 7fcabbe5061..eb6024dfc90 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -379,6 +379,12 @@ #endif +/* Define if your assembler supports gcs build attributes. */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_BUILD_ATTRIBUTES_GCS +#endif + + /* Define to the level of your assembler's compressed debug section support. */ #ifndef USED_FOR_TARGET diff --git a/gcc/config/aarch64/a.out b/gcc/config/aarch64/a.out new file mode 100644 index 0000000000000000000000000000000000000000..dd7982f2db625be166d33548dc5d00c7e7601629 GIT binary patch literal 656 zcmb<-^>JfjWMqH=MuzPS2p&w7f#Cvz$>0EHJ20>_upx<JGMTZO#K6GJz=Ww7D8dYc zm_V<%GPfi#i9xTpqzFQ1z*r@z6(tOMDTyVC40=h$#h7|Y7m)^P0r?-@XAU@wLJuoN zsD5;x5UXDusGkFf$<+^X54O;S*`ENE2LV<fW&vW5T_7L<p%^%UG`ig&sRbYc2+;kD W&KCr#!KQy9ST_TM4wQyb==uS05EWhk literal 0 HcmV?d00001 diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 8709f2b0cfb..2cff5317fc1 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -24679,6 +24679,33 @@ aarch64_post_cfi_startproc (FILE *f, tree ignored ATTRIBUTE_UNUSED) asm_fprintf (f, "\t.cfi_b_key_frame\n"); } +/* This function is used to emit an AEABI attribute with tag and its associated + value. We emit the numerical value of the tag and the textual tags as + comment so that anyone reading the assembler output will know which tag is + being set. + example: .aeabi_attribute 3, 1 // Tag_Feature_GCS */ + +void +aarch64_emit_aeabi_attribute (const char *name, uint8_t num, uint8_t val) +{ + asm_fprintf (asm_out_file, "\t.aeabi_attribute %u, %u", num, val); + if (flag_debug_asm) + asm_fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, name); + asm_fprintf (asm_out_file, "\n"); +} + +/* This function is used to emit an AEABI subsection with vendor name, + optional status and value type. + example: .aeabi_subsection .aeabi-feature-and-bits, 1, 0 */ + +void +aarch64_emit_aeabi_subsection (const char *name, uint8_t num, uint8_t val) +{ + asm_fprintf (asm_out_file, "\t.aeabi_subsection %s, %u, %u\n", + name, num, val); +} + + /* Implements TARGET_ASM_FILE_START. Output the assembly header. */ static void @@ -24699,6 +24726,20 @@ aarch64_start_file (void) asm_fprintf (asm_out_file, "\t.arch %s\n", aarch64_last_printed_arch_string.c_str ()); +/* Emit gcs build attributes only when building a native AArch64-hosted + compiler. */ +#if defined(__aarch64__) + /* Check the current assembly supports gcs build attributes, if not + fallback to .note.gnu.property section. */ + #ifdef HAVE_AS_BUILD_ATTRIBUTES_GCS + if (aarch64_gcs_enabled ()) + { + aarch64_emit_aeabi_subsection (".aeabi-feature-and-bits", 1, 0); + aarch64_emit_aeabi_attribute ("Tag_Feature_GCS", 3, 1); + } + #endif +#endif + default_file_start (); } @@ -29105,8 +29146,10 @@ aarch64_file_end_indicate_exec_stack () if (aarch_ra_sign_scope != AARCH_FUNCTION_NONE) feature_1_and |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC; +#ifndef HAVE_AS_BUILD_ATTRIBUTES_GCS if (aarch64_gcs_enabled ()) feature_1_and |= GNU_PROPERTY_AARCH64_FEATURE_1_GCS; +#endif if (feature_1_and) { diff --git a/gcc/configure b/gcc/configure index ec6124cb361..bec606f61b3 100755 --- a/gcc/configure +++ b/gcc/configure @@ -28036,6 +28036,41 @@ if test $gcc_cv_as_aarch64_picreloc = yes; then $as_echo "#define HAVE_AS_SMALL_PIC_RELOCS 1" >>confdefs.h +fi + + # Check if we have binutils support for gcs build attributes. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for gcs build attributes support" >&5 +$as_echo_n "checking assembler for gcs build attributes support... " >&6; } +if ${gcc_cv_as_aarch64_gcs_build_attributes+:} false; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_aarch64_gcs_build_attributes=no + if test x$gcc_cv_as != x; then + $as_echo ' + .aeabi_subsection .aeabi-feature-and-bits, 1, 0 + .aeabi_attribute 3, 1 + ' > conftest.s + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -o conftest.o conftest.s >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + gcc_cv_as_aarch64_gcs_build_attributes=yes + else + echo "configure: failed program was" >&5 + cat conftest.s >&5 + fi + rm -f conftest.o conftest.s + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_aarch64_gcs_build_attributes" >&5 +$as_echo "$gcc_cv_as_aarch64_gcs_build_attributes" >&6; } +if test $gcc_cv_as_aarch64_gcs_build_attributes = yes; then + +$as_echo "#define HAVE_AS_BUILD_ATTRIBUTES_GCS 1" >>confdefs.h + fi # Enable Branch Target Identification Mechanism and Return Address diff --git a/gcc/configure.ac b/gcc/configure.ac index d0b9865fc91..51b07417153 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -4388,6 +4388,13 @@ case "$target" in ldr x0, [[x2, #:gotpage_lo15:globalsym]] ],,[AC_DEFINE(HAVE_AS_SMALL_PIC_RELOCS, 1, [Define if your assembler supports relocs needed by -fpic.])]) + # Check if we have binutils support for gcs build attributes. + gcc_GAS_CHECK_FEATURE([gcs build attributes support], gcc_cv_as_aarch64_gcs_build_attributes,, + [ + .aeabi_subsection .aeabi-feature-and-bits, 1, 0 + .aeabi_attribute 3, 1 + ],,[AC_DEFINE(HAVE_AS_BUILD_ATTRIBUTES_GCS, 1, + [Define if your assembler supports gcs build attributes.])]) # Enable Branch Target Identification Mechanism and Return Address # Signing by default. AC_ARG_ENABLE(standard-branch-protection, diff --git a/gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c b/gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c new file mode 100644 index 00000000000..eb15772757e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/build-attribute-gcs.c @@ -0,0 +1,24 @@ +/* { dg-do compile { target aarch64*-*-linux* } } */ + +int main() +{ + return 0; +} + +/* { dg-options "-mbranch-protection=gcs" } */ +/* { dg-final { scan-assembler-not "\.aeabi_subsection \.aeabi-feature-and-bits, 1, 0" } } */ +/* { dg-final { scan-assembler-not "\.aeabi_attribute 3, 1\t\/\/ Tag_Feature_GCS" } } */ +/* { dg-final { scan-assembler ".note.gnu.property" } } */ + +/* { dg-options "-mbranch-protection=bti" } */ +/* { dg-final { scan-assembler ".note.gnu.property" } } */ + + +/* { dg-options "-mbranch-protection=pac-ret" } */ +/* { dg-final { scan-assembler ".note.gnu.property" } } */ + + +/* { dg-options "-mbranch-protection=standard" } */ +/* { dg-final { scan-assembler-not "\.aeabi_subsection \.aeabi-feature-and-bits, 1, 0" } } */ +/* { dg-final { scan-assembler-not "\.aeabi_attribute 3, 1\t\/\/ Tag_Feature_GCS" } } */ +/* { dg-final { scan-assembler ".note.gnu.property" } } */