From: Yury Khrustalev Date: Wed, 10 Dec 2025 15:06:47 +0000 (+0000) Subject: aarch64: Fix error messages for GCS and BTI incompatible modules X-Git-Tag: glibc-2.43~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ca2eb11946de5f73c643e295ca17cedc6c981a3;p=thirdparty%2Fglibc.git aarch64: Fix error messages for GCS and BTI incompatible modules 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  --- diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile index b939bcfc11..ee3981e3f6 100644 --- a/sysdeps/aarch64/Makefile +++ b/sysdeps/aarch64/Makefile @@ -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 \ diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c index 5d743e775f..1301ce2e73 100644 --- a/sysdeps/aarch64/dl-bti.c +++ b/sysdeps/aarch64/dl-bti.c @@ -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"); } diff --git a/sysdeps/aarch64/dl-gcs.c b/sysdeps/aarch64/dl-gcs.c index 7a80e14933..1c6944562d 100644 --- a/sysdeps/aarch64/dl-gcs.c +++ b/sysdeps/aarch64/dl-gcs.c @@ -33,18 +33,27 @@ 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 diff --git a/sysdeps/aarch64/tst-bti-abort-static.c b/sysdeps/aarch64/tst-bti-abort-static.c index 83871b1fdb..6385e41c65 100644 --- a/sysdeps/aarch64/tst-bti-abort-static.c +++ b/sysdeps/aarch64/tst-bti-abort-static.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -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; }