This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH]: Fix ld-HC11 linker relax (Bug 1417)
- From: Stephane Carrez <stcarrez at nerim dot fr>
- To: binutils at sources dot redhat dot com
- Date: Sun, 01 Dec 2002 15:24:48 +0100
- Subject: [PATCH]: Fix ld-HC11 linker relax (Bug 1417)
Hi!
I've committed this patch to fix the Savannah bug 1417:
http://savannah.gnu.org/bugs/?func=detailbug&bug_id=1417&group_id=2424
When doing linker relaxation for HC11, I was adjusting a branch when it should not.
I've committed a testcase in ld testsuite to check/validate the fix.
Stephane
bfd/ChangeLog
2002-12-01 Stephane Carrez <stcarrez@nerim.fr>
Fix PR savannah/1417:
* elf32-m68hc11.c (m68hc11_elf_relax_delete_bytes): Don't adjust
branch if it goes to the start of the deleted region.
ld/testsuite/ChangeLog
2002-12-01 Stephane Carrez <stcarrez@nerim.fr>
Fix PR savannah/1417:
* ld-m68hc11/bug-1417.s: New test.
* ld-m68hc11/bug-1417.d: Likewise.
Index: bfd/elf32-m68hc11.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m68hc11.c,v
retrieving revision 1.14
diff -u -p -r1.14 elf32-m68hc11.c
--- bfd/elf32-m68hc11.c 30 Nov 2002 08:39:37 -0000 1.14
+++ bfd/elf32-m68hc11.c 1 Dec 2002 13:18:48 -0000
@@ -1194,7 +1194,7 @@ m68hc11_elf_relax_delete_bytes (abfd, se
offset = bfd_get_8 (abfd, contents + irel->r_offset + branch_pos);
raddr += old_offset;
raddr += ((unsigned short) offset | ((offset & 0x80) ? 0xff00 : 0));
- if (irel->r_offset < addr && raddr >= addr)
+ if (irel->r_offset < addr && raddr > addr)
{
offset -= count;
bfd_put_8 (abfd, offset, contents + irel->r_offset + branch_pos);
Index: ld/testsuite/ld-m68hc11/bug-1417.d
===================================================================
RCS file: ld/testsuite/ld-m68hc11/bug-1417.d
diff -N ld/testsuite/ld-m68hc11/bug-1417.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-m68hc11/bug-1417.d 1 Dec 2002 13:18:49 -0000
@@ -0,0 +1,15 @@
+#source: bug-1417.s
+#as: -m68hc11
+#ld: --relax
+#objdump: -d --prefix-addresses -r
+#target: m6811-*-* m6812-*-*
+
+.*: +file format elf32-m68hc11
+
+Disassembly of section .text:
+0+8000 <_start> tst 0+ <__bss_size>
+0+8003 <_start\+0x3> bne 0+8008 <L1>
+0+8005 <_start\+0x5> jsr 0+800c <foo>
+0+8008 <L1> bset \*0+ <__bss_size> \#\$04
+0+800b <L2> rts
+0+800c <foo> rts
Index: ld/testsuite/ld-m68hc11/bug-1417.s
===================================================================
RCS file: ld/testsuite/ld-m68hc11/bug-1417.s
diff -N ld/testsuite/ld-m68hc11/bug-1417.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-m68hc11/bug-1417.s 1 Dec 2002 13:18:49 -0000
@@ -0,0 +1,21 @@
+;;; Bug #1417: Branch wrong after linker relaxation
+;;; http://savannah.gnu.org/bugs/?func=detailbug&bug_id=1417&group_id=2424
+;;;
+ .sect .text
+ .globl _start
+_start:
+ tst table
+ bne L1 ; Branch was adjusted but it must not
+ jsr foo
+L1:
+ .relax L2
+ ldx #table ; Instruction removed
+ bset 0,x #4 ; Changed to bset *table #4
+L2:
+ rts
+foo:
+ rts
+
+ .sect .page0
+ .globl table
+table: .long 0