PR 3958
[deliverable/binutils-gdb.git] / bfd / elf32-i370.c
index d0a28d5b8ade80cca0a268b266f172efab81a2f8..87e2189556e72ccecdeb540f876bd2c960d473de 100644 (file)
@@ -1,6 +1,6 @@
 /* i370-specific support for 32-bit ELF
-   Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005
-   Free Software Foundation, Inc.
+   Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004,
+   2005, 2006 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
    Hacked by Linas Vepstas for i370 linas@linas.org
 
@@ -379,7 +379,7 @@ i370_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
                        Elf_Internal_Shdr *shdr,
                        asection *asect)
 {
-  if ((asect->flags & SEC_EXCLUDE) != 0)
+  if ((asect->flags & (SEC_GROUP | SEC_EXCLUDE)) == SEC_EXCLUDE)
     shdr->sh_flags |= SHF_EXCLUDE;
 
   if ((asect->flags & SEC_SORT_ENTRIES) != 0)
@@ -486,6 +486,13 @@ i370_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   if (info->shared)
     return TRUE;
 
+  if (h->size == 0)
+    {
+      (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
+                            h->root.root.string);
+      return TRUE;
+    }
+
   /* We must allocate the symbol in our .dynbss section, which will
      become part of the .bss section of the executable.  There will be
      an entry for this symbol in the .dynsym section.  The dynamic
@@ -560,7 +567,7 @@ i370_elf_adjust_dynindx (struct elf_link_hash_entry *h, void * cparg)
 
 #ifdef DEBUG
   fprintf (stderr,
-          "i370_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n",
+          "i370_elf_adjust_dynindx called, h->dynindx = %ld, *cp = %d\n",
           h->dynindx, *cp);
 #endif
 
@@ -635,7 +642,6 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
-      bfd_boolean strip;
 
       if ((s->flags & SEC_LINKER_CREATED) == 0)
        continue;
@@ -643,32 +649,15 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
       /* It's OK to base decisions on the section name, because none
         of the dynobj section names depend upon the input files.  */
       name = bfd_get_section_name (dynobj, s);
-      strip = FALSE;
 
       if (strcmp (name, ".plt") == 0)
        {
-         if (s->size == 0)
-           /* Strip this section if we don't need it; see the
-              comment below.  */
-           strip = TRUE;
-         else
-           /* Remember whether there is a PLT.  */
-           plt = TRUE;
+         /* Remember whether there is a PLT.  */
+         plt = s->size != 0;
        }
-      else if (strncmp (name, ".rela", 5) == 0)
+      else if (CONST_STRNEQ (name, ".rela"))
        {
-         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
-              .rela.plt.  We must create both sections in
-              create_dynamic_sections, because they must be created
-              before the linker maps input sections to output
-              sections.  The linker does that before
-              adjust_dynamic_symbol is called, and it is that
-              function which decides whether anything needs to go
-              into these sections.  */
-           strip = TRUE;
-         else
+         if (s->size != 0)
            {
              asection *target;
              const char *outname;
@@ -693,24 +682,35 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
        }
       else if (strcmp (name, ".got") != 0
               && strcmp (name, ".sdata") != 0
-              && strcmp (name, ".sdata2") != 0)
-       /* It's not one of our sections, so don't allocate space.  */
-       continue;
+              && strcmp (name, ".sdata2") != 0
+              && strcmp (name, ".dynbss") != 0
+              && strcmp (name, ".dynsbss") != 0)
+       {
+         /* It's not one of our sections, so don't allocate space.  */
+         continue;
+       }
 
-      if (strip)
+      if (s->size == 0)
        {
-         if (!bfd_section_removed_from_list (s->output_section->owner,
-                                             s->output_section))
-           {
-             bfd_section_list_remove (s->output_section->owner,
-                                      s->output_section);
-             --s->output_section->owner->section_count;
-           }
+         /* If we don't need this section, strip it from the
+            output file.  This is mostly to handle .rela.bss and
+            .rela.plt.  We must create both sections in
+            create_dynamic_sections, because they must be created
+            before the linker maps input sections to output
+            sections.  The linker does that before
+            adjust_dynamic_symbol is called, and it is that
+            function which decides whether anything needs to go
+            into these sections.  */
+         s->flags |= SEC_EXCLUDE;
          continue;
        }
+
+      if ((s->flags & SEC_HAS_CONTENTS) == 0)
+       continue;
+
       /* Allocate memory for the section contents.  */
       s->contents = bfd_zalloc (dynobj, s->size);
-      if (s->contents == NULL && s->size != 0)
+      if (s->contents == NULL)
        return FALSE;
     }
 
@@ -867,7 +867,7 @@ i370_elf_check_relocs (bfd *abfd,
              if (name == NULL)
                return FALSE;
 
-             BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+             BFD_ASSERT (CONST_STRNEQ (name, ".rela")
                          && strcmp (bfd_get_section_name (abfd, sec), name + 5) == 0);
 
              sreloc = bfd_get_section_by_name (dynobj, name);
@@ -965,7 +965,7 @@ i370_elf_finish_dynamic_sections (bfd *output_bfd,
        }
     }
 
-  if (sgot)
+  if (sgot && sgot->size != 0)
     {
       unsigned char *contents = sgot->contents;
 
@@ -1077,9 +1077,6 @@ i370_elf_relocate_section (bfd *output_bfd,
   bfd_vma *local_got_offsets;
   bfd_boolean ret = TRUE;
 
-  if (info->relocatable)
-    return TRUE;
-
 #ifdef DEBUG
   _bfd_error_handler ("i370_elf_relocate_section called for %B section %A, %ld relocations%s",
                      input_bfd, input_section,
@@ -1122,6 +1119,7 @@ i370_elf_relocate_section (bfd *output_bfd,
 
       howto = i370_elf_howto_table[(int) r_type];
       r_symndx = ELF32_R_SYM (rel->r_info);
+      relocation = 0;
 
       if (r_symndx < symtab_hdr->sh_info)
        {
@@ -1154,18 +1152,18 @@ i370_elf_relocate_section (bfd *output_bfd,
                /* 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
                relocation = (h->root.u.def.value
                              + sec->output_section->vma
                              + sec->output_offset);
            }
          else if (h->root.type == bfd_link_hash_undefweak)
-           relocation = 0;
+           ;
          else if (info->unresolved_syms_in_objects == RM_IGNORE
                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
-           relocation = 0;
-         else
+           ;
+         else if (!info->relocatable)
            {
              if ((*info->callbacks->undefined_symbol)
                  (info, h->root.root.string, input_bfd,
@@ -1176,10 +1174,23 @@ i370_elf_relocate_section (bfd *output_bfd,
                  ret = FALSE;
                  continue;
                }
-             relocation = 0;
            }
        }
 
+      if (sec != NULL && elf_discarded_section (sec))
+       {
+         /* For relocs against symbols from removed linkonce sections,
+            or sections discarded by a linker script, we just want the
+            section contents zeroed.  Avoid any special processing.  */
+         _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+         rel->r_info = 0;
+         rel->r_addend = 0;
+         continue;
+       }
+
+      if (info->relocatable)
+       continue;
+
       switch ((int) r_type)
        {
        default:
@@ -1236,7 +1247,7 @@ i370_elf_relocate_section (bfd *output_bfd,
                  if (name == NULL)
                    return FALSE;
 
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
                              && strcmp (bfd_get_section_name (input_bfd,
                                                               input_section),
                                         name + 5) == 0);
@@ -1290,13 +1301,25 @@ i370_elf_relocate_section (bfd *output_bfd,
                        {
                          asection *osec;
 
+                         /* We are turning this relocation into one
+                            against a section symbol.  It would be
+                            proper to subtract the symbol's value,
+                            osec->vma, from the emitted reloc addend,
+                            but ld.so expects buggy relocs.  */
                          osec = sec->output_section;
                          indx = elf_section_data (osec)->dynindx;
-                         BFD_ASSERT(indx > 0);
+                         if (indx == 0)
+                           {
+                             struct elf_link_hash_table *htab;
+                             htab = elf_hash_table (info);
+                             osec = htab->text_index_section;
+                             indx = elf_section_data (osec)->dynindx;
+                           }
+                         BFD_ASSERT (indx != 0);
 #ifdef DEBUG
                          if (indx <= 0)
                            {
-                             printf ("indx=%d section=%s flags=%08x name=%s\n",
+                             printf ("indx=%ld section=%s flags=%08x name=%s\n",
                                      indx, osec->name, osec->flags,
                                      h->root.root.string);
                            }
@@ -1427,6 +1450,7 @@ i370_elf_post_process_headers (bfd * abfd,
    link glibc's ld.so without errors.  */
 #define elf_backend_create_dynamic_sections    i370_elf_create_dynamic_sections
 #define elf_backend_size_dynamic_sections      i370_elf_size_dynamic_sections
+#define elf_backend_init_index_section         _bfd_elf_init_1_index_section
 #define elf_backend_finish_dynamic_sections    i370_elf_finish_dynamic_sections
 #define elf_backend_fake_sections              i370_elf_fake_sections
 #define elf_backend_section_from_shdr          i370_elf_section_from_shdr
@@ -1440,19 +1464,9 @@ i370_noop (void)
   return 1;
 }
 
-/* We need to define these at least as no-ops to link glibc ld.so.  */
-
-#define elf_backend_add_symbol_hook \
-  (bfd_boolean (*) \
-     (bfd *, struct bfd_link_info *, Elf_Internal_Sym *, \
-      const char **, flagword *, asection **, bfd_vma *)) i370_noop
 #define elf_backend_finish_dynamic_symbol \
   (bfd_boolean (*) \
      (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, \
       Elf_Internal_Sym *)) i370_noop
-#define elf_backend_additional_program_headers \
-  (int (*) (bfd *)) i370_noop
-#define elf_backend_modify_segment_map \
-  (bfd_boolean (*) (bfd *, struct bfd_link_info *)) i370_noop
 
 #include "elf32-target.h"
This page took 0.033143 seconds and 4 git commands to generate.