[v2,3/4] elf: Suppress unused function clang for __ifunc_resolver

Message ID 20250110181508.350378-4-adhemerval.zanella@linaro.org (mailing list archive)
State Committed
Commit 6a498d780e6fd3b7db7575c4ec00c00dc8568fef
Headers
Series More fixes for building tests with clang |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Adhemerval Zanella Netto Jan. 10, 2025, 6:12 p.m. UTC
  The __ifunc_resolver macro expands to:

  extern __typeof (__redirect_name) name __attribute__ ((ifunc ("iname_ifunc")));
  static __typeof (__redirect_name) *name_ifunc (void) { [...] };

And although NAME_IFUNC is and alias for NAME, clang-18 still emits
an 'unused function 'name_ifunc' [-Werror,-Wunused-function]'
warning.
---
 elf/ifuncmain9.c           | 4 ++++
 elf/tst-ifunc-fault-lazy.c | 4 ++++
 2 files changed, 8 insertions(+)
  

Comments

Sam James Jan. 10, 2025, 6:26 p.m. UTC | #1
> On 10 Jan 2025, at 18:15, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
> 
> The __ifunc_resolver macro expands to:
> 
>  extern __typeof (__redirect_name) name __attribute__ ((ifunc ("iname_ifunc")));
>  static __typeof (__redirect_name) *name_ifunc (void) { [...] };
> 
> And although NAME_IFUNC is and alias for NAME, clang-18 still emits
> an 'unused function 'name_ifunc' [-Werror,-Wunused-function]'
> warning.

ok (bug report would be nice but I don't insist, ifunc is ifunc..)

> ---
> elf/ifuncmain9.c           | 4 ++++
> elf/tst-ifunc-fault-lazy.c | 4 ++++
> 2 files changed, 8 insertions(+)
> 
> diff --git a/elf/ifuncmain9.c b/elf/ifuncmain9.c
> index b2c9547db3..64539b4a86 100644
> --- a/elf/ifuncmain9.c
> +++ b/elf/ifuncmain9.c
> @@ -22,6 +22,7 @@
> 
> #include <stdbool.h>
> #include <stdio.h>
> +#include <libc-diag.h>
> 
> #if __GNUC_PREREQ (5, 5)
> /* Do not use the test framework, so that the process setup is not
> @@ -41,6 +42,8 @@ implementation (void)
>   return random_constant;
> }
> 
> +DIAG_PUSH_NEEDS_COMMENT_CLANG;
> +DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wunused-function");
> static __typeof__ (implementation) *
> inhibit_stack_protector
> resolver (void)
> @@ -50,6 +53,7 @@ resolver (void)
> }
> 
> static int magic (void) __attribute__ ((ifunc ("resolver")));
> +DIAG_POP_NEEDS_COMMENT_CLANG;
> 
> int
> main (void)
> diff --git a/elf/tst-ifunc-fault-lazy.c b/elf/tst-ifunc-fault-lazy.c
> index c86edde06c..072d2c6a7b 100644
> --- a/elf/tst-ifunc-fault-lazy.c
> +++ b/elf/tst-ifunc-fault-lazy.c
> @@ -21,6 +21,7 @@
>    relocations.  */
> 
> #include <config.h>
> +#include <libc-diag.h>
> 
> #ifdef HAVE_GCC_IFUNC
> 
> @@ -34,6 +35,8 @@ implementation (void)
>   *p = 0;
> }
> 
> +DIAG_PUSH_NEEDS_COMMENT_CLANG;
> +DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wunused-function");
> static __typeof__ (implementation) *
> resolver (void)
> {
> @@ -42,6 +45,7 @@ resolver (void)
>   *p = 0;
>   return implementation;
> }
> +DIAG_POP_NEEDS_COMMENT_CLANG;
> 
> static void magic (void) __attribute__ ((ifunc ("resolver")));
> 
> --
> 2.43.0
>
  

Patch

diff --git a/elf/ifuncmain9.c b/elf/ifuncmain9.c
index b2c9547db3..64539b4a86 100644
--- a/elf/ifuncmain9.c
+++ b/elf/ifuncmain9.c
@@ -22,6 +22,7 @@ 
 
 #include <stdbool.h>
 #include <stdio.h>
+#include <libc-diag.h>
 
 #if __GNUC_PREREQ (5, 5)
 /* Do not use the test framework, so that the process setup is not
@@ -41,6 +42,8 @@  implementation (void)
   return random_constant;
 }
 
+DIAG_PUSH_NEEDS_COMMENT_CLANG;
+DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wunused-function");
 static __typeof__ (implementation) *
 inhibit_stack_protector
 resolver (void)
@@ -50,6 +53,7 @@  resolver (void)
 }
 
 static int magic (void) __attribute__ ((ifunc ("resolver")));
+DIAG_POP_NEEDS_COMMENT_CLANG;
 
 int
 main (void)
diff --git a/elf/tst-ifunc-fault-lazy.c b/elf/tst-ifunc-fault-lazy.c
index c86edde06c..072d2c6a7b 100644
--- a/elf/tst-ifunc-fault-lazy.c
+++ b/elf/tst-ifunc-fault-lazy.c
@@ -21,6 +21,7 @@ 
    relocations.  */
 
 #include <config.h>
+#include <libc-diag.h>
 
 #ifdef HAVE_GCC_IFUNC
 
@@ -34,6 +35,8 @@  implementation (void)
   *p = 0;
 }
 
+DIAG_PUSH_NEEDS_COMMENT_CLANG;
+DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wunused-function");
 static __typeof__ (implementation) *
 resolver (void)
 {
@@ -42,6 +45,7 @@  resolver (void)
   *p = 0;
   return implementation;
 }
+DIAG_POP_NEEDS_COMMENT_CLANG;
 
 static void magic (void) __attribute__ ((ifunc ("resolver")));