This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH RFA] Do something useful w/ MIPS ELF header ASE flags.


The patch below does something useful with the MIPS ELF header ASE
flags.  In particular:

	* It prints them out when appropriate.

	* It sets them when appropriate (well, it does for mips16; it
	  doesn't yet for MDMX, but notes that that should be done).

	* It handles them (retains the union) when merging two BFDs.

As noted in the ChangeLogs, some parts of these patches were created
by one of my coworkers, Ed Satterthwaite.  He has an assignment on
file.

Changes like these have been in use for a while in our local sources.
I've tested these in the current binutils sources simply by building
binutils and running 'make check' on host sparc-solaris for each of:
mips{,64}{,el}-{elf,linux} and mips{,el}-ecoff w/ no new failures.


One comment not really related to this patch, but it occurred to me
when looking at this change: "we're probably gonna run out of ASE
marking space due to that pesky (IMO ill-advised) machine ID field."
I note that SGI's ELF headers apparently reserve those bits for new
ASEs.  See http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00418.html


Survey says?


chris
==============================================================================
[ bfd/ChangeLog ]
2001-11-04  Chris Demetriou  <cgd@broadcom.com>
            Ed Satterthwaite  <ehs@broadcom.com>

	* elf32-mips.c (_bfd_mips_elf_merge_private_bfd_data): Merge ASE
	use flags into resulting BFD.
	(_bfd_mips_elf_print_private_bfd_data): Print the architecture
	using a switch statement rather than a bunch of if statements.
	Print out information about the ASE flags set in the header.

[ binutils/ChangeLog ]
2001-11-04  Chris Demetriou  <cgd@broadcom.com>

	* readelf.c (get_machine_flags): Print MIPS architecture using
	a switch statement.  Print out which ASE flags are set.  Print
	"UNKNOWN machine" rather than just "UNKNOWN" for an unknown
	machine type.

[ gas/ChangeLog ]
2001-11-04  Chris Demetriou  <cgd@broadcom.com>
            Ed Satterthwaite  <ehs@broadcom.com>

	* config/tc-mips.c (mdmx_seen, mips16_seen): New flags to note use
	of ASE instructions.
	(mips_ip): Note that MDMX instructions should cause mdmx_seen to
	be set.
	(mips16_ip): Set mips16_seen.
	(mips_elf_final_processing): Set ELF flags to indicate ASE use.

[ gas/testsuite/ChangeLog ]
2001-11-04  Chris Demetriou  <cgd@broadcom.com>

	* gas/mips/elf_ase_mips16.d: New file to test ELF MIPS16 ASE marking.
	* gas/mips/elf_ase_mips16.s: Likewise.
	* gas/mips/mips.exp: Run the new test.

Index: bfd/elf32-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-mips.c,v
retrieving revision 1.123
diff -u -p -r1.123 elf32-mips.c
--- elf32-mips.c	2001/11/02 19:46:59	1.123
+++ elf32-mips.c	2001/11/04 10:19:59
@@ -2659,6 +2659,15 @@ _bfd_mips_elf_merge_private_bfd_data (ib
       old_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH);
     }
 
+  /* For now, allow arbitrary mixing of ASEs (retain the union).  */
+  if ((new_flags & EF_MIPS_ARCH_ASE) != (old_flags & EF_MIPS_ARCH_ASE))
+    {
+      elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_ARCH_ASE;
+
+      new_flags &= ~ EF_MIPS_ARCH_ASE;
+      old_flags &= ~ EF_MIPS_ARCH_ASE;
+    }
+
   /* Compare ABI's.  The 64-bit ABI does not use EF_MIPS_ABI.  But, it
      does set EI_CLASS differently from any 32-bit ABI.  */
   if ((new_flags & EF_MIPS_ABI) != (old_flags & EF_MIPS_ABI)
@@ -2732,22 +2741,23 @@ _bfd_mips_elf_print_private_bfd_data (ab
   else
     fprintf (file, _(" [no abi set]"));
 
-  if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
-    fprintf (file, _(" [mips1]"));
-  else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
-    fprintf (file, _(" [mips2]"));
-  else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
-    fprintf (file, _(" [mips3]"));
-  else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
-    fprintf (file, _(" [mips4]"));
-  else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
-    fprintf (file, _ (" [mips5]"));
-  else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
-    fprintf (file, _ (" [mips32]"));
-  else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
-    fprintf (file, _ (" [mips64]"));
-  else
-    fprintf (file, _(" [unknown ISA]"));
+  fprintf (file, _(" ["));
+  switch (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH)
+    {
+      case E_MIPS_ARCH_1:	fprintf (file, _("mips1"));	break;
+      case E_MIPS_ARCH_2:	fprintf (file, _("mips2"));	break;
+      case E_MIPS_ARCH_3:	fprintf (file, _("mips3"));	break;
+      case E_MIPS_ARCH_4:	fprintf (file, _("mips4"));	break;
+      case E_MIPS_ARCH_5:	fprintf (file, _("mips5"));	break;
+      case E_MIPS_ARCH_32:	fprintf (file, _("mips32"));	break;
+      case E_MIPS_ARCH_64:	fprintf (file, _("mips64"));	break;
+      default:			fprintf (file, _("unknown ISA")); break;
+    }
+  if (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH_ASE_MDMX)
+    fprintf (file, _(",mdmx"));
+  if (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH_ASE_M16)
+    fprintf (file, _(",mips16"));
+  fprintf (file, _("]"));
 
   if (elf_elfheader (abfd)->e_flags & EF_MIPS_32BITMODE)
     fprintf (file, _(" [32bitmode]"));
Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.129
diff -u -p -r1.129 readelf.c
--- readelf.c	2001/10/30 15:20:04	1.129
+++ readelf.c	2001/11/04 10:20:00
@@ -1620,26 +1620,23 @@ get_machine_flags (e_flags, e_machine)
 	  if (e_flags & EF_MIPS_32BITMODE)
 	    strcat (buf, ", 32bitmode");
 
-	  if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
-	    strcat (buf, ", mips1");
-
-	  if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
-	    strcat (buf, ", mips2");
-
-	  if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
-	    strcat (buf, ", mips3");
-
-	  if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
-	    strcat (buf, ", mips4");
-
-	  if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
-	    strcat (buf, ", mips5");
+	  switch (e_flags & EF_MIPS_ARCH)
+	    {
+	    case E_MIPS_ARCH_1:		strcat (buf, ", mips1");	break;
+	    case E_MIPS_ARCH_2:		strcat (buf, ", mips2");	break;
+	    case E_MIPS_ARCH_3:		strcat (buf, ", mips3");	break;
+	    case E_MIPS_ARCH_4:		strcat (buf, ", mips4");	break;
+	    case E_MIPS_ARCH_5:		strcat (buf, ", mips5");	break;
+	    case E_MIPS_ARCH_32:	strcat (buf, ", mips32");	break;
+	    case E_MIPS_ARCH_64:	strcat (buf, ", mips64");	break;
+	    default:			strcat (buf, ", UNKNOWN arch");	break;
+	    }
 
-	  if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
-	    strcat (buf, ", mips32");
+	  if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
+	    strcat (buf, ", mdmx");
 
-	  if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
-	    strcat (buf, ", mips64");
+	  if (e_flags & EF_MIPS_ARCH_ASE_M16)
+	    strcat (buf, ", mips16");
 
 	  switch ((e_flags & EF_MIPS_MACH))
 	    {
@@ -1649,7 +1646,7 @@ get_machine_flags (e_flags, e_machine)
 	    case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
 	    case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
 	    case E_MIPS_MACH_SB1:  strcat (buf, ", sb1");  break;
-	    default: strcat (buf, " UNKNOWN"); break;
+	    default: strcat (buf, " UNKNOWN machine"); break;
 	    }
 	  break;
 
Index: gas/config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.88
diff -u -p -r1.88 tc-mips.c
--- tc-mips.c	2001/11/01 01:33:46	1.88
+++ tc-mips.c	2001/11/04 10:20:02
@@ -325,6 +325,10 @@ static int mips_disable_float_constructi
 
 static int mips_any_noreorder;
 
+/* Record ASE use for bfd.  */
+static int mdmx_seen = 0;
+static int mips16_seen = 0;
+
 /* Non-zero if nops should be inserted when the register referenced in
    an mfhi/mflo instruction is read in the next two instructions.  */
 static int mips_7000_hilo_fix;
@@ -7485,6 +7489,7 @@ mips_ip (str, ip)
 	ok = true;
       else
 	ok = false;
+      /* XXX FIXME: set mdmx_seen if an MDMX instruction.  */
 
       if (insn->pinfo != INSN_MACRO)
 	{
@@ -8448,6 +8453,7 @@ mips16_ip (str, ip)
 
   insn_error = NULL;
 
+  mips16_seen = 1;
   mips16_small = false;
   mips16_ext = false;
 
@@ -12482,6 +12488,10 @@ mips_elf_final_processing ()
     elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NOREORDER;
   if (mips_pic != NO_PIC)
     elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
+  if (mdmx_seen)
+    elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_MDMX;
+  if (mips16_seen)
+    elf_elfheader (stdoutput)->e_flags |= EF_MIPS_ARCH_ASE_M16;
 
   /* Set the MIPS ELF ABI flags.  */
   if (mips_abi == NO_ABI)
Index: gas/testsuite/gas/mips/elf_ase_mips16.d
===================================================================
RCS file: elf_ase_mips16.d
diff -N elf_ase_mips16.d
--- /dev/null	Tue May  5 13:32:27 1998
+++ elf_ase_mips16.d	Sun Nov  4 02:20:03 2001
@@ -0,0 +1,8 @@
+# name: ELF MIPS16 ASE markings
+# source: elf_ase_mips16.s
+# objdump: -p
+# as: -mips3
+
+.*:.*file format.*mips.*
+private flags = 24......: .*[mips3,mips16].*
+
Index: gas/testsuite/gas/mips/elf_ase_mips16.s
===================================================================
RCS file: elf_ase_mips16.s
diff -N elf_ase_mips16.s
--- /dev/null	Tue May  5 13:32:27 1998
+++ elf_ase_mips16.s	Sun Nov  4 02:20:03 2001
@@ -0,0 +1,5 @@
+# Test of MIPS16 ASE file markings.
+
+	# any MIPS16 instruction will suffice.
+	.set mips16
+	nop
Index: gas/testsuite/gas/mips/mips.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/mips.exp,v
retrieving revision 1.23
diff -u -p -r1.23 mips.exp
--- mips.exp	2001/11/01 01:33:47	1.23
+++ mips.exp	2001/11/04 10:20:03
@@ -143,6 +143,9 @@ if { [istarget mips*-*-*] } then {
 	run_dump_test "elf_e_flags2"
 	run_dump_test "elf_e_flags3"
 	run_dump_test "elf_e_flags4"
+
+	# Verify that ASE markings are handled properly.
+	if { !$no_mips16 } { run_dump_test "elf_ase_mips16" }
     
  	run_dump_test "mips-gp32-fp32-pic"
  	run_dump_test "mips-gp32-fp64-pic"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]