[PATCH 5/7] elf: Suppress unused function clang for __ifunc_resolver
H.J. Lu
hjl.tools@gmail.com
Tue Dec 31 21:01:44 GMT 2024
On Wed, Jan 1, 2025 at 2:27 AM 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 still emits
> an 'unused function 'name_ifunc' [-Werror,-Wunused-function]'
Why didn't I see it on x86-64 with non-fortify build?
> warning. The static is used to avoid name pollution on static
> linkage.
> ---
> elf/ifuncmain9.c | 4 ++++
> elf/tst-ifunc-fault-lazy.c | 4 ++++
> include/libc-symbols.h | 6 +++++-
> 3 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/elf/ifuncmain9.c b/elf/ifuncmain9.c
> index 654beeadfe..f102b140bd 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 5157c6cc6c..04448b2b15 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")));
>
> diff --git a/include/libc-symbols.h b/include/libc-symbols.h
> index 56ae61015d..9fe047f4d3 100644
> --- a/include/libc-symbols.h
> +++ b/include/libc-symbols.h
> @@ -86,6 +86,7 @@
>
> /* Obtain the definition of symbol_version_reference. */
> #include <libc-symver.h>
> +#include <libc-diag.h>
>
> /* When PIC is defined and SHARED isn't defined, we are building PIE
> by default. */
> @@ -671,7 +672,10 @@ for linking")
> # define __ifunc_args(type_name, name, expr, init, ...) \
> extern __typeof (type_name) name __attribute__ \
> ((ifunc (#name "_ifunc"))); \
> - __ifunc_resolver (type_name, name, expr, init, static, __VA_ARGS__)
> + DIAG_PUSH_NEEDS_COMMENT_CLANG; \
> + DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wunused-function"); \
> + __ifunc_resolver (type_name, name, expr, init, static, __VA_ARGS__); \
> + DIAG_POP_NEEDS_COMMENT_CLANG;
>
> # define __ifunc_args_hidden(type_name, name, expr, init, ...) \
> __ifunc_args (type_name, name, expr, init, __VA_ARGS__)
> --
> 2.43.0
>
--
H.J.
More information about the Libc-alpha
mailing list