This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Test for overflow in the R_MIPS_26 reloc
- From: Ian Lance Taylor <ian at wasabisystems dot com>
- To: binutils at sourceware dot org
- Date: 8 Dec 2004 15:27:30 -0500
- Subject: Test for overflow in the R_MIPS_26 reloc
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"