[glibc] elf: Fix clang-18 build of ifunc resolver tests

Adhemerval Zanella via Glibc-cvs <[email protected]> Wed, 24 Jun 2026 16:45:08 +0000 (GMT)
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=16c74b94b9c3a5d1360cb1a1049ff0e7b0f031dd

commit 16c74b94b9c3a5d1360cb1a1049ff0e7b0f031dd
Author: Adhemerval Zanella <[email protected]>
Date:   Wed Jun 24 13:40:50 2026 -0300

    elf: Fix clang-18 build of ifunc resolver tests
    
    clang-18 errors on the static ifunc resolvers seen as unused.

Diff:
---
 elf/tst-ifunc-bz28817.c                       |  1 +
 elf/tst-ifunc-plt-lib.c                       | 11 +++++++----
 elf/tst-ifunc-resolver-protector-mod.c        |  3 +++
 elf/tst-ifunc-resolver-protector-static-mod.c |  1 +
 elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c   |  6 +++++-
 elf/tst-ifunc-tls-init-lib-skeleton.c         |  6 +++++-
 elf/tst-ifunc-tls-write-lib.c                 |  6 +++++-
 7 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/elf/tst-ifunc-bz28817.c b/elf/tst-ifunc-bz28817.c
index fe6f400f4e..21d73d27fd 100644
--- a/elf/tst-ifunc-bz28817.c
+++ b/elf/tst-ifunc-bz28817.c
@@ -41,6 +41,7 @@ my_foo (void)
 
 static __typeof (foo) *
 inhibit_stack_protector
+__attribute_used__
 foo_ifunc (void)
 {
   init_foo ();
diff --git a/elf/tst-ifunc-plt-lib.c b/elf/tst-ifunc-plt-lib.c
index a9c100a894..e65215059f 100644
--- a/elf/tst-ifunc-plt-lib.c
+++ b/elf/tst-ifunc-plt-lib.c
@@ -22,6 +22,7 @@
    .rel{a}.plt).  This verifies that every IRELATIVE entry is deferred
    until after .rela.plt has been processed, not just the first one.  */
 
+#include <sys/cdefs.h>
 #include <stddef.h>
 
 extern int get_value (void);
@@ -38,14 +39,16 @@ impl_b (void)
   return 2;
 }
 
-static int (*
-resolve_a (void)) (void)
+static typeof (impl_a) *
+__attribute_used__
+resolve_a (void)
 {
   return get_value () == 42 ? impl_a : NULL;
 }
 
-static int (*
-resolve_b (void)) (void)
+static typeof (impl_b) *
+__attribute_used__
+resolve_b (void)
 {
   return get_value () == 42 ? impl_b : NULL;
 }
diff --git a/elf/tst-ifunc-resolver-protector-mod.c b/elf/tst-ifunc-resolver-protector-mod.c
index 36d11f04de..4f18e82e6f 100644
--- a/elf/tst-ifunc-resolver-protector-mod.c
+++ b/elf/tst-ifunc-resolver-protector-mod.c
@@ -25,6 +25,8 @@
    always observe an initialised canary; this test guards against any future
    reordering that would break that invariant.  */
 
+#include <sys/cdefs.h>
+
 #define SENTINEL 0x5A5A1234
 
 static volatile int resolver_ran;
@@ -44,6 +46,7 @@ impl_ok (int x)
 typedef int (*fn_t) (int);
 
 static fn_t
+__attribute_used__
 resolver (void)
 {
   /* Buffer + zero-fill force -fstack-protector-all canary code.  */
diff --git a/elf/tst-ifunc-resolver-protector-static-mod.c b/elf/tst-ifunc-resolver-protector-static-mod.c
index b1cb704854..60d4071c43 100644
--- a/elf/tst-ifunc-resolver-protector-static-mod.c
+++ b/elf/tst-ifunc-resolver-protector-static-mod.c
@@ -50,6 +50,7 @@ impl_ok (int x)
 typedef int (*fn_t) (int);
 
 static fn_t
+__attribute_used__
 resolver (void)
 {
   /* Buffer forces -fstack-protector-all to emit canary code even with
diff --git a/elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c b/elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c
index b6fd6cf06e..3a2f33d162 100644
--- a/elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c
+++ b/elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c
@@ -23,6 +23,8 @@
    TLSDESC equivalent).  That dynamic-TLS access can lazily allocate a
    per-module TLS block, which is the path being exercised.  */
 
+#include <sys/cdefs.h>
+
 #ifndef TLS_MODEL
 # error "tst-ifunc-tls-init-gd-ld-lib-skeleton.c needs TLS_MODEL defined"
 #endif
@@ -58,7 +60,9 @@ get_last_seen_sentinel (void)
   return last_seen_sentinel;
 }
 
-static int (*resolver (void)) (void)
+static typeof (impl_ok) *
+__attribute_used__
+resolver (void)
 {
   int s = sentinel;
   last_seen_sentinel = s;
diff --git a/elf/tst-ifunc-tls-init-lib-skeleton.c b/elf/tst-ifunc-tls-init-lib-skeleton.c
index 7b8a1647a4..1d9592107c 100644
--- a/elf/tst-ifunc-tls-init-lib-skeleton.c
+++ b/elf/tst-ifunc-tls-init-lib-skeleton.c
@@ -20,6 +20,8 @@
    load, so the test is sensitive to whether the static TLS block has been
    populated rather than to any __tls_get_addr / DTV-update timing.  */
 
+#include <sys/cdefs.h>
+
 #define SENTINEL 0x5A5A1234
 
 /* The 'volatile' avoids constant fold optimization in impl_ok.  */
@@ -45,7 +47,9 @@ get_last_seen_sentinel (void)
   return last_seen_sentinel;
 }
 
-static int (*resolver (void)) (void)
+static typeof (impl_ok) *
+__attribute_used__
+resolver (void)
 {
   int s = sentinel;
   last_seen_sentinel = s;
diff --git a/elf/tst-ifunc-tls-write-lib.c b/elf/tst-ifunc-tls-write-lib.c
index ef1dff90e0..1d784fbe0e 100644
--- a/elf/tst-ifunc-tls-write-lib.c
+++ b/elf/tst-ifunc-tls-write-lib.c
@@ -21,6 +21,8 @@
    overwrites counter with MARKER, and the test then reads counter back
    through a getter.  */
 
+#include <sys/cdefs.h>
+
 #define SENTINEL 0x5A5A1234u
 #define MARKER   0x32125A5Au
 
@@ -34,7 +36,9 @@ impl (void)
   return 0;
 }
 
-static unsigned int (*resolver (void)) (void)
+static typeof (impl) *
+__attribute_used__
+resolver (void)
 {
   counter = MARKER;
   return impl;