[0/2] aarch64/testsuite: improve object-readelf and add LTO branch-protection tests

Message ID 20260408091202.13538-1-muhammad.kamran@arm.com
Headers
Series aarch64/testsuite: improve object-readelf and add LTO branch-protection tests |

Message

Muhammad Kamran April 8, 2026, 9:12 a.m. UTC
  When branch protection is enabled, every object file is marked with
compatibility tags. This tags can be either Build Attributes (BA) or GNU
properties, depending on the binutils version. When GCC is built with a version
of binutils (2.46) that supports BAs, GCC defaults to using BAs for tagging.

An issue [1] was recently identified when branch protection and LTO are used
together. LTO relies on utilities in libiberty to copy the tag sections from the
input objects to the output one. However, only the GNU properties section was
copied, while the BAs section was ignored. This issue went unnoticed during the
BA testing phase due to the lack of test coverage for this use case. It was
subsequently fixed by [2], but without adding any corresponding test cases.

This series adds the missing LTO tests for branch protection, focusing on robust
checks that handle both metadata formats, depending on whether GCC was built
with an older or a BA-enabled version of binutils. It also improves the
object-readelf testsuite helper used by these tests.

	PR target/124365

Series overview

	* Generalize object-readelf to accept option, regex and is-negative and
	add wrappers to check attributes, notes (and respective negative
	checks).
	* Add LTO test for build attributes with branch protection enabled.
	* Add LTO test for build attributes with mixed TUs (one without branch
	protection, one with it).
	* Add LTO test for .note.gnu.property with branch protection enabled.
	* Add LTO test for .note.gnu.property with mixed TUs (one without branch
	protection, one with it).
	* This should keep coverage for both old/new binutils configurations and
	prevent regressions in the fixed LTO behavior.

Regression tested on aarch64-linux-gnu and arm-linux-gnueabihf with no
regressions.

[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124365
[2]: 8b39ec70741b7fb9d059b6944f30a6743dea996a

Muhammad Kamran (2):
  testsuite: Extend object-readelf beyond attributes
  aarch64/testsuite: add LTO coverage for branch-protection notes and
    attributes

 gcc/doc/sourcebuild.texi                      | 23 ++++++
 gcc/testsuite/gcc.dg-selftests/dg-final.exp   |  5 +-
 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 ++
 .../gcc.target/arm/lto/pr61123-enum-size_0.c  |  2 +-
 gcc/testsuite/lib/lto.exp                     | 77 ++++++++++---------
 13 files changed, 219 insertions(+), 39 deletions(-)
 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