| 1 | /* Initialize CPU feature data via IFUNC relocation. |
| 2 | Copyright (C) 2015-2021 Free Software Foundation, Inc. |
| 3 | |
| 4 | The GNU C Library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | The GNU C Library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with the GNU C Library; if not, see |
| 16 | <https://www.gnu.org/licenses/>. */ |
| 17 | |
| 18 | |
| 19 | #include <ldsodefs.h> |
| 20 | |
| 21 | #ifdef SHARED |
| 22 | # include <cpu-features.c> |
| 23 | |
| 24 | /* NB: Normally, DL_PLATFORM_INIT calls init_cpu_features to initialize |
| 25 | CPU features in dynamic executable. But when loading ld.so inside of |
| 26 | static executable, DL_PLATFORM_INIT isn't called and IFUNC relocation |
| 27 | is used to call init_cpu_features. In static executable, it is called |
| 28 | once by IFUNC relocation. In dynamic executable, it is called twice |
| 29 | by DL_PLATFORM_INIT and by IFUNC relocation. */ |
| 30 | extern void __x86_cpu_features (void) attribute_hidden; |
| 31 | void (*const __x86_cpu_features_p) (void) attribute_hidden |
| 32 | = __x86_cpu_features; |
| 33 | |
| 34 | void |
| 35 | _dl_x86_init_cpu_features (void) |
| 36 | { |
| 37 | struct cpu_features *cpu_features = __get_cpu_features (); |
| 38 | if (cpu_features->basic.kind == arch_kind_unknown) |
| 39 | init_cpu_features (cpu_features); |
| 40 | } |
| 41 | |
| 42 | __ifunc (__x86_cpu_features, __x86_cpu_features, NULL, void, |
| 43 | _dl_x86_init_cpu_features); |
| 44 | #endif |
| 45 | |
| 46 | #undef _dl_x86_get_cpu_features |
| 47 | |
| 48 | const struct cpu_features * |
| 49 | _dl_x86_get_cpu_features (void) |
| 50 | { |
| 51 | return &GLRO(dl_x86_cpu_features); |
| 52 | } |
| 53 | |