[PATCH] loongarch: support new -mabi= and -mfpu= values

Xi Ruoyao xry111@mengyan1223.wang
Sat Nov 27 23:58:16 GMT 2021


LoongArch Toolchain Conventions [1] has updated the definition of -mabi
and -mfpu.  Now the GCC port for LoongArch [2] under reviewing has already
adapted for those changes, and fails to build with current binutils.

[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html
[2]: https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585555.html

gas/
	* config/tc-loongarch.c (md_parse_option): Recognize new -mabi=
	  and -mfpu= values defined in LoongArch Toolchain Conventions.
---
 gas/config/tc-loongarch.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index f7235a18864..7ef0d53a06a 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -138,23 +138,43 @@ size_t md_longopts_size = sizeof (md_longopts);
 int
 md_parse_option (int c, const char *arg)
 {
-  int ret = 1;
+  int ret = 1, len, frspec = 0;
   switch (c)
     {
     case OPTION_ABI:
-      if (strcasecmp (arg, "lp64") == 0)
+      len = strlen (arg);
+      if (strncasecmp (arg, "lp64", 4) == 0)
 	{
 	  LARCH_opts.ase_abi |= EF_LOONGARCH_ABI_LP64;
 	  LARCH_opts.ase_ilp32 = 1;
 	  LARCH_opts.ase_lp64 = 1;
+
+	  if (len == 5)
+	    frspec = tolower(arg[4]);
+	  else if (len != 4)
+	    ret = 0;
 	}
-      else if (strcasecmp (arg, "ilp32") == 0)
+      else if (strncasecmp (arg, "ilp32", 5) == 0)
 	{
 	  LARCH_opts.ase_abi |= EF_LOONGARCH_ABI_ILP32;
 	  LARCH_opts.ase_ilp32 = 1;
+
+	  if (len == 6)
+	    frspec = tolower(arg[5]);
+	  else if (len != 5)
+	    ret = 0;
 	}
       else
 	ret = 0;
+
+      if (frspec == 's')
+	LARCH_opts.ase_abi |= EF_LOONGARCH_FLOAT_ABI_SOFT;
+      else if (frspec == 'f')
+	LARCH_opts.ase_abi |= EF_LOONGARCH_FLOAT_ABI_SINGLE;
+      else if (frspec == 'd')
+	LARCH_opts.ase_abi |= EF_LOONGARCH_FLOAT_ABI_DOUBLE;
+      else if (frspec)
+	ret = 0;
       break;
 
     case OPTION_FLOAT_ABI:
@@ -169,11 +189,14 @@ md_parse_option (int c, const char *arg)
       break;
 
     case OPTION_FLOAT_ISA:
-      if (strcasecmp (arg, "soft") == 0)
+      if (strcasecmp (arg, "soft") == 0 ||
+	  strcasecmp (arg, "none") == 0)
 	LARCH_opts.ase_nf = 1;
-      else if (strcasecmp (arg, "single") == 0)
+      else if (strcasecmp (arg, "single") == 0 ||
+	       strcmp (arg, "32") == 0)
 	LARCH_opts.ase_sf = 1;
-      else if (strcasecmp (arg, "double") == 0)
+      else if (strcasecmp (arg, "double") == 0 ||
+	       strcmp (arg, "64") == 0)
 	{
 	  LARCH_opts.ase_sf = 1;
 	  LARCH_opts.ase_df = 1;
-- 
2.34.1


-- 
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University


More information about the Binutils mailing list