Patch Fix H8300 relax

Paul paulc@senet.com.au
Tue Jun 3 12:10:00 GMT 2003


There are multiple problems with the h8300-elf binutils target and relaxing.
Here is an example where a
     mov.b @0xFF00:16,r0l
can be relaxed to
    mov.b @0x00:8,r0l

Initial file without the linking
relax.o:     file format elf32-h8300

Disassembly of section .text:

00000000 <_main>:
   0:    6a 08 00 00     6a 08 00 00       mov.b    @0x0:16,r0l
   4:    54 70           54 70             rts    

00000006 <_start>:
   6:    5e 00 00 00     5e 00 00 00       jsr    @0x0:0
   a:    54 70           54 70             rts    
Disassembly of section .data:

Link and relax object file using address FFFF00

relax.out:     file format elf32-h8300

Disassembly of section .readonly:

00000000 <_main>:
   0:    28 08           28 08             mov.b    @0x8:8,r0l
   2:    00 70           00 70        .word    H'0,H'70

00000004 <_start>:
   4:    55 fa           55 fa             bsr    .-6 (0)
   6:    54 70           54 70             rts    

Note that the link address should have moved from address 2 to address 1.

With my patch

relax.out:     file format elf32-h8300

Disassembly of section .readonly:

00000000 <_main>:
   0:    28 00           28 00             mov.b    @0x0:8,r0l
   2:    54 70           54 70             rts    

00000004 <_start>:
   4:    55 fa           55 fa             bsr    .-6 (0)
   6:    54 70           54 70             rts    





Index: elf32-h8300.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-h8300.c,v
retrieving revision 1.26
diff -u -r1.26 elf32-h8300.c
--- elf32-h8300.c    16 May 2003 23:39:24 -0000    1.26
+++ elf32-h8300.c    3 Jun 2003 11:47:16 -0000
@@ -1068,10 +1068,12 @@
         /* Fix the relocation's type.  */
         irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
                          R_H8_DIR8);
+        /* Move the relocation */
+        irel->r_offset--;
 
         /* Delete two bytes of data.  */
         if (!elf32_h8_relax_delete_bytes (abfd, sec,
-                          irel->r_offset + 1, 2))
+                          irel->r_offset, 2))
           goto error_return;
 
         /* That will change things, so, we should relax again.
@@ -1141,6 +1143,8 @@
         /* Fix the relocation's type.  */
         irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
                          R_H8_DIR8);
+        /* Move the relocation */
+        irel->r_offset--;
 
         /* Delete two bytes of data.  */
         if (!elf32_h8_relax_delete_bytes (abfd, sec, irel->r_offset, 2))




More information about the Binutils mailing list