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 12:04:17 +0900
- Subject: Re: [PATCH/RFA] sh-elf: Unnecessary relocations
- References: <20021003114101.C25369@bubble.sa.bigpond.net.au>
Alan Modra <amodra@bigpond.net.au> wrote:
>> @@ -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)
>
> These three S_IS_* tests can be replaced with S_FORCE_RELOC.
I see. Here is a revised patch. There is no new regressions
for gas/ld on sh-unknown-linux-gnu and sh64-any-elf.
Is it OK?
Regards,
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.
(md_pcrel_from_section): Check the relocation type whether it
should be resolved locally. Use S_FORCE_RELOC.
* testsuite/gas/sh/pcrel2.d: Check code also.
Index: 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
--- tc-sh.c 28 Sep 2002 00:41:26 -0000 1.71
+++ tc-sh.c 3 Oct 2002 02:47:28 -0000
@@ -71,6 +71,7 @@ static void build_relax PARAMS ((sh_opco
static char *insert_loop_bounds PARAMS ((char *, sh_operand_info *));
static unsigned int build_Mytes
PARAMS ((sh_opcode_info *, sh_operand_info *));
+static boolean sh_local_pcrel PARAMS ((fixS *fix));
#ifdef OBJ_ELF
static void sh_elf_cons PARAMS ((int));
@@ -3211,6 +3212,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 +3238,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,10 +3694,9 @@ md_pcrel_from_section (fixP, sec)
fixS *fixP;
segT sec;
{
- if (fixP->fx_addsy != (symbolS *) NULL
- && (! S_IS_DEFINED (fixP->fx_addsy)
- || S_IS_EXTERN (fixP->fx_addsy)
- || S_IS_WEAK (fixP->fx_addsy)
+ if (! sh_local_pcrel (fixP)
+ && fixP->fx_addsy != (symbolS *) NULL
+ && (S_FORCE_RELOC (fixP->fx_addsy)
|| S_GET_SEGMENT (fixP->fx_addsy) != sec))
{
/* The symbol is undefined (or is defined but not in this section,
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 .*[ ]*.*