]>
Commit | Line | Data |
---|---|---|
4e17c78e AZ |
1 | /* IFUNC generic definitions. |
2 | This file is part of the GNU C Library. | |
04277e02 | 3 | Copyright (C) 2017-2019 Free Software Foundation, Inc. |
4e17c78e AZ |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
4e17c78e AZ |
18 | |
19 | /* These macros are used to implement ifunc selection in C. To implement | |
20 | an ifunc function, foo, which returns the address of __foo_impl1 or | |
21 | __foo_impl2: | |
22 | ||
23 | #define foo __redirect_foo | |
24 | #include <foo.h> | |
25 | #undef foo | |
26 | #define SYMBOL_NAME foo | |
27 | #include <ifunc-init.h> | |
28 | ||
29 | extern __typeof (REDIRECT_NAME) OPTIMIZE (impl1) attribute_hidden; | |
30 | extern __typeof (REDIRECT_NAME) OPTIMIZE (impl2) attribute_hidden; | |
31 | ||
32 | static inline void * | |
33 | foo_selector (void) | |
34 | { | |
35 | if (condition) | |
36 | return OPTIMIZE (impl2); | |
37 | ||
38 | return OPTIMIZE (impl1); | |
39 | } | |
40 | ||
41 | libc_ifunc_redirected (__redirect_foo, foo, IFUNC_SELECTOR ()); | |
42 | */ | |
43 | ||
44 | #define PASTER1(x,y) x##_##y | |
45 | #define EVALUATOR1(x,y) PASTER1 (x,y) | |
46 | #define PASTER2(x,y) __##x##_##y | |
47 | #define EVALUATOR2(x,y) PASTER2 (x,y) | |
48 | ||
49 | /* Basically set '__redirect_<symbol>' to use as type definition, | |
50 | '__<symbol>_<variant>' as the optimized implementation and | |
51 | '<symbol>_ifunc_selector' as the IFUNC selector. */ | |
52 | #define REDIRECT_NAME EVALUATOR1 (__redirect, SYMBOL_NAME) | |
53 | #define OPTIMIZE(name) EVALUATOR2 (SYMBOL_NAME, name) | |
54 | #define IFUNC_SELECTOR EVALUATOR1 (SYMBOL_NAME, ifunc_selector) |