Blame sysdeps/x86/dl-get-cpu-features.c

Packit Service 4f62bc
/* Initialize CPU feature data via IFUNC relocation.
Packit Service 4f62bc
   Copyright (C) 2015-2020 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
Packit 6c4009
#include <ldsodefs.h>
Packit 6c4009
Packit Service 4f62bc
#ifdef SHARED
Packit Service 4f62bc
# include <cpu-features.c>
Packit Service 4f62bc
Packit Service 4f62bc
/* NB: Normally, DL_PLATFORM_INIT calls init_cpu_features to initialize
Packit Service 4f62bc
   CPU features in dynamic executable.  But when loading ld.so inside of
Packit Service 4f62bc
   static executable, DL_PLATFORM_INIT isn't called and IFUNC relocation
Packit Service 4f62bc
   is used to call init_cpu_features.  In static executable, it is called
Packit Service 4f62bc
   once by IFUNC relocation.  In dynamic executable, it is called twice
Packit Service 4f62bc
   by DL_PLATFORM_INIT and by IFUNC relocation.  */
Packit Service 4f62bc
extern void __x86_cpu_features (void) attribute_hidden;
Packit Service 4f62bc
const void (*__x86_cpu_features_p) (void) attribute_hidden
Packit Service 4f62bc
  = __x86_cpu_features;
Packit Service 4f62bc
Packit Service 4f62bc
void
Packit Service 4f62bc
_dl_x86_init_cpu_features (void)
Packit Service 4f62bc
{
Packit Service 4f62bc
  struct cpu_features *cpu_features = __get_cpu_features ();
Packit Service 4f62bc
  if (cpu_features->basic.kind == arch_kind_unknown)
Packit Service 4f62bc
    init_cpu_features (cpu_features);
Packit Service 4f62bc
}
Packit Service 4f62bc
Packit Service 4f62bc
__ifunc (__x86_cpu_features, __x86_cpu_features, NULL, void,
Packit Service 4f62bc
	 _dl_x86_init_cpu_features);
Packit Service 4f62bc
#endif
Packit Service 4f62bc
Packit Service 15646a
#undef __x86_get_cpu_features
Packit 6c4009
Packit 6c4009
const struct cpu_features *
Packit Service 15646a
__x86_get_cpu_features (unsigned int max)
Packit 6c4009
{
Packit Service 15646a
  if (max > COMMON_CPUID_INDEX_MAX)
Packit Service 15646a
    return NULL;
Packit 6c4009
  return &GLRO(dl_x86_cpu_features);
Packit 6c4009
}