/bfd/ChangeLog
[deliverable/binutils-gdb.git] / bfd / elf-m10300.c
index 7591833589d491ac5c3b7016a809b55900547355..c64d34f4e258f02235639510ef94034111cb154c 100644 (file)
@@ -1,5 +1,5 @@
 /* Matsushita 10300 specific support for 32-bit ELF
-   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -85,7 +85,7 @@ struct elf32_mn10300_link_hash_entry {
      to the target when it's valid and profitable to do so.  */
   unsigned char movm_args;
 
-  /* For funtion symbols, the amount of stack space that would be allocated
+  /* For function symbols, the amount of stack space that would be allocated
      by the movm instruction.  This is redundant with movm_args, but we
      add it to the hash table to avoid computing it over and over.  */
   unsigned char movm_stack_size;
@@ -561,8 +561,9 @@ _bfd_mn10300_elf_create_got_section (abfd, info)
   flagword   flags;
   flagword   pltflags;
   asection * s;
+  struct bfd_link_hash_entry * bh;
   struct elf_link_hash_entry * h;
-  struct elf_backend_data *    bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data * bed = get_elf_backend_data (abfd);
   int ptralign;
 
   /* This function may be called more than once.  */
@@ -604,18 +605,18 @@ _bfd_mn10300_elf_create_got_section (abfd, info)
     {
       /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
         .plt section.  */
-      struct elf_link_hash_entry *h = NULL;
+      bh = NULL;
       if (! (_bfd_generic_link_add_one_symbol
             (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
              (bfd_vma) 0, (const char *) NULL, FALSE,
-             get_elf_backend_data (abfd)->collect,
-             (struct bfd_link_hash_entry **) &h)))
+             get_elf_backend_data (abfd)->collect, &bh)))
        return FALSE;
+      h = (struct elf_link_hash_entry *) bh;
       h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
       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;
     }
 
@@ -638,17 +639,18 @@ _bfd_mn10300_elf_create_got_section (abfd, info)
      (or .got.plt) section.  We don't do this in the linker script
      because we don't want to define the symbol if we are not creating
      a global offset table.  */
-  h = NULL;
+  bh = NULL;
   if (!(_bfd_generic_link_add_one_symbol
        (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
         bed->got_symbol_offset, (const char *) NULL, FALSE,
-        bed->collect, (struct bfd_link_hash_entry **) &h)))
+        bed->collect, &bh)))
     return FALSE;
+  h = (struct elf_link_hash_entry *) bh;
   h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
   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;
 
   elf_hash_table (info)->hgot = h;
@@ -768,14 +770,14 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
        /* This relocation describes the C++ object vtable hierarchy.
           Reconstruct it for later use during GC.  */
        case R_MN10300_GNU_VTINHERIT:
-         if (!_bfd_elf32_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_MN10300_GNU_VTENTRY:
-         if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return FALSE;
          break;
        case R_MN10300_GOT32:
@@ -820,7 +822,7 @@ mn10300_elf_check_relocs (abfd, info, sec, relocs)
              /* Make sure this symbol is output as a dynamic symbol.  */
              if (h->dynindx == -1)
                {
-                 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+                 if (! bfd_elf_link_record_dynamic_symbol (info, h))
                    return FALSE;
                }
 
@@ -1158,9 +1160,8 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
            }
 
          bfd_elf32_swap_reloca_out (output_bfd, &outrel,
-                                    (((Elf32_External_Rela *)
-                                      sreloc->contents)
-                                     + sreloc->reloc_count));
+                                    (bfd_byte *) (((Elf32_External_Rela *) sreloc->contents)
+                                                  + sreloc->reloc_count));
          ++sreloc->reloc_count;
 
          /* If this reloc is against an external symbol, we do
@@ -1295,9 +1296,9 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
            }
 
          bfd_elf32_swap_reloca_out (output_bfd, &outrel,
-                                    (((Elf32_External_Rela *)
-                                      sreloc->contents)
-                                     + sreloc->reloc_count));
+                                    (bfd_byte *) (((Elf32_External_Rela *)
+                                                   sreloc->contents)
+                                                  + sreloc->reloc_count));
          ++sreloc->reloc_count;
 
          return bfd_reloc_ok;
@@ -1480,9 +1481,9 @@ mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
                  outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
                  outrel.r_addend = value;
                  bfd_elf32_swap_reloca_out (output_bfd, &outrel,
-                                            (((Elf32_External_Rela *)
-                                              srelgot->contents)
-                                             + srelgot->reloc_count));
+                                            (bfd_byte *) (((Elf32_External_Rela *)
+                                                           srelgot->contents)
+                                                          + srelgot->reloc_count));
                  ++ srelgot->reloc_count;
                }
 
@@ -1536,15 +1537,14 @@ mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
      asection **local_sections;
 {
   Elf_Internal_Shdr *symtab_hdr;
-  struct elf32_mn10300_link_hash_entry **sym_hashes;
+  struct elf_link_hash_entry **sym_hashes;
   Elf_Internal_Rela *rel, *relend;
 
   if (info->relocatable)
     return TRUE;
 
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
-  sym_hashes = (struct elf32_mn10300_link_hash_entry **)
-                (elf_sym_hashes (input_bfd));
+  sym_hashes = elf_sym_hashes (input_bfd);
 
   rel = relocs;
   relend = relocs + input_section->reloc_count;
@@ -1575,19 +1575,24 @@ mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        {
          sym = local_syms + r_symndx;
          sec = local_sections[r_symndx];
-         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
+         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
        }
       else
        {
-         h = sym_hashes[r_symndx - symtab_hdr->sh_info];
-         while (h->root.root.type == bfd_link_hash_indirect
-                || h->root.root.type == bfd_link_hash_warning)
-           h = (struct elf32_mn10300_link_hash_entry *) h->root.root.u.i.link;
-         if (h->root.root.type == bfd_link_hash_defined
+         bfd_boolean unresolved_reloc;
+         bfd_boolean warned;
+         struct elf_link_hash_entry *hh;
+
+         RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
+                                  r_symndx, symtab_hdr, sym_hashes,
+                                  hh, sec, relocation,
+                                  unresolved_reloc, warned);
+
+         h = (struct elf32_mn10300_link_hash_entry *) hh;
+
+         if ((h->root.root.type == bfd_link_hash_defined
              || h->root.root.type == bfd_link_hash_defweak)
-           {
-             sec = h->root.root.u.def.section;
-             if (   r_type == R_MN10300_GOTPC32
+             && (   r_type == R_MN10300_GOTPC32
                  || r_type == R_MN10300_GOTPC16
                  || ((   r_type == R_MN10300_PLT32
                       || r_type == R_MN10300_PLT16)
@@ -1615,41 +1620,17 @@ mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                             do anything with them here.  */
                          || ((input_section->flags & SEC_DEBUGGING) != 0
                              && (h->root.elf_link_hash_flags
-                                 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))))
-               {
-                 /* In these cases, we don't need the relocation
-                     value.  We check specially because in some
-                     obscure cases sec->output_section will be NULL.  */
-                 relocation = 0;
-               }
-             else if (sec->output_section == NULL)
-               {
-                 (*_bfd_error_handler)
-                   (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
-                    bfd_get_filename (input_bfd), h->root.root.root.string,
-                    bfd_get_section_name (input_bfd, input_section));
-                 relocation = 0;
-               }
-             else            
-               relocation = (h->root.root.u.def.value
-                             + sec->output_section->vma
-                             + sec->output_offset);
-           }
-         else if (h->root.root.type == bfd_link_hash_undefweak)
-           relocation = 0;
-         else if (info->shared && !info->symbolic && !info->no_undefined
-                  && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
+                                 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))))
+           /* In these cases, we don't need the relocation
+              value.  We check specially because in some
+              obscure cases sec->output_section will be NULL.  */
            relocation = 0;
-         else
-           {
-             if (! ((*info->callbacks->undefined_symbol)
-                    (info, h->root.root.root.string, input_bfd,
-                     input_section, rel->r_offset,
-                     (!info->shared || info->no_undefined
-                      || ELF_ST_VISIBILITY (h->root.other)))))
-               return FALSE;
-             relocation = 0;
-           }
+
+         else if (unresolved_reloc)
+           (*_bfd_error_handler)
+             (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
+              bfd_get_filename (input_bfd), h->root.root.root.string,
+              bfd_get_section_name (input_bfd, input_section));
        }
 
       r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
@@ -1761,13 +1742,16 @@ elf32_mn10300_finish_hash_table_entry (gen_entry, in_args)
     byte_count += 2;
 
   /* Count the insn to allocate stack space too.  */
-  if (entry->stack_size > 0 && entry->stack_size <= 128)
-    byte_count += 3;
-  else if (entry->stack_size > 0 && entry->stack_size < 256)
-    byte_count += 4;
+  if (entry->stack_size > 0)
+    {
+      if (entry->stack_size <= 128)
+       byte_count += 3;
+      else
+       byte_count += 4;
+    }
 
   /* If using "call" will result in larger code, then turn all
-     the associated "call" instructions into "calls" instrutions.  */
+     the associated "call" instructions into "calls" instructions.  */
   if (byte_count < entry->direct_calls)
     entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
 
@@ -1777,7 +1761,7 @@ elf32_mn10300_finish_hash_table_entry (gen_entry, in_args)
 
 /* This function handles relaxing for the mn10300.
 
-   There's quite a few relaxing opportunites available on the mn10300:
+   There are quite a few relaxing opportunities available on the mn10300:
 
        * calls:32 -> calls:16                                     2 bytes
        * call:32  -> call:16                                      2 bytes
@@ -2065,7 +2049,7 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
 
                  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
                              - symtab_hdr->sh_info);
-                 hashes = elf_sym_hashes (abfd);
+                 hashes = elf_sym_hashes (input_bfd);
                  end_hashes = hashes + symcount;
                  for (; hashes < end_hashes; hashes++)
                    {
@@ -2256,11 +2240,13 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
                      if (sym_hash->movm_args)
                        bytes += 2;
 
-                     if (sym_hash->stack_size && sym_hash->stack_size <= 128)
-                       bytes += 3;
-                     else if (sym_hash->stack_size
-                              && sym_hash->stack_size < 256)
-                       bytes += 4;
+                     if (sym_hash->stack_size > 0)
+                       {
+                         if (sym_hash->stack_size <= 128)
+                           bytes += 3;
+                         else
+                           bytes += 4;
+                       }
 
                      /* Note that we've deleted prologue bytes for this
                         function.  */
@@ -2283,7 +2269,7 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
                 need insns deleted from their prologues.  */
              symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
                          - symtab_hdr->sh_info);
-             hashes = elf_sym_hashes (abfd);
+             hashes = elf_sym_hashes (input_bfd);
              end_hashes = hashes + symcount;
              for (; hashes < end_hashes; hashes++)
                {
@@ -2308,11 +2294,13 @@ mn10300_elf_relax_section (abfd, sec, link_info, again)
                      if (sym_hash->movm_args)
                        bytes += 2;
 
-                     if (sym_hash->stack_size && sym_hash->stack_size <= 128)
-                       bytes += 3;
-                     else if (sym_hash->stack_size
-                              && sym_hash->stack_size < 256)
-                       bytes += 4;
+                     if (sym_hash->stack_size > 0)
+                       {
+                         if (sym_hash->stack_size <= 128)
+                           bytes += 3;
+                         else
+                           bytes += 4;
+                       }
 
                      /* Note that we've deleted prologue bytes for this
                         function.  */
@@ -3505,7 +3493,7 @@ compute_function_info (abfd, hash, addr, contents)
     }
 
   /* Now figure out how much stack space will be allocated by the movm
-     instruction.  We need this kept separate from the funtion's normal
+     instruction.  We need this kept separate from the function's normal
      stack space.  */
   if (hash->movm_args)
     {
@@ -4026,7 +4014,7 @@ static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
 /* Return offset of the GOT id in PLT0 entry.  */
 #define elf_mn10300_plt0_gotid_offset(info) 9
 
-/* Return offset of the tempoline in PLT entry */
+/* Return offset of the temporary in PLT entry */
 #define elf_mn10300_plt_temp_offset(info) 8
 
 /* Return offset of the symbol in PLT entry.  */
@@ -4049,7 +4037,7 @@ _bfd_mn10300_elf_create_dynamic_sections (abfd, info)
 {
   flagword   flags;
   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)
@@ -4198,7 +4186,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
       /* Make sure this symbol is output as a dynamic symbol.  */
       if (h->dynindx == -1)
        {
-         if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+         if (! bfd_elf_link_record_dynamic_symbol (info, h))
            return FALSE;
        }
 
@@ -4369,7 +4357,7 @@ _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -4503,31 +4491,31 @@ _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
         in by the dynamic linker and used by the debugger.  */
       if (! info->shared)
        {
-         if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
+         if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
            return FALSE;
        }
 
       if (plt)
        {
-         if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
-             || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-             || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
-             || ! bfd_elf32_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_elf32_add_dynamic_entry (info, DT_RELA, 0)
-             || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
-             || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
-                                               sizeof (Elf32_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 (Elf32_External_Rela)))
            return FALSE;
        }
 
       if (reltext)
        {
-         if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
+         if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
            return FALSE;
        }
     }
@@ -4626,8 +4614,8 @@ _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
       rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT);
       rel.r_addend = 0;
       bfd_elf32_swap_reloca_out (output_bfd, &rel,
-                               ((Elf32_External_Rela *) srel->contents
-                                + plt_index));
+                                (bfd_byte *) ((Elf32_External_Rela *) srel->contents
+                                              + plt_index));
 
       if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
        /* Mark the symbol as undefined, rather than as defined in
@@ -4673,8 +4661,8 @@ _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
        }
 
       bfd_elf32_swap_reloca_out (output_bfd, &rel,
-                                ((Elf32_External_Rela *) srel->contents
-                                 + srel->reloc_count));
+                                (bfd_byte *) ((Elf32_External_Rela *) srel->contents
+                                              + srel->reloc_count));
       ++ srel->reloc_count;
     }
 
@@ -4698,8 +4686,8 @@ _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
       rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY);
       rel.r_addend = 0;
       bfd_elf32_swap_reloca_out (output_bfd, &rel,
-                                ((Elf32_External_Rela *) s->contents
-                                 + s->reloc_count));
+                                (bfd_byte *) ((Elf32_External_Rela *) s->contents
+                                              + s->reloc_count));
       ++ s->reloc_count;
     }
 
@@ -4842,12 +4830,14 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
   return TRUE;
 }
 
+#ifndef ELF_ARCH
 #define TARGET_LITTLE_SYM      bfd_elf32_mn10300_vec
 #define TARGET_LITTLE_NAME     "elf32-mn10300"
 #define ELF_ARCH               bfd_arch_mn10300
 #define ELF_MACHINE_CODE       EM_MN10300
 #define ELF_MACHINE_ALT1       EM_CYGNUS_MN10300
 #define ELF_MAXPAGESIZE                0x1000
+#endif
 
 #define elf_info_to_howto              mn10300_info_to_howto
 #define elf_info_to_howto_rel          0
@@ -4864,7 +4854,9 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
 #define bfd_elf32_bfd_link_hash_table_free \
                                elf32_mn10300_link_hash_table_free
 
+#ifndef elf_symbol_leading_char
 #define elf_symbol_leading_char '_'
+#endif
 
 /* So we can set bits in e_flags.  */
 #define elf_backend_final_write_processing \
@@ -4890,6 +4882,5 @@ _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
 #define elf_backend_plt_readonly       1
 #define elf_backend_want_plt_sym       0
 #define elf_backend_got_header_size    12
-#define elf_backend_plt_header_size    PLT0_ENTRY_SIZE
 
 #include "elf32-target.h"
This page took 0.030794 seconds and 4 git commands to generate.