2010-09-24 Thomas Schwinge <thomas@codesourcery.com>
[deliverable/binutils-gdb.git] / bfd / elf32-microblaze.c
index 47e4d518177855e382cf72f1333173b2958671fb..e260c5557758351bfb8e8663a792388153a9e6a8 100644 (file)
@@ -576,7 +576,8 @@ struct elf32_mb_link_hash_table
 /* Get the ELF linker hash table from a link_info structure.  */
 
 #define elf32_mb_hash_table(p)                         \
-  ((struct elf32_mb_link_hash_table *) ((p)->hash))
+  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
+  == MICROBLAZE_ELF_DATA ? ((struct elf32_mb_link_hash_table *) ((p)->hash)) : NULL)
 
 /* Create an entry in a microblaze ELF linker hash table.  */
 
@@ -621,7 +622,8 @@ microblaze_elf_link_hash_table_create (bfd *abfd)
     return NULL;
 
   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
-                                     sizeof (struct elf32_mb_link_hash_entry)))
+                                     sizeof (struct elf32_mb_link_hash_entry),
+                                     MICROBLAZE_ELF_DATA))
     {
       free (ret);
       return NULL;
@@ -709,6 +711,9 @@ microblaze_elf_relocate_section (bfd *output_bfd,
     microblaze_elf_howto_init ();
 
   htab = elf32_mb_hash_table (info);
+  if (htab == NULL)
+    return FALSE;
+
   local_got_offsets = elf_local_got_offsets (input_bfd);
 
   sreloc = elf_section_data (input_section)->sreloc;
@@ -1062,10 +1067,10 @@ microblaze_elf_relocate_section (bfd *output_bfd,
            case (int) R_MICROBLAZE_64:
            case (int) R_MICROBLAZE_32:
              {
-               /* r_symndx will be zero only for relocs against symbols
+               /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
                   from removed linkonce sections, or sections discarded by
                   a linker script.  */
-               if (r_symndx == 0 || (input_section->flags & SEC_ALLOC) == 0)
+               if (r_symndx == STN_UNDEF || (input_section->flags & SEC_ALLOC) == 0)
                  {
                    relocation += addend;
                    if (r_type == R_MICROBLAZE_32)
@@ -1104,7 +1109,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
                  {
                    Elf_Internal_Rela outrel;
                    bfd_byte *loc;
-                   bfd_boolean skip, relocate = FALSE;
+                   bfd_boolean skip;
 
                    /* When generating a shared object, these relocations
                       are copied into the output file to be resolved at run
@@ -1120,7 +1125,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
                    if (outrel.r_offset == (bfd_vma) -1)
                      skip = TRUE;
                    else if (outrel.r_offset == (bfd_vma) -2)
-                     skip = TRUE, relocate = TRUE;
+                     skip = TRUE;
                    outrel.r_offset += (input_section->output_section->vma
                                        + input_section->output_offset);
 
@@ -1867,6 +1872,9 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info)
   if (! _bfd_elf_create_got_section (dynobj, info))
     return FALSE;
   htab = elf32_mb_hash_table (info);
+  if (htab == NULL)
+    return FALSE;
+
   htab->sgot = bfd_get_section_by_name (dynobj, ".got");
   htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
   if (!htab->sgot || !htab->sgotplt)
@@ -1899,14 +1907,15 @@ microblaze_elf_check_relocs (bfd * abfd,
   const Elf_Internal_Rela *     rel;
   const Elf_Internal_Rela *     rel_end;
   struct elf32_mb_link_hash_table *htab;
-  bfd_vma *local_got_offsets;
   asection *sreloc = NULL;
 
   if (info->relocatable)
     return TRUE;
 
   htab = elf32_mb_hash_table (info);
-  local_got_offsets = elf_local_got_offsets (abfd);
+  if (htab == NULL)
+    return FALSE;
+
   symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
   sym_hashes_end = sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
@@ -2148,6 +2157,9 @@ microblaze_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
   struct elf32_mb_link_hash_table *htab;
 
   htab = elf32_mb_hash_table (info);
+  if (htab == NULL)
+    return FALSE;
+
   if (!htab->sgot && !create_got_section (dynobj, info))
     return FALSE;
 
@@ -2228,6 +2240,8 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   bfd *dynobj;
 
   htab = elf32_mb_hash_table (info);
+  if (htab == NULL)
+    return FALSE;
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later,
@@ -2376,6 +2390,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
 
   info = (struct bfd_link_info *) dat;
   htab = elf32_mb_hash_table (info);
+  if (htab == NULL)
+    return FALSE;
 
   if (htab->elf.dynamic_sections_created
       && h->plt.refcount > 0)
@@ -2538,6 +2554,9 @@ microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   bfd *ibfd;
 
   htab = elf32_mb_hash_table (info);
+  if (htab == NULL)
+    return FALSE;
+
   dynobj = htab->elf.dynobj;
   BFD_ASSERT (dynobj != NULL);
 
@@ -2726,11 +2745,11 @@ microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
                                      struct elf_link_hash_entry *h,
                                      Elf_Internal_Sym *sym)
 {
-  bfd *dynobj;
   struct elf32_mb_link_hash_table *htab;
 
   htab = elf32_mb_hash_table (info);
-  dynobj = htab->elf.dynobj;
+  if (htab == NULL)
+    return FALSE;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
@@ -2888,6 +2907,9 @@ microblaze_elf_finish_dynamic_sections (bfd *output_bfd,
   struct elf32_mb_link_hash_table *htab;
 
   htab = elf32_mb_hash_table (info);
+  if (htab == NULL)
+    return FALSE;
+
   dynobj = htab->elf.dynobj;
 
   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
@@ -3004,6 +3026,7 @@ microblaze_elf_add_symbol_hook (bfd *abfd,
 #define TARGET_BIG_NAME                "elf32-microblaze"
 
 #define ELF_ARCH               bfd_arch_microblaze
+#define ELF_TARGET_ID          MICROBLAZE_ELF_DATA
 #define ELF_MACHINE_CODE       EM_MICROBLAZE
 #define ELF_MACHINE_ALT1       EM_MICROBLAZE_OLD
 #define ELF_MAXPAGESIZE                0x4             /* 4k, if we ever have 'em.  */
This page took 0.032698 seconds and 4 git commands to generate.