From: Chao-ying Fu <[email protected]>

Introduce the -mclib option for newlib, small, and tiny C library
configurations. For small and tiny libraries, define the corresponding
preprocessor macros and infer -mnan=2008 for hard-float builds.

gcc/ChangeLog:

        * config/mips/mips-opts.h: Add enum mips_lib_setting.
        * config/mips/mips.h (TARGET_CPU_CPP_BUILTINS): Define
        __mips_clib_small or __mips_clib_tiny based on the used C
        library.
        (MIPS_ISA_NAN2008_SPEC): Infer a -mnan=2008 setting if
        mclib is small or tiny for hard-float.
        * config/mips/mips.opt: Add -mclib option.

Cherry-picked 3c800e0a3278de913ccefa7eed6eb070d4f7c558
from https://github.com/MIPS/gcc

Signed-off-by: Jaydeep Patil <[email protected]>
Signed-off-by: Faraz Shahbazker <[email protected]>
Signed-off-by: Chao-ying Fu <[email protected]>
Signed-off-by: Aleksandar Rakic <[email protected]>
Signed-off-by: Eldar Osmanovic <[email protected]>
---
 gcc/config/mips/mips-opts.h |  7 +++++++
 gcc/config/mips/mips.h      | 10 ++++++++--
 gcc/config/mips/mips.opt    | 17 +++++++++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gcc/config/mips/mips-opts.h b/gcc/config/mips/mips-opts.h
index d8b1b4c632c..63ed6383124 100644
--- a/gcc/config/mips/mips-opts.h
+++ b/gcc/config/mips/mips-opts.h
@@ -60,4 +60,11 @@ enum mips_explicit_relocs {
   MIPS_EXPLICIT_RELOCS_BASE,
   MIPS_EXPLICIT_RELOCS_PCREL
 };
+
+/* Enumerates the setting of the -mclib= option.  */
+enum mips_lib_setting {
+  MIPS_LIB_NEWLIB,
+  MIPS_LIB_SMALL,
+  MIPS_LIB_TINY
+};
 #endif
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index 48a562f2d39..ae34159ed37 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -611,6 +611,12 @@ struct mips_cpu_info {
       if (mips_nan == MIPS_IEEE_754_2008)                              \
        builtin_define ("__mips_nan2008");                              \
                                                                        \
+      if (mips_c_lib == MIPS_LIB_SMALL)                                        
\
+       builtin_define ("__mips_clib_small");                           \
+                                                                       \
+      if (mips_c_lib == MIPS_LIB_TINY)                                 \
+       builtin_define ("__mips_clib_tiny");                            \
+                                                                       \
       if (TARGET_BIG_ENDIAN)                                           \
        {                                                               \
          builtin_define_std ("MIPSEB");                                \
@@ -881,8 +887,8 @@ struct mips_cpu_info {
 
 /* Infer a -mnan=2008 setting from a -mips argument.  */
 #define MIPS_ISA_NAN2008_SPEC \
-  "%{mnan*:;mips32r6|mips64r6:-mnan=2008;march=m51*: \
-                                        %{!msoft-float:-mnan=2008}}"
+  "%{mnan*:;mips32r6|mips64r6:-mnan=2008; \
+     march=m51*|mclib=small|mclib=tiny:%{!msoft-float:-mnan=2008}}"
 
 #if (MIPS_ABI_DEFAULT == ABI_O64 \
      || MIPS_ABI_DEFAULT == ABI_N32 \
diff --git a/gcc/config/mips/mips.opt b/gcc/config/mips/mips.opt
index eb14761ea27..9f6849d1b5e 100644
--- a/gcc/config/mips/mips.opt
+++ b/gcc/config/mips/mips.opt
@@ -512,3 +512,20 @@ Use Loongson EXTension (EXT) instructions.
 mloongson-ext2
 Target Var(TARGET_LOONGSON_EXT2)
 Use Loongson EXTension R2 (EXT2) instructions.
+
+mclib=
+Target RejectNegative Joined Var(mips_c_lib) ToLower Enum(mips_lib_setting) 
Init(MIPS_LIB_NEWLIB)
+Specify the C library to use with this application.
+
+Enum
+Name(mips_lib_setting) Type(enum mips_lib_setting)
+Known MIPS C libraries (for use with the -mclib= option):
+
+EnumValue
+Enum(mips_lib_setting) String(newlib) Value(MIPS_LIB_NEWLIB)
+
+EnumValue
+Enum(mips_lib_setting) String(small) Value(MIPS_LIB_SMALL)
+
+EnumValue
+Enum(mips_lib_setting) String(tiny) Value(MIPS_LIB_TINY)
-- 
2.43.0

Reply via email to