H8 targets.

Jeff Law law@porcupine.slc.redhat.com
Mon Aug 12 10:37:00 GMT 2002


In message <m3d6tpw0t1.fsf@north-pole.nickc.cambridge.redhat.com>, Nick Clifton
 writes:
 >Hi Nitin,
 >
 >> The elf.h contains the follwoing different e_machine value for
 >> different H8 architectures:
 >
 >You mean include/elf/common.h, but anyway...
 >
 >> Then why is it that H8300-elf uses e_machine = EM_H8_300 
 >> for all  <default> , -ms , -mh targets?  To differentiate between
 >> targets, it uses Processor specific flags (e_flags) instead.
 >
 >There is no comment in the code to explain this discrepancy.  It may
 >be that these numbers were allocated after the code in the BFD library
 >was written, and so they were not known to the author.  Or it may be
 >that the ABI for the h8300x series specifies that the e_flags field
 >should be used.  Or it may well be a bug in the h8300 code in the BFD
 >library.
I believe this is my fault.  I wasn't aware of the existing spec
which used different ELF_MACHINE values for the different H8 variants
so instead I used a scheme which encodes that information into the 
flags field in a manner similar to what is done for MIPS and other targets.

The only problem with changing things now is that you'll make the GNU
tools incompatible with previous releases of the GNU tools.  Then again,
it's probably still the right thing to do, but it'll need to be clearly
documented in the release notes for the binutils release where the change
becomes effective.

I've got these changes sitting in my local tree -- I haven't looked at them
in any detail in nearly a year, but they may be useful to anyone trying to
fix this little problem.



jeff
-------------- next part --------------
Index: elf32-h8300.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-h8300.c,v
retrieving revision 1.15
diff -c -3 -p -r1.15 elf32-h8300.c
*** elf32-h8300.c	23 Jul 2002 12:29:32 -0000	1.15
--- elf32-h8300.c	12 Aug 2002 17:35:57 -0000
*************** static void elf32_h8_info_to_howto
*** 30,37 ****
    PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
  static void elf32_h8_info_to_howto_rel
    PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
! static unsigned long elf32_h8_mach
!   PARAMS ((flagword));
  static void elf32_h8_final_write_processing
    PARAMS ((bfd *, boolean));
  static boolean elf32_h8_object_p
--- 30,45 ----
    PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
  static void elf32_h8_info_to_howto_rel
    PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
! static bfd_reloc_status_type special 
!   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
! static bfd_reloc_status_type elf32_h8_final_link_relocate
!   PARAMS ((unsigned long, bfd *, bfd *, asection *,
! 	   bfd_byte *, bfd_vma, bfd_vma, bfd_vma,
! 	   struct bfd_link_info *, asection *, int));
! static boolean elf32_h8_relocate_section
!   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
! 	   bfd_byte *, Elf_Internal_Rela *,
! 	   Elf_Internal_Sym *, asection **));
  static void elf32_h8_final_write_processing
    PARAMS ((bfd *, boolean));
  static boolean elf32_h8_object_p
*************** static boolean elf32_h8_symbol_address_p
*** 47,62 ****
  static bfd_byte *elf32_h8_get_relocated_section_contents
    PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
  	   bfd_byte *, boolean, asymbol **));
- static bfd_reloc_status_type elf32_h8_final_link_relocate
-   PARAMS ((unsigned long, bfd *, bfd *, asection *,
- 	   bfd_byte *, bfd_vma, bfd_vma, bfd_vma,
- 	   struct bfd_link_info *, asection *, int));
- static boolean elf32_h8_relocate_section
-   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
- 	   bfd_byte *, Elf_Internal_Rela *,
- 	   Elf_Internal_Sym *, asection **));
- static bfd_reloc_status_type special
-   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
  
  /* This does not include any relocation information, but should be
     good enough for GDB or objdump to read the file.  */
--- 55,60 ----
*************** elf32_h8_relocate_section (output_bfd, i
*** 556,584 ****
    return true;
  }
  
- /* Object files encode the specific H8 model they were compiled
-    for in the ELF flags field.
- 
-    Examine that field and return the proper BFD machine type for
-    the object file.  */
- static unsigned long
- elf32_h8_mach (flags)
-      flagword flags;
- {
-   switch (flags & EF_H8_MACH)
-     {
-     case E_H8_MACH_H8300:
-     default:
-       return bfd_mach_h8300;
- 
-     case E_H8_MACH_H8300H:
-       return bfd_mach_h8300h;
- 
-     case E_H8_MACH_H8300S:
-       return bfd_mach_h8300s;
-     }
- }
- 
  /* The final processing done just before writing out a H8 ELF object
     file.  We use this opportunity to encode the BFD machine type
     into the flags field in the object file.  */
--- 554,559 ----
*************** elf32_h8_final_write_processing (abfd, l
*** 594,613 ****
      {
      default:
      case bfd_mach_h8300:
!       val = E_H8_MACH_H8300;
        break;
  
      case bfd_mach_h8300h:
!       val = E_H8_MACH_H8300H;
        break;
  
      case bfd_mach_h8300s:
!       val = E_H8_MACH_H8300S;
        break;
      }
  
!   elf_elfheader (abfd)->e_flags &= ~ (EF_H8_MACH);
!   elf_elfheader (abfd)->e_flags |= val;
  }
  
  /* Return nonzero if ABFD represents a valid H8 ELF object file; also
--- 569,587 ----
      {
      default:
      case bfd_mach_h8300:
!       val = EM_H8_300;
        break;
  
      case bfd_mach_h8300h:
!       val = EM_H8_300H;
        break;
  
      case bfd_mach_h8300s:
!       val = EM_H8S;
        break;
      }
  
!    elf_elfheader (abfd)->e_machine = val;
  }
  
  /* Return nonzero if ABFD represents a valid H8 ELF object file; also
*************** static boolean
*** 617,624 ****
  elf32_h8_object_p (abfd)
       bfd *abfd;
  {
!   bfd_default_set_arch_mach (abfd, bfd_arch_h8300,
! 			     elf32_h8_mach (elf_elfheader (abfd)->e_flags));
    return true;
  }
  
--- 591,613 ----
  elf32_h8_object_p (abfd)
       bfd *abfd;
  {
!   switch (elf_elfheader(abfd)->e_machine)
!     {
!       case EM_H8_300:
!         bfd_default_set_arch_mach (abfd, bfd_arch_h8300,
! 				   bfd_mach_h8300);
! 	break;
!       case EM_H8_300H:
!         bfd_default_set_arch_mach (abfd, bfd_arch_h8300,
! 				   bfd_mach_h8300h);
! 	break;
!       case EM_H8S:
!         bfd_default_set_arch_mach (abfd, bfd_arch_h8300,
! 				   bfd_mach_h8300s);
! 	break;
!       default:
! 	return false;
!     }
    return true;
  }
  
*************** elf32_h8_get_relocated_section_contents 
*** 1425,1430 ****
--- 1414,1421 ----
  #define TARGET_BIG_NAME			"elf32-h8300"
  #define ELF_ARCH			bfd_arch_h8300
  #define ELF_MACHINE_CODE		EM_H8_300
+ #define ELF_MACHINE_ALT1		EM_H8_300H
+ #define ELF_MACHINE_ALT2		EM_H8S
  #define ELF_MAXPAGESIZE			0x1
  #define bfd_elf32_bfd_reloc_type_lookup elf32_h8_reloc_type_lookup
  #define elf_info_to_howto		elf32_h8_info_to_howto


More information about the Binutils mailing list