elf: Suppress unused function clang for __ifunc_resolver

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]'
warning.  The static is used to avoid name pollution on static
linkage.
This commit is contained in:
Adhemerval Zanella 2022-08-04 09:43:18 -03:00
parent 68cbe438b5
commit 413a452b5c
3 changed files with 13 additions and 1 deletions

View File

@ -22,6 +22,7 @@
# include <stdbool.h>
# include <stdio.h>
# include <libc-diag.h>
/* Do not use the test framework, so that the process setup is not
disturbed. */
@ -40,6 +41,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)
@ -49,6 +52,7 @@ resolver (void)
}
static int magic (void) __attribute__ ((ifunc ("resolver")));
DIAG_POP_NEEDS_COMMENT_CLANG;
int
main (void)

View File

@ -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")));

View File

@ -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. */
@ -685,7 +686,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__)