[PATCH v3 2/2] ld.so: Add tests for ldd --target-info

Yury Khrustalev yury.khrustalev@arm.com
Thu Nov 19 13:36:16 GMT 2026


Tests cover both static and dynamic binaries and account for
compiler support of the aarch64 that affect output.
---
 sysdeps/aarch64/Makefile                      |  47 ++++++++
 sysdeps/aarch64/configure                     | 108 ++++++++++++++++++
 sysdeps/aarch64/configure.ac                  |  29 +++++
 sysdeps/aarch64/tst-ldd-target-info-bti.c     |   3 +
 sysdeps/aarch64/tst-ldd-target-info-gcs.c     |   3 +
 sysdeps/aarch64/tst-ldd-target-info-mod.c     |   5 +
 sysdeps/aarch64/tst-ldd-target-info-none.c    |   3 +
 sysdeps/aarch64/tst-ldd-target-info-pac.c     |   3 +
 .../aarch64/tst-ldd-target-info-static.awk    |  25 ++++
 sysdeps/aarch64/tst-ldd-target-info-static.c  |  28 +++++
 sysdeps/aarch64/tst-ldd-target-info.awk       |  59 ++++++++++
 sysdeps/aarch64/tst-ldd-target-info.c         |  52 +++++++++
 sysdeps/aarch64/tst-ldd-target-info.sh        |  38 ++++++
 13 files changed, 403 insertions(+)
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info-bti.c
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info-gcs.c
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info-mod.c
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info-none.c
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info-pac.c
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info-static.awk
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info-static.c
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info.awk
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info.c
 create mode 100644 sysdeps/aarch64/tst-ldd-target-info.sh

diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile
index f046148091..aba118cebe 100644
--- a/sysdeps/aarch64/Makefile
+++ b/sysdeps/aarch64/Makefile
@@ -29,8 +29,55 @@ $(objpfx)tst-audit27: $(objpfx)tst-audit27mod.so \
 $(objpfx)tst-audit27mod.so: $(libsupport)
 LDFLAGS-tst-audit27 += -Wl,-z,lazy
 tst-audit27-ENV = LD_AUDIT=$(objpfx)tst-auditmod27.so
+
+tests += \
+  tst-ldd-target-info \
+  # tests
+
+tests-static += \
+  tst-ldd-target-info-static \
+  # tests-static
+
+$(objpfx)tst-ldd-target-info: $(objpfx)tst-ldd-target-info-none.so
+modules-names += tst-ldd-target-info-none
+
+ifeq (yes,$(have-test-bti))
+$(objpfx)tst-ldd-target-info: $(objpfx)tst-ldd-target-info-bti.so
+modules-names += tst-ldd-target-info-bti
+CFLAGS-tst-ldd-target-info.o += -D_HAS_BTI
 endif
 
+ifeq (yes,$(have-test-pac))
+$(objpfx)tst-ldd-target-info: $(objpfx)tst-ldd-target-info-pac.so
+modules-names += tst-ldd-target-info-pac
+CFLAGS-tst-ldd-target-info.o += -D_HAS_PAC
+endif
+
+ifeq (yes,$(have-test-gcs))
+$(objpfx)tst-ldd-target-info: $(objpfx)tst-ldd-target-info-gcs.so
+modules-names += tst-ldd-target-info-gcs
+CFLAGS-tst-ldd-target-info.o += -D_HAS_GCS
+endif
+
+tests-special += $(objpfx)tst-ldd-target-info.out
+$(objpfx)tst-ldd-target-info.out: \
+	$(addprefix $(..)sysdeps/aarch64/,tst-ldd-target-info.sh tst-ldd-target-info.awk) \
+	$(objpfx)tst-ldd-target-info
+	$(SHELL) $< $(objpfx)ld.so '$(test-wrapper-env)' '$(run_program_env)' \
+	  $(objpfx)tst-ldd-target-info \
+	  $(..)sysdeps/aarch64/tst-ldd-target-info.awk > $@; $(evaluate-test)
+
+tests-special += $(objpfx)tst-ldd-target-info-static.out
+$(objpfx)tst-ldd-target-info-static.out: \
+	$(addprefix $(..)sysdeps/aarch64/,tst-ldd-target-info.sh tst-ldd-target-info-static.awk) \
+	$(objpfx)tst-ldd-target-info-static
+	$(SHELL) $< $(objpfx)ld.so '$(test-wrapper-env)' '$(run_program_env)' \
+	  $(objpfx)tst-ldd-target-info-static \
+	  $(..)sysdeps/aarch64/tst-ldd-target-info-static.awk \
+	  '$(have-test-bti)' '$(have-test-pac)' '$(have-test-gcs)' > $@; $(evaluate-test)
+
+endif # elf directory
+
 ifeq ($(subdir),elf)
 sysdep-rtld-routines += \
   dl-start \
diff --git a/sysdeps/aarch64/configure b/sysdeps/aarch64/configure
index 7cded1d461..abe9cbc934 100644
--- a/sysdeps/aarch64/configure
+++ b/sysdeps/aarch64/configure
@@ -340,6 +340,114 @@ else
 have-test-bti = no"
 fi
 
+# Check if compilers support PAC in branch protection:
+
+{ printf '%s\n' "$as_me:${as_lineno-$LINENO}: checking if compiler supports -mbranch-protection=pac-ret" >&5
+printf %s "checking if compiler supports -mbranch-protection=pac-ret... " >&6; }
+if test ${libc_cv_cc_pac+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) if { ac_try='${CC-cc} -Werror -mbranch-protection=pac-ret -xc /dev/null -S -o /dev/null'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf '%s\n' "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+then :
+  libc_cv_cc_pac=yes
+else case e in #(
+  e) libc_cv_cc_pac=no ;;
+esac
+fi ;;
+esac
+fi
+{ printf '%s\n' "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_pac" >&5
+printf '%s\n' "$libc_cv_cc_pac" >&6; }
+if test "$TEST_CC" = "$CC"; then
+  libc_cv_test_cc_pac=$libc_cv_cc_pac
+else
+
+saved_CC="$CC"
+CC="$TEST_CC"
+{ printf '%s\n' "$as_me:${as_lineno-$LINENO}: checking if compiler supports -mbranch-protection=pac-ret in testing" >&5
+printf %s "checking if compiler supports -mbranch-protection=pac-ret in testing... " >&6; }
+if test ${libc_cv_test_cc_pac+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) if { ac_try='${CC-cc} -Werror -mbranch-protection=pac-ret -xc /dev/null -S -o /dev/null'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf '%s\n' "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+then :
+  libc_cv_test_cc_pac=yes
+else case e in #(
+  e) libc_cv_test_cc_pac=no
+ ;;
+esac
+fi ;;
+esac
+fi
+{ printf '%s\n' "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_cc_pac" >&5
+printf '%s\n' "$libc_cv_test_cc_pac" >&6; }
+
+CC="$saved_CC"
+
+fi
+
+
+# Check if toolchain is enabled to support PAC
+{ printf '%s\n' "$as_me:${as_lineno-$LINENO}: checking if toolchain is enabled to support PAC" >&5
+printf %s "checking if toolchain is enabled to support PAC... " >&6; }
+libc_elf_property=no
+cat > conftest.c <<EOF
+int foo (void) { return 42; }
+EOF
+if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
+		  -fPIC -shared -o conftest.so conftest.c
+		  1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf '%s\n' "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+then
+  if { ac_try='LC_ALL=C $READELF -n --wide conftest.so | grep "AArch64 feature: .*PAC" 1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf '%s\n' "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+  then
+    libc_elf_property=yes
+  else
+    libc_elf_property=no
+  fi
+fi
+rm -f conftest*
+if test $libc_elf_property = yes; then
+  libc_cv_pac_supported=yes
+else
+  libc_cv_pac_supported=no
+
+fi
+{ printf '%s\n' "$as_me:${as_lineno-$LINENO}: result: $libc_elf_property" >&5
+printf '%s\n' "$libc_elf_property" >&6; }
+
+if test $libc_cv_cc_pac = yes && \
+  test $libc_cv_test_cc_pac = yes && \
+  test $libc_cv_pac_supported = yes
+then
+  config_vars="$config_vars
+have-test-pac = yes"
+else
+  config_vars="$config_vars
+have-test-pac = no"
+fi
+
 # Check if compilers support GCS in branch protection:
 
 { printf '%s\n' "$as_me:${as_lineno-$LINENO}: checking if compiler supports -mbranch-protection=gcs" >&5
diff --git a/sysdeps/aarch64/configure.ac b/sysdeps/aarch64/configure.ac
index b9981861f6..a1ffe1dfb9 100644
--- a/sysdeps/aarch64/configure.ac
+++ b/sysdeps/aarch64/configure.ac
@@ -70,6 +70,35 @@ else
   LIBC_CONFIG_VAR([have-test-bti], [no])
 fi
 
+# Check if compilers support PAC in branch protection:
+LIBC_TRY_CC_AND_TEST_CC_OPTION(
+  [if compiler supports -mbranch-protection=pac-ret],
+  [-Werror -mbranch-protection=pac-ret],
+  libc_cv_cc_pac,
+  [libc_cv_cc_pac=yes],
+  [libc_cv_cc_pac=no],
+  libc_cv_test_cc_pac,
+  [libc_cv_test_cc_pac=yes],
+  [libc_cv_test_cc_pac=no]
+)
+
+# Check if toolchain is enabled to support PAC
+LIBC_CHECK_ELF_PROPERTY(
+  [if toolchain is enabled to support PAC],
+  [AArch64 feature: .*PAC],
+  [libc_cv_pac_supported=yes],
+  [libc_cv_pac_supported=no]
+)
+
+if test $libc_cv_cc_pac = yes && \
+  test $libc_cv_test_cc_pac = yes && \
+  test $libc_cv_pac_supported = yes
+then
+  LIBC_CONFIG_VAR([have-test-pac], [yes])
+else
+  LIBC_CONFIG_VAR([have-test-pac], [no])
+fi
+
 # Check if compilers support GCS in branch protection:
 LIBC_TRY_CC_AND_TEST_CC_OPTION(
   [if compiler supports -mbranch-protection=gcs],
diff --git a/sysdeps/aarch64/tst-ldd-target-info-bti.c b/sysdeps/aarch64/tst-ldd-target-info-bti.c
new file mode 100644
index 0000000000..d9148c24dc
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info-bti.c
@@ -0,0 +1,3 @@
+#pragma GCC target("branch-protection=bti")
+#define name "fun_bti"
+#include "tst-ldd-target-info-mod.c"
diff --git a/sysdeps/aarch64/tst-ldd-target-info-gcs.c b/sysdeps/aarch64/tst-ldd-target-info-gcs.c
new file mode 100644
index 0000000000..edde4e7294
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info-gcs.c
@@ -0,0 +1,3 @@
+#pragma GCC target("branch-protection=gcs")
+#define name "fun_gcs"
+#include "tst-ldd-target-info-mod.c"
\ No newline at end of file
diff --git a/sysdeps/aarch64/tst-ldd-target-info-mod.c b/sysdeps/aarch64/tst-ldd-target-info-mod.c
new file mode 100644
index 0000000000..5a24a66344
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info-mod.c
@@ -0,0 +1,5 @@
+#ifndef name
+#define name "fun"
+#endif
+int fun(void) __asm__(name);
+int fun(void) { return 0; }
diff --git a/sysdeps/aarch64/tst-ldd-target-info-none.c b/sysdeps/aarch64/tst-ldd-target-info-none.c
new file mode 100644
index 0000000000..47d3b7d735
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info-none.c
@@ -0,0 +1,3 @@
+#pragma GCC target("branch-protection=none")
+#define name "fun_none"
+#include "tst-ldd-target-info-mod.c"
\ No newline at end of file
diff --git a/sysdeps/aarch64/tst-ldd-target-info-pac.c b/sysdeps/aarch64/tst-ldd-target-info-pac.c
new file mode 100644
index 0000000000..33282c5668
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info-pac.c
@@ -0,0 +1,3 @@
+#pragma GCC target("branch-protection=pac-ret")
+#define name "fun_pac"
+#include "tst-ldd-target-info-mod.c"
diff --git a/sysdeps/aarch64/tst-ldd-target-info-static.awk b/sysdeps/aarch64/tst-ldd-target-info-static.awk
new file mode 100644
index 0000000000..65a5cdca95
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info-static.awk
@@ -0,0 +1,25 @@
+BEGIN {
+  bti = ARGV[1] == "yes"
+  pac = ARGV[2] == "yes"
+  gcs = ARGV[3] == "yes"
+  ARGC = 1
+}
+
+/statically linked:/ && bti && index($0, "bti") == 0 {
+  print "Error: expected `bti` in program properties"
+  failed = 1
+}
+
+/statically linked:/ && pac && index($0, "pac") == 0 {
+  print "Error: expected `pac` in program properties"
+  failed = 1
+}
+
+/statically linked:/ && gcs && index($0, "gcs") == 0 {
+  print "Error: expected `gcs` in program properties"
+  failed = 1
+}
+
+END {
+  exit failed
+}
diff --git a/sysdeps/aarch64/tst-ldd-target-info-static.c b/sysdeps/aarch64/tst-ldd-target-info-static.c
new file mode 100644
index 0000000000..ab4e9c4167
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info-static.c
@@ -0,0 +1,28 @@
+/* Test to check target info in ldd output: static version.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#pragma GCC target("branch-protection=standard")
+
+static int
+do_test (void)
+{
+  /* This test is not meant to be run.  */
+  return 1;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/aarch64/tst-ldd-target-info.awk b/sysdeps/aarch64/tst-ldd-target-info.awk
new file mode 100644
index 0000000000..2a3abd72aa
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info.awk
@@ -0,0 +1,59 @@
+/tst-ldd-target-info-bti.so/ {
+  bti = 1
+}
+/tst-ldd-target-info-pac.so/ {
+  pac = 1
+}
+/tst-ldd-target-info-gcs.so/ {
+  gcs = 1
+}
+/tst-ldd-target-info-pac.so/ && !/: pac/ {
+  print "Error: expected `pac` after `tst-ldd-target-info-pac.so`"
+  failed = 1
+}/tst-ldd-target-info-bti.so/ && !/: bti$/ {
+  print "Error: expected `bti` after `tst-ldd-target-info-bti.so`"
+  failed = 1
+}
+/tst-ldd-target-info-gcs.so/ && !/: gcs/ {
+  print "Error: expected `gcs` after `tst-ldd-target-info-gcs.so`"
+  failed = 1
+}
+/^.*libc[.]so[.]6 \(.*\):.*/ {
+  has_libc = 1
+  prop_libc = $0
+  sub(/^.*: /, "", prop_libc)
+}
+/tst-ldd-target-info-none.so/ {
+  none = 1
+  prop_none = $0
+  sub(/^.*tst-ldd-target-info-none.so \(.*\)/, "", prop_none)
+}
+/^.*\/elf\/tst-ldd-target-info \(.*\):.*/ {
+  has_main = 1
+  prop_main = $0
+  sub(/^.*: /, "", prop_main)
+}
+END {
+  if (has_libc && has_main) {
+    if (prop_main != prop_libc) {
+      print "Error: expected same properties in main program and libc.so"
+    }
+    if (pac && prop_main !~ /pac/) {
+      print "Error: expected pac in main program properties"
+      failed = 1
+    }
+    if (bti && prop_main !~ /bti/) {
+      print "Error: expected bti in main program properties"
+      failed = 1
+    }
+    if (gcs && prop_main !~ /gcs/) {
+      print "Error: expected gcs in main program properties"
+      failed = 1
+    }
+  }
+  if (!none || prop_none != "") {
+    print "Error: expected `tst-ldd-target-info-none.so` with no properties"
+    failed = 1
+  }
+  exit failed
+}
diff --git a/sysdeps/aarch64/tst-ldd-target-info.c b/sysdeps/aarch64/tst-ldd-target-info.c
new file mode 100644
index 0000000000..196d9bcfe2
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info.c
@@ -0,0 +1,52 @@
+/* Test to check target info in ldd output.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#pragma GCC target("branch-protection=standard")
+
+extern int fun_none (void);
+
+#ifdef _HAS_BTI
+extern int fun_bti (void);
+#endif
+
+#ifdef _HAS_PAC
+extern int fun_pac (void);
+#endif
+
+#ifdef _HAS_GCS
+extern int fun_gcs (void);
+#endif
+
+static int
+do_test (void)
+{
+  return fun_none ()
+#ifdef _HAS_BTI
+  + fun_bti ()
+#endif
+#ifdef _HAS_PAC
+  + fun_pac ()
+#endif
+#ifdef _HAS_GCS
+  + fun_gcs ()
+#endif
+  /* This test is not meant to be run.  */
+  + 1;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/aarch64/tst-ldd-target-info.sh b/sysdeps/aarch64/tst-ldd-target-info.sh
new file mode 100644
index 0000000000..1aca5b8bca
--- /dev/null
+++ b/sysdeps/aarch64/tst-ldd-target-info.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Test for ldd --target-info. AArch64 version.
+# Copyright (C) 2026 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+#
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# The GNU C Library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+
+set -e
+
+rtld=$1; shift
+test_wrapper_env=$1; shift
+run_program_env=$1; shift
+test_program=$1; shift
+awk_script=$1; shift
+
+LC_ALL=C
+export LC_ALL
+
+output=$(${test_wrapper_env} ${run_program_env} \
+  LD_TRACE_LOADED_OBJECTS=2 \
+  $rtld --target-info ${test_program})
+status=$?
+
+printf "%s\n" "${output}"
+
+printf "%s\n" "${output}" | awk -f ${awk_script} -- $@
-- 
2.47.3



More information about the Libc-alpha mailing list