[2/2] aarch64/testsuite: add LTO coverage for branch-protection notes and attributes
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
Commit Message
Recent binutils (e.g. 2.46) switched AArch64 branch-protection emission
from .note.gnu.property to build attributes
(Tag_Feature_BTI, Tag_Feature_PAC, Tag_Feature_GCS) when GCC is
configured with such toolchains.
PR target/124365 exposed an issue where -flto with
-mbranch-protection=standard caused loss of branch-protection metadata in build
attributes. This was due to an LTO bug, now fixed upstream
(8b39ec70741b7fb9d059b6944f30a6743dea996a).
Add tests to verify both forms in LTO builds, covering:
• older binutils behaviour (.note.gnu.property), and
• newer binutils behaviour (build attributes).
This ensures branch-protection metadata is preserved across LTO for both
toolchain configurations.
PR target/124365
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/lto/lto.exp: New DejaGnu test driver for LTO tests
for aarch64. Copied from gcc/testsuite/gcc.target/arm/lto/lto.exp with
minor changes.
* gcc.target/aarch64/lto/pr124365-build-attributes-1_0.c: New test
for build attributes with branch protection.
* gcc.target/aarch64/lto/pr124365-build-attributes-1_1.c: Companion
source file for the LTO test.
* gcc.target/aarch64/lto/pr124365-build-attributes-2_0.c: New test
for build attributes without branch protection.
* gcc.target/aarch64/lto/pr124365-build-attributes-2_1.c: Companion
source file for the LTO test with branch protection enabled.
* gcc.target/aarch64/lto/pr124365-gnu-property-1_0.c: New test for
`.note.gnu.property` with branch protection.
* gcc.target/aarch64/lto/pr124365-gnu-property-1_1.c: Companion
source file for the LTO test.
* gcc.target/aarch64/lto/pr124365-gnu-property-2_0.c: New test for
`.note.gnu.property` without branch protection.
* gcc.target/aarch64/lto/pr124365-gnu-property-2_1.c: Companion
source file for the LTO test with branch protection enabled.
---
gcc/testsuite/gcc.target/aarch64/lto/lto.exp | 61 +++++++++++++++++++
.../lto/pr124365-build-attributes-1_0.c | 18 ++++++
.../lto/pr124365-build-attributes-1_1.c | 5 ++
.../lto/pr124365-build-attributes-2_0.c | 18 ++++++
.../lto/pr124365-build-attributes-2_1.c | 6 ++
.../aarch64/lto/pr124365-gnu-property-1_0.c | 16 +++++
.../aarch64/lto/pr124365-gnu-property-1_1.c | 5 ++
.../aarch64/lto/pr124365-gnu-property-2_0.c | 16 +++++
.../aarch64/lto/pr124365-gnu-property-2_1.c | 6 ++
9 files changed, 151 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/lto.exp
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/pr124365-build-attributes-1_0.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/pr124365-build-attributes-1_1.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/pr124365-build-attributes-2_0.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/pr124365-build-attributes-2_1.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/pr124365-gnu-property-1_0.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/pr124365-gnu-property-1_1.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/pr124365-gnu-property-2_0.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/lto/pr124365-gnu-property-2_1.c
new file mode 100644
@@ -0,0 +1,61 @@
+# Copyright (C) 2009-2026 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/>.
+
+# Exit immediately if this isn't an AArch64 target.
+if ![istarget aarch64*-*-*] then {
+ return
+}
+
+# Test link-time optimization across multiple files.
+#
+# Programs are broken into multiple files. Each one is compiled
+# separately with LTO information. The final executable is generated
+# by collecting all the generated object files using regular LTO or WHOPR.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+# Load procedures from common libraries.
+load_lib standard.exp
+load_lib gcc.exp
+
+# Load the language-independent compatibility support procedures.
+load_lib lto.exp
+
+# If LTO has not been enabled, bail.
+if { ![check_effective_target_lto] } {
+ return
+}
+
+gcc_init
+lto_init no-mathlib
+
+# Define an identifier for use with this suite to avoid name conflicts
+# with other lto tests running at the same time.
+set sid "c_lto"
+
+# Main loop.
+foreach src [lsort [find $srcdir/$subdir *_0.c]] {
+ # If we're only testing specific files and this isn't one of them, skip it.
+ if ![runtest_file_p $runtests $src] then {
+ continue
+ }
+
+ lto-execute $src $sid
+}
+
+lto_finish
new file mode 100644
@@ -0,0 +1,18 @@
+/* PR target/124365 */
+/* { dg-lto-do link } */
+/* { dg-skip-if "" { ! aarch64*-*-linux* } } */
+/* { dg-require-effective-target aarch64_gas_has_build_attributes } */
+/* { dg-require-effective-target mbranch_protection_ok } */
+/* { dg-lto-options { { -flto -O2 -mbranch-protection=standard } } } */
+/* { dg-extra-ld-options "-nostdlib -nostartfiles -Wl,-e,main" } */
+
+int foo ();
+int
+main (void)
+{
+ return foo ();
+}
+
+/* { dg-final { object-readelf-attributes {Tag_Feature_BTI:\s+1\s+\(0x1\)} } } */
+/* { dg-final { object-readelf-attributes {Tag_Feature_PAC:\s+1\s+\(0x1\)} } } */
+/* { dg-final { object-readelf-attributes {Tag_Feature_GCS:\s+1\s+\(0x1\)} } } */
new file mode 100644
@@ -0,0 +1,5 @@
+int
+foo ()
+{
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,18 @@
+/* PR target/124365 */
+/* { dg-lto-do link } */
+/* { dg-skip-if "" { ! aarch64*-*-linux* } } */
+/* { dg-require-effective-target aarch64_gas_has_build_attributes } */
+/* { dg-require-effective-target mbranch_protection_ok } */
+/* { dg-lto-options { { -flto -O2 -mbranch-protection=none } } } */
+/* { dg-extra-ld-options "-nostdlib -nostartfiles -Wl,-e,main" } */
+
+int foo ();
+int
+main (void)
+{
+ return foo ();
+}
+
+/* { dg-final { object-readelf-attributes {Tag_Feature_BTI:\s+0\s+\(0x0\)} } } */
+/* { dg-final { object-readelf-attributes {Tag_Feature_PAC:\s+0\s+\(0x0\)} } } */
+/* { dg-final { object-readelf-attributes {Tag_Feature_GCS:\s+0\s+\(0x0\)} } } */
new file mode 100644
@@ -0,0 +1,6 @@
+/* { dg-options "-O2 -flto -mbranch-protection=standard" } */
+int
+foo ()
+{
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,16 @@
+/* PR target/124365 */
+/* { dg-lto-do link } */
+/* { dg-skip-if "" { ! aarch64*-*-linux* } } */
+/* { dg-skip-if "" { aarch64_gas_has_build_attributes } } */
+/* { dg-require-effective-target mbranch_protection_ok } */
+/* { dg-lto-options { { -flto -O2 -mbranch-protection=standard } } } */
+/* { dg-extra-ld-options "-nostdlib -nostartfiles -Wl,-e,main" } */
+
+int foo ();
+int
+main (void)
+{
+ return 0;
+}
+
+/* { dg-final { object-readelf-notes {AArch64 feature:\s+BTI,\s+PAC,\s+(GCS|<unknown:\s+[0-9]+>)} } } */
new file mode 100644
@@ -0,0 +1,5 @@
+int
+foo ()
+{
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,16 @@
+/* PR target/124365 */
+/* { dg-lto-do link } */
+/* { dg-skip-if "" { ! aarch64*-*-linux* } } */
+/* { dg-skip-if "" { aarch64_gas_has_build_attributes } } */
+/* { dg-require-effective-target mbranch_protection_ok } */
+/* { dg-lto-options { { -flto -O2 -mbranch-protection=none } } } */
+/* { dg-extra-ld-options "-nostdlib -nostartfiles -Wl,-e,main" } */
+
+int foo ();
+int
+main (void)
+{
+ return 0;
+}
+
+/* { dg-final { object-readelf-notes-not {AArch64 feature:\s+BTI\s+PAC\s+(GCS|<unknown:\s+[0-9]+>)} } } */
new file mode 100644
@@ -0,0 +1,6 @@
+/* { dg-options "-O2 -flto -mbranch-protection=standard" } */
+int
+foo ()
+{
+ return 0;
+}