Blame sysdeps/generic/ifunc-init.h

Packit 6c4009
/* IFUNC generic definitions.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Copyright (C) 2017-2018 Free Software Foundation, Inc.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* These macros are used to implement ifunc selection in C.  To implement
Packit 6c4009
   an ifunc function, foo, which returns the address of __foo_impl1 or
Packit 6c4009
   __foo_impl2:
Packit 6c4009
Packit 6c4009
   #define foo __redirect_foo
Packit 6c4009
   #include <foo.h>
Packit 6c4009
   #undef foo
Packit 6c4009
   #define SYMBOL_NAME foo
Packit 6c4009
   #include <ifunc-init.h>
Packit 6c4009
Packit 6c4009
   extern __typeof (REDIRECT_NAME) OPTIMIZE (impl1) attribute_hidden;
Packit 6c4009
   extern __typeof (REDIRECT_NAME) OPTIMIZE (impl2) attribute_hidden;
Packit 6c4009
Packit 6c4009
   static inline void *
Packit 6c4009
   foo_selector (void)
Packit 6c4009
   {
Packit 6c4009
     if (condition)
Packit 6c4009
      return OPTIMIZE (impl2);
Packit 6c4009
Packit 6c4009
     return OPTIMIZE (impl1);
Packit 6c4009
   }
Packit 6c4009
Packit 6c4009
   libc_ifunc_redirected (__redirect_foo, foo, IFUNC_SELECTOR ());
Packit 6c4009
*/
Packit 6c4009
Packit 6c4009
#define PASTER1(x,y)	x##_##y
Packit 6c4009
#define EVALUATOR1(x,y)	PASTER1 (x,y)
Packit 6c4009
#define PASTER2(x,y)	__##x##_##y
Packit 6c4009
#define EVALUATOR2(x,y)	PASTER2 (x,y)
Packit 6c4009
Packit 6c4009
/* Basically set '__redirect_<symbol>' to use as type definition,
Packit 6c4009
   '__<symbol>_<variant>' as the optimized implementation and
Packit 6c4009
   '<symbol>_ifunc_selector' as the IFUNC selector.  */
Packit 6c4009
#define REDIRECT_NAME	EVALUATOR1 (__redirect, SYMBOL_NAME)
Packit 6c4009
#define OPTIMIZE(name)	EVALUATOR2 (SYMBOL_NAME, name)
Packit 6c4009
#define IFUNC_SELECTOR	EVALUATOR1 (SYMBOL_NAME, ifunc_selector)