Matthieu Longo <matthieu.longo@arm.com> writes:
> @@ -24803,6 +24834,16 @@ aarch64_start_file (void)
> asm_fprintf (asm_out_file, "\t.arch %s\n",
> aarch64_last_printed_arch_string.c_str ());
>
> + /* Check whether the current assembly supports gcs build attributes, if not
> + fallback to .note.gnu.property section. */
> +#if (HAVE_AS_AEABI_BUILD_ATTRIBUTES)
> + if (aarch64_gcs_enabled ())
I was hoping we could instead use:
if (HAVE_AS_AEABI_BUILD_ATTRIBUTES && aarch64_gcs_enabled ())
so that the code is parsed but compiled out when the new syntax is not
supported. This avoids cases where a patch that works with a new
assembler breaks bootstrap when using an older assembler, or vice
versa.
> + {
> + aarch64_emit_aeabi_subsection (".aeabi-feature-and-bits", 1, 0);
> + aarch64_emit_aeabi_attribute ("Tag_Feature_GCS", 3, 1);
> + }
> +#endif
> +
> default_file_start ();
> }
>
> [...]
> diff --git a/gcc/configure.ac b/gcc/configure.ac
> index 8a5fed516b3..f4b1343ca70 100644
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -4387,6 +4387,16 @@ 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 AEABI build attributes.
> + gcc_GAS_CHECK_FEATURE([support of AEABI build attributes], gcc_cv_as_aarch64_aeabi_build_attributes,,
> + [
> + .set ATTR_TYPE_uleb128, 0
> + .set ATTR_TYPE_asciz, 1
Very minor, but: we can drop this line, since it isn't used in the test.
Same for the corresponding Tcl test.
OK with those changes, thanks.
Richard
> + .set Tag_Feature_foo, 1
> + .aeabi_subsection .aeabi-feature-and-bits, 1, ATTR_TYPE_uleb128
> + .aeabi_attribute Tag_Feature_foo, 1
> + ],,[AC_DEFINE(HAVE_AS_AEABI_BUILD_ATTRIBUTES, 1,
> + [Define if your assembler supports AEABI build attributes.])])
> # Enable Branch Target Identification Mechanism and Return Address
> # Signing by default.
> AC_ARG_ENABLE(standard-branch-protection,
@@ -355,6 +355,12 @@
#endif
+/* Define if your assembler supports AEABI build attributes. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_AEABI_BUILD_ATTRIBUTES
+#endif
+
+
/* Define if your assembler supports architecture modifiers. */
#ifndef USED_FOR_TARGET
#undef HAVE_AS_ARCHITECTURE_MODIFIERS
@@ -109,6 +109,10 @@
and 1 MOVI/DUP (same size as a call). */
#define MAX_SET_SIZE(speed) (speed ? 256 : 96)
+#ifndef HAVE_AS_AEABI_BUILD_ATTRIBUTES
+#define HAVE_AS_AEABI_BUILD_ATTRIBUTES 0
+#endif
+
/* Flags that describe how a function shares certain architectural state
with its callers.
@@ -24783,6 +24787,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
@@ -24803,6 +24834,16 @@ aarch64_start_file (void)
asm_fprintf (asm_out_file, "\t.arch %s\n",
aarch64_last_printed_arch_string.c_str ());
+ /* Check whether the current assembly supports gcs build attributes, if not
+ fallback to .note.gnu.property section. */
+#if (HAVE_AS_AEABI_BUILD_ATTRIBUTES)
+ if (aarch64_gcs_enabled ())
+ {
+ aarch64_emit_aeabi_subsection (".aeabi-feature-and-bits", 1, 0);
+ aarch64_emit_aeabi_attribute ("Tag_Feature_GCS", 3, 1);
+ }
+#endif
+
default_file_start ();
}
@@ -28035,6 +28035,44 @@ 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 AEABI build attributes.
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for support of AEABI build attributes" >&5
+$as_echo_n "checking assembler for support of AEABI build attributes... " >&6; }
+if ${gcc_cv_as_aarch64_aeabi_build_attributes+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ gcc_cv_as_aarch64_aeabi_build_attributes=no
+ if test x$gcc_cv_as != x; then
+ $as_echo '
+ .set ATTR_TYPE_uleb128, 0
+ .set ATTR_TYPE_asciz, 1
+ .set Tag_Feature_foo, 1
+ .aeabi_subsection .aeabi-feature-and-bits, 1, ATTR_TYPE_uleb128
+ .aeabi_attribute Tag_Feature_foo, 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_aeabi_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_aeabi_build_attributes" >&5
+$as_echo "$gcc_cv_as_aarch64_aeabi_build_attributes" >&6; }
+if test $gcc_cv_as_aarch64_aeabi_build_attributes = yes; then
+
+$as_echo "#define HAVE_AS_AEABI_BUILD_ATTRIBUTES 1" >>confdefs.h
+
fi
# Enable Branch Target Identification Mechanism and Return Address
@@ -4387,6 +4387,16 @@ 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 AEABI build attributes.
+ gcc_GAS_CHECK_FEATURE([support of AEABI build attributes], gcc_cv_as_aarch64_aeabi_build_attributes,,
+ [
+ .set ATTR_TYPE_uleb128, 0
+ .set ATTR_TYPE_asciz, 1
+ .set Tag_Feature_foo, 1
+ .aeabi_subsection .aeabi-feature-and-bits, 1, ATTR_TYPE_uleb128
+ .aeabi_attribute Tag_Feature_foo, 1
+ ],,[AC_DEFINE(HAVE_AS_AEABI_BUILD_ATTRIBUTES, 1,
+ [Define if your assembler supports AEABI build attributes.])])
# Enable Branch Target Identification Mechanism and Return Address
# Signing by default.
AC_ARG_ENABLE(standard-branch-protection,
new file mode 100644
@@ -0,0 +1,35 @@
+# Copyright (C) 2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't an AArch64 target.
+if ![istarget aarch64*-*-*] then {
+ return
+}
+
+# Load support procs.
+load_lib gcc-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \
+ "" ""
+
+# All done.
+dg-finish
new file mode 100644
@@ -0,0 +1,12 @@
+/* { dg-do compile { target { aarch64*-*-linux* && { aarch64_gas_has_build_attributes } } } } */
+/* { dg-options "-mbranch-protection=gcs -dA" } */
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler "\.aeabi_subsection \.aeabi-feature-and-bits, 1, 0" } } */
+/* { dg-final { scan-assembler "\.aeabi_attribute 3, 1\t\/\/ Tag_Feature_GCS" } } */
+/* { dg-final { scan-assembler "\.section\t\.note\.gnu\.property" } } */
+/* { dg-final { scan-assembler "\.word\t0x4\t\/\/ GNU_PROPERTY_AARCH64_FEATURE_1_AND \\(GCS\\)" } } */
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,12 @@
+/* { dg-do compile { target { aarch64*-*-linux* && aarch64_gas_has_build_attributes } } } */
+/* { dg-options "-mbranch-protection=standard -dA" } */
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler "\.aeabi_subsection \.aeabi-feature-and-bits, 1, 0" } } */
+/* { dg-final { scan-assembler "\.aeabi_attribute 3, 1\t\/\/ Tag_Feature_GCS" } } */
+/* { dg-final { scan-assembler "\.section\t\.note\.gnu\.property" } } */
+/* { dg-final { scan-assembler "\.word\t0x7\t\/\/ GNU_PROPERTY_AARCH64_FEATURE_1_AND \\(BTI, PAC, GCS\\)" } } */
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,12 @@
+/* { dg-do compile { target { aarch64*-*-linux* && { ! aarch64_gas_has_build_attributes } } } } */
+/* { dg-options "-mbranch-protection=bti -dA" } */
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "\.aeabi_subsection" } } */
+/* { dg-final { scan-assembler-not "\.aeabi_attribute" } } */
+/* { dg-final { scan-assembler "\.section\t\.note\.gnu\.property" } } */
+/* { dg-final { scan-assembler "\.word\t0x1\t\/\/ GNU_PROPERTY_AARCH64_FEATURE_1_AND \\(BTI\\)" } } */
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,12 @@
+/* { dg-do compile { target { aarch64*-*-linux* && { ! aarch64_gas_has_build_attributes } } } } */
+/* { dg-options "-mbranch-protection=gcs -dA" } */
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "\.aeabi_subsection" } } */
+/* { dg-final { scan-assembler-not "\.aeabi_attribute" } } */
+/* { dg-final { scan-assembler "\.section\t\.note\.gnu\.property" } } */
+/* { dg-final { scan-assembler "\.word\t0x4\t\/\/ GNU_PROPERTY_AARCH64_FEATURE_1_AND \\(GCS\\)" } } */
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,12 @@
+/* { dg-do compile { target { aarch64*-*-linux* && { ! aarch64_gas_has_build_attributes } } } } */
+/* { dg-options "-mbranch-protection=pac-ret -dA" } */
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "\.aeabi_subsection" } } */
+/* { dg-final { scan-assembler-not "\.aeabi_attribute" } } */
+/* { dg-final { scan-assembler "\.section\t\.note\.gnu\.property" } } */
+/* { dg-final { scan-assembler "\.word\t0x2\t\/\/ GNU_PROPERTY_AARCH64_FEATURE_1_AND \\(PAC\\)" } } */
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,12 @@
+/* { dg-do compile { target { aarch64*-*-linux* && { ! aarch64_gas_has_build_attributes } } } } */
+/* { dg-options "-mbranch-protection=standard -dA" } */
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "\.aeabi_subsection" } } */
+/* { dg-final { scan-assembler-not "\.aeabi_attribute" } } */
+/* { dg-final { scan-assembler "\.section\t\.note\.gnu\.property" } } */
+/* { dg-final { scan-assembler "\.word\t0x7\t\/\/ GNU_PROPERTY_AARCH64_FEATURE_1_AND \\(BTI, PAC, GCS\\)" } } */
\ No newline at end of file
@@ -12031,6 +12031,22 @@ proc check_effective_target_aarch64_tiny { } {
}
}
+# Return 1 if Gas supports AEABI build attributes on AArch64 target
+proc check_effective_target_aarch64_gas_has_build_attributes { } {
+ if { ![istarget aarch64*-*-*] } {
+ return 0
+ }
+
+ return [check_no_compiler_messages aarch64_gas_has_build_attributes object {
+ /* Assembly */
+ .set ATTR_TYPE_uleb128, 0
+ .set ATTR_TYPE_asciz, 1
+ .set Tag_Feature_foo, 1
+ .aeabi_subsection .aeabi-feature-and-bits, 1, ATTR_TYPE_uleb128
+ .aeabi_attribute Tag_Feature_foo, 1
+ }]
+}
+
# Create functions to check that the AArch64 assembler supports the
# various architecture extensions via the .arch_extension pseudo-op.