aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2002-11-15 11:18:49 +0000
committerNick Clifton <nickc@redhat.com>2002-11-15 11:18:49 +0000
commite514ac71cb3fa3b772e19dd7ab2024a0f00b5bc2 (patch)
tree26cd8cb5b77ab128e5461b806ddaf6b40f21a2dc /bfd
parenteddc4f813f72608685e5e301d0980bbc60d7f653 (diff)
downloadgdb-e514ac71cb3fa3b772e19dd7ab2024a0f00b5bc2.zip
gdb-e514ac71cb3fa3b772e19dd7ab2024a0f00b5bc2.tar.gz
gdb-e514ac71cb3fa3b772e19dd7ab2024a0f00b5bc2.tar.bz2
Fix h8300 relaxation.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/coff-h8300.c53
-rw-r--r--bfd/elf32-h8300.c51
3 files changed, 78 insertions, 32 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 8b096bc..479674b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2002-11-15 Kazu Hirata <kazu@cs.umass.edu>
+
+ * coff-h8300.c (h8300_reloc16_estimate): Do not optimize away
+ jsr after a short jump.
+ * elf32-h8300.c (elf32_h8_relax_section): Likewise.
+
2002-11-15 Klee Dienes <kdienes@apple.com>
* pef.c (bfd_pef_convert_architecture): Move declaration of
diff --git a/bfd/coff-h8300.c b/bfd/coff-h8300.c
index 4aab46b..c83015e 100644
--- a/bfd/coff-h8300.c
+++ b/bfd/coff-h8300.c
@@ -4,21 +4,21 @@
Free Software Foundation, Inc.
Written by Steve Chamberlain, <sac@cygnus.com>.
-This file is part of BFD, the Binary File Descriptor library.
+ This file is part of BFD, the Binary File Descriptor library.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
@@ -483,6 +483,13 @@ h8300_reloc16_estimate (abfd, input_section, reloc, shrink, link_info)
closer if we do relax this branch. */
if ((int) gap >= -128 && (int) gap <= 128)
{
+ bfd_byte code;
+
+ if (!bfd_get_section_contents (abfd, input_section, & code,
+ reloc->address, 1))
+ break;
+ code = bfd_get_8 (abfd, & code);
+
/* It's possible we may be able to eliminate this branch entirely;
if the previous instruction is a branch around this instruction,
and there's no label at this instruction, then we can reverse
@@ -494,9 +501,25 @@ h8300_reloc16_estimate (abfd, input_section, reloc, shrink, link_info)
lab1: lab1:
This saves 4 bytes instead of two, and should be relatively
- common. */
-
- if (gap <= 126
+ common.
+
+ Only perform this optimisation for jumps (code 0x5a) not
+ subroutine calls, as otherwise it could transform:
+
+ mov.w r0,r0
+ beq .L1
+ jsr @_bar
+ .L1: rts
+ _bar: rts
+ into:
+ mov.w r0,r0
+ bne _bar
+ rts
+ _bar: rts
+
+ which changes the call (jsr) into a branch (bne). */
+ if (code == 0x5a
+ && gap <= 126
&& last_reloc
&& last_reloc->howto->type == R_PCRBYTE)
{
diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c
index 1d643cb..9cb900b 100644
--- a/bfd/elf32-h8300.c
+++ b/bfd/elf32-h8300.c
@@ -2,21 +2,21 @@
Copyright 1993, 1995, 1998, 1999, 2001, 2002
Free Software Foundation, Inc.
-This file is part of BFD, the Binary File Descriptor library.
+ This file is part of BFD, the Binary File Descriptor library.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
@@ -827,14 +827,34 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
elf_section_data (sec)->this_hdr.contents = contents;
symtab_hdr->contents = (unsigned char *) isymbuf;
+ /* Get the instruction code being relaxed. */
+ code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
+
/* If the previous instruction conditionally jumped around
this instruction, we may be able to reverse the condition
and redirect the previous instruction to the target of
this instruction.
Such sequences are used by the compiler to deal with
- long conditional branches. */
- if ((int) gap <= 130
+ long conditional branches.
+
+ Only perform this optimisation for jumps (code 0x5a) not
+ subroutine calls, as otherwise it could transform:
+
+ mov.w r0,r0
+ beq .L1
+ jsr @_bar
+ .L1: rts
+ _bar: rts
+ into:
+ mov.w r0,r0
+ bne _bar
+ rts
+ _bar: rts
+
+ which changes the call (jsr) into a branch (bne). */
+ if (code == 0x5a
+ && (int) gap <= 130
&& (int) gap >= -128
&& last_reloc
&& ELF32_R_TYPE (last_reloc->r_info) == R_H8_PCREL8
@@ -890,9 +910,6 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
}
}
- /* We could not eliminate this jump, so just shorten it. */
- code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
-
if (code == 0x5e)
bfd_put_8 (abfd, 0x55, contents + irel->r_offset - 1);
else if (code == 0x5a)