aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf32-h8300.c
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/elf32-h8300.c
parenteddc4f813f72608685e5e301d0980bbc60d7f653 (diff)
downloadgdb-e514ac71cb3fa3b772e19dd7ab2024a0f00b5bc2.zip
gdb-e514ac71cb3fa3b772e19dd7ab2024a0f00b5bc2.tar.gz
gdb-e514ac71cb3fa3b772e19dd7ab2024a0f00b5bc2.tar.bz2
Fix h8300 relaxation.
Diffstat (limited to 'bfd/elf32-h8300.c')
-rw-r--r--bfd/elf32-h8300.c51
1 files changed, 34 insertions, 17 deletions
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)