]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/elf32-i370.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / bfd / elf32-i370.c
index d9e6fbf52806df2a726923050a4a6c2bf9477e0c..88be84b57914243a8887a4ad67f9284e5b4e6404 100644 (file)
@@ -1,6 +1,5 @@
 /* i370-specific support for 32-bit ELF
-   Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005
-   Free Software Foundation, Inc.
+   Copyright (C) 1994-2018 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
    Hacked by Linas Vepstas for i370 linas@linas.org
 
@@ -8,7 +7,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -27,8 +26,8 @@
    else is a wild card.  In particular, don't expect shared libs or
    dynamic loading to work ...  its never been tested.  */
 
-#include "bfd.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
@@ -41,11 +40,11 @@ static reloc_howto_type i370_elf_howto_raw[] =
   /* This reloc does nothing.  */
   HOWTO (R_I370_NONE,          /* type */
         0,                     /* rightshift */
-        2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        32,                    /* bitsize */
+        3,                     /* size (0 = byte, 1 = short, 2 = long) */
+        0,                     /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_bitfield, /* complain_on_overflow */
+        complain_overflow_dont, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_I370_NONE",         /* name */
         FALSE,                 /* partial_inplace */
@@ -267,6 +266,22 @@ i370_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   return i370_elf_howto_table[ (int)i370_reloc ];
 };
 
+static reloc_howto_type *
+i370_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+                           const char *r_name)
+{
+  unsigned int i;
+
+  for (i = 0;
+       i < sizeof (i370_elf_howto_raw) / sizeof (i370_elf_howto_raw[0]);
+       i++)
+    if (i370_elf_howto_raw[i].name != NULL
+       && strcasecmp (i370_elf_howto_raw[i].name, r_name) == 0)
+      return &i370_elf_howto_raw[i];
+
+  return NULL;
+}
+
 /* The name of the dynamic interpreter.  This is put in the .interp
     section.  */
 
@@ -279,12 +294,22 @@ i370_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
                        arelent *cache_ptr,
                        Elf_Internal_Rela *dst)
 {
+  unsigned int r_type;
+
   if (!i370_elf_howto_table[ R_I370_ADDR31 ])
     /* Initialize howto table.  */
     i370_elf_howto_init ();
 
-  BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_I370_max);
-  cache_ptr->howto = i370_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
+  r_type = ELF32_R_TYPE (dst->r_info);
+  if (r_type >= R_I370_max)
+    {
+      /* xgettext:c-format */
+      _bfd_error_handler (_("%B: unrecognised I370 reloc number: %d"),
+                         abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      r_type = R_I370_NONE;
+    }
+  cache_ptr->howto = i370_elf_howto_table[r_type];
 }
 
 /* Hack alert --  the following several routines look generic to me ...
@@ -306,8 +331,9 @@ i370_elf_set_private_flags (bfd *abfd, flagword flags)
    object file when linking.  */
 
 static bfd_boolean
-i370_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
+i370_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 {
+  bfd *obfd = info->output_bfd;
   flagword old_flags;
   flagword new_flags;
 
@@ -328,9 +354,10 @@ i370_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
 
   else                                 /* Incompatible flags.  */
     {
-      (*_bfd_error_handler)
-       ("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
-        ibfd, (long) new_flags, (long) old_flags);
+      _bfd_error_handler
+       /* xgettext:c-format */
+       (_("%B: uses different e_flags (%#x) fields than previous modules (%#x)"),
+        ibfd, new_flags, old_flags);
 
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
@@ -359,9 +386,6 @@ i370_elf_section_from_shdr (bfd *abfd,
 
   newsect = hdr->bfd_section;
   flags = bfd_get_section_flags (abfd, newsect);
-  if (hdr->sh_flags & SHF_EXCLUDE)
-    flags |= SEC_EXCLUDE;
-
   if (hdr->sh_type == SHT_ORDERED)
     flags |= SEC_SORT_ENTRIES;
 
@@ -407,23 +431,23 @@ i370_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
           | SEC_LINKER_CREATED);
 
-  s = bfd_make_section_with_flags (abfd, ".dynsbss",
-                                  SEC_ALLOC | SEC_LINKER_CREATED);
+  s = bfd_make_section_anyway_with_flags (abfd, ".dynsbss",
+                                         SEC_ALLOC | SEC_LINKER_CREATED);
   if (s == NULL)
     return FALSE;
 
-  if (! info->shared)
+  if (! bfd_link_pic (info))
     {
-      s = bfd_make_section_with_flags (abfd, ".rela.sbss",
-                                      flags | SEC_READONLY);
+      s = bfd_make_section_anyway_with_flags (abfd, ".rela.sbss",
+                                             flags | SEC_READONLY);
       if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, 2))
        return FALSE;
     }
 
    /* XXX beats me, seem to need a rela.text ...  */
-   s = bfd_make_section_with_flags (abfd, ".rela.text",
-                                   flags | SEC_READONLY);
+   s = bfd_make_section_anyway_with_flags (abfd, ".rela.text",
+                                          flags | SEC_READONLY);
    if (s == NULL
       || ! bfd_set_section_alignment (abfd, s, 2))
     return FALSE;
@@ -445,7 +469,6 @@ i370_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 {
   bfd *dynobj = elf_hash_table (info)->dynobj;
   asection *s;
-  unsigned int power_of_two;
 
 #ifdef DEBUG
   fprintf (stderr, "i370_elf_adjust_dynamic_symbol called for %s\n",
@@ -455,24 +478,24 @@ i370_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (dynobj != NULL
              && (h->needs_plt
-                 || h->u.weakdef != NULL
+                 || h->is_weakalias
                  || (h->def_dynamic
                      && h->ref_regular
                      && !h->def_regular)));
 
-  s = bfd_get_section_by_name (dynobj, ".rela.text");
+  s = bfd_get_linker_section (dynobj, ".rela.text");
   BFD_ASSERT (s != NULL);
   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->u.weakdef != NULL)
+  if (h->is_weakalias)
     {
-      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;
+      struct elf_link_hash_entry *def = weakdef (h);
+      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
+      h->root.u.def.section = def->root.u.def.section;
+      h->root.u.def.value = def->root.u.def.value;
       return TRUE;
     }
 
@@ -483,16 +506,9 @@ i370_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
      only references to the symbol are via the global offset table.
      For such cases we need not do anything here; the relocations will
      be handled correctly by relocate_section.  */
-  if (info->shared)
+  if (bfd_link_pic (info))
     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
@@ -508,50 +524,29 @@ i370_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
      only if there were actually SDAREL relocs for that symbol.  */
 
   if (h->size <= elf_gp_size (dynobj))
-    s = bfd_get_section_by_name (dynobj, ".dynsbss");
+    s = bfd_get_linker_section (dynobj, ".dynsbss");
   else
-    s = bfd_get_section_by_name (dynobj, ".dynbss");
+    s = bfd_get_linker_section (dynobj, ".dynbss");
   BFD_ASSERT (s != NULL);
 
   /* We must generate a R_I370_COPY reloc to tell the dynamic linker to
      copy the initial value out of the dynamic object and into the
      runtime process image.  We need to remember the offset into the
      .rela.bss section we are going to use.  */
-  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
+  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
     {
       asection *srel;
 
       if (h->size <= elf_gp_size (dynobj))
-       srel = bfd_get_section_by_name (dynobj, ".rela.sbss");
+       srel = bfd_get_linker_section (dynobj, ".rela.sbss");
       else
-       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
+       srel = bfd_get_linker_section (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
       srel->size += sizeof (Elf32_External_Rela);
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 4)
-    power_of_two = 4;
-
-  /* Apply the required alignment.  */
-  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))
-       return FALSE;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (info, h, s);
 }
 \f
 /* Increment the index of a dynamic symbol by a given amount.  Called
@@ -567,13 +562,10 @@ 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
 
-  if (h->root.type == bfd_link_hash_warning)
-    h = (struct elf_link_hash_entry *) h->root.u.i.link;
-
   if (h->dynindx != -1)
     h->dynindx += *cp;
 
@@ -605,9 +597,9 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (info->executable)
+      if (bfd_link_executable (info) && !info->nointerp)
        {
-         s = bfd_get_section_by_name (dynobj, ".interp");
+         s = bfd_get_linker_section (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
@@ -627,7 +619,7 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
 
       for (p = rela_sections; *p != NULL; p++)
        {
-         s = bfd_get_section_by_name (dynobj, *p);
+         s = bfd_get_linker_section (dynobj, *p);
          if (s != NULL)
            s->size = 0;
        }
@@ -655,7 +647,7 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
          /* 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)
            {
@@ -724,7 +716,7 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (!info->shared)
+      if (!bfd_link_pic (info))
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
@@ -766,7 +758,7 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
      locations in linker-created sections that do not have
      externally-visible names. Instead, we should work out precisely
      which sections relocations are targeted at.  */
-  if (info->shared)
+  if (bfd_link_pic (info))
     {
       int c;
 
@@ -813,10 +805,9 @@ i370_elf_check_relocs (bfd *abfd,
   struct elf_link_hash_entry **sym_hashes;
   const Elf_Internal_Rela *rel;
   const Elf_Internal_Rela *rel_end;
-  bfd_vma *local_got_offsets;
   asection *sreloc;
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     return TRUE;
 
 #ifdef DEBUG
@@ -827,7 +818,6 @@ i370_elf_check_relocs (bfd *abfd,
   dynobj = elf_hash_table (info)->dynobj;
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
-  local_got_offsets = elf_local_got_offsets (abfd);
 
   sreloc = NULL;
 
@@ -848,7 +838,7 @@ i370_elf_check_relocs (bfd *abfd,
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
        }
 
-      if (info->shared)
+      if (bfd_link_pic (info))
        {
 #ifdef DEBUG
          fprintf (stderr,
@@ -858,33 +848,11 @@ i370_elf_check_relocs (bfd *abfd,
 #endif
          if (sreloc == NULL)
            {
-             const char *name;
-
-             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;
-
-             BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                         && strcmp (bfd_get_section_name (abfd, sec), name + 5) == 0);
+             sreloc = _bfd_elf_make_dynamic_reloc_section
+               (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
 
-             sreloc = bfd_get_section_by_name (dynobj, name);
              if (sreloc == NULL)
-               {
-                 flagword flags;
-
-                 flags = (SEC_HAS_CONTENTS | SEC_READONLY
-                          | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-                 if ((sec->flags & SEC_ALLOC) != 0)
-                   flags |= SEC_ALLOC | SEC_LOAD;
-                 sreloc = bfd_make_section_with_flags (dynobj, name,
-                                                       flags);
-                 if (sreloc == NULL
-                     || ! bfd_set_section_alignment (dynobj, sreloc, 2))
-                   return FALSE;
-               }
+               return FALSE;
            }
 
          sreloc->size += sizeof (Elf32_External_Rela);
@@ -912,20 +880,20 @@ i370_elf_finish_dynamic_sections (bfd *output_bfd,
 {
   asection *sdyn;
   bfd *dynobj = elf_hash_table (info)->dynobj;
-  asection *sgot = bfd_get_section_by_name (dynobj, ".got");
+  asection *sgot = elf_hash_table (info)->sgot;
 
 #ifdef DEBUG
   fprintf (stderr, "i370_elf_finish_dynamic_sections called\n");
 #endif
 
-  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
+  sdyn = bfd_get_linker_section (dynobj, ".dynamic");
 
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       asection *splt;
       Elf32_External_Dyn *dyncon, *dynconend;
 
-      splt = bfd_get_section_by_name (dynobj, ".plt");
+      splt = elf_hash_table (info)->splt;
       BFD_ASSERT (splt != NULL && sdyn != NULL);
 
       dyncon = (Elf32_External_Dyn *) sdyn->contents;
@@ -933,35 +901,39 @@ i370_elf_finish_dynamic_sections (bfd *output_bfd,
       for (; dyncon < dynconend; dyncon++)
        {
          Elf_Internal_Dyn dyn;
-         const char *name;
+         asection *s;
          bfd_boolean size;
 
          bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
 
          switch (dyn.d_tag)
            {
-           case DT_PLTGOT:   name = ".plt";      size = FALSE; break;
-           case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE;  break;
-           case DT_JMPREL:   name = ".rela.plt"; size = FALSE; break;
-           default:          name = NULL;        size = FALSE; break;
+           case DT_PLTGOT:
+             s = elf_hash_table (info)->splt;
+             size = FALSE;
+             break;
+           case DT_PLTRELSZ:
+             s = elf_hash_table (info)->srelplt;
+             size = TRUE;
+             break;
+           case DT_JMPREL:
+             s = elf_hash_table (info)->srelplt;
+             size = FALSE;
+             break;
+           default:
+             continue;
            }
 
-         if (name != NULL)
+         if (s == NULL)
+           dyn.d_un.d_val = 0;
+         else
            {
-             asection *s;
-
-             s = bfd_get_section_by_name (output_bfd, name);
-             if (s == NULL)
-               dyn.d_un.d_val = 0;
+             if (!size)
+               dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              else
-               {
-                 if (! size)
-                   dyn.d_un.d_ptr = s->vma;
-                 else
-                   dyn.d_un.d_val = s->size;
-               }
-             bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
+               dyn.d_un.d_val = s->size;
            }
+         bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
        }
     }
 
@@ -979,7 +951,7 @@ i370_elf_finish_dynamic_sections (bfd *output_bfd,
       elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
     }
 
-  if (info->shared)
+  if (bfd_link_pic (info))
     {
       asection *sdynsym;
       asection *s;
@@ -988,13 +960,14 @@ i370_elf_finish_dynamic_sections (bfd *output_bfd,
 
       /* Set up the section symbols for the output sections.  */
 
-      sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
+      sdynsym = bfd_get_linker_section (dynobj, ".dynsym");
       BFD_ASSERT (sdynsym != NULL);
 
       sym.st_size = 0;
       sym.st_name = 0;
       sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
       sym.st_other = 0;
+      sym.st_target_internal = 0;
 
       for (s = output_bfd->sections; s != NULL; s = s->next)
        {
@@ -1070,29 +1043,22 @@ i370_elf_relocate_section (bfd *output_bfd,
 {
   Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
-  bfd *dynobj = elf_hash_table (info)->dynobj;
   Elf_Internal_Rela *rel = relocs;
   Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
   asection *sreloc = NULL;
-  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",
+  _bfd_error_handler ("i370_elf_relocate_section called for %B section %A, %u relocations%s",
                      input_bfd, input_section,
-                     (long) input_section->reloc_count,
-                     (info->relocatable) ? " (relocatable)" : "");
+                     input_section->reloc_count,
+                     (bfd_link_relocatable (info)) ? " (relocatable)" : "");
 #endif
 
   if (!i370_elf_howto_table[ R_I370_ADDR31 ])
     /* Initialize howto table if needed.  */
     i370_elf_howto_init ();
 
-  local_got_offsets = elf_local_got_offsets (input_bfd);
-
   for (; rel < relend; rel++)
     {
       enum i370_reloc_type r_type    = (enum i370_reloc_type) ELF32_R_TYPE (rel->r_info);
@@ -1111,9 +1077,9 @@ i370_elf_relocate_section (bfd *output_bfd,
       if ((unsigned) r_type >= (unsigned) R_I370_max
          || !i370_elf_howto_table[(int)r_type])
        {
-         (*_bfd_error_handler) ("%B: unknown relocation type %d",
-                                input_bfd,
-                                (int) r_type);
+         /* xgettext:c-format */
+         _bfd_error_handler (_("%B: unknown relocation type %d"),
+                             input_bfd, (int) r_type);
 
          bfd_set_error (bfd_error_bad_value);
          ret = FALSE;
@@ -1122,6 +1088,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)
        {
@@ -1135,6 +1102,12 @@ i370_elf_relocate_section (bfd *output_bfd,
       else
        {
          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+
+         if (info->wrap_hash != NULL
+             && (input_section->flags & SEC_DEBUGGING) != 0)
+           h = ((struct elf_link_hash_entry *)
+                unwrap_hash_lookup (info, input_bfd, &h->root));
+
          while (h->root.type == bfd_link_hash_indirect
                 || h->root.type == bfd_link_hash_warning)
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
@@ -1143,7 +1116,7 @@ i370_elf_relocate_section (bfd *output_bfd,
              || h->root.type == bfd_link_hash_defweak)
            {
              sec = h->root.u.def.section;
-             if (info->shared
+             if (bfd_link_pic (info)
                  && ((! info->symbolic && h->dynindx != -1)
                      || !h->def_regular)
                  && (input_section->flags & SEC_ALLOC) != 0
@@ -1154,37 +1127,41 @@ 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 (!bfd_link_relocatable (info))
            {
-             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;
+             (*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;
            }
        }
 
+      if (sec != NULL && discarded_section (sec))
+       RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+                                        rel, 1, relend, howto, 0, contents);
+
+      if (bfd_link_relocatable (info))
+       continue;
+
       switch ((int) r_type)
        {
        default:
-         (*_bfd_error_handler)
-           ("%B: unknown relocation type %d for symbol %s",
+         _bfd_error_handler
+           (_("%B: unknown relocation type %d for symbol %s"),
             input_bfd, (int) r_type, sym_name);
 
          bfd_set_error (bfd_error_bad_value);
@@ -1208,8 +1185,8 @@ i370_elf_relocate_section (bfd *output_bfd,
           object.  */
        case (int) R_I370_ADDR31:
        case (int) R_I370_ADDR16:
-         if (info->shared
-             && r_symndx != 0)
+         if (bfd_link_pic (info)
+             && r_symndx != STN_UNDEF)
            {
              Elf_Internal_Rela outrel;
              bfd_byte *loc;
@@ -1227,22 +1204,10 @@ i370_elf_relocate_section (bfd *output_bfd,
 
              if (sreloc == NULL)
                {
-                 const char *name;
-
-                 name = (bfd_elf_string_from_elf_section
-                         (input_bfd,
-                          elf_elfheader (input_bfd)->e_shstrndx,
-                          elf_section_data (input_section)->rel_hdr.sh_name));
-                 if (name == NULL)
+                 sreloc = _bfd_elf_get_dynamic_reloc_section
+                   (input_bfd, input_section, /*rela?*/ TRUE);
+                 if (sreloc == NULL)
                    return FALSE;
-
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (input_bfd,
-                                                              input_section),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 BFD_ASSERT (sreloc != NULL);
                }
 
              skip = 0;
@@ -1290,13 +1255,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);
                            }
@@ -1324,8 +1301,9 @@ i370_elf_relocate_section (bfd *output_bfd,
 
        case (int) R_I370_COPY:
        case (int) R_I370_RELATIVE:
-         (*_bfd_error_handler)
-           ("%B: Relocation %s is not yet supported for symbol %s.",
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%B: Relocation %s is not yet supported for symbol %s."),
             input_bfd,
             i370_elf_howto_table[(int) r_type]->name,
             sym_name);
@@ -1394,18 +1372,8 @@ i370_elf_relocate_section (bfd *output_bfd,
 
   return ret;
 }
-
-static void
-i370_elf_post_process_headers (bfd * abfd,
-                              struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
-{
-  Elf_Internal_Ehdr * i_ehdrp;  /* Elf file header, internal form.  */
-
-  i_ehdrp = elf_elfheader (abfd);
-  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_LINUX;
-}
 \f
-#define TARGET_BIG_SYM         bfd_elf32_i370_vec
+#define TARGET_BIG_SYM         i370_elf32_vec
 #define TARGET_BIG_NAME                "elf32-i370"
 #define ELF_ARCH               bfd_arch_i370
 #define ELF_MACHINE_CODE       EM_S370
@@ -1413,12 +1381,15 @@ i370_elf_post_process_headers (bfd * abfd,
 #define ELF_MACHINE_ALT1       EM_I370_OLD
 #endif
 #define ELF_MAXPAGESIZE                0x1000
+#define ELF_OSABI              ELFOSABI_GNU
+
 #define elf_info_to_howto      i370_elf_info_to_howto
 
 #define elf_backend_plt_not_loaded 1
 #define elf_backend_rela_normal    1
 
 #define bfd_elf32_bfd_reloc_type_lookup                i370_elf_reloc_type_lookup
+#define bfd_elf32_bfd_reloc_name_lookup        i370_elf_reloc_name_lookup
 #define bfd_elf32_bfd_set_private_flags                i370_elf_set_private_flags
 #define bfd_elf32_bfd_merge_private_bfd_data   i370_elf_merge_private_bfd_data
 #define elf_backend_relocate_section           i370_elf_relocate_section
@@ -1427,12 +1398,12 @@ 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
 #define elf_backend_adjust_dynamic_symbol      i370_elf_adjust_dynamic_symbol
 #define elf_backend_check_relocs               i370_elf_check_relocs
-#define elf_backend_post_process_headers       i370_elf_post_process_headers
 
 static int
 i370_noop (void)
@@ -1440,19 +1411,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"