1  /* Get CPU type and Features for x86 processors.
       2     Copyright (C) 2012-2023 Free Software Foundation, Inc.
       3     Contributed by Sriraman Tallam (tmsriram@google.com)
       4  
       5  This file is part of GCC.
       6  
       7  GCC is free software; you can redistribute it and/or modify it under
       8  the terms of the GNU General Public License as published by the Free
       9  Software Foundation; either version 3, or (at your option) any later
      10  version.
      11  
      12  GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13  WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15  for more details.
      16  
      17  Under Section 7 of GPL version 3, you are granted additional
      18  permissions described in the GCC Runtime Library Exception, version
      19  3.1, as published by the Free Software Foundation.
      20  
      21  You should have received a copy of the GNU General Public License and
      22  a copy of the GCC Runtime Library Exception along with this program;
      23  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      24  <http://www.gnu.org/licenses/>.  */
      25  
      26  #include "cpuid.h"
      27  #include "tsystem.h"
      28  #include "auto-target.h"
      29  #include "common/config/i386/i386-cpuinfo.h"
      30  #include "common/config/i386/cpuinfo.h"
      31  
      32  #ifdef HAVE_INIT_PRIORITY
      33  #define CONSTRUCTOR_PRIORITY (101)
      34  #else
      35  #define CONSTRUCTOR_PRIORITY
      36  #endif
      37  
      38  int __cpu_indicator_init (void)
      39    __attribute__ ((constructor CONSTRUCTOR_PRIORITY));
      40  
      41  
      42  struct __processor_model __cpu_model = { };
      43  /* We want to move away from __cpu_model in libgcc_s.so.1 and the
      44     size of __cpu_model is part of ABI.  So, new features that don't
      45     fit into __cpu_model.__cpu_features[0] go into extra variables
      46     in libgcc.a only, preferably hidden.
      47  
      48     NB: Since older 386-builtins.c accesses __cpu_features2 as scalar or
      49     smaller array, it can only access the first few elements.  */
      50  unsigned int __cpu_features2[SIZE_OF_CPU_FEATURES];
      51  
      52  /* A constructor function that is sets __cpu_model and __cpu_features with
      53     the right values.  This needs to run only once.  This constructor is
      54     given the highest priority and it should run before constructors without
      55     the priority set.  However, it still runs after ifunc initializers and
      56     needs to be called explicitly there.  */
      57  
      58  int __attribute__ ((constructor CONSTRUCTOR_PRIORITY))
      59  __cpu_indicator_init (void)
      60  {
      61    struct __processor_model2 cpu_model2;
      62    return cpu_indicator_init (&__cpu_model, &cpu_model2,
      63  			     __cpu_features2);
      64  }
      65  
      66  #if defined SHARED && defined USE_ELF_SYMVER
      67  __asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0");
      68  __asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0");
      69  #endif