* Test for overflow in the R_MIPS_26 reloc
@ 2004-12-08 20:27 Ian Lance Taylor
2004-12-13 13:21 ` Richard Sandiford
0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2004-12-08 20:27 UTC (permalink / raw)
To: binutils
A long time ago I patched the linker to detect overflow when
processing the R_MIPS_26 reloc. At some point after that that
overflow test was lost.
I'm about to check in this patch to restore it. I am also adding a
test case to the linker testsuite.
Ian
bfd/ChangeLog:
2004-12-08 Ian Lance Taylor <ian@wasabisystems.com>
* elfxx-mips.c (mips_elf_calculate_relocation): Test for R_MIPS_26
overflow.
ld/testsuite/ChangeLog:
2004-12-08 Ian Lance Taylor <ian@wasabisystems.com>
* ld-mips-elf/jaloverflow.d: New test.
* ld-mips-elf/jaloverflow.s: New test.
* ld-mips-elf/mips-elf.exp: Run it.
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;
Index: ld-mips-elf/jaloverflow.d
===================================================================
RCS file: ld-mips-elf/jaloverflow.d
diff -N ld-mips-elf/jaloverflow.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-mips-elf/jaloverflow.d 8 Dec 2004 20:24:16 -0000
@@ -0,0 +1,11 @@
+#name: JAL overflow
+#source: jaloverflow.s
+#as:
+#ld: -Ttext=0xffffff0 -e start
+#error: .*relocation truncated to fit.*
+
+# This tests whether we correctly detect overflow in the jal
+# instruction. jal is a bit weird since the upper four bits of the
+# destination address are taken from the source address. So overflow
+# occurs if the source and destination address do not have the same
+# most significant four bits.
Index: ld-mips-elf/jaloverflow.s
===================================================================
RCS file: ld-mips-elf/jaloverflow.s
diff -N ld-mips-elf/jaloverflow.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-mips-elf/jaloverflow.s 8 Dec 2004 20:24:16 -0000
@@ -0,0 +1,12 @@
+# This file gets linked to start at 0xffffff0, so the call is an overflow.
+ .text
+ .global start
+ .set noreorder
+start:
+ nop
+ nop
+ nop
+ nop
+ jal start
+ nop
+ .type start, @function
Index: ld-mips-elf/mips-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/mips-elf.exp,v
retrieving revision 1.19
diff -u -r1.19 mips-elf.exp
--- ld-mips-elf/mips-elf.exp 16 Nov 2004 10:16:30 -0000 1.19
+++ ld-mips-elf/mips-elf.exp 8 Dec 2004 20:24:16 -0000
@@ -79,3 +79,5 @@
run_dump_test "eh-frame1-n32"
run_dump_test "eh-frame1-n64"
}
+
+run_dump_test "jaloverflow"
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Test for overflow in the R_MIPS_26 reloc
2004-12-08 20:27 Test for overflow in the R_MIPS_26 reloc Ian Lance Taylor
@ 2004-12-13 13:21 ` Richard Sandiford
2004-12-14 3:24 ` Ian Lance Taylor
0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2004-12-13 13:21 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: binutils
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Test for overflow in the R_MIPS_26 reloc
2004-12-13 13:21 ` Richard Sandiford
@ 2004-12-14 3:24 ` Ian Lance Taylor
0 siblings, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2004-12-14 3:24 UTC (permalink / raw)
To: Richard Sandiford; +Cc: binutils
Richard Sandiford <rsandifo@redhat.com> writes:
> 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.
This is OK. Sorry about the breakage.
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-12-14 3:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-08 20:27 Test for overflow in the R_MIPS_26 reloc Ian Lance Taylor
2004-12-13 13:21 ` Richard Sandiford
2004-12-14 3:24 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).