1  /* Definitions for MIPS systems using GNU userspace.
       2     Copyright (C) 1998-2023 Free Software Foundation, Inc.
       3  
       4  This file is part of GCC.
       5  
       6  GCC is free software; you can redistribute it and/or modify
       7  it under the terms of the GNU General Public License as published by
       8  the Free Software Foundation; either version 3, or (at your option)
       9  any later version.
      10  
      11  GCC is distributed in the hope that it will be useful,
      12  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14  GNU General Public License for more details.
      15  
      16  You should have received a copy of the GNU General Public License
      17  along with GCC; see the file COPYING3.  If not see
      18  <http://www.gnu.org/licenses/>.  */
      19  
      20  #undef WCHAR_TYPE
      21  #define WCHAR_TYPE "int"
      22  
      23  #undef WCHAR_TYPE_SIZE
      24  #define WCHAR_TYPE_SIZE 32
      25  
      26  #undef ASM_DECLARE_OBJECT_NAME
      27  #define ASM_DECLARE_OBJECT_NAME mips_declare_object_name
      28  
      29  /* If we don't set MASK_ABICALLS, we can't default to PIC.  */
      30  #undef TARGET_DEFAULT
      31  #define TARGET_DEFAULT MASK_ABICALLS
      32  
      33  #define TARGET_OS_CPP_BUILTINS()				\
      34    do {								\
      35      GNU_USER_TARGET_OS_CPP_BUILTINS();				\
      36      /* The GNU C++ standard library requires this.  */		\
      37      if (c_dialect_cxx ())					\
      38        builtin_define ("_GNU_SOURCE");				\
      39    } while (0)
      40  
      41  #undef SUBTARGET_CPP_SPEC
      42  #define SUBTARGET_CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
      43  
      44  /* A standard GNU/Linux mapping.  On most targets, it is included in
      45     CC1_SPEC itself by config/linux.h, but mips.h overrides CC1_SPEC
      46     and provides this hook instead.  */
      47  #undef SUBTARGET_CC1_SPEC
      48  #define SUBTARGET_CC1_SPEC GNU_USER_TARGET_CC1_SPEC
      49  
      50  /* -G is incompatible with -KPIC which is the default, so only allow objects
      51     in the small data section if the user explicitly asks for it.  */
      52  #undef MIPS_DEFAULT_GVALUE
      53  #define MIPS_DEFAULT_GVALUE 0
      54  
      55  #undef GNU_USER_TARGET_LINK_SPEC
      56  #define GNU_USER_TARGET_LINK_SPEC "\
      57    %{G*} %{EB} %{EL} %{mips*} %{shared} \
      58    %{!shared: \
      59      %{!static: \
      60        %{rdynamic:-export-dynamic} \
      61        %{mabi=n32: -dynamic-linker " GNU_USER_DYNAMIC_LINKERN32 "} \
      62        %{mabi=64: -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
      63        %{mabi=32: -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}} \
      64      %{static}} \
      65    %{mabi=n32:-m" GNU_USER_LINK_EMULATIONN32 "} \
      66    %{mabi=64:-m" GNU_USER_LINK_EMULATION64 "} \
      67    %{mabi=32:-m" GNU_USER_LINK_EMULATION32 "}"
      68  
      69  #undef LINK_SPEC
      70  #define LINK_SPEC GNU_USER_TARGET_LINK_SPEC
      71  
      72  #undef SUBTARGET_ASM_SPEC
      73  #define SUBTARGET_ASM_SPEC \
      74    "%{!mno-abicalls:%{mplt:-call_nonpic;:-KPIC}}"
      75  
      76  /* The MIPS assembler has different syntax for .set. We set it to
      77     .dummy to trap any errors.  */
      78  #undef SET_ASM_OP
      79  #define SET_ASM_OP "\t.dummy\t"
      80  
      81  #undef ASM_OUTPUT_DEF
      82  #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)				\
      83   do {									\
      84  	fputc ( '\t', FILE);						\
      85  	assemble_name (FILE, LABEL1);					\
      86  	fputs ( " = ", FILE);						\
      87  	assemble_name (FILE, LABEL2);					\
      88  	fputc ( '\n', FILE);						\
      89   } while (0)
      90  
      91  /* The glibc _mcount stub will save $v0 for us.  Don't mess with saving
      92     it, since ASM_OUTPUT_REG_PUSH/ASM_OUTPUT_REG_POP do not work in the
      93     presence of $gp-relative calls.  */
      94  #undef ASM_OUTPUT_REG_PUSH
      95  #undef ASM_OUTPUT_REG_POP
      96  
      97  #undef LIB_SPEC
      98  #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
      99  
     100  #ifdef HAVE_AS_NO_SHARED
     101  /* Default to -mno-shared for non-PIC.  */
     102  # define NO_SHARED_SPECS \
     103    " %{mshared|mno-shared:;:%{" NO_FPIE_AND_FPIC_SPEC ":-mno-shared}}"
     104  #else
     105  # define NO_SHARED_SPECS ""
     106  #endif
     107  
     108  /* -march=native handling only makes sense with compiler running on
     109     a MIPS chip.  */
     110  #if defined(__mips__)
     111  extern const char *host_detect_local_cpu (int argc, const char **argv);
     112  # define EXTRA_SPEC_FUNCTIONS \
     113    { "local_cpu_detect", host_detect_local_cpu },
     114  
     115  # define MARCH_MTUNE_NATIVE_SPECS				\
     116    " %{march=native:%<march=native %:local_cpu_detect(arch)}"	\
     117    " %{mtune=native:%<mtune=native %:local_cpu_detect(tune)}"
     118  #else
     119  # define MARCH_MTUNE_NATIVE_SPECS ""
     120  #endif
     121  
     122  #define LINUX_DRIVER_SELF_SPECS \
     123    NO_SHARED_SPECS							\
     124    MARCH_MTUNE_NATIVE_SPECS,						\
     125    /* -mplt has no effect without -mno-shared.  Simplify later		\
     126       specs handling by removing a redundant option.  */			\
     127    "%{!mno-shared:%<mplt}",						\
     128    /* -mplt likewise has no effect for -mabi=64 without -msym32.  */	\
     129    "%{mabi=64:%{!msym32:%<mplt}}",					\
     130    "%{!EB:%{!EL:%(endian_spec)}}",					\
     131    "%{!mabi=*: -" MULTILIB_ABI_DEFAULT "}"
     132  
     133  #undef DRIVER_SELF_SPECS
     134  #define DRIVER_SELF_SPECS \
     135    MIPS_ISA_LEVEL_SPEC,    \
     136    BASE_DRIVER_SELF_SPECS, \
     137    LINUX_DRIVER_SELF_SPECS
     138  
     139  /* Similar to standard Linux, but adding -ffast-math support.  */
     140  #undef	GNU_USER_TARGET_MATHFILE_SPEC
     141  #define GNU_USER_TARGET_MATHFILE_SPEC \
     142    "%{Ofast|ffast-math|funsafe-math-optimizations:%{!shared:crtfastmath.o%s}}"
     143  #undef  ENDFILE_SPEC
     144  #define ENDFILE_SPEC \
     145    GNU_USER_TARGET_MATHFILE_SPEC " " \
     146    GNU_USER_TARGET_ENDFILE_SPEC
     147  
     148  #undef LOCAL_LABEL_PREFIX
     149  #define LOCAL_LABEL_PREFIX (TARGET_OLDABI ? "$" : ".")