]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
aarch64: Fix error messages for GCS and BTI incompatible modules
authorYury Khrustalev <yury.khrustalev@arm.com>
Wed, 10 Dec 2025 15:06:47 +0000 (15:06 +0000)
committerYury Khrustalev <yury.khrustalev@arm.com>
Mon, 12 Jan 2026 09:32:16 +0000 (09:32 +0000)
When either program path of module name is empty, don't print an
empty string followed by a colon.

Also fix-up test for a static BTI binary to check error message
for this case.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
sysdeps/aarch64/Makefile
sysdeps/aarch64/dl-bti.c
sysdeps/aarch64/dl-gcs.c
sysdeps/aarch64/tst-bti-abort-static.c

index b939bcfc1192f9ead043bf0b07da3c53c832df35..ee3981e3f65a7123b42cb7bde4fe2f3e7518d0d2 100644 (file)
@@ -90,6 +90,7 @@ ifeq (yes,$(have-test-bti))
 
 tests += \
   tst-bti-abort-imm \
+  tst-bti-abort-static \
   tst-bti-abort-transitive \
   tst-bti-abort-unprot \
   tst-bti-dep-prot \
index 5d743e775f855d78fdd51fc48f3028b1494d6b4c..1301ce2e73898bad355ae99a454bab16ab788c27 100644 (file)
@@ -66,13 +66,23 @@ _dl_bti_protect (struct link_map *map, int fd)
 static void
 bti_failed (struct link_map *l, const char *program)
 {
-  if (program)
-    _dl_fatal_printf ("%s: %s: failed to turn on BTI protection\n",
-                     program, l->l_name);
+  if (program != NULL)
+    {
+      if (program[0] != '\0' && l->l_name[0] != '\0')
+       /* A program's dependency is not BTI compatible.  */
+       _dl_fatal_printf ("%s: %s: failed to turn on BTI protection\n",
+                         program, l->l_name);
+      if (program[0] != '\0')
+       /* The program itself is not BTI compatible.  */
+       _dl_fatal_printf ("%s: failed to turn on BTI protection\n", program);
+      /* For static binaries, program will be an empty string.  */
+      _dl_fatal_printf ("error: failed to turn on BTI protection\n");
+    }
   else
-    /* Note: the errno value is not available any more.  */
+    /* If program is NULL, we are processing a dlopen operation.
+       Note: the errno value is not available any more.  */
     _dl_signal_error (0, l->l_name, "dlopen",
-                     N_("failed to turn on BTI protection"));
+                     "failed to turn on BTI protection");
 }
 
 
index 7a80e149332134c4f9e5f37b1e987078b05d54b5..1c6944562d7744215f6e95b81a4fdd7f2b96d208 100644 (file)
 static void
 fail (struct link_map *l, const char *program)
 {
-  if (program && program[0])
-    _dl_fatal_printf ("%s: %s: %s\n", program, l->l_name, "not GCS compatible");
-  else if (program)
-    _dl_fatal_printf ("%s\n", "not GCS compatible");
+    if (program != NULL)
+    {
+      if (program[0] != '\0' && l->l_name[0] != '\0')
+       /* A program's dependency is not GCS compatible.  */
+       _dl_fatal_printf ("%s: %s: not GCS compatible\n", program, l->l_name);
+      if (program[0] != '\0')
+       /* The program itself is not GCS compatible.  */
+       _dl_fatal_printf ("%s: not GCS compatible\n", program);
+      /* For static binaries, program will be an empty string.  */
+      _dl_fatal_printf ("error: not GCS compatible\n");
+    }
   else
+    /* If program is NULL, we are processing a dlopen operation.
+       Note: the errno value is not available any more.  */
     _dl_signal_error (0, l->l_name, "dlopen", "not GCS compatible");
 }
 
 static void
 unsupported (void)
 {
-  _dl_fatal_printf ("%s\n", "unsupported GCS policy");
+  _dl_fatal_printf ("unsupported GCS policy\n");
 }
 
 /* This function is called only when binary markings are not
index 83871b1fdb0c849073be02f7d1b0b8c74849877d..6385e41c6559015c2546d74230b562b248d4efc3 100644 (file)
@@ -22,6 +22,7 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <string.h>
+#include <sys/auxv.h>
 
 #include <support/check.h>
 #include <support/support.h>
@@ -30,6 +31,9 @@
 static int
 do_test (void)
 {
+  unsigned long hwcap2 = getauxval (AT_HWCAP2);
+  if ((hwcap2 & HWCAP2_BTI) == 0)
+    FAIL_UNSUPPORTED ("BTI is not supported by this system");
   return 0;
 }