* gdb.base/attach.exp (do_attach_tests): Don't forget to kill second
[deliverable/binutils-gdb.git] / bfd / elf64-sh64.c
index 234b237bd00dd9a771d4c167e6df9f48d8316663..e94aff18c88558a8fe985570d14204d614fa6cf5 100644 (file)
@@ -1,5 +1,5 @@
 /* SuperH SH64-specific support for 64-bit ELF
-   Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -141,11 +141,11 @@ static bfd_boolean sh_elf64_check_relocs
 static int sh64_elf64_get_symbol_type
   (Elf_Internal_Sym *, int);
 static bfd_boolean sh64_elf64_add_symbol_hook
-  (bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, const char **,
+  (bfd *, struct bfd_link_info *, Elf_Internal_Sym *, const char **,
    flagword *, asection **, bfd_vma *);
 static bfd_boolean sh64_elf64_link_output_symbol_hook
-  (bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
-   asection *);
+  (struct bfd_link_info *, const char *, Elf_Internal_Sym *, asection *,
+   struct elf_link_hash_entry *);
 static bfd_boolean sh64_elf64_fake_sections
   (bfd *, Elf_Internal_Shdr *, asection *);
 static void sh64_elf64_final_write_processing
@@ -1532,8 +1532,10 @@ sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
              && r_type <= (int) R_SH_LAST_INVALID_RELOC)
          || (r_type >= (int) R_SH_DIR8WPN
-             && r_type <= (int) R_SH_LAST_INVALID_RELOC_2)
-         || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
+             && r_type <= (int) R_SH_LAST_INVALID_RELOC)
+         || (r_type >= (int) R_SH_GNU_VTINHERIT
+             && r_type <= (int) R_SH_PSHL)
+         || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
              && r_type <= R_SH_GOTPLT32)
          || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
              && r_type <= (int) R_SH_LAST_INVALID_RELOC_4))
@@ -1580,7 +1582,7 @@ sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
            }
          else if (! howto->partial_inplace)
            {
-             relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
+             relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
              relocation |= ((sym->st_other & STO_SH5_ISA32) != 0);
            }
          else if ((sec->flags & SEC_MERGE)
@@ -1610,6 +1612,8 @@ sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
        }
       else
        {
+         /* ??? Could we use the RELOC_FOR_GLOBAL_SYMBOL macro here ?  */
+
          /* Section symbols are never (?) placed in the hash table, so
             we can just ignore hash relocations when creating a
             relocatable object file.  */
@@ -1699,13 +1703,16 @@ sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
            }
          else if (h->root.type == bfd_link_hash_undefweak)
            relocation = 0;
-         else if (info->shared && !info->symbolic && !info->no_undefined)
+         else if (info->unresolved_syms_in_objects == RM_IGNORE
+                  && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            relocation = 0;
          else
            {
              if (! ((*info->callbacks->undefined_symbol)
                     (info, h->root.root.string, input_bfd,
-                     input_section, rel->r_offset, TRUE)))
+                     input_section, rel->r_offset,
+                     (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
+                      || ELF_ST_VISIBILITY (h->other)))))
                return FALSE;
              relocation = 0;
            }
@@ -2184,7 +2191,7 @@ sh_elf64_get_relocated_section_contents (bfd *output_bfd,
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
 
   memcpy (data, elf_section_data (input_section)->this_hdr.contents,
-         input_section->_raw_size);
+         input_section->size);
 
   if ((input_section->flags & SEC_RELOC) != 0
       && input_section->reloc_count > 0)
@@ -2555,14 +2562,14 @@ sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
          /* This relocation describes the C++ object vtable hierarchy.
             Reconstruct it for later use during GC.  */
         case R_SH_GNU_VTINHERIT:
-          if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
+          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
             return FALSE;
           break;
 
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
         case R_SH_GNU_VTENTRY:
-          if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
             return FALSE;
           break;
 
@@ -2612,7 +2619,7 @@ sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                  if (hsh->datalabel_got_offset != (bfd_vma) -1)
                    break;
 
-                 hsh->datalabel_got_offset = sgot->_raw_size;
+                 hsh->datalabel_got_offset = sgot->size;
                }
              else
                {
@@ -2621,17 +2628,17 @@ sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                      /* We have already allocated space in the .got.  */
                      break;
                    }
-                 h->got.offset = sgot->_raw_size;
+                 h->got.offset = sgot->size;
                }
 
              /* Make sure this symbol is output as a dynamic symbol.  */
              if (h->dynindx == -1)
                {
-                 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
+                 if (! bfd_elf_link_record_dynamic_symbol (info, h))
                    return FALSE;
                }
 
-             srelgot->_raw_size += sizeof (Elf64_External_Rela);
+             srelgot->size += sizeof (Elf64_External_Rela);
            }
          else
            {
@@ -2664,7 +2671,7 @@ sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                      break;
                    }
                  local_got_offsets[symtab_hdr->sh_info
-                                   + r_symndx] = sgot->_raw_size;
+                                   + r_symndx] = sgot->size;
                }
              else
                {
@@ -2673,7 +2680,7 @@ sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                      /* We have already allocated space in the .got.  */
                      break;
                    }
-                 local_got_offsets[r_symndx] = sgot->_raw_size;
+                 local_got_offsets[r_symndx] = sgot->size;
                }
 
              if (info->shared)
@@ -2681,11 +2688,11 @@ sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                  /* If we are generating a shared object, we need to
                     output a R_SH_RELATIVE reloc so that the dynamic
                     linker can adjust this GOT entry.  */
-                 srelgot->_raw_size += sizeof (Elf64_External_Rela);
+                 srelgot->size += sizeof (Elf64_External_Rela);
                }
            }
 
-         sgot->_raw_size += 8;
+         sgot->size += 8;
 
          break;
 
@@ -2710,7 +2717,7 @@ sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
          /* Make sure this symbol is output as a dynamic symbol.  */
          if (h->dynindx == -1)
            {
-             if (! bfd_elf64_link_record_dynamic_symbol (info, h))
+             if (! bfd_elf_link_record_dynamic_symbol (info, h))
                return FALSE;
            }
 
@@ -2802,7 +2809,7 @@ sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                    }
                }
 
-             sreloc->_raw_size += sizeof (Elf64_External_Rela);
+             sreloc->size += sizeof (Elf64_External_Rela);
 
              /* If we are linking with -Bsymbolic, and this is a
                 global symbol, we count the number of PC relative
@@ -2880,13 +2887,13 @@ sh64_elf64_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
 
 static bfd_boolean
 sh64_elf64_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
-                           const Elf_Internal_Sym *sym, const char **namep,
+                           Elf_Internal_Sym *sym, const char **namep,
                            flagword *flagsp ATTRIBUTE_UNUSED,
                            asection **secp, bfd_vma *valp)
 {
   /* We want to do this for relocatable as well as final linking.  */
   if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL
-      && info->hash->creator->flavour == bfd_target_elf_flavour)
+      && is_elf_hash_table (info->hash))
     {
       struct elf_link_hash_entry *h;
 
@@ -2917,7 +2924,7 @@ sh64_elf64_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
        {
          /* No previous datalabel symbol.  Make one.  */
          struct bfd_link_hash_entry *bh = NULL;
-         struct elf_backend_data *bed = get_elf_backend_data (abfd);
+         const struct elf_backend_data *bed = get_elf_backend_data (abfd);
 
          if (! _bfd_generic_link_add_one_symbol (info, abfd, dl_name,
                                                  flags, *secp, *valp,
@@ -2976,11 +2983,11 @@ sh64_elf64_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
    DataLabel symbol.  */
 
 static bfd_boolean
-sh64_elf64_link_output_symbol_hook (bfd *abfd ATTRIBUTE_UNUSED,
-                                   struct bfd_link_info *info,
+sh64_elf64_link_output_symbol_hook (struct bfd_link_info *info,
                                    const char *cname,
                                    Elf_Internal_Sym *sym,
-                                   asection *input_sec ATTRIBUTE_UNUSED)
+                                   asection *input_sec ATTRIBUTE_UNUSED,
+                                   struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
 {
   char *name = (char *) cname;
 
@@ -3238,7 +3245,7 @@ sh64_elf64_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
 {
   flagword flags, pltflags;
   register asection *s;
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   int ptralign = 0;
 
   switch (bed->s->arch_size)
@@ -3292,7 +3299,7 @@ sh64_elf64_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
       h->type = STT_OBJECT;
 
       if (info->shared
-         && ! _bfd_elf_link_record_dynamic_symbol (info, h))
+         && ! bfd_elf_link_record_dynamic_symbol (info, h))
        return FALSE;
     }
 
@@ -3418,7 +3425,7 @@ sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
       /* Make sure this symbol is output as a dynamic symbol.  */
       if (h->dynindx == -1)
        {
-         if (! bfd_elf64_link_record_dynamic_symbol (info, h))
+         if (! bfd_elf_link_record_dynamic_symbol (info, h))
            return FALSE;
        }
 
@@ -3427,8 +3434,8 @@ sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
 
       /* If this is the first .plt entry, make room for the special
         first entry.  */
-      if (s->_raw_size == 0)
-       s->_raw_size += PLT_ENTRY_SIZE;
+      if (s->size == 0)
+       s->size += PLT_ENTRY_SIZE;
 
       /* If this symbol is not defined in a regular file, and we are
         not generating a shared library, then set the symbol to this
@@ -3439,26 +3446,26 @@ sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
          && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
        {
          h->root.u.def.section = s;
-         h->root.u.def.value = s->_raw_size;
+         h->root.u.def.value = s->size;
        }
 
-      h->plt.offset = s->_raw_size;
+      h->plt.offset = s->size;
 
       /* Make room for this entry.  */
-      s->_raw_size += elf_sh64_sizeof_plt (info);
+      s->size += elf_sh64_sizeof_plt (info);
 
       /* We also need to make an entry in the .got.plt section, which
         will be placed in the .got section by the linker script.  */
 
       s = bfd_get_section_by_name (dynobj, ".got.plt");
       BFD_ASSERT (s != NULL);
-      s->_raw_size += 8;
+      s->size += 8;
 
       /* We also need to make an entry in the .rela.plt section.  */
 
       s = bfd_get_section_by_name (dynobj, ".rela.plt");
       BFD_ASSERT (s != NULL);
-      s->_raw_size += sizeof (Elf64_External_Rela);
+      s->size += sizeof (Elf64_External_Rela);
 
       return TRUE;
     }
@@ -3513,7 +3520,7 @@ sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
 
       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
-      srel->_raw_size += sizeof (Elf64_External_Rela);
+      srel->size += sizeof (Elf64_External_Rela);
       h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
     }
 
@@ -3524,8 +3531,7 @@ sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
     power_of_two = 3;
 
   /* Apply the required alignment.  */
-  s->_raw_size = BFD_ALIGN (s->_raw_size,
-                           (bfd_size_type) (1 << power_of_two));
+  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
   if (power_of_two > bfd_get_section_alignment (dynobj, s))
     {
       if (! bfd_set_section_alignment (dynobj, s, power_of_two))
@@ -3534,10 +3540,10 @@ sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
-  h->root.u.def.value = s->_raw_size;
+  h->root.u.def.value = s->size;
 
   /* Increment the section size to make room for the symbol.  */
-  s->_raw_size += h->size;
+  s->size += h->size;
 
   return TRUE;
 }
@@ -3563,7 +3569,7 @@ sh64_elf64_discard_copies (struct elf_sh64_link_hash_entry *h,
     return TRUE;
 
   for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
-    s->section->_raw_size -= s->count * sizeof (Elf64_External_Rela);
+    s->section->size -= s->count * sizeof (Elf64_External_Rela);
 
   return TRUE;
 }
@@ -3590,7 +3596,7 @@ sh64_elf64_size_dynamic_sections (bfd *output_bfd,
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
-         s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
+         s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
        }
     }
@@ -3603,7 +3609,7 @@ sh64_elf64_size_dynamic_sections (bfd *output_bfd,
         below.  */
       s = bfd_get_section_by_name (dynobj, ".rela.got");
       if (s != NULL)
-       s->_raw_size = 0;
+       s->size = 0;
     }
 
   /* If this is a -Bsymbolic shared link, then we need to discard all
@@ -3636,7 +3642,7 @@ sh64_elf64_size_dynamic_sections (bfd *output_bfd,
 
       if (strcmp (name, ".plt") == 0)
        {
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              /* Strip this section if we don't need it; see the
                 comment below.  */
@@ -3650,7 +3656,7 @@ sh64_elf64_size_dynamic_sections (bfd *output_bfd,
        }
       else if (strncmp (name, ".rela", 5) == 0)
        {
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              /* If we don't need this section, strip it from the
                 output file.  This is mostly to handle .rela.bss and
@@ -3707,8 +3713,8 @@ sh64_elf64_size_dynamic_sections (bfd *output_bfd,
        }
 
       /* Allocate memory for the section contents.  */
-      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
-      if (s->contents == NULL && s->_raw_size != 0)
+      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
+      if (s->contents == NULL && s->size != 0)
        return FALSE;
     }
 
@@ -3721,31 +3727,31 @@ sh64_elf64_size_dynamic_sections (bfd *output_bfd,
         dynamic linker and used by the debugger.  */
       if (info->executable)
        {
-         if (! bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
+         if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
            return FALSE;
        }
 
       if (plt)
        {
-         if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
+         if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
+             || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
+             || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
+             || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
            return FALSE;
        }
 
       if (relocs)
        {
-         if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
-                                               sizeof (Elf64_External_Rela)))
+         if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
+             || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
+             || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
+                                             sizeof (Elf64_External_Rela)))
            return FALSE;
        }
 
       if (reltext)
        {
-         if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
+         if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
            return FALSE;
        }
     }
@@ -3977,7 +3983,7 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
       BFD_ASSERT (sdyn != NULL);
 
       dyncon = (Elf64_External_Dyn *) sdyn->contents;
-      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
       for (; dyncon < dynconend; dyncon++)
        {
          Elf_Internal_Dyn dyn;
@@ -4027,10 +4033,7 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
            case DT_PLTRELSZ:
              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
              BFD_ASSERT (s != NULL);
-             if (s->_cooked_size != 0)
-               dyn.d_un.d_val = s->_cooked_size;
-             else
-               dyn.d_un.d_val = s->_raw_size;
+             dyn.d_un.d_val = s->size;
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
 
@@ -4046,12 +4049,7 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
                 about changing the DT_RELA entry.  */
              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
              if (s != NULL)
-               {
-                 if (s->_cooked_size != 0)
-                   dyn.d_un.d_val -= s->_cooked_size;
-                 else
-                   dyn.d_un.d_val -= s->_raw_size;
-               }
+               dyn.d_un.d_val -= s->size;
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
            }
@@ -4059,7 +4057,7 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
 
       /* Fill in the first entry in the procedure linkage table.  */
       splt = bfd_get_section_by_name (dynobj, ".plt");
-      if (splt && splt->_raw_size > 0)
+      if (splt && splt->size > 0)
        {
          if (info->shared)
            {
@@ -4095,7 +4093,7 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
     }
 
   /* Fill in the first three entries in the global offset table.  */
-  if (sgot->_raw_size > 0)
+  if (sgot->size > 0)
     {
       if (sdyn == NULL)
        bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
@@ -4112,6 +4110,33 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
   return TRUE;
 }
 
+/* Merge non visibility st_other attribute when the symbol comes from
+   a dynamic object.  */
+static void
+sh64_elf64_merge_symbol_attribute (struct elf_link_hash_entry *h,
+                                  const Elf_Internal_Sym *isym,
+                                  bfd_boolean definition,
+                                  bfd_boolean dynamic)
+{
+  if (isym->st_other != 0 && dynamic)
+    {
+      unsigned char other;
+
+      /* Take the balance of OTHER from the definition.  */
+      other = (definition ? isym->st_other : h->other);
+      other &= ~ ELF_ST_VISIBILITY (-1);
+      h->other = other | ELF_ST_VISIBILITY (h->other);
+    }
+
+  return;
+}
+
+static struct bfd_elf_special_section const sh64_elf64_special_sections[]=
+{
+  { ".cranges", 8, 0, SHT_PROGBITS, 0 },
+  { NULL,       0, 0, 0,            0 }
+};
+
 #define TARGET_BIG_SYM         bfd_elf64_sh64_vec
 #define TARGET_BIG_NAME                "elf64-sh64"
 #define TARGET_LITTLE_SYM      bfd_elf64_sh64l_vec
@@ -4152,6 +4177,9 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
 #define elf_backend_link_output_symbol_hook \
        sh64_elf64_link_output_symbol_hook
 
+#define        elf_backend_merge_symbol_attribute \
+       sh64_elf64_merge_symbol_attribute
+
 #define elf_backend_final_write_processing \
        sh64_elf64_final_write_processing
 
@@ -4167,12 +4195,12 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
                                        sh64_elf64_finish_dynamic_symbol
 #define elf_backend_finish_dynamic_sections \
                                        sh64_elf64_finish_dynamic_sections
+#define elf_backend_special_sections   sh64_elf64_special_sections
 
 #define elf_backend_want_got_plt       1
 #define elf_backend_plt_readonly       1
 #define elf_backend_want_plt_sym       0
 #define elf_backend_got_header_size    24
-#define elf_backend_plt_header_size    PLT_ENTRY_SIZE
 
 #include "elf64-target.h"
 
This page took 0.033718 seconds and 4 git commands to generate.