This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Test for overflow in the R_MIPS_26 reloc
- From: Richard Sandiford <rsandifo at redhat dot com>
- To: Ian Lance Taylor <ian at wasabisystems dot com>
- Cc: binutils at sourceware dot org
- Date: Mon, 13 Dec 2004 13:20:56 +0000
- Subject: Re: Test for overflow in the R_MIPS_26 reloc
- References: <20041208202730.11374.qmail@gossamer.airs.com>
Ian Lance Taylor <ian@wasabisystems.com> writes:
> Index: elfxx-mips.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
> retrieving revision 1.113
> diff -p -u -r1.113 elfxx-mips.c
> --- elfxx-mips.c 16 Nov 2004 09:54:10 -0000 1.113
> +++ elfxx-mips.c 8 Dec 2004 20:24:55 -0000
> @@ -3350,7 +3350,10 @@ mips_elf_calculate_relocation (bfd *abfd
> if (local_p)
> value = ((addend | ((p + 4) & 0xf0000000)) + symbol) >> 2;
> else
> - value = (_bfd_mips_elf_sign_extend (addend, 28) + symbol) >> 2;
> + {
> + value = (_bfd_mips_elf_sign_extend (addend, 28) + symbol) >> 2;
> + overflowed_p = (value >> 26) != ((p + 4) >> 28);
> + }
> value &= howto->dst_mask;
> break;
On non-PIC targets, the overflow triggers for code like:
void foo (void)
{
if (weak_symbol)
weak_symbol ();
}
when weak_symbol is undefined and foo() is outside the low 256MB
(in KSEG0, for example). This is causing lots of link failures
in the mips64-elf gcc testsuite.
Is the patch below OK? Tested against the gcc testsuite on mips64-elf.
Also tested against the gas, ld & binutils testsuite on mips64-elf,
mips-elf, mipsisa64el-elf and mips64-linux-gnu.
Richard
bfd/
* elfxx-mips.c (mips_elf_calculate_relocation): Don't report an
overflow for calls to undefined weak symbols.
ld/testsuite/
* ld-mips-elf/jal-overflow-2.[sd]: New test.
* ld-mips-elf/mips-elf.exp: Run it.
Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.116
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.116 elfxx-mips.c
*** bfd/elfxx-mips.c 9 Dec 2004 07:12:28 -0000 1.116
--- bfd/elfxx-mips.c 13 Dec 2004 13:10:31 -0000
*************** mips_elf_calculate_relocation (bfd *abfd
*** 3352,3358 ****
else
{
value = (_bfd_mips_elf_sign_extend (addend, 28) + symbol) >> 2;
! overflowed_p = (value >> 26) != ((p + 4) >> 28);
}
value &= howto->dst_mask;
break;
--- 3352,3359 ----
else
{
value = (_bfd_mips_elf_sign_extend (addend, 28) + symbol) >> 2;
! if (h->root.root.type != bfd_link_hash_undefweak)
! overflowed_p = (value >> 26) != ((p + 4) >> 28);
}
value &= howto->dst_mask;
break;
Index: ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/mips-elf.exp,v
retrieving revision 1.22
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.22 mips-elf.exp
*** ld/testsuite/ld-mips-elf/mips-elf.exp 13 Dec 2004 13:09:55 -0000 1.22
--- ld/testsuite/ld-mips-elf/mips-elf.exp 13 Dec 2004 13:10:31 -0000
*************** if {$has_newabi && $linux_gnu} {
*** 81,86 ****
--- 81,87 ----
}
run_dump_test "jaloverflow"
+ run_dump_test "jaloverflow-2"
if {$has_newabi} {
run_dump_test "jalbal"
}
diff -c /dev/null ld/testsuite/ld-mips-elf/jaloverflow-2.d
*** /dev/null Fri Apr 23 00:21:55 2004
--- ld/testsuite/ld-mips-elf/jaloverflow-2.d Mon Dec 13 11:39:44 2004
***************
*** 0 ****
--- 1,8 ----
+ #name: JAL overflow 2
+ #source: jaloverflow-2.s
+ #as:
+ #ld: -Ttext=0x10000000 -e start
+ #objdump: -dr
+ #...
+ 0*10000000: 0c000000.*
+ #pass
diff -c /dev/null ld/testsuite/ld-mips-elf/jaloverflow-2.s
*** /dev/null Fri Apr 23 00:21:55 2004
--- ld/testsuite/ld-mips-elf/jaloverflow-2.s Mon Dec 13 11:39:29 2004
***************
*** 0 ****
--- 1,7 ----
+ # jal relocs against undefined weak symbols should not be treated as
+ # overflowing
+
+ .globl start
+ .weak foo
+ start:
+ jal foo