This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [PATCH/RFA] sh-elf: Unnecessary relocations
- From: kaz Kojima <kkojima at rr dot iij4u dot or dot jp>
- To: amodra at bigpond dot net dot au
- Cc: stephen dot clarke at earthling dot net, hp at bitrange dot com, binutils at sources dot redhat dot com
- Date: Thu, 03 Oct 2002 10:05:17 +0900
- Subject: Re: [PATCH/RFA] sh-elf: Unnecessary relocations
- References: <20021003102622.Y25369@bubble.sa.bigpond.net.au>
Alan Modra <amodra@bigpond.net.au> wrote:
> On Wed, Oct 02, 2002 at 11:53:54AM -0700, Stephen Clarke wrote:
> > 00000000 <lab2-0x4>:
> > 0: d0 01 mov.l 8 <lab2+0x4>,r0
> > 2: 00 09 nop
> >
> > 00000004 <lab2>:
> > 4: 00 00 .word 0x0000
>
> sh-linux binutils built on Sep 28 assembles and links your testcase
> OK, so it's not the gas reloc rewrite. phew! I believe the problem
> is in tc-sh.c:md_pcrel_from_section where it looks like we have some
> hacks to counteract bfd_install_relocation brain-damage. Since Kaz
> changed the conditions under which we emit relocs, the test there
> needs changing too. Also, IMO it would be cleaner to move the hacks
> into md_apply_fix3.
Hmm... Surely it's my bad. I've compared the behaviors of old/new
assemblers with gdb and found that tc-sh.c:md_pcrel_from_section()
of the new assember returns 0 instead of 4 which the old one returns.
I don't know why but fixP->fx_addsy->bsym is "lab2" in the new one
and ".text" in the old one.
Now I'm testing the following patch for tc-sh.c. Fixing md_apply_fix3
seems cleaner, but I'm unsure how to do it.
Anyway, we should catch such problems by the testsuite, I think.
How about the following patch for pcrel2 test?
kaz
--
2002-10-03 Kaz Kojima <kkojima@rr.iij4u.or.jp>
* contig/tc-sh.c (sh_local_pcrel): New.
(sh_force_relocation): Use sh_local_pcrel.
* testsuite/gas/sh/pcrel2.d: Check code also.
Index: config/tc-sh.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-sh.c,v
retrieving revision 1.71
diff -u -3 -p -r1.71 tc-sh.c
--- config/tc-sh.c 28 Sep 2002 00:41:26 -0000 1.71
+++ config/tc-sh.c 3 Oct 2002 00:43:18 -0000
@@ -3211,6 +3211,22 @@ sh_handle_align (frag)
BFD_RELOC_SH_ALIGN);
}
+/* See whether the relocation should be resolved locally. */
+
+static boolean
+sh_local_pcrel (fix)
+ fixS *fix;
+{
+ return (! 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));
+}
+
/* See whether we need to force a relocation into the output file.
This is used to force out switch and PC relative relocations when
relaxing. */
@@ -3221,14 +3237,7 @@ sh_force_relocation (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))
+ if (sh_local_pcrel (fix))
return 0;
if (fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT
@@ -3684,7 +3693,8 @@ md_pcrel_from_section (fixP, sec)
fixS *fixP;
segT sec;
{
- if (fixP->fx_addsy != (symbolS *) NULL
+ if (! sh_local_pcrel (fixP)
+ && fixP->fx_addsy != (symbolS *) NULL
&& (! S_IS_DEFINED (fixP->fx_addsy)
|| S_IS_EXTERN (fixP->fx_addsy)
|| S_IS_WEAK (fixP->fx_addsy)
Index: testsuite/gas/sh/pcrel2.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/sh/pcrel2.d,v
retrieving revision 1.1
diff -u -3 -p -r1.1 pcrel2.d
--- testsuite/gas/sh/pcrel2.d 28 Sep 2002 00:41:27 -0000 1.1
+++ testsuite/gas/sh/pcrel2.d 3 Oct 2002 00:43:37 -0000
@@ -1,5 +1,23 @@
#as: -big
-#objdump: -r
+#objdump: -drj.text
#name: PC-relative loads
.*: file format .*sh.*
+
+Disassembly of section \.text:
+
+00000000 <code>:
+ 0: 8b 01 bf 6 <foo>
+ 2: d0 02 mov\.l c <bar>,r0 ! 0x6
+ 4: 90 02 mov\.w c <bar>,r0 ! 0x0
+
+00000006 <foo>:
+ 6: af fe bra 6 <foo>
+ 8: 00 09 nop
+ a: 00 09 nop
+
+0000000c <bar>:
+ c: 00 00 .*[ ]*.*
+ e: 00 06 .*[ ]*.*
+ 10: 00 0a .*[ ]*.*
+ 12: 0c 00 .*[ ]*.*