This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Committing MIPS -mno-shared patch
- From: Ian Lance Taylor <ian at wasabisystems dot com>
- To: binutils at sourceware dot org
- Date: 10 Dec 2004 14:48:00 -0500
- Subject: Committing MIPS -mno-shared patch
This is the patch I am committing to add support for the -mno-shared
option to the MIPS target.
Ian
gas/ChangeLog:
2004-12-10 Ian Lance Taylor <ian@wasabisystems.com>
* config/tc-mips.c (mips_in_shared): New static variable.
(macro_build_lui): Permit "_gp" if !mips_in_shared.
(md_longopts): Add -mshared and -mno-shared.
(md_parse_option): Handle OPTION_MSHARED and OPTION_MNO_SHARED.
(s_cpload): Implement !mips_in_shared case.
(s_cpsetup): Likewise.
* doc/c-mips.texi (MIPS Opts): Document -mno-shared.
* NEWS: Mention -mno-shared.
gas/testsuite/ChangeLog:
2004-12-10 Ian Lance Taylor <ian@wasabisystems.com>
* gas/mips/elf-rel23a.d: New test.
* gas/mips/elf-rel23b.d: New test.
* gas/mips/elf-rel25.s: New test.
* gas/mips/elf-rel25.d: New test.
* gas/mips/elf-rel25a.d: New test.
* gas/mips/mips.exp: Run new tests.
Index: config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.276
diff -u -r1.276 tc-mips.c
--- config/tc-mips.c 9 Dec 2004 15:51:32 -0000 1.276
+++ config/tc-mips.c 10 Dec 2004 19:39:43 -0000
@@ -136,6 +136,10 @@
/* 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. */
@@ -3388,10 +3392,13 @@
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)
+ || (! mips_in_shared
+ && strcmp (S_GET_NAME (ep->X_add_symbol), "_gp") == 0));
*r = BFD_RELOC_HI16_S;
}
@@ -10120,10 +10127,14 @@
#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},
@@ -10336,6 +10347,14 @@
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
@@ -11794,12 +11813,22 @@
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;
+ int in_shared;
/* If we are not generating SVR4 PIC code, or if this is NewABI code,
.cpload is ignored. */
@@ -11813,8 +11842,14 @@
if (mips_opts.noreorder == 0)
as_warn (_(".cpload not in noreorder section"));
+ reg = tc_get_register (0);
+
+ /* If we need to produce a 64-bit address, we are better off using
+ the default instruction sequence. */
+ in_shared = mips_in_shared || HAVE_64BIT_ADDRESSES;
+
ex.X_op = O_symbol;
- ex.X_add_symbol = symbol_find_or_make ("_gp_disp");
+ ex.X_add_symbol = symbol_find_or_make (in_shared ? "_gp_disp" : "_gp");
ex.X_op_symbol = NULL;
ex.X_add_number = 0;
@@ -11825,8 +11860,9 @@
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 (in_shared)
+ macro_build (NULL, "addu", "d,v,t", mips_gp_register,
+ mips_gp_register, reg);
macro_end ();
demand_empty_rest_of_line ();
@@ -11846,7 +11882,13 @@
lui $gp, %hi(%neg(%gp_rel(label)))
addiu $gp, $gp, %lo(%neg(%gp_rel(label)))
daddu $gp, $gp, $reg1
- $reg1 is normally $25 == $t9. */
+ $reg1 is normally $25 == $t9.
+
+ The -mno-shared option replaces the last three instructions with
+ lui $gp,%hi(_gp)
+ addiu $gp,$gp,%lo(_gp)
+ */
+
static void
s_cpsetup (int ignore ATTRIBUTE_UNUSED)
{
@@ -11908,15 +11950,36 @@
macro_build (NULL, "daddu", "d,v,t", mips_cpreturn_register,
mips_gp_register, 0);
- macro_build (&ex_sym, "lui", "t,u", mips_gp_register,
- -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB, BFD_RELOC_HI16_S);
+ if (mips_in_shared || HAVE_64BIT_ADDRESSES)
+ {
+ macro_build (&ex_sym, "lui", "t,u", mips_gp_register,
+ -1, BFD_RELOC_GPREL16, BFD_RELOC_MIPS_SUB,
+ BFD_RELOC_HI16_S);
+
+ macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
+ mips_gp_register, -1, BFD_RELOC_GPREL16,
+ BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
- macro_build (&ex_sym, "addiu", "t,r,j", mips_gp_register,
- mips_gp_register, -1, BFD_RELOC_GPREL16,
- BFD_RELOC_MIPS_SUB, BFD_RELOC_LO16);
+ macro_build (NULL, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
+ mips_gp_register, reg1);
+ }
+ else
+ {
+ expressionS ex;
+
+ ex.X_op = O_symbol;
+ ex.X_add_symbol = symbol_find_or_make ("_gp");
+ ex.X_op_symbol = NULL;
+ ex.X_add_number = 0;
+
+ /* In ELF, this symbol is implicitly an STT_OBJECT symbol. */
+ symbol_get_bfdsym (ex.X_add_symbol)->flags |= BSF_OBJECT;
+
+ 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, ADDRESS_ADD_INSN, "d,v,t", mips_gp_register,
- mips_gp_register, reg1);
macro_end ();
demand_empty_rest_of_line ();
cvs diff: Diffing .
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gas/NEWS,v
retrieving revision 1.66
diff -u -r1.66 NEWS
--- NEWS 8 Nov 2004 13:17:12 -0000 1.66
+++ NEWS 10 Dec 2004 19:39:43 -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.
cvs diff: Diffing doc
Index: doc/c-mips.texi
===================================================================
RCS file: /cvs/src/src/gas/doc/c-mips.texi,v
retrieving revision 1.31
diff -u -r1.31 c-mips.texi
--- doc/c-mips.texi 14 Apr 2004 07:48:48 -0000 1.31
+++ doc/c-mips.texi 10 Dec 2004 19:39:43 -0000
@@ -238,6 +238,16 @@
@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} and @samp{.cpsetup} pseudo-ops.
@end table
@node MIPS Object
Index: gas/mips/elf-rel23a.d
===================================================================
RCS file: gas/mips/elf-rel23a.d
diff -N gas/mips/elf-rel23a.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gas/mips/elf-rel23a.d 10 Dec 2004 19:45:26 -0000
@@ -0,0 +1,20 @@
+#source: elf-rel23.s
+#as: -march=mips3 -mabi=64 -mno-shared
+#objdump: -dr -Mgpr-names=numeric
+#name: MIPS ELF reloc 23 -mabi=64 -mno-shared
+
+.*: * file format elf64-tradbigmips
+
+Disassembly of section \.text:
+
+0+00 <.*>:
+.*: 0380282d move \$5,\$28
+.*: 3c1c0000 lui \$28,0x0
+ .*: R_MIPS_GPREL16 foo
+ .*: R_MIPS_SUB \*ABS\*
+ .*: R_MIPS_HI16 \*ABS\*
+.*: 279c0000 addiu \$28,\$28,0
+ .*: R_MIPS_GPREL16 foo
+ .*: R_MIPS_SUB \*ABS\*
+ .*: R_MIPS_LO16 \*ABS\*
+.*: 0384e02d daddu \$28,\$28,\$4
Index: gas/mips/elf-rel23b.d
===================================================================
RCS file: gas/mips/elf-rel23b.d
diff -N gas/mips/elf-rel23b.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gas/mips/elf-rel23b.d 10 Dec 2004 19:45:26 -0000
@@ -0,0 +1,16 @@
+#source: elf-rel23.s
+#as: -march=mips3 -mabi=n32 -mno-shared
+#objdump: -dr -Mgpr-names=numeric
+#name: MIPS ELF reloc 23 -mabi=n32 -mno-shared
+
+.*: * file format elf.*mips.*
+
+Disassembly of section \.text:
+
+0+00 <.*>:
+.*: 0380282d move \$5,\$28
+.*: 3c1c0000 lui \$28,0x0
+ .*: R_MIPS_HI16 _gp
+.*: 279c0000 addiu \$28,\$28,0
+ .*: R_MIPS_LO16 _gp
+.*: 00000000 nop
Index: gas/mips/elf-rel25.d
===================================================================
RCS file: gas/mips/elf-rel25.d
diff -N gas/mips/elf-rel25.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gas/mips/elf-rel25.d 10 Dec 2004 19:45:26 -0000
@@ -0,0 +1,15 @@
+#as: -march=mips1 -mabi=32
+#objdump: -dr -Mgpr-names=numeric
+#name: MIPS ELF reloc 25
+
+.*: * file format elf.*mips.*
+
+Disassembly of section \.text:
+
+0+00 <.*>:
+.*: 3c1c0000 lui \$28,0x0
+ .*: R_MIPS_HI16 _gp_disp
+.*: 279c0000 addiu \$28,\$28,0
+ .*: R_MIPS_LO16 _gp_disp
+.*: 0399e021 addu \$28,\$28,\$25
+.*: 00000000 nop
Index: gas/mips/elf-rel25.s
===================================================================
RCS file: gas/mips/elf-rel25.s
diff -N gas/mips/elf-rel25.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gas/mips/elf-rel25.s 10 Dec 2004 19:45:26 -0000
@@ -0,0 +1,8 @@
+ .abicalls
+ .globl foo
+ .ent foo
+foo:
+ .set noreorder
+ .cpload $25
+ .set reorder
+ .end foo
Index: gas/mips/elf-rel25a.d
===================================================================
RCS file: gas/mips/elf-rel25a.d
diff -N gas/mips/elf-rel25a.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gas/mips/elf-rel25a.d 10 Dec 2004 19:45:26 -0000
@@ -0,0 +1,15 @@
+#source: elf-rel25.s
+#as: -march=mips1 -mabi=32 -mno-shared
+#objdump: -dr -Mgpr-names=numeric
+#name: MIPS ELF reloc 25 -mno-shared
+
+.*: * file format elf.*mips.*
+
+Disassembly of section \.text:
+
+0+00 <.*>:
+.*: 3c1c0000 lui \$28,0x0
+ .*: R_MIPS_HI16 _gp
+.*: 279c0000 addiu \$28,\$28,0
+ .*: R_MIPS_LO16 _gp
+ \.\.\.
Index: gas/mips/mips.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/mips.exp,v
retrieving revision 1.96
diff -u -r1.96 mips.exp
--- gas/mips/mips.exp 7 Oct 2004 22:29:19 -0000 1.96
+++ gas/mips/mips.exp 10 Dec 2004 19:45:26 -0000
@@ -666,9 +666,14 @@
run_dump_test "elf-rel21"
run_dump_test "elf-rel22"
run_dump_test "elf-rel23"
+ run_dump_test "elf-rel23a"
+ run_dump_test "elf-rel23b"
run_dump_test "elf-rel24"
}
+ run_dump_test "elf-rel25"
+ run_dump_test "elf-rel25a"
+
if { !$no_mips16 } {
run_dump_test "${tmips}mips${el}16-e"
run_dump_test "${tmips}mips${el}16-f"