This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Patch/RFA]: Patch to fix R_ARM_THM_JUMP24 relocation truncated bug
- From: Matthew Gretton-Dann <matthew dot gretton-dann at arm dot com>
- To: binutils at sourceware dot org
- Date: Thu, 14 Jan 2010 14:01:11 +0000
- Subject: [Patch/RFA]: Patch to fix R_ARM_THM_JUMP24 relocation truncated bug
Hi,
Please can someone review, approve, and commit the attached patch?
This patch fixes a bug in ld where it incorrectly reports 'relocation
truncated to fit: R_ARM_THM_JUMP24 ...' for certain relocation addends.
The following test case demonstrates the bug:
testcase.s:
.text
.syntax unified
.thumb_func
.global _start
.type _start,%function
_start:
b.w dest
.section destsect, "x"
.thumb_func
dest:
b dest
To demonstrate:
arm-none-linux-gnueabi-as -march=armv7-a -mthumb \
testcase.s -o testcase.o
arm-none-linux-gnueabi-ld -defsym _start=0x8000 \
--section-start destsect=0x00900000 \
testcase.o -o testcase
Output:
testcase.o: In function `_start':
(.text+0x0): relocation truncated to fit: R_ARM_THM_JUMP24 against
`dest'
This should never occur. Either the calculated branch offset for the
relocation should fit or ld should have created a veneer within range
and relocated to that.
In this particular case the branch is actually in range (and so no
veneer is needed), but the elf32_arm_howto_table_1 in bfd/elf32-arm.c
contains an incorrect value for the number of bits to be relocated (24
instead of 25). The fix is to just update the table.
The ChangeLog entries are as follows:
bfd/ChangeLog:
2010-01-14 Matthew Gretton-Dann <matthew.gretton-dann@arm.com>
* elf32-arm.c (elf32_arm_howto_table_1): Correct bitsize of
R_ARM_THM_JUMP24 entry.
ld/testsuite/ChangeLog:
2010-01-14 Matthew Gretton-Dann <matthew.gretton-dann@arm.com>
* ld-arm/jump-reloc-veneers-long.d: New test.
* ld-arm/jump-reloc-veneers-short1.d: Likewise.
* ld-arm/jump-reloc-veneers-short2.d: Likewise.
* ld-arm/jump-reloc-veneers.s: Likewise.
* ld-arm/arm-elf.exp (armelftests): Run them.
Thanks,
Matt
--
Matthew Gretton-Dann
Principal Engineer - Tools, PD Software
ARM Limited
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.218
diff -u -r1.218 elf32-arm.c
--- bfd/elf32-arm.c 28 Dec 2009 18:55:16 -0000 1.218
+++ bfd/elf32-arm.c 8 Jan 2010 15:27:57 -0000
@@ -508,7 +508,7 @@
HOWTO (R_ARM_THM_JUMP24, /* type */
1, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
- 24, /* bitsize */
+ 25, /* bitsize */
TRUE, /* pc_relative */
0, /* bitpos */
complain_overflow_signed,/* complain_on_overflow */
Index: ld/testsuite/ld-arm/arm-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-arm/arm-elf.exp,v
retrieving revision 1.67
diff -u -r1.67 arm-elf.exp
--- ld/testsuite/ld-arm/arm-elf.exp 28 Dec 2009 18:55:16 -0000 1.67
+++ ld/testsuite/ld-arm/arm-elf.exp 8 Jan 2010 15:28:14 -0000
@@ -239,6 +239,24 @@
{"Relocation boundaries" "-defsym x=0 -defsym y=0 -defsym _start=0" "" {reloc-boundaries.s}
{{objdump -s reloc-boundaries.d}}
"reloc-boundaries"}
+ {"R_ARM_THM_JUMP24 Relocation veneers: Short 1"
+ "-defsym _start=0x8000 --section-start destsect=0x00009000"
+ "-march=armv7-a -mthumb"
+ {jump-reloc-veneers.s}
+ {{objdump -d jump-reloc-veneers-short1.d}}
+ "jump-reloc-veneers-short1"}
+ {"R_ARM_THM_JUMP24 Relocation veneers: Short 2"
+ "-defsym _start=0x8000 --section-start destsect=0x00900000"
+ "-march=armv7-a -mthumb"
+ {jump-reloc-veneers.s}
+ {{objdump -d jump-reloc-veneers-short2.d}}
+ "jump-reloc-veneers-short2"}
+ {"R_ARM_THM_JUMP24 Relocation veneers: Long"
+ "-defsym _start=0x8000 --section-start destsect=0x09000000"
+ "-march=armv7-a -mthumb"
+ {jump-reloc-veneers.s}
+ {{objdump -d jump-reloc-veneers-long.d}}
+ "jump-reloc-veneers-long"}
}
run_ld_link_tests $armelftests
Index: ld/testsuite/ld-arm/jump-reloc-veneers.s
===================================================================
diff -u /dev/null jump-reloc-veneers.s
--- /dev/null 2009-05-17 13:34:33.498340648 +0100
+++ ld/testsuite/ld-arm/jump-reloc-veneers.s 2010-01-08 10:58:48.054129000 +0000
@@ -0,0 +1,12 @@
+ .text
+ .syntax unified
+ .thumb_func
+ .global _start
+ .type _start,%function
+_start:
+ b.w dest
+
+ .section destsect, "x"
+ .thumb_func
+dest:
+ b dest
Index: ld/testsuite/ld-arm/jump-reloc-short1.d
===================================================================
diff -u /dev/null jump-reloc-veneers-short1.d
--- /dev/null 2009-05-17 13:34:33.498340648 +0100
+++ ld/testsuite/ld-arm/jump-reloc-veneers-short1.d 2010-01-08 11:23:43.572369000 +0000
@@ -0,0 +1,13 @@
+
+.*: file format.*
+
+
+Disassembly of section destsect:
+
+00009000 <[^>]*>:
+ 9000: e7fe b.n 9000 <dest>
+
+Disassembly of section .text:
+
+00008054 <[^>]*>:
+ 8054: f000 bfd4 b.w 9000 <dest>
Index: ld/testsuite/ld-arm/jump-reloc-short2.d
===================================================================
diff -u /dev/null jump-reloc-veneers-short2.d
--- /dev/null 2009-05-17 13:34:33.498340648 +0100
+++ ld/testsuite/ld-arm/jump-reloc-veneers-short2.d 2010-01-08 11:32:56.653566000 +0000
@@ -0,0 +1,13 @@
+
+.*: file format.*
+
+
+Disassembly of section destsect:
+
+00900000 <[^>]*>:
+ 900000: e7fe b.n 900000 <dest>
+
+Disassembly of section .text:
+
+00008054 <[^>]*>:
+ 8054: f0f7 9fd4 b.w 900000 <dest>
Index: ld/testsuite/ld-arm/jump-reloc-long.d
===================================================================
diff -u /dev/null jump-reloc-veneers-long.d
--- /dev/null 2009-05-17 13:34:33.498340648 +0100
+++ ld/testsuite/ld-arm/jump-reloc-veneers-long.d 2010-01-08 11:23:06.012845000 +0000
@@ -0,0 +1,21 @@
+
+.*: file format.*
+
+
+Disassembly of section destsect:
+
+09000000 <[^>]*>:
+ 9000000: e7fe b.n 9000000 <dest>
+
+Disassembly of section .text:
+
+00008058 <[^>]*>:
+ 8058: b802f000 .word 0xb802f000
+ 805c: 00000000 andeq r0, r0, r0
+
+00008060 <[^>]*>:
+ 8060: 4778 bx pc
+ 8062: 46c0 nop ; \(mov r8, r8\)
+ 8064: e59fc000 ldr ip, \[pc, #0\] ; 806c <__dest_veneer\+0xc>
+ 8068: e12fff1c bx ip
+ 806c: 09000001 .word 0x09000001