[PATCH v2] ld.so: Support showing target info in ldd output

Yury Khrustalev yury.khrustalev@arm.com
Wed Nov 11 14:00:45 GMT 2026


The ldd script calls ld.so with a non empty LD_TRACE_LOADED_OBJECTS
env variable which prints dependencies of a program.

On some targets the result of dynamic loader may depend on target
specific binary markings or other properties of the loaded objects.

To make this information easier to access, we add support to print
this information: targets may implement the _dl_trace_print_props
function that should print any target-specific properties on one
line without any new line at the end using _dl_printf.

This patch implements printing of target-specific properties for
aarch64 and currently covers BTI, PAC and GCS but more features can
be added in the future.

On aarch64, the properties of ld.so and linux-vdso are not printed
because GNU properties of these modules are not processed.
---
 elf/rtld.c                | 32 ++++++++++++++++++++++----------
 sysdeps/aarch64/dl-prop.h | 15 ++++++++++++++-
 sysdeps/aarch64/linkmap.h |  1 +
 sysdeps/generic/dl-prop.h |  5 +++++
 sysdeps/x86/dl-prop.h     |  5 +++++
 5 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/elf/rtld.c b/elf/rtld.c
index 65c10edff2..e8b6e586d5 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -2074,7 +2074,11 @@ dl_main (const ElfW(Phdr) *phdr,
 	  _exit (first != true);
 	}
       else if (! main_map->l_info[DT_NEEDED])
-	_dl_printf ("\tstatically linked\n");
+	{
+	  _dl_printf ("\tstatically linked");
+	  _dl_trace_print_props (main_map);
+	  _dl_printf ("\n");
+	}
       else
 	{
 	  for (l = state.mode_trace_program ? main_map : main_map->l_next;
@@ -2085,16 +2089,24 @@ dl_main (const ElfW(Phdr) *phdr,
 	    else if (strcmp (l->l_libname->name, l->l_name) == 0)
 	      /* Print vDSO like libraries without duplicate name.  Some
 		 consumers depend of this format.  */
-	      _dl_printf ("\t%s (0x%0*zx)\n",
-			  DSO_FILENAME (l->l_libname->name),
-			  (int) sizeof l->l_map_start * 2,
-			  (size_t) l->l_map_start);
+	      {
+		_dl_printf ("\t%s (0x%0*zx)",
+			    DSO_FILENAME (l->l_libname->name),
+			    (int) sizeof l->l_map_start * 2,
+			    (size_t) l->l_map_start);
+		_dl_trace_print_props (l);
+		_dl_printf ("\n");
+	      }
 	    else
-	      _dl_printf ("\t%s => %s (0x%0*zx)\n",
-			  DSO_FILENAME (l->l_libname->name),
-			  DSO_FILENAME (l->l_name),
-			  (int) sizeof l->l_map_start * 2,
-			  (size_t) l->l_map_start);
+	      {
+		_dl_printf ("\t%s => %s (0x%0*zx)",
+			    DSO_FILENAME (l->l_libname->name),
+			    DSO_FILENAME (l->l_name),
+			    (int) sizeof l->l_map_start * 2,
+			    (size_t) l->l_map_start);
+		_dl_trace_print_props (l);
+		_dl_printf ("\n");
+	      }
 	  }
 	}
 
diff --git a/sysdeps/aarch64/dl-prop.h b/sysdeps/aarch64/dl-prop.h
index 26fc639405..85ef8cab71 100644
--- a/sysdeps/aarch64/dl-prop.h
+++ b/sysdeps/aarch64/dl-prop.h
@@ -56,12 +56,13 @@ _dl_process_gnu_property (struct link_map *l, int fd, uint32_t type,
 	return 0;
 
       unsigned int feature_1 = *(unsigned int *) data;
+      l->l_mach.feature_1 = feature_1;
       if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
 	if (GLRO(dl_aarch64_cpu_features).bti)
 	  _dl_bti_protect (l, fd);
 
       if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
-	l->l_mach.gcs = 1;
+	l->l_mach.gcs = true;
 
       /* Stop if we processed the property note.  */
       return 0;
@@ -70,4 +71,16 @@ _dl_process_gnu_property (struct link_map *l, int fd, uint32_t type,
   return 1;
 }
 
+static inline void
+_dl_trace_print_props (const struct link_map *l)
+{
+  unsigned int feature_1 = l->l_mach.feature_1;
+  if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
+    _dl_printf (" bti");
+  if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)
+    _dl_printf (" pac");
+  if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
+    _dl_printf (" gcs");
+}
+
 #endif /* _DL_PROP_H */
diff --git a/sysdeps/aarch64/linkmap.h b/sysdeps/aarch64/linkmap.h
index 2a1e9325ae..90460c3f94 100644
--- a/sysdeps/aarch64/linkmap.h
+++ b/sysdeps/aarch64/linkmap.h
@@ -25,4 +25,5 @@ struct link_map_machine
   bool bti_fail;	  /* Failed to enable Branch Target Identification.  */
   bool gcs;		  /* Guarded Control Stack marking.  */
   bool bti;		  /* Branch Target Identification marking.  */
+  unsigned int feature_1; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND.  */
 };
diff --git a/sysdeps/generic/dl-prop.h b/sysdeps/generic/dl-prop.h
index 6a1e1eeff8..54ef425b0d 100644
--- a/sysdeps/generic/dl-prop.h
+++ b/sysdeps/generic/dl-prop.h
@@ -36,6 +36,11 @@ _dl_open_check (struct link_map *m, int dlopen_mode)
 {
 }
 
+static inline void __attribute__ ((always_inline))
+_dl_trace_print_props (const struct link_map *m)
+{
+}
+
 /* Called for each property in the NT_GNU_PROPERTY_TYPE_0 note of L,
    processing of the properties continues until this returns 0.  */
 static inline int __attribute__ ((always_inline))
diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h
index a466eba331..37e3a69230 100644
--- a/sysdeps/x86/dl-prop.h
+++ b/sysdeps/x86/dl-prop.h
@@ -81,6 +81,11 @@ _dl_open_check (struct link_map *m, int dlopne_mode)
 #endif
 }
 
+static inline void __attribute__ ((always_inline))
+_dl_trace_print_props (const struct link_map *m)
+{
+}
+
 /* Check the GNU property and return its value.  It returns:
    -1: Skip this note.
     0: Stop checking.

base-commit: fcc57fe96f8f27a84f7493d9540a4268b187d67f
-- 
2.47.3



More information about the Libc-alpha mailing list