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]

News MIPS option -mno-shared


I'd like to see whether anybody has an opinion about this patch before
I check it in.

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.  Of course, the resulting code is
not position independent and can not be put into a shared library.
Hence the name -mno-shared.  (Note that nothing will prevent you from
trying to put -mno-shared code into a shared library, but the
resulting shared library will not work correctly.)

Of course the new MIPS ABI does not use .cpload.  I have a different
patch adding -mno-shared to gcc, but since gcc is currently in stage 3
I'll wait on submitting that.

This patch relies on the fact that the GNU linker always defines the
symbol _gp to be the value that should go into the $gp register.

Does anybody want to comment on this patch before I check it in?

Ian

Index: config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.275
diff -p -u -r1.275 tc-mips.c
--- config/tc-mips.c	9 Dec 2004 06:17:14 -0000	1.275
+++ config/tc-mips.c	9 Dec 2004 15:03:26 -0000
@@ -136,6 +136,10 @@ static enum mips_abi_level mips_abi = NO
 /* Whether or not we have code that can call pic code.  */
 int mips_abicalls = FALSE;
 
+/* Whether or not we have code which can be put into a shared
+   library.  */
+static bfd_boolean mips_in_shared = TRUE;
+
 /* This is the set of options which may be modified by the .set
    pseudo-op.  We use a struct so that .set push and .set pop are more
    reliable.  */
@@ -3386,10 +3390,12 @@ macro_build_lui (expressionS *ep, int re
   else
     {
       assert (ep->X_op == O_symbol);
-      /* _gp_disp is a special case, used from s_cpload.  */
+      /* _gp_disp is a special case, used from s_cpload.  _gp is used
+	 if mips_no_shared.  */
       assert (mips_pic == NO_PIC
 	      || (! HAVE_NEWABI
-		  && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0));
+		  && (strcmp (S_GET_NAME (ep->X_add_symbol), "_gp_disp") == 0
+		      || strcmp (S_GET_NAME (ep->X_add_symbol), "_gp") == 0)));
       *r = BFD_RELOC_HI16_S;
     }
 
@@ -10118,10 +10124,14 @@ struct option md_longopts[] =
 #define OPTION_NO_RELAX_BRANCH (OPTION_MISC_BASE + 11)
   {"relax-branch", no_argument, NULL, OPTION_RELAX_BRANCH},
   {"no-relax-branch", no_argument, NULL, OPTION_NO_RELAX_BRANCH},
+#define OPTION_MSHARED (OPTION_MISC_BASE + 12)
+#define OPTION_MNO_SHARED (OPTION_MISC_BASE + 13)
+  {"mshared", no_argument, NULL, OPTION_MSHARED},
+  {"mno-shared", no_argument, NULL, OPTION_MNO_SHARED},
 
   /* ELF-specific options.  */
 #ifdef OBJ_ELF
-#define OPTION_ELF_BASE    (OPTION_MISC_BASE + 12)
+#define OPTION_ELF_BASE    (OPTION_MISC_BASE + 14)
 #define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
   {"KPIC",        no_argument, NULL, OPTION_CALL_SHARED},
   {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
@@ -10334,6 +10344,14 @@ md_parse_option (int c, char *arg)
       mips_relax_branch = 0;
       break;
 
+    case OPTION_MSHARED:
+      mips_in_shared = TRUE;
+      break;
+
+    case OPTION_MNO_SHARED:
+      mips_in_shared = FALSE;
+      break;
+
 #ifdef OBJ_ELF
       /* When generating ELF code, we permit -KPIC and -call_shared to
 	 select SVR4_PIC, and -non_shared to select no PIC.  This is
@@ -11792,12 +11810,21 @@ s_abicalls (int ignore ATTRIBUTE_UNUSED)
 	lui	$gp,%hi(_gp_disp)
 	addiu	$gp,$gp,%lo(_gp_disp)
 	addu	$gp,$gp,.cpload argument
-   The .cpload argument is normally $25 == $t9.  */
+   The .cpload argument is normally $25 == $t9.
+
+   The -mno-shared option changes this to:
+	lui	$gp,%hi(_gp)
+	addiu	$gp,$gp,%lo(_gp)
+   and the argument is ignored.  This saves an instruction, but the
+   resulting code is not position independent; it uses an absolute
+   address for _gp.  Thus code assembled with -mno-shared can go into
+   an ordinary executable, but not into a shared library.  */
 
 static void
 s_cpload (int ignore ATTRIBUTE_UNUSED)
 {
   expressionS ex;
+  int reg;
 
   /* If we are not generating SVR4 PIC code, or if this is NewABI code,
      .cpload is ignored.  */
@@ -11811,8 +11838,10 @@ s_cpload (int ignore ATTRIBUTE_UNUSED)
   if (mips_opts.noreorder == 0)
     as_warn (_(".cpload not in noreorder section"));
 
+  reg = tc_get_register (0);
+
   ex.X_op = O_symbol;
-  ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
+  ex.X_add_symbol = symbol_find_or_make (mips_in_shared ? "_gp_disp" : "_gp");
   ex.X_op_symbol = NULL;
   ex.X_add_number = 0;
 
@@ -11823,8 +11852,9 @@ s_cpload (int ignore ATTRIBUTE_UNUSED)
   macro_build_lui (&ex, mips_gp_register);
   macro_build (&ex, "addiu", "t,r,j", mips_gp_register,
 	       mips_gp_register, BFD_RELOC_LO16);
-  macro_build (NULL, "addu", "d,v,t", mips_gp_register,
-	       mips_gp_register, tc_get_register (0));
+  if (mips_in_shared)
+    macro_build (NULL, "addu", "d,v,t", mips_gp_register,
+		 mips_gp_register, reg);
   macro_end ();
 
   demand_empty_rest_of_line ();
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gas/NEWS,v
retrieving revision 1.66
diff -p -u -r1.66 NEWS
--- NEWS	8 Nov 2004 13:17:12 -0000	1.66
+++ NEWS	9 Dec 2004 15:03:26 -0000
@@ -19,6 +19,8 @@
 * Support for ColdFire EMAC instructions added and Motorola syntax for MAC/EMAC
   instrucitons.
 
+* New command line option -mno-shared for MIPS ELF targets.
+
 * New command line option --alternate and pseudo-ops .altmacro and .noaltmacro
   added to enter (and leave) alternate macro syntax mode.
 
Index: doc/c-mips.texi
===================================================================
RCS file: /cvs/src/src/gas/doc/c-mips.texi,v
retrieving revision 1.31
diff -p -u -r1.31 c-mips.texi
--- doc/c-mips.texi	14 Apr 2004 07:48:48 -0000	1.31
+++ doc/c-mips.texi	9 Dec 2004 15:03:26 -0000
@@ -238,6 +238,16 @@ error is detected.  This is the default.
 @itemx -mno-pdr
 Control generation of @code{.pdr} sections.  Off by default on IRIX, on
 elsewhere.
+
+@item -mshared
+@itemx -mno-shared
+When generating code using the Unix calling conventions (selected by
+@samp{-KPIC} or @samp{-mcall_shared}), gas will normally generate code
+which can go into a shared library.  The @samp{-mno-shared} option
+tells gas to generate code which uses the calling convention, but can
+not go into a shared library.  The resulting code is slightly more
+efficient.  This option only affects the handling of the
+@samp{.cpload} pseudo-op.
 @end table
 
 @node MIPS Object


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