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]

Add -mxgot option to mips backend


Now that the mips backend can use explicit relocs, we need some way of
choosing between normal- and big-GOT accesses.

At the moment we just use the generic -fPIC option.  The problem with
this is that big-GOT accesses are very rarely needed for mips, especially
when using multigot linkers.  And since many libraries are compiled with
-fPIC by default, they will end up being bigger and slower than they really
need to be.

So... rather than force mips users to change each use of -fPIC to -fpic,
it seems better to have a separate target-specific option.  This patch
adds one (called -mxgot, following a suggestion from Eric).

Tested on mips-sgi-irix6.5, mips-sgi-irix6.5o32, mips64-linux-gnu
and mips64el-linux-gnu.  OK to install?

Richard


	* config/mips/mips.h (MASK_UNUSED1): Remove.
	(MASK_XGOT, TARGET_XGOT): Define.
	(TARGET_SWITCHES): Add an entry for -mxgot.
	(ASM_SPEC): Map -mxgot to -xgot.
	* config/mips/mips.c (mips_symbol_insns): Use TARGET_XGOT to decide
	whether we're using big-GOT sequences.
	(mips_legitimize_const_move, mips_expand_call): Likewise.
	(override_options): Revert 2003-01-09 change.
	* doc/invoke.texi: Document -mxgot.

Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.329
diff -u -d -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.329 invoke.texi
--- doc/invoke.texi	19 Aug 2003 20:29:00 -0000	1.329
+++ doc/invoke.texi	28 Aug 2003 19:28:08 -0000
@@ -471,7 +471,7 @@ in the following sections.
 -mgas  -mgp32  -mgp64  -mhard-float  -mint64  -mips1 @gol
 -mips2  -mips3  -mips4  -mips32  -mips32r2  -mips64 @gol
 -mlong64  -mlong32  -mlong-calls  -mmemcpy @gol
--mmips-as  -mmips-tfile  -mno-abicalls @gol
+-mmips-as  -mmips-tfile  -mno-abicalls  -mxgot @gol
 -mno-embedded-data  -mno-uninit-const-in-rodata @gol
 -mno-embedded-pic  -mno-long-calls @gol
 -mno-memcpy  -mno-mips-tfile  -mno-rnames @gol
@@ -8065,6 +8065,35 @@ default if you use the unmodified source
 Emit (or do not emit) the pseudo operations @samp{.abicalls},
 @samp{.cpload}, and @samp{.cprestore} that some System V.4 ports use for
 position independent code.
+
+@item -mxgot
+@itemx -mno-xgot
+@opindex mxgot
+@opindex mno-xgot
+Lift (or do not lift) the usual restrictions on the size of the global
+offset table.
+
+GCC normally uses a single instruction to load values from the GOT.
+While this is relatively efficient, it will only work if the GOT
+is smaller than about 64k.  Anything larger will cause the linker
+to report an error such as:
+
+@cindex relocation truncated to fit (MIPS)
+@smallexample
+relocation truncated to fit: R_MIPS_GOT16 foobar
+@end smallexample
+
+If this happens, you should recompile your code with @option{-mxgot}.
+It should then work with very large GOTs, although it will also be
+less efficient, since it will take three instructions to fetch the
+value of a global symbol.
+
+Note that some linkers can create multiple GOTs.  If you have such a
+linker, you should only need to use @option{-mxgot} when a single object
+file accesses more than 64k's worth of GOT entries.  Very few do.
+
+These options have no effect unless GCC is generating position
+independent code.
 
 @item -mlong-calls
 @itemx -mno-long-calls
Index: config/mips/mips.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.c,v
retrieving revision 1.306
diff -u -d -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.306 mips.c
--- config/mips/mips.c	27 Aug 2003 07:05:17 -0000	1.306
+++ config/mips/mips.c	28 Aug 2003 19:28:10 -0000
@@ -1081,7 +1081,7 @@ mips_symbol_insns (enum mips_symbol_type
 	      daddu   $at,$at,$gp
 
 	 and the final address is $at + %got_lo(symbol).  */
-      return (flag_pic == 1 ? 1 : 3);
+      return (TARGET_XGOT ? 3 : 1);
 
     case SYMBOL_GOT_LOCAL:
       /* For o32 and o64, the sequence is:
@@ -1881,10 +1881,10 @@ mips_legitimize_const_move (enum machine
       && GET_CODE (src) == SYMBOL_REF
       && mips_classify_symbol (src) == SYMBOL_GOT_GLOBAL)
     {
-      if (flag_pic == 1)
-	src = mips_load_got16 (src, RELOC_GOT_DISP);
-      else
+      if (TARGET_XGOT)
 	src = mips_load_got32 (temp, src, RELOC_GOT_HI, RELOC_GOT_LO);
+      else
+	src = mips_load_got16 (src, RELOC_GOT_DISP);
       emit_insn (gen_rtx_SET (VOIDmode, dest, src));
       return;
     }
@@ -3213,10 +3213,10 @@ mips_expand_call (rtx result, rtx addr, 
 	  && GET_CODE (addr) == SYMBOL_REF
 	  && mips_classify_symbol (addr) == SYMBOL_GOT_GLOBAL)
 	{
-	  if (flag_pic == 1)
-	    addr = mips_load_got16 (addr, RELOC_CALL16);
-	  else
+	  if (TARGET_XGOT)
 	    addr = mips_load_got32 (0, addr, RELOC_CALL_HI, RELOC_CALL_LO);
+	  else
+	    addr = mips_load_got16 (addr, RELOC_CALL16);
 	}
       addr = force_reg (Pmode, addr);
     }
@@ -4632,8 +4632,7 @@ override_options (void)
      implemented.  */
   if (TARGET_ABICALLS)
     {
-      if (flag_pic == 0)
-	flag_pic = 1;
+      flag_pic = 1;
       if (mips_section_threshold > 0)
 	warning ("-G is incompatible with PIC code which is the default");
     }
Index: config/mips/mips.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.h,v
retrieving revision 1.287
diff -u -d -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.287 mips.h
--- config/mips/mips.h	27 Aug 2003 07:05:18 -0000	1.287
+++ config/mips/mips.h	28 Aug 2003 19:28:12 -0000
@@ -153,7 +153,7 @@ #define MASK_MEMCPY	   0x00000080	/* cal
 #define MASK_SOFT_FLOAT	   0x00000100	/* software floating point */
 #define MASK_FLOAT64	   0x00000200	/* fp registers are 64 bits */
 #define MASK_ABICALLS	   0x00000400	/* emit .abicalls/.cprestore/.cpload */
-#define MASK_UNUSED1	   0x00000800	/* Unused Mask.  */
+#define MASK_XGOT	   0x00000800	/* emit big-got PIC */
 #define MASK_LONG_CALLS	   0x00001000	/* Always call through a register */
 #define MASK_64BIT	   0x00002000	/* Use 64 bit GP registers and insns */
 #define MASK_EMBEDDED_PIC  0x00004000	/* Generate embedded PIC code */
@@ -218,6 +218,7 @@ #define TARGET_MEMCPY		(target_flags & M
 
 					/* .abicalls, etc from Pyramid V.4 */
 #define TARGET_ABICALLS		(target_flags & MASK_ABICALLS)
+#define TARGET_XGOT		(target_flags & MASK_XGOT)
 
 					/* software floating point */
 #define TARGET_SOFT_FLOAT	(target_flags & MASK_SOFT_FLOAT)
@@ -602,6 +603,10 @@ #define TARGET_SWITCHES							\
      N_("Generate mips16 code") },					\
   {"no-mips16",		 -MASK_MIPS16,					\
      N_("Generate normal-mode code") },					\
+  {"xgot",		  MASK_XGOT,					\
+     N_("Lift restrictions on GOT size") },				\
+  {"no-xgot",		 -MASK_XGOT,					\
+     N_("Do not lift restrictions on GOT size") },			\
   {"debug",		  MASK_DEBUG,					\
      NULL},								\
   {"debuga",		  MASK_DEBUG_A,					\
@@ -1082,7 +1087,7 @@ #define ASM_SPEC "\
 %{membedded-pic} \
 %{mabi=32:-32}%{mabi=n32:-n32}%{mabi=64:-64}%{mabi=n64:-64} \
 %{mabi=eabi} %{mabi=o64} %{!mabi*: %(asm_abi_default_spec)} \
-%{mgp32} %{mgp64} %{march=*} \
+%{mgp32} %{mgp64} %{march=*} %{mxgot:-xgot} \
 %(target_asm_spec) \
 %(subtarget_asm_spec)"
 


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