This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: H8 support for --gc-sections ?


Hello again,

Here's what I've done (it seems to work for trivial test
cases).  It doesn't look like the H8 stuff does reference
counting, so I don't have to do anything in the "sweep" hook,
right?  

The H8 target also doesn't have any VTINHERIT or VTENTRY
relocation types, so the "mark" hook is even simpler than
usual.

If somebody with better understanding than I wants to take a
look at this, I'd be grateful.



Index: elf32-h8300.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-h8300.c,v
retrieving revision 1.34
diff -U8 -r1.34 elf32-h8300.c
--- elf32-h8300.c	27 Nov 2003 18:49:37 -0000	1.34
+++ elf32-h8300.c	30 Dec 2003 19:09:22 -0000
@@ -42,16 +42,21 @@
   (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
 static bfd_boolean elf32_h8_relax_delete_bytes
   (bfd *, asection *, bfd_vma, int);
 static bfd_boolean elf32_h8_symbol_address_p
   (bfd *, asection *, bfd_vma);
 static bfd_byte *elf32_h8_get_relocated_section_contents
   (bfd *, struct bfd_link_info *, struct bfd_link_order *,
    bfd_byte *, bfd_boolean, asymbol **);
+static asection * elf32_h8_gc_mark_hook
+  (asection *, struct bfd_link_info *, Elf_Internal_Rela *,
+   struct elf_link_hash_entry *, Elf_Internal_Sym *);
+static bfd_boolean elf32_h8_gc_sweep_hook
+  (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
 static bfd_reloc_status_type elf32_h8_final_link_relocate
   (unsigned long, bfd *, bfd *, asection *,
    bfd_byte *, bfd_vma, bfd_vma, bfd_vma,
    struct bfd_link_info *, asection *, int);
 static bfd_boolean elf32_h8_relocate_section
   (bfd *, struct bfd_link_info *, bfd *, asection *,
    bfd_byte *, Elf_Internal_Rela *,
    Elf_Internal_Sym *, asection **);
@@ -1423,16 +1428,49 @@
       && symtab_hdr->contents != (unsigned char *) isymbuf)
     free (isymbuf);
   if (internal_relocs != NULL
       && elf_section_data (input_section)->relocs != internal_relocs)
     free (internal_relocs);
   return NULL;
 }
 
+static asection *
+elf32_h8_gc_mark_hook (asection *sec,
+		     struct bfd_link_info *info ATTRIBUTE_UNUSED,
+		     Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
+		     Elf_Internal_Sym *sym)
+{
+  if (h != NULL)
+    {
+      switch (h->root.type)
+        {
+         case bfd_link_hash_defined:
+         case bfd_link_hash_defweak:
+          return h->root.u.def.section;
+          
+         case bfd_link_hash_common:
+          return h->root.u.c.p->section;
+          
+         default:
+          break;
+        }
+    }
+  else
+    return bfd_section_from_elf_index(sec->owner, sym->st_shndx);
+  return NULL;
+}
+
+static bfd_boolean
+elf32_h8_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
+                        asection *sec, const Elf_Internal_Rela *relocs)
+{
+  return TRUE;
+}
+
 
 #define TARGET_BIG_SYM			bfd_elf32_h8300_vec
 #define TARGET_BIG_NAME			"elf32-h8300"
 #define ELF_ARCH			bfd_arch_h8300
 #define ELF_MACHINE_CODE		EM_H8_300
 #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
@@ -1441,27 +1479,30 @@
 /* So we can set/examine bits in e_flags to get the specific
    H8 architecture in use.  */
 #define elf_backend_final_write_processing \
   elf32_h8_final_write_processing
 #define elf_backend_object_p \
   elf32_h8_object_p
 #define bfd_elf32_bfd_merge_private_bfd_data \
   elf32_h8_merge_private_bfd_data
+#define elf_backend_gc_mark_hook        elf32_h8_gc_mark_hook
+#define elf_backend_gc_sweep_hook       elf32_h8_gc_sweep_hook
 
 /* ??? when elf_backend_relocate_section is not defined, elf32-target.h
    defaults to using _bfd_generic_link_hash_table_create, but
    elflink.h:bfd_elf32_size_dynamic_sections uses
    dynobj = elf_hash_table (info)->dynobj;
    and thus requires an elf hash table.  */
 #define bfd_elf32_bfd_link_hash_table_create _bfd_elf_link_hash_table_create
 
 /* Use an H8 specific linker, not the ELF generic linker.  */
 #define elf_backend_relocate_section elf32_h8_relocate_section
 #define elf_backend_rela_normal		1
+#define elf_backend_can_gc_sections	1
 
 /* And relaxing stuff.  */
 #define bfd_elf32_bfd_relax_section     elf32_h8_relax_section
 #define bfd_elf32_bfd_get_relocated_section_contents \
                                 elf32_h8_get_relocated_section_contents
 
 
 #include "elf32-target.h"


-- 
Grant Edwards
grante@visi.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]