[PATCH RFA] small fix to MIPS abi selection/decoding.

cgd@broadcom.com cgd@broadcom.com
Sat Mar 9 12:02:00 GMT 2002


So, I was compiling some code w/ -mips32, and noticed that:

touch foo.s
./as-new -mips2 -o foo_mips2.o foo.s
./as-new -mips32 -o foo_mips32.o foo.s
../binutils/objdump -x foo_mips2.o > foo_mips2.dis
../binutils/objdump -x foo_mips32.o > foo_mips32.dis

produces more difference that one might think.  In particular, the ABI
markings for the binaries are different:

diff foo_mips2.dis foo_mips32.dis produces:

< foo_mips2.o:     file format elf32-bigmips
< foo_mips2.o
< architecture: mips:6000, flags 0x00000010:
---
> foo_mips32.o:     file format elf32-bigmips
> foo_mips32.o
> architecture: mips:isa32, flags 0x00000010:
7c7
< private flags = 10001000: [abi=O32] [mips2] [not 32bitmode]
---
> private flags = 50000000: [no abi set] [mips32] [not 32bitmode]

(!!)

The tc-mips.c patch below addresses this: the default of o32 or o64 is
selected based on GPR size, which yields the more expected:

2,4c2,4
< foo_mips2.o:     file format elf32-bigmips
< foo_mips2.o
< architecture: mips:6000, flags 0x00000010:
---
> foo_mips32.o:     file format elf32-bigmips
> foo_mips32.o
> architecture: mips:isa32, flags 0x00000010:
7c7
< private flags = 10001000: [abi=O32] [mips2] [not 32bitmode]
---
> private flags = 50001000: [abi=O32] [mips32] [not 32bitmode]


However, doing this causes the MIPS32 and MIPS64 instruction tests to
fail in the gas testsuite, with diffs like:

regexp "^0+000c <[^>]*> 70e80001        maddu   a3,t0$"
line   "0000000c <text_label+0xc> 70e80001      maddu   a3,a4"

yes, that's right, marking them O32 caused $8 to be interpreted as a4,
rather than t0.  (!!  "but, that's supposed to happen if a new abi
(n32, n64, eabi32 or eabi64 -- _not_ o32 or o64).")

I tracked this down, and it's caused by a (very) bogus test for the
ABI in the ELF header flags in mips-dis.c.  That's fixed by the patch
below, as well.


built and checked binutils for mips-elf and mips64-elf, no
(unexpected) failures.


chris
===================================================================
[ gas/ChangeLog ]
2002-03-09  Chris Demetriou  <cgd@broadcom.com>

	* config/tc-mips.c (md_begin): Fix default ABI selection
	for ISAs other than MIPS I, II, III, and IV.

[ opcodes/ChangeLog ]
2002-03-09  Chris Demetriou  <cgd@broadcom.com>

	* mips-dis.c (is_newabi): Fix ABI decoding.

Index: gas/config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.112
diff -u -p -r1.112 tc-mips.c
--- tc-mips.c	2002/02/26 22:18:51	1.112
+++ tc-mips.c	2002/03/09 19:55:02
@@ -1098,9 +1098,9 @@ md_begin ()
       /* Default mips_abi.  */
       if (mips_opts.abi == NO_ABI)
 	{
-	  if (mips_opts.isa == ISA_MIPS1 || mips_opts.isa == ISA_MIPS2)
+	  if (! ISA_HAS_64BIT_REGS (mips_opts.isa))
 	    mips_opts.abi = O32_ABI;
-	  else if (mips_opts.isa == ISA_MIPS3 || mips_opts.isa == ISA_MIPS4)
+	  else
 	    mips_opts.abi = O64_ABI;
 	}
     }
Index: opcodes/mips-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/mips-dis.c,v
retrieving revision 1.24
diff -u -p -r1.24 mips-dis.c
--- mips-dis.c	2001/11/05 03:07:51	1.24
+++ mips-dis.c	2002/03/09 19:55:07
@@ -397,10 +397,11 @@ static int
 is_newabi (header)
      Elf_Internal_Ehdr *header;
 {
-  if ((header->e_flags
-       & (E_MIPS_ABI_EABI32 | E_MIPS_ABI_EABI64 | EF_MIPS_ABI2)) != 0
+  if ((header->e_flags & EF_MIPS_ABI2) != 0
+      || (header->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI32
+      || (header->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
       || (header->e_ident[EI_CLASS] == ELFCLASS64
-	  && (header->e_flags & E_MIPS_ABI_O64) == 0))
+	  && (header->e_flags & EF_MIPS_ABI) != E_MIPS_ABI_O64))
     return 1;
 
   return 0;



More information about the Binutils mailing list