]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Merge from mainline:
authorKazu Hirata <kazu@codesourcery.com>
Mon, 16 Dec 2002 03:52:33 +0000 (03:52 +0000)
committerKazu Hirata <kazu@codesourcery.com>
Mon, 16 Dec 2002 03:52:33 +0000 (03:52 +0000)
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.

bfd/ChangeLog
bfd/coff-h8300.c
bfd/elf32-h8300.c

index a0a47f833bbf6344a3db89bff98e4eeaad065e73..46344907790ad779299b93b2666e10a0842f331d 100644 (file)
@@ -1,3 +1,11 @@
+2002-12-15  Kazu Hirata  <kazu@cs.umass.edu>
+
+       Merge from mainline:
+       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-12-15  Daniel Jacobowitz  <drow@mvista.com>
 
        Merge from mainline:
index 82b7bca5b013ed61165dd9e5fa73de9250238ef5..d078d9114f80888ae41270ef2c0e2b3d30e85079 100644 (file)
@@ -485,6 +485,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
@@ -496,9 +503,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)
            {
index 5dfad2acd0b85fb99f878302b30d95e6483ad559..92bb1384835ac13e34089f20b341bf5b9b0fea5c 100644 (file)
@@ -847,14 +847,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
@@ -911,9 +931,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)