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]
Other format: [Raw text]

Re: News MIPS option -mno-shared


Richard Sandiford <rsandifo@redhat.com> writes:

> Ian Lance Taylor <ian@wasabisystems.com> writes:
> > This patch adds a new option to the MIPS assembler: -mno-shared.
> > Normally the .cpload pseudo-op generates code which looks like this:
> >
> > 	lui	$gp,%hi(_gp_disp)
> > 	addiu	$gp,$gp,%lo(_gp_disp)
> > 	addu	$gp,$gp,.cpload argument
> >
> > With -mno-shared, the .cpload pseudo-op will generate code that looks
> > like this:
> >
> > 	lui	$gp,%hi(_gp)
> > 	addiu	$gp,$gp,%lo(_gp)
> >
> > The idea is that you can use -KPIC -mno-shared and get code which
> > still uses the usual Unix calling convention, but is slightly more
> > efficient at each function entry.
> 
> Yeah, this has been on my to-do list for a while ;)  Are you going to
> do the same thing for n32 or are you only interested in o32?

For n32 the patch is to gcc, not the binutils.  I have that patch, but
it's a new feature and as such is not going to be acceptable in stage
3.  I'll submit it when gcc goes back to stage 1.

The gcc patch looks more or like the following, plus some obvious
mips.h and doc stuff.

Ian

Index: mips.c
===================================================================
RCS file: /cvsroot/gnu/gcc/config/mips/mips.c,v
retrieving revision 1.3.4.2
retrieving revision 1.3.4.6
diff -u -r1.3.4.2 -r1.3.4.6
--- mips.c	21 Sep 2004 05:10:50 -0000	1.3.4.2
+++ mips.c	11 Nov 2004 23:44:38 -0000	1.3.4.6
@@ -145,7 +145,11 @@
 
    SYMBOL_GOTOFF_LOADGP
        An UNSPEC wrapper around a function's address.  It represents the
-       offset of _gp from the start of the function.  */
+       offset of _gp from the start of the function.
+
+   SYMBOL_GP
+       An UNSPEC wrapper around the _gp symbol.  This is the absolute
+       value of _gp.  */
 enum mips_symbol_type {
   SYMBOL_GENERAL,
   SYMBOL_SMALL_DATA,
@@ -155,9 +159,10 @@
   SYMBOL_GOTOFF_PAGE,
   SYMBOL_GOTOFF_GLOBAL,
   SYMBOL_GOTOFF_CALL,
-  SYMBOL_GOTOFF_LOADGP
+  SYMBOL_GOTOFF_LOADGP,
+  SYMBOL_GP
 };
-#define NUM_SYMBOL_TYPES (SYMBOL_GOTOFF_LOADGP + 1)
+#define NUM_SYMBOL_TYPES (SYMBOL_GP + 1)
 
 
 /* Classifies an address.
@@ -970,6 +975,7 @@
     case SYMBOL_GOTOFF_GLOBAL:
     case SYMBOL_GOTOFF_CALL:
     case SYMBOL_GOTOFF_LOADGP:
+    case SYMBOL_GP:
       return false;
     }
   abort ();
@@ -1060,6 +1066,7 @@
     case SYMBOL_GOTOFF_GLOBAL:
     case SYMBOL_GOTOFF_CALL:
     case SYMBOL_GOTOFF_LOADGP:
+    case SYMBOL_GP:
       return true;
     }
   abort ();
@@ -1185,6 +1192,11 @@
     case SYMBOL_GOTOFF_LOADGP:
       /* Check whether the offset is a 16- or 32-bit value.  */
       return mips_split_p[type] ? 2 : 1;
+
+    case SYMBOL_GP:
+      if (ABI_HAS_64BIT_SYMBOLS)
+	abort ();
+      return 2;
     }
   abort ();
 }
@@ -5145,6 +5163,13 @@
       mips_split_p[SYMBOL_GOTOFF_LOADGP] = true;
       mips_hi_relocs[SYMBOL_GOTOFF_LOADGP] = "%hi(%neg(%gp_rel(";
       mips_lo_relocs[SYMBOL_GOTOFF_LOADGP] = "%lo(%neg(%gp_rel(";
+
+      if (! ABI_HAS_64BIT_SYMBOLS)
+	{
+	  mips_split_p[SYMBOL_GP] = true;
+	  mips_hi_relocs[SYMBOL_GP] = "%hi(";
+	  mips_lo_relocs[SYMBOL_GP] = "%lo(";
+	}
     }
 }
 
@@ -6643,12 +6686,24 @@
 {
   if (TARGET_ABICALLS && TARGET_NEWABI && cfun->machine->global_pointer > 0)
     {
-      rtx addr, offset, incoming_address;
+      if (TARGET_SHARED || ABI_HAS_64BIT_SYMBOLS || TARGET_MIPS16)
+	{
+	  rtx addr, offset, incoming_address;
 
-      addr = XEXP (DECL_RTL (current_function_decl), 0);
-      offset = mips_unspec_address (addr, SYMBOL_GOTOFF_LOADGP);
-      incoming_address = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
-      emit_insn (gen_loadgp (offset, incoming_address));
+	  addr = XEXP (DECL_RTL (current_function_decl), 0);
+	  offset = mips_unspec_address (addr, SYMBOL_GOTOFF_LOADGP);
+	  incoming_address = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
+	  emit_insn (gen_loadgp (offset, incoming_address));
+	}
+      else
+	{
+	  rtx addr;
+
+	  addr = mips_unspec_address (gen_rtx_SYMBOL_REF (Pmode, "_gp"),
+				      SYMBOL_GP);
+	  emit_move_insn (pic_offset_table_rtx,
+			  mips_split_symbol (pic_offset_table_rtx, addr));
+	}
       if (!TARGET_EXPLICIT_RELOCS)
 	emit_insn (gen_loadgp_blockage ());
     }


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