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

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