diff options
Diffstat (limited to 'bfd/elf32-h8300.c')
-rw-r--r-- | bfd/elf32-h8300.c | 51 |
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) |