This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] MIPS gas: Reallow branches to global file-internal labels
- From: Thiemo Seufer <ica2_ts at csv dot ica dot uni-stuttgart dot de>
- To: binutils at sources dot redhat dot com
- Date: Wed, 12 Feb 2003 19:31:47 +0100
- Subject: [PATCH] MIPS gas: Reallow branches to global file-internal labels
Hello All,
the Patch
2002-12-12 Alexandre Oliva <aoliva@redhat.com>
* tc-mips.c (RELAX_BRANCH_ENCODE): Remove reloc_s2 argument.
Adjust callers.
(RELAX_BRANCH_RELOC_S2): Delete.
(append_insn): Use only BFD_RELOC_16_PCREL_S2 for branches.
Do not handle BFD_RELOC_16_PCREL.
(macro_build, mips_ip): Likewise.
(md_pcrel_from): Return 4 for undefined symbols regardless of
mips_pic.
(md_apply_fix3): Use only BFD_RELOC_16_PCREL_S2 for branches.
Don't dereference howto if no such relocation is available.
Do not apply hack for in-place zero addend in NEWABI.
(md_convert_frag): Use only BFD_RELOC_16_PCREL_S2 for branches.
simplified the (broken) MIPS branch relocation handling and removed the
possibility to branch to globally visible symbols for any ABI other than
EMBEDDED PIC, which have no external pendant for the BFD_RELOC_16_PCREL_S2
relocation.
This seems to be intentional, as the testcase was adjusted accordingly.
However, this breaks much code, especially performance-critical hand-coded
one. To my knowledge, it affects at least the Linux Kernel, glibc and
dietlibc. GCC seems not to be good enough to do such optimizations.
I'm not sure if this patch is the right way to do, especially the
calculation of 'value' looks suspicious, but it happens to produce
good results for the Linux Kernel.
Tested with no new regressions for linux-mips.
Thiemo
2003-02-12 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
/gas/ChangeLog
* tc-mips.c (tc_gen_reloc): Resolve file-internal
BFD_RELOC_16_PCREL_S2 relocations for ABIs without external
representation for it.
/gas/testsuite/ChangeLog
* gas/mips/branch-misc-2.l: Adjust accordingly.
diff -BurpNX /bigdisk/src/gcc-exclude source-orig/gas/config/tc-mips.c source/gas/config/tc-mips.c
--- source-orig/gas/config/tc-mips.c Wed Jan 29 18:30:32 2003
+++ source/gas/config/tc-mips.c Fri Feb 7 07:01:49 2003
@@ -13533,7 +13542,27 @@ tc_gen_reloc (section, fixp)
|| OUTPUT_FLAVOR == bfd_target_elf_flavour)
&& code == BFD_RELOC_16_PCREL_S2
&& mips_pic != EMBEDDED_PIC)
- reloc->howto = NULL;
+ {
+ valueT value = -fixp->fx_addnumber - 8;
+ if (! fixp->fx_done
+ && S_IS_DEFINED (fixp->fx_addsy)
+ && value + 0x20000 <= 0x3ffff
+ && ! mips_relax_branch)
+ {
+ bfd_byte *buf;
+
+ fixp->fx_done = 1;
+ fixp->fx_addsy = NULL;
+ buf = (bfd_byte *) fixp->fx_frag->fr_literal + fixp->fx_where;
+ if (target_big_endian)
+ buf += 2;
+ md_number_to_chars ((char *) buf, (value >> 2) & 0xffff, 2);
+ retval[0] = NULL;
+ reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
+ }
+ else
+ reloc->howto = NULL;
+ }
else
reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
diff -BurpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/branch-misc-2.l source/gas/testsuite/gas/mips/branch-misc-2.l
--- source-orig/gas/testsuite/gas/mips/branch-misc-2.l Thu Dec 12 05:40:22 2002
+++ source/gas/testsuite/gas/mips/branch-misc-2.l Wed Feb 5 10:29:18 2003
@@ -1,9 +1,3 @@
.*: Assembler messages:
-.*:21: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:22: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:23: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:24: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:25: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:26: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
.*:35: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
.*:36: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format