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: [PATCH/RFA] sh-elf: Unnecessary relocations


Hans-Peter Nilsson <hp@bitrange.com> wrote:
>> 2002-09-27  Kaz Kojima  <kkojima@rr.iij4u.or.jp>
>>
>> 	* config/tc-sh.c (sh_force_relocation): Return 0 for
>> 	some PC relative relocations when not relaxing.
> 
> With a comment as mentioned below, and a test-case, this is ok.
> Sorry to be anuiscance, but when there's a bug fixed, there
> should always be a test-case added to the test-suite, one like
> in your first message about this.  Preferrably the test-case
> covers all of these relocs that you can easily produce.  I
> suggest using run_dump_test, adding a call from
> gas/sh/basic.exp.
[snip]
>>  sh_force_relocation (fix)
>>       fixS *fix;
>>  {
>> +  if (! sh_relax
>> +      && (fix->fx_r_type == BFD_RELOC_SH_PCDISP8BY2
> 
> Add a comment to the code why it's not useful to "force" these
> relocs despite symbol globalness.  Something like "they can't
> make it into a DSO" or that "ld.so can't handle these anyway if
> they make it to a DSO with DT_TEXTREL, so no use forcing them
> for global symbols".

Very reasonable. How about this? The test-case covers all 7
relocs.

	kaz
--
2002-09-27  Kaz Kojima  <kkojima@rr.iij4u.or.jp>

	* config/tc-sh.c (sh_force_relocation): Return 0 for
	some PC relative relocations when not relaxing.
        * testsuite/gas/sh/pcrel2.s: New.
        * testsuite/gas/sh/pcrel2.d: New.
        * testsuite/gas/sh/basic.exp: Add pcrel2 test.

diff -urN ORIG/src/gas/config/tc-sh.c TMP/src/gas/config/tc-sh.c
--- ORIG/src/gas/config/tc-sh.c	Sun Sep 15 07:09:09 2002
+++ TMP/src/gas/config/tc-sh.c	Fri Sep 27 12:29:33 2002
@@ -3219,6 +3219,18 @@
 sh_force_relocation (fix)
      fixS *fix;
 {
+  /* These relocations can't make it into a DSO, so no use forcing
+     them for global symbols.  */
+  if (! sh_relax
+      && (fix->fx_r_type == BFD_RELOC_SH_PCDISP8BY2
+	  || fix->fx_r_type == BFD_RELOC_SH_PCDISP12BY2
+	  || fix->fx_r_type == BFD_RELOC_SH_PCRELIMM8BY2
+	  || fix->fx_r_type == BFD_RELOC_SH_PCRELIMM8BY4
+	  || fix->fx_r_type == BFD_RELOC_8_PCREL
+	  || fix->fx_r_type == BFD_RELOC_SH_SWITCH16
+	  || fix->fx_r_type == BFD_RELOC_SH_SWITCH32))
+    return 0;
+
   if (fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT
       || fix->fx_r_type == BFD_RELOC_VTABLE_ENTRY
       || fix->fx_r_type == BFD_RELOC_SH_LOOP_START
diff -urN ORIG/src/gas/testsuite/gas/sh/basic.exp TMP/src/gas/testsuite/gas/sh/basic.exp
--- ORIG/src/gas/testsuite/gas/sh/basic.exp	Sun Sep 15 07:09:29 2002
+++ TMP/src/gas/testsuite/gas/sh/basic.exp	Fri Sep 27 11:46:00 2002
@@ -129,6 +129,8 @@
 	run_dump_test "dsp"
 
 	run_dump_test "pcrel"
+
+	run_dump_test "pcrel2"
     }
 
     if {[istarget sh*-*elf] || [istarget sh*-linux*]} then {
diff -urN ORIG/src/gas/testsuite/gas/sh/pcrel2.d TMP/src/gas/testsuite/gas/sh/pcrel2.d
--- ORIG/src/gas/testsuite/gas/sh/pcrel2.d	Thu Jan  1 09:00:00 1970
+++ TMP/src/gas/testsuite/gas/sh/pcrel2.d	Fri Sep 27 12:20:31 2002
@@ -0,0 +1,5 @@
+#as: -big
+#objdump: -r
+#name: PC-relative loads
+
+.*:     file format .*sh.*
diff -urN ORIG/src/gas/testsuite/gas/sh/pcrel2.s TMP/src/gas/testsuite/gas/sh/pcrel2.s
--- ORIG/src/gas/testsuite/gas/sh/pcrel2.s	Thu Jan  1 09:00:00 1970
+++ TMP/src/gas/testsuite/gas/sh/pcrel2.s	Fri Sep 27 12:19:15 2002
@@ -0,0 +1,17 @@
+	.text
+
+	.p2align 2
+code:
+	bf	foo
+	mov.l	bar, r0
+	mov.w	bar, r0
+	.globl	foo
+foo:
+	bra	foo
+	nop
+	.align 2
+	.globl	bar
+bar:
+	.long	. - foo
+	.word	. - foo
+	.byte	. - foo


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