This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[mips] generate PIC jump tables for n32 and n64


This patch enables GCC to generate PIC jump tables for switch
statements.  It depends on changes to support .gpdword and .cpadd in
n32 and n64 modes that I've just checked in binutils mainline.  These
changes are supposed to work with the IRIX assembler/linker, but I
haven't tested in that environment because the IRIX6 box I used to
have access to is currently out of order.  I'd appreciate if someone
could give it a bootstrap test, perhaps both with native and GNU
tools.  Any takers?

I've tested this with significant success on a mips64-based port that
uses shared libraries, so I'm quite confident the changes are correct.
This is arguably a bug-fix, since our jump tables are non-PIC even
though we attempt to generate PIC by default, but I'm not sure it's
appropriate for GCC 3.3 to depend on a CVS version of binutils on
IRIX6.  It's not like we were able to use the GNU assembler and linker
on IRIX 6 before, though, so perhaps this fix is acceptable for 3.3.
Ok to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* config/mips/mips.h (ASM_OUTPUT_ADDR_DIFF_ELT): Output
	.gpword/.gpdword for ABI_N32 and ABI_64 too.
	* config/mips/mips.md (tablejump_internal3): Output .cpadd
	before jump on ABI_N32 too.
	(tablejump_internal4): Ditto on ABI_64.  Increase maximum
	length to match.

Index: gcc/config/mips/mips.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/mips.h,v
retrieving revision 1.225
diff -u -p -r1.225 mips.h
--- gcc/config/mips/mips.h 6 Oct 2002 17:50:42 -0000 1.225
+++ gcc/config/mips/mips.h 13 Oct 2002 21:29:08 -0000
@@ -4422,7 +4422,8 @@ do {									\
     fprintf (STREAM, "\t%s\t%sL%d-%sLS%d\n",				\
 	     Pmode == DImode ? ".dword" : ".word",			\
 	     LOCAL_LABEL_PREFIX, VALUE, LOCAL_LABEL_PREFIX, REL);	\
-  else if (mips_abi == ABI_32 || mips_abi == ABI_O64)			\
+  else if (mips_abi == ABI_32 || mips_abi == ABI_O64			\
+	   || mips_abi == ABI_N32 || mips_abi == ABI_64)		\
     fprintf (STREAM, "\t%s\t%sL%d\n",					\
 	     Pmode == DImode ? ".gpdword" : ".gpword",			\
 	     LOCAL_LABEL_PREFIX, VALUE);				\
Index: gcc/config/mips/mips.md
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/mips.md,v
retrieving revision 1.148
diff -u -p -r1.148 mips.md
--- gcc/config/mips/mips.md 8 Oct 2002 14:01:39 -0000 1.148
+++ gcc/config/mips/mips.md 13 Oct 2002 21:29:11 -0000
@@ -1,6 +1,6 @@
 ;;  Mips.md	     Machine Description for MIPS based processors
 ;;  Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-;;  1999, 2000, 2001 Free Software Foundation, Inc.
+;;  1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 ;;  Contributed by   A. Lichnewsky, lich@inria.inria.fr
 ;;  Changes by       Michael Meissner, meissner@osf.org
 ;;  64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
@@ -9780,7 +9780,7 @@ move\\t%0,%z4\\n\\
   "*
 {
   /* .cpadd expands to add REG,REG,$gp when pic, and nothing when not pic.  */
-  if (mips_abi == ABI_32 || mips_abi == ABI_O64)
+  if (mips_abi == ABI_32 || mips_abi == ABI_O64 || mips_abi == ABI_N32)
     output_asm_insn (\".cpadd\\t%0\", operands);
   return \"%*j\\t%0\";
 }"
@@ -9808,9 +9808,16 @@ move\\t%0,%z4\\n\\
   "Pmode == DImode && next_active_insn (insn) != 0
    && GET_CODE (PATTERN (next_active_insn (insn))) == ADDR_DIFF_VEC
    && PREV_INSN (next_active_insn (insn)) == operands[1]"
-  "%*j\\t%0"
+  "*
+{
+  /* .cpadd expands to add REG,REG,$gp when pic, and nothing when not pic.  */
+  if (mips_abi == ABI_64)
+    output_asm_insn (\".cpadd\\t%0\", operands);
+  return \"%*j\\t%0\";
+}"
   [(set_attr "type"	"jump")
-   (set_attr "mode"	"none")])
+   (set_attr "mode"	"none")
+   (set_attr "length"	"8")])
 
 ;; Implement a switch statement when generating embedded PIC code.
 ;; Switches are implemented by `tablejump' when not using -membedded-pic.
-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

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