2005-03-20 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / bfd / elf32-i370.c
index 83783ae888ba36263782289f2eda860e49ce22a1..2166e8aaa7e2d4404cb32a9036735b15fb34432e 100644 (file)
@@ -1,5 +1,5 @@
 /* i370-specific support for 32-bit ELF
-   Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003
+   Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
    Hacked by Linas Vepstas for i370 linas@linas.org
@@ -286,8 +286,6 @@ static void i370_elf_post_process_headers
   PARAMS ((bfd *, struct bfd_link_info *));
 static bfd_boolean i370_elf_create_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
-static bfd_boolean i370_elf_section_from_shdr
-  PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
 static bfd_boolean i370_elf_fake_sections
   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
 static bfd_boolean i370_elf_check_relocs
@@ -367,8 +365,8 @@ i370_elf_merge_private_bfd_data (ibfd, obfd)
   else                                 /* Incompatible flags */
     {
       (*_bfd_error_handler)
-       ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
-        bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
+       ("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
+        ibfd, (long) new_flags, (long) old_flags);
 
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
@@ -385,15 +383,15 @@ i370_elf_merge_private_bfd_data (ibfd, obfd)
  */
 
 static bfd_boolean
-i370_elf_section_from_shdr (abfd, hdr, name)
-     bfd *abfd;
-     Elf_Internal_Shdr *hdr;
-     const char *name;
+i370_elf_section_from_shdr (bfd *abfd,
+                           Elf_Internal_Shdr *hdr,
+                           const char *name,
+                           int shindex)
 {
   asection *newsect;
   flagword flags;
 
-  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
+  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
     return FALSE;
 
   newsect = hdr->bfd_section;
@@ -500,28 +498,25 @@ i370_elf_adjust_dynamic_symbol (info, h)
 
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (dynobj != NULL
-             && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
-                 || h->weakdef != NULL
-                 || ((h->elf_link_hash_flags
-                      & ELF_LINK_HASH_DEF_DYNAMIC) != 0
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_REF_REGULAR) != 0
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) == 0)));
+             && (h->needs_plt
+                 || h->u.weakdef != NULL
+                 || (h->def_dynamic
+                     && h->ref_regular
+                     && !h->def_regular)));
 
   s = bfd_get_section_by_name (dynobj, ".rela.text");
   BFD_ASSERT (s != NULL);
-  s->_raw_size += sizeof (Elf32_External_Rela);
+  s->size += sizeof (Elf32_External_Rela);
 
   /* If this is a weak symbol, and there is a real definition, the
      processor independent code will have arranged for us to see the
      real definition first, and we can just use the same value.  */
-  if (h->weakdef != NULL)
+  if (h->u.weakdef != NULL)
     {
-      BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
-                 || h->weakdef->root.type == bfd_link_hash_defweak);
-      h->root.u.def.section = h->weakdef->root.u.def.section;
-      h->root.u.def.value = h->weakdef->root.u.def.value;
+      BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
+                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
+      h->root.u.def.section = h->u.weakdef->root.u.def.section;
+      h->root.u.def.value = h->u.weakdef->root.u.def.value;
       return TRUE;
     }
 
@@ -568,8 +563,8 @@ i370_elf_adjust_dynamic_symbol (info, h)
       else
        srel = bfd_get_section_by_name (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
-      srel->_raw_size += sizeof (Elf32_External_Rela);
-      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
+      srel->size += sizeof (Elf32_External_Rela);
+      h->needs_copy = 1;
     }
 
   /* We need to figure out the alignment required for this symbol.  I
@@ -579,8 +574,7 @@ i370_elf_adjust_dynamic_symbol (info, h)
     power_of_two = 4;
 
   /* 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))
@@ -589,10 +583,10 @@ i370_elf_adjust_dynamic_symbol (info, h)
 
   /* 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;
 }
@@ -657,7 +651,7 @@ i370_elf_size_dynamic_sections (output_bfd, info)
        {
          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;
        }
     }
@@ -677,7 +671,7 @@ i370_elf_size_dynamic_sections (output_bfd, info)
        {
          s = bfd_get_section_by_name (dynobj, *p);
          if (s != NULL)
-           s->_raw_size = 0;
+           s->size = 0;
        }
     }
 
@@ -702,7 +696,7 @@ i370_elf_size_dynamic_sections (output_bfd, info)
 
       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.  */
@@ -716,7 +710,7 @@ i370_elf_size_dynamic_sections (output_bfd, info)
        }
       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
@@ -778,8 +772,8 @@ i370_elf_size_dynamic_sections (output_bfd, info)
          continue;
        }
       /* 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;
     }
 
@@ -791,7 +785,7 @@ i370_elf_size_dynamic_sections (output_bfd, info)
         the .dynamic section.  The DT_DEBUG entry is filled in by the
         dynamic linker and used by the debugger.  */
 #define add_dynamic_entry(TAG, VAL) \
-  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
+  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
       if (!info->shared)
        {
@@ -834,7 +828,7 @@ i370_elf_size_dynamic_sections (output_bfd, info)
      FIXME: We assume that there will never be relocations to
      locations in linker-created sections that do not have
      externally-visible names. Instead, we should work out precisely
-     which sections relocations are targetted at.  */
+     which sections relocations are targeted at.  */
   if (info->shared)
     {
       int c;
@@ -892,9 +886,8 @@ i370_elf_check_relocs (abfd, info, sec, relocs)
     return TRUE;
 
 #ifdef DEBUG
-  fprintf (stderr, "i370_elf_check_relocs called for section %s in %s\n",
-          bfd_get_section_name (abfd, sec),
-          bfd_archive_filename (abfd));
+  _bfd_error_handler ("i370_elf_check_relocs called for section %A in %B",
+                     sec, abfd);
 #endif
 
   dynobj = elf_hash_table (info)->dynobj;
@@ -955,7 +948,7 @@ i370_elf_check_relocs (abfd, info, sec, relocs)
                }
            }
 
-         sreloc->_raw_size += sizeof (Elf32_External_Rela);
+         sreloc->size += sizeof (Elf32_External_Rela);
 
          /* FIXME: We should here do what the m68k and i386
             backends do: if the reloc is pc-relative, record it
@@ -999,7 +992,7 @@ i370_elf_finish_dynamic_sections (output_bfd, info)
       BFD_ASSERT (splt != NULL && sdyn != NULL);
 
       dyncon = (Elf32_External_Dyn *) sdyn->contents;
-      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
       for (; dyncon < dynconend; dyncon++)
        {
          Elf_Internal_Dyn dyn;
@@ -1028,12 +1021,7 @@ i370_elf_finish_dynamic_sections (output_bfd, info)
                  if (! size)
                    dyn.d_un.d_ptr = s->vma;
                  else
-                   {
-                     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_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
            }
@@ -1162,11 +1150,10 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
     return TRUE;
 
 #ifdef DEBUG
-  fprintf (stderr, "i370_elf_relocate_section called for %s section %s, %ld relocations%s\n",
-          bfd_archive_filename (input_bfd),
-          bfd_section_name(input_bfd, input_section),
-          (long) input_section->reloc_count,
-          (info->relocatable) ? " (relocatable)" : "");
+  _bfd_error_handler ("i370_elf_relocate_section called for %B section %A, %ld relocations%s",
+                     input_bfd, input_section,
+                     (long) input_section->reloc_count,
+                     (info->relocatable) ? " (relocatable)" : "");
 #endif
 
   if (!i370_elf_howto_table[ R_I370_ADDR31 ])  /* Initialize howto table if needed */
@@ -1192,8 +1179,8 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
       if ((unsigned)r_type >= (unsigned)R_I370_max
          || !i370_elf_howto_table[(int)r_type])
        {
-         (*_bfd_error_handler) ("%s: unknown relocation type %d",
-                                bfd_archive_filename (input_bfd),
+         (*_bfd_error_handler) ("%B: unknown relocation type %d",
+                                input_bfd,
                                 (int) r_type);
 
          bfd_set_error (bfd_error_bad_value);
@@ -1226,8 +1213,7 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              sec = h->root.u.def.section;
              if (info->shared
                  && ((! info->symbolic && h->dynindx != -1)
-                     || (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) == 0)
+                     || !h->def_regular)
                  && (input_section->flags & SEC_ALLOC) != 0
                  && (r_type == R_I370_ADDR31
                      || r_type == R_I370_COPY
@@ -1246,19 +1232,21 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            }
          else if (h->root.type == bfd_link_hash_undefweak)
            relocation = 0;
-         else if (info->shared
+         else if (info->unresolved_syms_in_objects == RM_IGNORE
                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            relocation = 0;
          else
            {
-             (*info->callbacks->undefined_symbol) (info,
-                                                   h->root.root.string,
-                                                   input_bfd,
-                                                   input_section,
-                                                   rel->r_offset,
-                                                   TRUE);
-             ret = FALSE;
-             continue;
+             if ((*info->callbacks->undefined_symbol)
+                 (info, h->root.root.string, input_bfd,
+                  input_section, rel->r_offset,
+                  (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
+                   || ELF_ST_VISIBILITY (h->other))))
+               {
+                 ret = FALSE;
+                 continue;
+               }
+             relocation = 0;
            }
        }
 
@@ -1266,9 +1254,8 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        {
        default:
          (*_bfd_error_handler)
-           ("%s: unknown relocation type %d for symbol %s",
-            bfd_archive_filename (input_bfd),
-            (int) r_type, sym_name);
+           ("%B: unknown relocation type %d for symbol %s",
+            input_bfd, (int) r_type, sym_name);
 
          bfd_set_error (bfd_error_bad_value);
          ret = FALSE;
@@ -1345,8 +1332,7 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                  become local.  */
              else if (h != NULL
                       && ((! info->symbolic && h->dynindx != -1)
-                          || (h->elf_link_hash_flags
-                              & ELF_LINK_HASH_DEF_REGULAR) == 0))
+                          || !h->def_regular))
                {
                  BFD_ASSERT (h->dynindx != -1);
                  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
@@ -1409,8 +1395,8 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        case (int)R_I370_COPY:
        case (int)R_I370_RELATIVE:
          (*_bfd_error_handler)
-           ("%s: Relocation %s is not yet supported for symbol %s.",
-            bfd_archive_filename (input_bfd),
+           ("%B: Relocation %s is not yet supported for symbol %s.",
+            input_bfd,
             i370_elf_howto_table[(int) r_type]->name,
             sym_name);
 
@@ -1450,7 +1436,7 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                const char *name;
 
                if (h != NULL)
-                 name = h->root.root.string;
+                 name = NULL;
                else
                  {
                    name = bfd_elf_string_from_elf_section (input_bfd,
@@ -1464,6 +1450,7 @@ i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                  }
 
                (*info->callbacks->reloc_overflow) (info,
+                                                   (h ? &h->root : NULL),
                                                    name,
                                                    howto->name,
                                                    (bfd_vma) 0,
@@ -1546,7 +1533,7 @@ static int i370_noop ()
 
 #define elf_backend_add_symbol_hook \
   (bfd_boolean (*) \
-     PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, \
+     PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Sym *, \
              const char **, flagword *, asection **, bfd_vma *))) i370_noop
 #define elf_backend_finish_dynamic_symbol \
   (bfd_boolean (*) \
@@ -1555,6 +1542,6 @@ static int i370_noop ()
 #define elf_backend_additional_program_headers \
   (int (*) PARAMS ((bfd *))) i370_noop
 #define elf_backend_modify_segment_map \
-  (bfd_boolean (*) PARAMS ((bfd *))) i370_noop
+  (bfd_boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) i370_noop
 
 #include "elf32-target.h"
This page took 0.031265 seconds and 4 git commands to generate.