[v3,2/3] MIPS: default output r6 object if configured to r6

Message ID 20210328143520.2926076-3-yunqiang.su@cipunited.com
State New
Headers show
Series
  • MIPS: default output isa rev base on configuration
Related show

Commit Message

YunQiang Su March 28, 2021, 2:35 p.m.
From: YunQiang Su <ysu@wavecomp.com>


currently we find 2 usecases with problem:

1. mipsisa32r6el-linux-gnu-ld -r -b binary xx.dat -o xx.o
   the output will be MIPS I, while we expect MIPS32r6.
2. mipsisa32r6el-linux-gnu-as -march=from-abi xx.s
   the output will be MIPS I, while we expect MIPS32r6.

We found this problem when we build glib2.0, which use ld directly
to generate object file from data files.

We introduce --with-arch-64 and --with-arch-32 build option for
generic triples.

ChangeLog:
2021-03-28  YunQiang Su  <ysu@wavecomp.com>

	PR MIPS/25494
        * bfd/config.bfd: set mips_default_r6 for mipsisa32/64r6
            or --with-arch-32/64=mips32/64r6
        * bfd/configure: Regenerate.
        * bfd/configure.ac: Define MIPS_DEFAULT_R6 for MIPSr6
        * bfd/elfxx-mips.c (mips_set_isa_flags):
          set isa flag to R6 if MIPS_DEFAULT_R6
        * gas/config.in: Define MIPS_CPU32_DEFAULT/MIPS_CPU64_DEFAULT
        * gas/config/tc-mips.c (macro_build):
          (mips_parse_cpu): set isa flag base on MIPS_CPU32_DEFAULT and
            MIPS_CPU64_DEFAULT.
          (mips_after_parse_args): likewise
        * gas/configure: Regenerate.
        * gas/configure.ac: Define MIPS_DEFAULT_R6 for MIPSr6
        * ld/testsuite/ld-mips-elf/mips-elf.exp: add New test.
        * ld/testsuite/ld-mips-elf/convert-data-to-obj.hd: New test.
---
 bfd/config.bfd                                | 16 ++++
 bfd/configure                                 |  2 +
 bfd/configure.ac                              |  2 +
 bfd/elfxx-mips.c                              |  8 ++
 gas/config.in                                 |  6 ++
 gas/config/tc-mips.c                          | 19 +++--
 gas/configure                                 | 83 ++++++++++++-------
 gas/configure.ac                              | 77 ++++++++++-------
 .../ld-mips-elf/convert-data-to-obj.hd        |  4 +
 ld/testsuite/ld-mips-elf/mips-elf.exp         | 11 +++
 10 files changed, 163 insertions(+), 65 deletions(-)
 create mode 100644 ld/testsuite/ld-mips-elf/convert-data-to-obj.hd

-- 
2.30.2

Patch

diff --git a/bfd/config.bfd b/bfd/config.bfd
index 9434fd6c7e4..30796b595ab 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -1439,6 +1439,22 @@  case "${host64}${want64}" in
     ;;
 esac
 
+mips_default_64r6=
+mips_default_32r6=
+case "${targ_cpu}" in
+  mipsisa32r6* | mipsisa64r6*)
+    mips_default_64r6=true
+    mips_default_32r6=true
+    ;;
+  mips | mipsbe | mipseb | mipsle | mipsel | mips64 | mips64el)
+    if test "x${with_arch_32}" = xmips32r6; then
+      mips_default_32r6=true
+    fi
+    if test "x${with_arch_64}" = xmips64r6; then
+      mips_default_64r6=true
+    fi
+    ;;
+esac
 # If we support any ELF target, then automatically add support for the
 # generic ELF targets.  This permits an objdump with some ELF support
 # to be used on an arbitrary ELF file for anything other than
diff --git a/bfd/configure b/bfd/configure
index accd39cc59e..7c5ea82b04a 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -14697,6 +14697,8 @@  do
 	TDEFINES="$TDEFINES $targ_cflags"
     fi
 done
+test -n "${mips_default_32r6}" && TDEFINES="$TDEFINES -DMIPS_DEFAULT_32R6=1"
+test -n "${mips_default_64r6}" && TDEFINES="$TDEFINES -DMIPS_DEFAULT_64R6=1"
 
 
 # This processing still needs to be done if we're to decide properly whether
diff --git a/bfd/configure.ac b/bfd/configure.ac
index e9a07b8ff05..24c079f2643 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -382,6 +382,8 @@  do
 	TDEFINES="$TDEFINES $targ_cflags"
     fi
 done
+test -n "${mips_default_32r6}" && TDEFINES="$TDEFINES -DMIPS_DEFAULT_32R6=1"
+test -n "${mips_default_64r6}" && TDEFINES="$TDEFINES -DMIPS_DEFAULT_64R6=1"
 AC_SUBST(TDEFINES)
 
 # This processing still needs to be done if we're to decide properly whether
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 41abf4954dc..ba63707c49c 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -12220,9 +12220,17 @@  mips_set_isa_flags (bfd *abfd)
     {
     default:
       if (ABI_N32_P (abfd) || ABI_64_P (abfd))
+#ifdef MIPS_DEFAULT_64R6
+        val = E_MIPS_ARCH_64R6 | EF_MIPS_NAN2008;
+#else
         val = E_MIPS_ARCH_3;
+#endif
       else
+#ifdef MIPS_DEFAULT_32R6
+        val = E_MIPS_ARCH_32R6 | EF_MIPS_NAN2008;
+#else
         val = E_MIPS_ARCH_1;
+#endif
       break;
 
     case bfd_mach_mips3000:
diff --git a/gas/config.in b/gas/config.in
index bd125047d56..b701e01b923 100644
--- a/gas/config.in
+++ b/gas/config.in
@@ -204,6 +204,12 @@ 
    */
 #undef LT_OBJDIR
 
+/* Default CPU for MIPS32 targets. */
+#undef MIPS_CPU32_DEFAULT
+
+/* Default CPU for MIPS64 targets. */
+#undef MIPS_CPU64_DEFAULT
+
 /* Default CPU for MIPS targets. */
 #undef MIPS_CPU_STRING_DEFAULT
 
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 538b69710f5..2807182bea2 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -20229,6 +20229,15 @@  static const struct mips_cpu_info *
 mips_parse_cpu (const char *option, const char *cpu_string)
 {
   const struct mips_cpu_info *p;
+  int default_isa32 = ISA_MIPS1;
+  int default_isa64 = ISA_MIPS3;
+
+#if defined(MIPS_CPU32_DEFAULT)
+  default_isa32 = MIPS_CPU32_DEFAULT;
+#endif
+#if defined(MIPS_CPU64_DEFAULT)
+  default_isa64 = MIPS_CPU64_DEFAULT;
+#endif
 
   /* 'from-abi' selects the most compatible architecture for the given
      ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs.  For the
@@ -20243,18 +20252,18 @@  mips_parse_cpu (const char *option, const char *cpu_string)
   if (strcasecmp (cpu_string, "from-abi") == 0)
     {
       if (ABI_NEEDS_32BIT_REGS (mips_abi))
-	return mips_cpu_info_from_isa (ISA_MIPS1);
+	return mips_cpu_info_from_isa (default_isa32);
 
       if (ABI_NEEDS_64BIT_REGS (mips_abi))
-	return mips_cpu_info_from_isa (ISA_MIPS3);
+	return mips_cpu_info_from_isa (default_isa64);
 
       if (file_mips_opts.gp >= 0)
 	return mips_cpu_info_from_isa (file_mips_opts.gp == 32
-				       ? ISA_MIPS1 : ISA_MIPS3);
+				       ? default_isa32 : default_isa64);
 
       return mips_cpu_info_from_isa (MIPS_DEFAULT_64BIT
-				     ? ISA_MIPS3
-				     : ISA_MIPS1);
+				     ? default_isa64
+				     : default_isa32);
     }
 
   /* 'default' has traditionally been a no-op.  Probably not very useful.  */
diff --git a/gas/configure b/gas/configure
index 5965f2bc242..494f1ef801c 100755
--- a/gas/configure
+++ b/gas/configure
@@ -12757,40 +12757,49 @@  _ACEOF
 
     case ${cpu_type} in
       mips)
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for default configuration of --with-arch-32" >&5
+$as_echo_n "checking for default configuration of --with-arch-32... " >&6; }
+	if test "x${with_arch_32}" != x; then
+	  case ${with_arch_32} in
+	    mips1 | mips2 | mips32 | mips32r2 | mips32r3 | mips32r5 | mips32r6)
+	      ;;
+	    *)
+	      as_fn_error $? "This kind of arch name does *NOT* exist!" "$LINENO" 5
+	      ;;
+	  esac
+	else
+	  with_arch_32=mips1
+	fi
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for default configuration of --with-arch-64" >&5
+$as_echo_n "checking for default configuration of --with-arch-64... " >&6; }
+	if test "x${with_arch_64}" != x; then
+	  case ${with_arch_64} in
+	    mips3 | mips4 | mips5 | mips64 | mips64r2 | mips64r3 | mips64r5 | mips64r6)
+	      ;;
+	    *)
+	      as_fn_error $? "This kind of arch name does *NOT* exist!" "$LINENO" 5
+	      ;;
+	  esac
+	else
+	  with_arch_64=mips3
+	fi
 	# Set mips_cpu to the name of the default CPU.
+	mips_cpu=from-abi
+	#   ISA_MIPS*, aka the index+1 in mips_cpu_info_table
+	mips_cpu64_rev=
+	mips_cpu32_rev=
 	case ${target_cpu} in
 	  mips | mipsbe | mipseb | mipsle | mipsel | mips64 | mips64el)
-	    mips_cpu=from-abi
-	    ;;
-	  mipsisa32 | mipsisa32el)
-	    mips_cpu=mips32
-	    ;;
-	  mipsisa32r2 | mipsisa32r2el)
-	    mips_cpu=mips32r2
-	    ;;
-	  mipsisa32r3 | mipsisa32r3el)
-	    mips_cpu=mips32r3
+	    uppercase=`echo ${with_arch_32} | tr a-z A-Z`
+	    mips_cpu32_rev=ISA_${uppercase}
+	    uppercase=`echo ${with_arch_64} | tr a-z A-Z`
+	    mips_cpu64_rev=ISA_${uppercase}
 	    ;;
-	  mipsisa32r5 | mipsisa32r5el)
-	    mips_cpu=mips32r5
-	    ;;
-	  mipsisa32r6 | mipsisa32r6el)
-	    mips_cpu=mips32r6
-	    ;;
-	  mipsisa64 | mipsisa64el)
-	    mips_cpu=mips64
-	    ;;
-	  mipsisa64r2 | mipsisa64r2el)
-	    mips_cpu=mips64r2
-	    ;;
-	  mipsisa64r3 | mipsisa64r3el)
-	    mips_cpu=mips64r3
-	    ;;
-	  mipsisa64r5 | mipsisa64r5el)
-	    mips_cpu=mips64r5
-	    ;;
-	  mipsisa64r6 | mipsisa64r6el)
-	    mips_cpu=mips64r6
+	  mipsisa32 | mipsisa32el | mipsisa64 | mipsisa64el | mipsisa32r[2356] | mipsisa32r[2356]el | mipsisa64r[2356] | mipsisa64r[2356]el)
+	    uppercase=`echo ${target_cpu} | sed -e 's/isa//' -e 's/64/32/' -e 's/el//' | tr a-z A-Z`
+	    mips_cpu32_rev=ISA_${uppercase}
+	    uppercase=`echo ${target_cpu} | sed -e 's/isa//' -e 's/32/64/' -e 's/el//' | tr a-z A-Z`
+	    mips_cpu64_rev=ISA_${uppercase}
 	    ;;
 	  mipstx39 | mipstx39el)
 	    mips_cpu=r3900
@@ -12855,6 +12864,20 @@  cat >>confdefs.h <<_ACEOF
 #define MIPS_CPU_STRING_DEFAULT "$mips_cpu"
 _ACEOF
 
+	if test -n "$mips_cpu64_rev";then
+
+cat >>confdefs.h <<_ACEOF
+#define MIPS_CPU64_DEFAULT $mips_cpu64_rev
+_ACEOF
+
+	fi
+	if test -n "$mips_cpu32_rev";then
+
+cat >>confdefs.h <<_ACEOF
+#define MIPS_CPU32_DEFAULT $mips_cpu32_rev
+_ACEOF
+
+	fi
 
 cat >>confdefs.h <<_ACEOF
 #define USE_E_MIPS_ABI_O32 $use_e_mips_abi_o32
diff --git a/gas/configure.ac b/gas/configure.ac
index 6a96bb70d7d..143df880f9d 100644
--- a/gas/configure.ac
+++ b/gas/configure.ac
@@ -297,40 +297,49 @@  changequote([,])dnl
 
     case ${cpu_type} in
       mips)
+	AC_MSG_CHECKING(for default configuration of --with-arch-32)
+	if test "x${with_arch_32}" != x; then
+	  case ${with_arch_32} in
+	    mips1 | mips2 | mips32 | mips32r2 | mips32r3 | mips32r5 | mips32r6)
+	      ;;
+	    *)
+	      AC_MSG_ERROR(This kind of arch name does *NOT* exist!)
+	      ;;
+	  esac
+	else
+	  with_arch_32=mips1
+	fi
+	AC_MSG_CHECKING(for default configuration of --with-arch-64)
+	if test "x${with_arch_64}" != x; then
+	  case ${with_arch_64} in
+	    mips3 | mips4 | mips5 | mips64 | mips64r2 | mips64r3 | mips64r5 | mips64r6)
+	      ;;
+	    *)
+	      AC_MSG_ERROR(This kind of arch name does *NOT* exist!)
+	      ;;
+	  esac
+	else
+	  with_arch_64=mips3
+	fi
 	# Set mips_cpu to the name of the default CPU.
+	mips_cpu=from-abi
+	#   ISA_MIPS*, aka the index+1 in mips_cpu_info_table
+	mips_cpu64_rev=
+	mips_cpu32_rev=
 	case ${target_cpu} in
 	  mips | mipsbe | mipseb | mipsle | mipsel | mips64 | mips64el)
-	    mips_cpu=from-abi
+	    uppercase=`echo ${with_arch_32} | tr a-z A-Z`
+	    mips_cpu32_rev=ISA_${uppercase}
+	    uppercase=`echo ${with_arch_64} | tr a-z A-Z`
+	    mips_cpu64_rev=ISA_${uppercase}
 	    ;;
-	  mipsisa32 | mipsisa32el)
-	    mips_cpu=mips32
-	    ;;
-	  mipsisa32r2 | mipsisa32r2el)
-	    mips_cpu=mips32r2
-	    ;;
-	  mipsisa32r3 | mipsisa32r3el)
-	    mips_cpu=mips32r3
-	    ;;
-	  mipsisa32r5 | mipsisa32r5el)
-	    mips_cpu=mips32r5
-	    ;;
-	  mipsisa32r6 | mipsisa32r6el)
-	    mips_cpu=mips32r6
-	    ;;
-	  mipsisa64 | mipsisa64el)
-	    mips_cpu=mips64
-	    ;;
-	  mipsisa64r2 | mipsisa64r2el)
-	    mips_cpu=mips64r2
-	    ;;
-	  mipsisa64r3 | mipsisa64r3el)
-	    mips_cpu=mips64r3
-	    ;;
-	  mipsisa64r5 | mipsisa64r5el)
-	    mips_cpu=mips64r5
-	    ;;
-	  mipsisa64r6 | mipsisa64r6el)
-	    mips_cpu=mips64r6
+changequote(,)dnl
+	  mipsisa32 | mipsisa32el | mipsisa64 | mipsisa64el | mipsisa32r[2356] | mipsisa32r[2356]el | mipsisa64r[2356] | mipsisa64r[2356]el)
+changequote([,])dnl
+	    uppercase=`echo ${target_cpu} | sed -e 's/isa//' -e 's/64/32/' -e 's/el//' | tr a-z A-Z`
+	    mips_cpu32_rev=ISA_${uppercase}
+	    uppercase=`echo ${target_cpu} | sed -e 's/isa//' -e 's/32/64/' -e 's/el//' | tr a-z A-Z`
+	    mips_cpu64_rev=ISA_${uppercase}
 	    ;;
 	  mipstx39 | mipstx39el)
 	    mips_cpu=r3900
@@ -400,6 +409,14 @@  changequote([,])dnl
 	esac
 	AC_DEFINE_UNQUOTED(MIPS_CPU_STRING_DEFAULT, "$mips_cpu",
 			   [Default CPU for MIPS targets. ])
+	if test -n "$mips_cpu64_rev";then
+	  AC_DEFINE_UNQUOTED(MIPS_CPU64_DEFAULT, $mips_cpu64_rev,
+			     [Default CPU for MIPS64 targets. ])
+	fi
+	if test -n "$mips_cpu32_rev";then
+	  AC_DEFINE_UNQUOTED(MIPS_CPU32_DEFAULT, $mips_cpu32_rev,
+			     [Default CPU for MIPS32 targets. ])
+	fi
 	AC_DEFINE_UNQUOTED(USE_E_MIPS_ABI_O32, $use_e_mips_abi_o32,
 			   [Allow use of E_MIPS_ABI_O32 on MIPS targets. ])
 	AC_DEFINE_UNQUOTED(MIPS_DEFAULT_64BIT, $mips_default_64bit,
diff --git a/ld/testsuite/ld-mips-elf/convert-data-to-obj.hd b/ld/testsuite/ld-mips-elf/convert-data-to-obj.hd
new file mode 100644
index 00000000000..f1875df446f
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/convert-data-to-obj.hd
@@ -0,0 +1,4 @@ 
+ELF Header:
+#...
+ +Flags: +.*nan2008.*mips..r6.*
+#pass
diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp
index 958eac261ed..8c840e8635a 100644
--- a/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ b/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -137,6 +137,7 @@  set has_abi(eabi) [expr [istarget *-*-elf] \
 set irix [expr [istarget *-*-irix*]]
 set linux_gnu [expr [istarget mips*-*-linux*]]
 set embedded_elf [expr [istarget mips*-*-elf]]
+set is_r6 [expr [istarget mipsisa*r6*-*]]
 
 # Set defaults.
 set abi_asflags(o32) ""
@@ -766,6 +767,16 @@  if {$linux_gnu} {
     run_ld_link_tests $eh_frame5_test
 }
 
+if {$is_r6} {
+    run_ld_link_tests {
+	{"Convert data to object (MIPSr6)"
+	 "-r -b binary config.log tmpdir/config.log.o" ""
+	 "" {}
+	 {{readelf -h convert-data-to-obj.hd}}
+	 "config.log.o"}
+    }
+}
+
 if {$embedded_elf} {
     run_dump_test "compact-eh1"
     run_dump_test "compact-eh2"