* elf-eh-frame.c (ENSURE_NO_RELOCS): Disregard R_*_NONE relocs.
[deliverable/binutils-gdb.git] / bfd / elf64-s390.c
index 3bba1b3543865913c7788d081443ac28caca74c1..296e349320070c6aa2130652c29cd0a7da2159e2 100644 (file)
@@ -1,5 +1,5 @@
 /* IBM S/390-specific support for 64-bit ELF
-   Copyright 2000, 2001 Free Software Foundation, Inc.
+   Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
    Contributed Martin Schwidefsky (schwidefsky@de.ibm.com).
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -40,12 +40,13 @@ static boolean create_got_section
 static boolean elf_s390_create_dynamic_sections
   PARAMS((bfd *, struct bfd_link_info *));
 static void elf_s390_copy_indirect_symbol
-  PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
+  PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
+          struct elf_link_hash_entry *));
 static boolean elf_s390_check_relocs
   PARAMS ((bfd *, struct bfd_link_info *, asection *,
           const Elf_Internal_Rela *));
 static asection *elf_s390_gc_mark_hook
-  PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
+  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
           struct elf_link_hash_entry *, Elf_Internal_Sym *));
 static boolean elf_s390_gc_sweep_hook
   PARAMS ((bfd *, struct bfd_link_info *, asection *,
@@ -70,8 +71,6 @@ static boolean elf_s390_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static boolean elf_s390_object_p PARAMS ((bfd *));
 
-#define USE_RELA 1             /* We want RELA relocations, not REL.  */
-
 #include "elf/s390.h"
 
 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
@@ -374,6 +373,9 @@ struct elf_s390_link_hash_table
   asection *srelplt;
   asection *sdynbss;
   asection *srelbss;
+
+  /* Small local sym to section mapping cache.  */
+  struct sym_sec_cache sym_sec;
 };
 
 /* Get the s390 ELF linker hash table from a link_info structure.  */
@@ -421,13 +423,13 @@ elf_s390_link_hash_table_create (abfd)
   struct elf_s390_link_hash_table *ret;
   bfd_size_type amt = sizeof (struct elf_s390_link_hash_table);
 
-  ret = (struct elf_s390_link_hash_table *) bfd_alloc (abfd, amt);
+  ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt);
   if (ret == NULL)
     return NULL;
 
   if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc))
     {
-      bfd_release (abfd, ret);
+      free (ret);
       return NULL;
     }
 
@@ -438,6 +440,7 @@ elf_s390_link_hash_table_create (abfd)
   ret->srelplt = NULL;
   ret->sdynbss = NULL;
   ret->srelbss = NULL;
+  ret->sym_sec.abfd = NULL;
 
   return &ret->elf.root;
 }
@@ -467,7 +470,7 @@ create_got_section (dynobj, info)
                                  (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
                                   | SEC_IN_MEMORY | SEC_LINKER_CREATED
                                   | SEC_READONLY))
-      || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
+      || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
     return false;
   return true;
 }
@@ -506,7 +509,8 @@ elf_s390_create_dynamic_sections (dynobj, info)
 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
 
 static void
-elf_s390_copy_indirect_symbol (dir, ind)
+elf_s390_copy_indirect_symbol (bed, dir, ind)
+     struct elf_backend_data *bed;
      struct elf_link_hash_entry *dir, *ind;
 {
   struct elf_s390_link_hash_entry *edir, *eind;
@@ -548,7 +552,7 @@ elf_s390_copy_indirect_symbol (dir, ind)
       eind->dyn_relocs = NULL;
     }
 
-  _bfd_elf_link_hash_copy_indirect (dir, ind);
+  _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
 }
 
 /* Look through the relocs for a section during the first phase, and
@@ -620,7 +624,7 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
              if (local_got_refcounts == NULL)
                {
                  bfd_size_type size;
-               
+
                  size = symtab_hdr->sh_info;
                  size *= sizeof (bfd_signed_vma);
                  local_got_refcounts = ((bfd_signed_vma *)
@@ -644,7 +648,7 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
                return false;
            }
          break;
-       
+
         case R_390_PLT16DBL:
        case R_390_PLT32:
        case R_390_PLT32DBL:
@@ -655,16 +659,16 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
              never referenced by a dynamic object, in which case we
              don't need to generate a procedure linkage table entry
              after all.  */
-       
+
          /* If this is a local symbol, we resolve it directly without
              creating a procedure linkage table entry.  */
          if (h == NULL)
            continue;
-       
+
          h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
          h->plt.refcount += 1;
          break;
-       
+
         case R_390_8:
         case R_390_16:
        case R_390_32:
@@ -683,12 +687,12 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
                 Tentatively set the flag for now, and correct in
                 adjust_dynamic_symbol.  */
              h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
-       
+
              /* We may need a .plt entry if the function this reloc
                 refers to is in a shared lib.  */
              h->plt.refcount += 1;
            }
-       
+
          /* If we are creating a shared library, and this is a reloc
             against a global symbol, or a non PC relative reloc
             against a local symbol, then we need to copy the reloc
@@ -729,6 +733,9 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
                      || (h->elf_link_hash_flags
                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
            {
+             struct elf_s390_dyn_relocs *p;
+             struct elf_s390_dyn_relocs **head;
+
              /* We must copy these reloc types into the output file.
                 Create a reloc section in dynobj and make room for
                 this reloc.  */
@@ -736,14 +743,14 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
                {
                  const char *name;
                  bfd *dynobj;
-               
+
                  name = (bfd_elf_string_from_elf_section
                          (abfd,
                           elf_elfheader (abfd)->e_shstrndx,
                           elf_section_data (sec)->rel_hdr.sh_name));
                  if (name == NULL)
                    return false;
-               
+
                  if (strncmp (name, ".rela", 5) != 0
                      || strcmp (bfd_get_section_name (abfd, sec),
                                 name + 5) != 0)
@@ -752,7 +759,7 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
                        (_("%s: bad relocation section name `%s\'"),
                         bfd_archive_filename (abfd), name);
                    }
-               
+
                  if (htab->elf.dynobj == NULL)
                    htab->elf.dynobj = abfd;
 
@@ -761,7 +768,7 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
                  if (sreloc == NULL)
                    {
                      flagword flags;
-               
+
                      sreloc = bfd_make_section (dynobj, name);
                      flags = (SEC_HAS_CONTENTS | SEC_READONLY
                               | SEC_IN_MEMORY | SEC_LINKER_CREATED);
@@ -769,66 +776,73 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
                        flags |= SEC_ALLOC | SEC_LOAD;
                      if (sreloc == NULL
                          || ! bfd_set_section_flags (dynobj, sreloc, flags)
-                         || ! bfd_set_section_alignment (dynobj, sreloc, 2))
+                         || ! bfd_set_section_alignment (dynobj, sreloc, 3))
                        return false;
                    }
                  elf_section_data (sec)->sreloc = sreloc;
                }
-       
+
              /* If this is a global symbol, we count the number of
                 relocations we need for this symbol.  */
              if (h != NULL)
                {
-                 struct elf_s390_link_hash_entry *eh;
-                 struct elf_s390_dyn_relocs *p;
-               
-                 eh = (struct elf_s390_link_hash_entry *) h;
-                 p = eh->dyn_relocs;
-
-                 if (p == NULL || p->sec != sec)
-                   {
-                     bfd_size_type amt = sizeof *p;
-                     p = ((struct elf_s390_dyn_relocs *)
-                          bfd_alloc (htab->elf.dynobj, amt));
-                     if (p == NULL)
-                       return false;
-                     p->next = eh->dyn_relocs;
-                     eh->dyn_relocs = p;
-                     p->sec = sec;
-                     p->count = 0;
-                     p->pc_count = 0;
-                   }
-               
-                 p->count += 1;
-                 if (ELF64_R_TYPE (rel->r_info) == R_390_PC16
-                     || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL
-                     || ELF64_R_TYPE (rel->r_info) == R_390_PC32
-                     || ELF64_R_TYPE (rel->r_info) == R_390_PC32DBL
-                     || ELF64_R_TYPE (rel->r_info) == R_390_PC64)
-                   p->pc_count += 1;
+                 head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs;
                }
              else
                {
-                 /* Track dynamic relocs needed for local syms too.  */
-                 elf_section_data (sec)->local_dynrel += 1;
+                 /* Track dynamic relocs needed for local syms too.
+                    We really need local syms available to do this
+                    easily.  Oh well.  */
+
+                 asection *s;
+                 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
+                                                sec, r_symndx);
+                 if (s == NULL)
+                   return false;
+
+                 head = ((struct elf_s390_dyn_relocs **)
+                         &elf_section_data (s)->local_dynrel);
+               }
+
+             p = *head;
+             if (p == NULL || p->sec != sec)
+               {
+                 bfd_size_type amt = sizeof *p;
+                 p = ((struct elf_s390_dyn_relocs *)
+                      bfd_alloc (htab->elf.dynobj, amt));
+                 if (p == NULL)
+                   return false;
+                 p->next = *head;
+                 *head = p;
+                 p->sec = sec;
+                 p->count = 0;
+                 p->pc_count = 0;
                }
+
+             p->count += 1;
+             if (ELF64_R_TYPE (rel->r_info) == R_390_PC16
+                 || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL
+                 || ELF64_R_TYPE (rel->r_info) == R_390_PC32
+                 || ELF64_R_TYPE (rel->r_info) == R_390_PC32DBL
+                 || ELF64_R_TYPE (rel->r_info) == R_390_PC64)
+               p->pc_count += 1;
            }
          break;
-       
+
          /* This relocation describes the C++ object vtable hierarchy.
             Reconstruct it for later use during GC.  */
         case R_390_GNU_VTINHERIT:
           if (!_bfd_elf64_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_390_GNU_VTENTRY:
-          if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_offset))
+          if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
             return false;
           break;
-       
+
        default:
          break;
        }
@@ -841,8 +855,8 @@ elf_s390_check_relocs (abfd, info, sec, relocs)
    relocation.  */
 
 static asection *
-elf_s390_gc_mark_hook (abfd, info, rel, h, sym)
-     bfd *abfd;
+elf_s390_gc_mark_hook (sec, info, rel, h, sym)
+     asection *sec;
      struct bfd_link_info *info ATTRIBUTE_UNUSED;
      Elf_Internal_Rela *rel;
      struct elf_link_hash_entry *h;
@@ -872,15 +886,7 @@ elf_s390_gc_mark_hook (abfd, info, rel, h, sym)
        }
     }
   else
-    {
-      if (!(elf_bad_symtab (abfd)
-           && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
-         && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
-               && sym->st_shndx != SHN_COMMON))
-       {
-         return bfd_section_from_elf_index (abfd, sym->st_shndx);
-       }
-    }
+    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
 
   return NULL;
 }
@@ -900,13 +906,8 @@ elf_s390_gc_sweep_hook (abfd, info, sec, relocs)
   const Elf_Internal_Rela *rel, *relend;
   unsigned long r_symndx;
   struct elf_link_hash_entry *h;
-  bfd *dynobj;
 
-  elf_section_data (sec)->local_dynrel = 0;
-
-  dynobj = elf_hash_table (info)->dynobj;
-  if (dynobj == NULL)
-    return true;
+  elf_section_data (sec)->local_dynrel = NULL;
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
@@ -1016,14 +1017,16 @@ elf_s390_adjust_dynamic_symbol (info, h)
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later
-     (although we could actually do it here). */
+     (although we could actually do it here).  */
   if (h->type == STT_FUNC
       || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
     {
       if (h->plt.refcount <= 0
          || (! info->shared
              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
+             && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
+             && h->root.type != bfd_link_hash_undefweak
+             && h->root.type != bfd_link_hash_undefined))
        {
          /* This case can occur if we saw a PLT32 reloc in an input
              file, but the symbol was never referred to by a dynamic
@@ -1164,10 +1167,12 @@ allocate_dynrelocs (h, inf)
   struct elf_s390_link_hash_entry *eh;
   struct elf_s390_dyn_relocs *p;
 
-  if (h->root.type == bfd_link_hash_indirect
-      || h->root.type == bfd_link_hash_warning)
+  if (h->root.type == bfd_link_hash_indirect)
     return true;
 
+  if (h->root.type == bfd_link_hash_warning)
+    h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
   info = (struct bfd_link_info *) inf;
   htab = elf_s390_hash_table (info);
 
@@ -1205,10 +1210,10 @@ allocate_dynrelocs (h, inf)
              h->root.u.def.section = s;
              h->root.u.def.value = h->plt.offset;
            }
-       
+
          /* Make room for this entry.  */
          s->_raw_size += PLT_ENTRY_SIZE;
-       
+
          /* We also need to make an entry in the .got.plt section, which
             will be placed in the .got section by the linker script.  */
          htab->sgotplt->_raw_size += GOT_ENTRY_SIZE;
@@ -1311,7 +1316,7 @@ allocate_dynrelocs (h, inf)
 
       eh->dyn_relocs = NULL;
 
-    keep:
+    keep: ;
     }
 
   /* Finally, allocate space.  */
@@ -1334,6 +1339,9 @@ readonly_dynrelocs (h, inf)
   struct elf_s390_link_hash_entry *eh;
   struct elf_s390_dyn_relocs *p;
 
+  if (h->root.type == bfd_link_hash_warning)
+    h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
   eh = (struct elf_s390_link_hash_entry *) h;
   for (p = eh->dyn_relocs; p != NULL; p = p->next)
     {
@@ -1398,12 +1406,28 @@ elf_s390_size_dynamic_sections (output_bfd, info)
 
       for (s = ibfd->sections; s != NULL; s = s->next)
        {
-         bfd_size_type count = elf_section_data (s)->local_dynrel;
+         struct elf_s390_dyn_relocs *p;
 
-         if (count != 0)
+         for (p = *((struct elf_s390_dyn_relocs **)
+                    &elf_section_data (s)->local_dynrel);
+              p != NULL;
+              p = p->next)
            {
-             srela = elf_section_data (s)->sreloc;
-             srela->_raw_size += count * sizeof (Elf64_External_Rela);
+             if (!bfd_is_abs_section (p->sec)
+                 && bfd_is_abs_section (p->sec->output_section))
+               {
+                 /* Input section has been discarded, either because
+                    it is a copy of a linkonce section or due to
+                    linker script /DISCARD/, so we'll be discarding
+                    the relocs too.  */
+               }
+             else if (p->count != 0)
+               {
+                 srela = elf_section_data (p->sec)->sreloc;
+                 srela->_raw_size += p->count * sizeof (Elf64_External_Rela);
+                 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
+                   info->flags |= DF_TEXTREL;
+               }
            }
        }
 
@@ -1453,7 +1477,7 @@ elf_s390_size_dynamic_sections (output_bfd, info)
        {
          if (s->_raw_size != 0 && s != htab->srelplt)
            relocs = true;
-       
+
          /* We use the reloc_count field as a counter if we need
             to copy relocs into the output file.  */
          s->reloc_count = 0;
@@ -1521,11 +1545,13 @@ elf_s390_size_dynamic_sections (output_bfd, info)
               || !add_dynamic_entry (DT_RELASZ, 0)
               || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
            return false;
-       
+
          /* If any dynamic relocs apply to a read-only section,
             then we need a DT_TEXTREL entry.  */
-         elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, (PTR) info);
-       
+         if ((info->flags & DF_TEXTREL) == 0)
+           elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
+                                   (PTR) info);
+
          if ((info->flags & DF_TEXTREL) != 0)
            {
              if (!add_dynamic_entry (DT_TEXTREL, 0))
@@ -1559,6 +1585,9 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
+  if (info->relocateable)
+    return true;
+
   htab = elf_s390_hash_table (info);
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
@@ -1588,30 +1617,9 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
          bfd_set_error (bfd_error_bad_value);
          return false;
        }
-      howto = elf_howto_table + r_type;
 
+      howto = elf_howto_table + r_type;
       r_symndx = ELF64_R_SYM (rel->r_info);
-
-      if (info->relocateable)
-       {
-         /* This is a relocateable link.  We don't have to change
-            anything, unless the reloc is against a section symbol,
-            in which case we have to adjust according to where the
-            section symbol winds up in the output section.  */
-         if (r_symndx < symtab_hdr->sh_info)
-           {
-             sym = local_syms + r_symndx;
-             if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-               {
-                 sec = local_sections[r_symndx];
-                 rel->r_addend += sec->output_offset + sym->st_value;
-               }
-           }
-
-         continue;
-       }
-
-      /* This is a final link.  */
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -1620,9 +1628,7 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
        {
          sym = local_syms + r_symndx;
          sec = local_sections[r_symndx];
-         relocation = (sec->output_section->vma
-                       + sec->output_offset
-                       + sym->st_value);
+         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
        }
       else
        {
@@ -1635,52 +1641,7 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
              || h->root.type == bfd_link_hash_defweak)
            {
              sec = h->root.u.def.section;
-             if (r_type == R_390_GOTPC
-                 || r_type == R_390_GOTPCDBL
-                 || ((r_type == R_390_PLT16DBL
-                      || r_type == R_390_PLT32
-                      || r_type == R_390_PLT32DBL
-                      || r_type == R_390_PLT64)
-                      && htab->splt != NULL
-                     && h->plt.offset != (bfd_vma) -1)
-                 || ((r_type == R_390_GOT12
-                       || r_type == R_390_GOT16
-                      || r_type == R_390_GOT32
-                      || r_type == R_390_GOT64
-                      || r_type == R_390_GOTENT)
-                     && elf_hash_table (info)->dynamic_sections_created
-                     && (! info->shared
-                         || (! info->symbolic && h->dynindx != -1)
-                         || (h->elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) == 0))
-                 || (info->shared
-                     && ((! info->symbolic && h->dynindx != -1)
-                         || (h->elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) == 0)
-                     && (r_type == R_390_8
-                         || r_type == R_390_16
-                         || r_type == R_390_32
-                         || r_type == R_390_64
-                         || r_type == R_390_PC16
-                         || r_type == R_390_PC16DBL
-                         || r_type == R_390_PC32
-                         || r_type == R_390_PC32DBL
-                         || r_type == R_390_PC64)
-                      && ((input_section->flags & SEC_ALLOC) != 0
-                          /* DWARF will emit R_390_32 relocations in its
-                             sections against symbols defined externally
-                             in shared libraries.  We can't do anything
-                             with them here.  */
-                          || ((input_section->flags & SEC_DEBUGGING) != 0
-                             && (h->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)
+             if (sec->output_section == NULL)
                {
                  /* Set a flag that will be cleared later if we find a
                     relocation value for this symbol.  output_section
@@ -1875,8 +1836,14 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
         case R_390_PC32:
        case R_390_PC32DBL:
         case R_390_PC64:
+         /* r_symndx will be 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)
+           break;
+
           if ((info->shared
-              && (input_section->flags & SEC_ALLOC) != 0
               && ((r_type != R_390_PC16
                    && r_type != R_390_PC16DBL
                    && r_type != R_390_PC32
@@ -1888,7 +1855,6 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
                           || (h->elf_link_hash_flags
                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
              || (!info->shared
-                 && (input_section->flags & SEC_ALLOC) != 0
                  && h != NULL
                  && h->dynindx != -1
                  && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
@@ -1909,28 +1875,21 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
                  time.  */
 
               skip = false;
+              relocate = false;
 
-              if (elf_section_data (input_section)->stab_info == NULL)
-                outrel.r_offset = rel->r_offset;
-              else
-                {
-                  off = (_bfd_stab_section_offset
-                         (output_bfd, htab->elf.stab_info, input_section,
-                          &elf_section_data (input_section)->stab_info,
-                          rel->r_offset));
-                  if (off == (bfd_vma) -1)
-                    skip = true;
-                  outrel.r_offset = off;
-                }
+             outrel.r_offset =
+               _bfd_elf_section_offset (output_bfd, info, input_section,
+                                        rel->r_offset);
+             if (outrel.r_offset == (bfd_vma) -1)
+               skip = true;
+             else if (outrel.r_offset == (bfd_vma) -2)
+               skip = true, relocate = true;
 
               outrel.r_offset += (input_section->output_section->vma
                                   + input_section->output_offset);
 
               if (skip)
-                {
-                  memset (&outrel, 0, sizeof outrel);
-                  relocate = false;
-                }
+               memset (&outrel, 0, sizeof outrel);
               else if (h != NULL
                       && h->dynindx != -1
                       && (r_type == R_390_PC16
@@ -1943,9 +1902,8 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
                           || (h->elf_link_hash_flags
                               & ELF_LINK_HASH_DEF_REGULAR) == 0))
                 {
-                 relocate = false;
                   outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
-                 outrel.r_addend = relocation + rel->r_addend;
+                 outrel.r_addend = rel->r_addend;
                 }
               else
                 {
@@ -1977,9 +1935,11 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
           break;
         }
 
+      /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
+        because such sections are not SEC_ALLOC and thus ld.so will
+        not process them.  */
       if (unresolved_reloc
-         && !(info->shared
-              && (input_section->flags & SEC_DEBUGGING) != 0
+         && !((input_section->flags & SEC_DEBUGGING) != 0
               && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
        (*_bfd_error_handler)
          (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
@@ -1995,7 +1955,7 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
       if (r != bfd_reloc_ok)
        {
          const char *name;
-       
+
          if (h != NULL)
            name = h->root.root.string;
          else
@@ -2008,10 +1968,10 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
              if (*name == '\0')
                name = bfd_section_name (input_bfd, sec);
            }
-       
+
          if (r == bfd_reloc_overflow)
            {
-       
+
              if (! ((*info->callbacks->reloc_overflow)
                     (info, name, howto->name, (bfd_vma) 0,
                      input_bfd, input_section, rel->r_offset)))
@@ -2255,22 +2215,22 @@ elf_s390_finish_dynamic_sections (output_bfd, info)
        {
          Elf_Internal_Dyn dyn;
          asection *s;
-       
+
          bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
-       
+
          switch (dyn.d_tag)
            {
            default:
              continue;
-       
+
            case DT_PLTGOT:
              dyn.d_un.d_ptr = htab->sgot->output_section->vma;
              break;
-       
+
            case DT_JMPREL:
              dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
              break;
-       
+
            case DT_PLTRELSZ:
              s = htab->srelplt->output_section;
              if (s->_cooked_size != 0)
@@ -2278,7 +2238,7 @@ elf_s390_finish_dynamic_sections (output_bfd, info)
              else
                dyn.d_un.d_val = s->_raw_size;
              break;
-       
+
            case DT_RELASZ:
              /* The procedure linkage table relocs (DT_JMPREL) should
                 not be included in the overall relocs (DT_RELA).
@@ -2352,7 +2312,7 @@ static boolean
 elf_s390_object_p (abfd)
      bfd *abfd;
 {
-  return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_esame);
+  return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_64);
 }
 
 /*
@@ -2379,6 +2339,7 @@ const struct elf_size_info s390_elf64_size_info =
   bfd_elf64_write_out_phdrs,
   bfd_elf64_write_shdrs_and_ehdr,
   bfd_elf64_write_relocs,
+  bfd_elf64_swap_symbol_in,
   bfd_elf64_swap_symbol_out,
   bfd_elf64_slurp_reloc_table,
   bfd_elf64_slurp_symbol_table,
@@ -2406,6 +2367,7 @@ const struct elf_size_info s390_elf64_size_info =
 #define elf_backend_want_plt_sym       0
 #define elf_backend_got_header_size    24
 #define elf_backend_plt_header_size    PLT_ENTRY_SIZE
+#define elf_backend_rela_normal                1
 
 #define elf_info_to_howto              elf_s390_info_to_howto
 
This page took 0.034816 seconds and 4 git commands to generate.