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]

[PATCH RFA] fix generation of MIPS -membedded-pic jumps


The patch below:

* fixes the generation of MIPS -membedded-pic jumps (which get
  turned into branches) to global symbols.

* adds an -membedded-pic ELF result file for the existing MIPS 'jal'
  test, and

* adds a new -membedded-pic ELF testcase which actually shows the
  problem with the existing code generation; the previous test
  doesn't.


This 'fixP->fx_pcrel' case only is hit, as far as I can tell, for
embedded-pic code.  To verify this, I removed the '! fixP->fx_pcrel'
condition from the test and added an assertion of that fact in its
place, and compiled kernels (non-PIC) and a large amount of userland
stuff ('normal' PIC) for both Linux and NetBSD.

Amusingly, the only time i could find that fixP->fx_pcrel was non-zero
even for -membedded-pic code was for BFD_RELOC_16_PCREL_S2
relocations, and for relocations in one of the tests i recently added
to the test suite.  8-)

(All of the above using a binutils slightly modded from master
development sources as of 2002-01-31.)

Further tested for sanity by "gmake && gmake check" for targets
mips-elf, mips64-elf, and mips-linux, with host sparc-solaris.



cgd
===================================================================
[gas/ChangeLog]
2002-02-07  Chris Demetriou  <cgd@broadcom.com>

	* config/tc-mips.c (md_apply_fix3): Add further code to
	the existing hackery, so that -membedded-pic branches
	to external symbols are handled properly.

[gas/testsuite/ChangeLog]
2002-02-07  Chris Demetriou  <cgd@broadcom.com>

	* gas/mips/jal-empic-elf.d: New file.
	* gas/mips/jal-empic-elf-2.d: Likewise.
	* gas/mips/jal-empic-elf-2.s: Likewise.
	* gas/mips/mips.exp: Run the jal-empic-elf and
	jal-empic-elf-2	tests.

Index: gas/config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.106
diff -u -p -r1.106 tc-mips.c
--- tc-mips.c	2002/01/30 02:14:19	1.106
+++ tc-mips.c	2002/02/08 00:50:16
@@ -10450,7 +10450,8 @@ md_apply_fix3 (fixP, valP, seg)
 	  valueT symval = S_GET_VALUE (fixP->fx_addsy);
 
 	  value -= symval;
-	  if (value != 0 && ! fixP->fx_pcrel)
+	  if (value != 0
+	      && (! fixP->fx_pcrel || fixP->fx_r_type == BFD_RELOC_16_PCREL_S2))
 	    {
 	      /* In this case, the bfd_install_relocation routine will
 		 incorrectly add the symbol value back in.  We just want
Index: gas/testsuite/gas/mips/jal-empic-elf.d
===================================================================
RCS file: jal-empic-elf.d
diff -N jal-empic-elf.d
--- /dev/null	Tue May  5 13:32:27 1998
+++ jal-empic-elf.d	Thu Feb  7 16:50:17 2002
@@ -0,0 +1,26 @@
+#objdump: -dr --prefix-addresses -mmips:3000 --show-raw-insn
+#name: MIPS jal-empic-elf
+#as: -mips1 -membedded-pic
+#source: jal.s
+
+# Test the jal macro with -membedded-pic.
+
+.*: +file format .*mips.*
+
+Disassembly of section .text:
+0+0000 <[^>]*> 0320f809 	jalr	t9
+0+0004 <[^>]*> 00000000 	nop
+0+0008 <[^>]*> 03202009 	jalr	a0,t9
+0+000c <[^>]*> 00000000 	nop
+0+0010 <[^>]*> 0411ffff 	bal	0+0010 <text_label\+0x10>
+[ 	]*10: R_MIPS_GNU_REL16_S2	text_label
+0+0014 <[^>]*> 00000000 	nop
+0+0018 <[^>]*> 0411ffff 	bal	0+0018 <text_label\+0x18>
+[ 	]*18: R_MIPS_GNU_REL16_S2	external_text_label
+0+001c <[^>]*> 00000000 	nop
+0+0020 <[^>]*> 1000ffff 	b	0+0020 <text_label\+0x20>
+[ 	]*20: R_MIPS_GNU_REL16_S2	text_label
+0+0024 <[^>]*> 00000000 	nop
+0+0028 <[^>]*> 1000ffff 	b	0+0028 <text_label\+0x28>
+[ 	]*28: R_MIPS_GNU_REL16_S2	external_text_label
+0+002c <[^>]*> 00000000 	nop
Index: gas/testsuite/gas/mips/jal-empic-elf-2.d
===================================================================
RCS file: jal-empic-elf-2.d
diff -N jal-empic-elf-2.d
--- /dev/null	Tue May  5 13:32:27 1998
+++ jal-empic-elf-2.d	Thu Feb  7 16:50:17 2002
@@ -0,0 +1,30 @@
+#objdump: -dr --prefix-addresses -mmips:3000 --show-raw-insn
+#name: MIPS jal-empic-elf-2
+#as: -mips1 -membedded-pic
+
+# Test the jal macro harder with -membedded-pic.
+
+.*: +file format .*mips.*
+
+Disassembly of section .text:
+	\.\.\.
+	\.\.\.
+0+0018 <[^>]*> 0411ffff 	bal	0+0018 <g1\+0xc>
+[ 	]*18: R_MIPS_GNU_REL16_S2	g1
+0+001c <[^>]*> 00000000 	nop
+0+0020 <[^>]*> 04110002 	bal	0+002c <g1\+0x20>
+[ 	]*20: R_MIPS_GNU_REL16_S2	.text
+0+0024 <[^>]*> 00000000 	nop
+0+0028 <[^>]*> 0411ffff 	bal	0+0028 <g1\+0x1c>
+[ 	]*28: R_MIPS_GNU_REL16_S2	e1
+0+002c <[^>]*> 00000000 	nop
+0+0030 <[^>]*> 1000ffff 	b	0+0030 <g1\+0x24>
+[ 	]*30: R_MIPS_GNU_REL16_S2	g1
+0+0034 <[^>]*> 00000000 	nop
+0+0038 <[^>]*> 10000002 	b	0+0044 <g1\+0x38>
+[ 	]*38: R_MIPS_GNU_REL16_S2	.text
+0+003c <[^>]*> 00000000 	nop
+0+0040 <[^>]*> 1000ffff 	b	0+0040 <g1\+0x34>
+[ 	]*40: R_MIPS_GNU_REL16_S2	e1
+0+0044 <[^>]*> 00000000 	nop
+	\.\.\.
Index: gas/testsuite/gas/mips/jal-empic-elf-2.s
===================================================================
RCS file: jal-empic-elf-2.s
diff -N jal-empic-elf-2.s
--- /dev/null	Tue May  5 13:32:27 1998
+++ jal-empic-elf-2.s	Thu Feb  7 16:50:17 2002
@@ -0,0 +1,20 @@
+# Source file used to test the jal macro even harder
+	# some space so offets won't be 0.
+	.space 0xc
+
+	.globl	g1	.text
+g1:
+l1:
+	# some more space, so offset from label won't be 0.
+	.space 0xc
+
+	jal	g1
+	jal	l1
+	jal	e1
+
+	j	g1
+	j	l1
+	j	e1
+
+# Force at least 8 (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.space  8
Index: gas/testsuite/gas/mips/mips.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/mips.exp,v
retrieving revision 1.27
diff -u -p -r1.27 mips.exp
--- mips.exp	2002/01/02 18:59:30	1.27
+++ mips.exp	2002/02/08 00:50:17
@@ -55,6 +55,8 @@ if { [istarget mips*-*-*] } then {
     if $elf { run_dump_test "jal-svr4pic" }
     if $elf { run_dump_test "jal-xgot" }
     if $ecoff { run_dump_test "jal-empic" }
+    if $elf { run_dump_test "jal-empic-elf" }
+    if $elf { run_dump_test "jal-empic-elf-2" }
     if !$aout { run_dump_test "la" }
     if $elf { run_dump_test "la-svr4pic" }
     if $elf { run_dump_test "la-xgot" }


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