Blame SOURCES/binutils-copy-multiple-relocs.patch

7db648
diff -rup binutils.orig/bfd/elf-bfd.h binutils-2.30/bfd/elf-bfd.h
7db648
--- binutils.orig/bfd/elf-bfd.h	2020-02-12 13:31:20.348605538 +0000
7db648
+++ binutils-2.30/bfd/elf-bfd.h	2020-02-12 13:31:33.831507582 +0000
7db648
@@ -1479,6 +1479,19 @@ struct elf_backend_data
7db648
   /* Opcode representing no unwind.  */
7db648
   int (*cant_unwind_opcode) (struct bfd_link_info *);
7db648
 
7db648
+  /* Called when a section has extra reloc sections.  */
7db648
+  bfd_boolean (*init_secondary_reloc_section) (bfd *, Elf_Internal_Shdr *, const char *, unsigned int);
7db648
+
7db648
+  /* Called when after loading the normal relocs for a section.  */
7db648
+  bfd_boolean (*slurp_secondary_relocs) (bfd *, asection *, asymbol **);
7db648
+
7db648
+  /* Called after writing the normal relocs for a section.  */
7db648
+  bfd_boolean (*write_secondary_relocs) (bfd *, asection *);
7db648
+
7db648
+  /* Called to return the value to set in the ST_SHNDX field of an ELF symbol
7db648
+     from an iternal symbol which does not map to any known section.  */
7db648
+  unsigned int (*symbol_section_index) (bfd *, elf_symbol_type *);
7db648
+  
7db648
   /* This is non-zero if static TLS segments require a special alignment.  */
7db648
   unsigned static_tls_alignment;
7db648
 
7db648
@@ -2696,6 +2709,19 @@ extern bfd_vma elf64_r_sym (bfd_vma);
7db648
 extern bfd_vma elf32_r_info (bfd_vma, bfd_vma);
7db648
 extern bfd_vma elf32_r_sym (bfd_vma);
7db648
 
7db648
+
7db648
+extern bfd_boolean _bfd_elf_init_secondary_reloc_section
7db648
+  (bfd *, Elf_Internal_Shdr *, const char *, unsigned int);
7db648
+extern bfd_boolean _bfd_elf_slurp_secondary_reloc_section
7db648
+  (bfd *, asection *, asymbol **);
7db648
+extern bfd_boolean _bfd_elf_copy_special_section_fields
7db648
+  (const bfd *, bfd *, const Elf_Internal_Shdr *, Elf_Internal_Shdr *);
7db648
+extern bfd_boolean _bfd_elf_write_secondary_reloc_section
7db648
+  (bfd *, asection *);
7db648
+extern unsigned int _bfd_elf_symbol_section_index
7db648
+  (bfd *, elf_symbol_type *);
7db648
+
7db648
+
7db648
 /* Large common section.  */
7db648
 extern asection _bfd_elf_large_com_section;
7db648
 
7db648
diff -rup binutils.orig/bfd/elf.c binutils-2.30/bfd/elf.c
7db648
--- binutils.orig/bfd/elf.c	2020-02-12 13:31:20.347605546 +0000
7db648
+++ binutils-2.30/bfd/elf.c	2020-02-12 13:33:19.635738944 +0000
7db648
@@ -1572,7 +1572,7 @@ _bfd_elf_copy_private_bfd_data (bfd *ibf
7db648
 	  /* Final attempt.  Call the backend copy function
7db648
 	     with a NULL input section.  */
7db648
 	  if (bed->elf_backend_copy_special_section_fields != NULL)
7db648
-	    bed->elf_backend_copy_special_section_fields (ibfd, obfd, NULL, oheader);
7db648
+	    (void) bed->elf_backend_copy_special_section_fields (ibfd, obfd, NULL, oheader);
7db648
 	}
7db648
     }
7db648
 
7db648
@@ -2416,11 +2416,14 @@ bfd_section_from_shdr (bfd *abfd, unsign
7db648
 	   sections.  */
7db648
 	if (*p_hdr != NULL)
7db648
 	  {
7db648
-	    _bfd_error_handler
7db648
-	      /* xgettext:c-format */
7db648
-	      (_("%B: warning: multiple relocation sections for section %A \
7db648
-found - ignoring all but the first"),
7db648
-	       abfd, target_sect);
7db648
+	    if (bed->init_secondary_reloc_section == NULL
7db648
+		|| ! bed->init_secondary_reloc_section (abfd, hdr, name, shindex))
7db648
+	      {
7db648
+		_bfd_error_handler
7db648
+		  /* xgettext:c-format */
7db648
+		  (_("%pB: warning: secondary relocation section '%s' for section %pA found - ignoring"),
7db648
+		   abfd, name, target_sect);
7db648
+	      }
7db648
 	    goto success;
7db648
 	  }
7db648
 	hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, sizeof (*hdr2));
7db648
@@ -7948,9 +7951,20 @@ error_return:
7db648
 		  if (elf_symtab_shndx_list (abfd))
7db648
 		    shndx = elf_symtab_shndx_list (abfd)->ndx;
7db648
 		  break;
7db648
-		default:
7db648
+		case SHN_COMMON:
7db648
+		case SHN_ABS:
7db648
 		  shndx = SHN_ABS;
7db648
 		  break;
7db648
+		default:
7db648
+		  if (bed->symbol_section_index)
7db648
+		    shndx = bed->symbol_section_index (abfd, type_ptr);
7db648
+		  else
7db648
+		    {
7db648
+		      _bfd_error_handler (_("%pB: Unable to handle section index %x in ELF symbol.  Using ABS instead. (%x)"),
7db648
+					  abfd, shndx, SHN_COMMON);
7db648
+		      shndx = SHN_ABS;
7db648
+		    }
7db648
+		  break;
7db648
 		}
7db648
 	    }
7db648
 	  else
7db648
@@ -11556,3 +11570,354 @@ _bfd_elf_maybe_function_sym (const asymb
7db648
     size = 1;
7db648
   return size;
7db648
 }
7db648
+
7db648
+/* Set to non-zero to enable some debug messages.  */
7db648
+#define DEBUG_SECONDARY_RELOCS	 0
7db648
+
7db648
+/* An internal-to-the-bfd-library only section type
7db648
+   used to indicate a cached secondary reloc section.  */
7db648
+#define SHT_SECONDARY_RELOC	 (SHT_LOOS + SHT_RELA)
7db648
+
7db648
+/* Create a BFD section to hold a secondary reloc section.  */
7db648
+
7db648
+bfd_boolean
7db648
+_bfd_elf_init_secondary_reloc_section (bfd * abfd,
7db648
+				       Elf_Internal_Shdr *hdr,
7db648
+				       const char * name,
7db648
+				       unsigned int shindex)
7db648
+{
7db648
+  /* We only support RELA secondary relocs.  */
7db648
+  if (hdr->sh_type != SHT_RELA)
7db648
+    return FALSE;
7db648
+
7db648
+#if DEBUG_SECONDARY_RELOCS
7db648
+  fprintf (stderr, "secondary reloc section %s encountered\n", name);
7db648
+#endif
7db648
+  hdr->sh_type = SHT_SECONDARY_RELOC;
7db648
+  return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
7db648
+}
7db648
+
7db648
+/* Read in any secondary relocs associated with SEC.  */
7db648
+
7db648
+bfd_boolean
7db648
+_bfd_elf_slurp_secondary_reloc_section (bfd *      abfd,
7db648
+					asection * sec,
7db648
+					asymbol ** symbols)
7db648
+{
7db648
+  const struct elf_backend_data * const ebd = get_elf_backend_data (abfd);
7db648
+  asection * relsec;
7db648
+  bfd_boolean result = TRUE;
7db648
+  bfd_vma (*r_sym) (bfd_vma);
7db648
+
7db648
+
7db648
+#ifdef BFD64
7db648
+  if (bfd_arch_bits_per_address (abfd) != 32)
7db648
+    r_sym = elf64_r_sym;
7db648
+  else
7db648
+#endif
7db648
+    r_sym = elf32_r_sym;
7db648
+  
7db648
+  /* Discover if there are any secondary reloc sections
7db648
+     associated with SEC.  */
7db648
+  for (relsec = abfd->sections; relsec != NULL; relsec = relsec->next)
7db648
+    {
7db648
+      Elf_Internal_Shdr * hdr = & elf_section_data (relsec)->this_hdr;
7db648
+
7db648
+      if (hdr->sh_type == SHT_SECONDARY_RELOC
7db648
+	  && hdr->sh_info == (unsigned) elf_section_data (sec)->this_idx)
7db648
+	{
7db648
+	  bfd_byte * native_relocs;
7db648
+	  bfd_byte * native_reloc;
7db648
+	  arelent * internal_relocs;
7db648
+	  arelent * internal_reloc;
7db648
+	  unsigned int i;
7db648
+	  unsigned int entsize;
7db648
+	  unsigned int symcount;
7db648
+	  unsigned int reloc_count;
7db648
+
7db648
+#if DEBUG_SECONDARY_RELOCS
7db648
+	  fprintf (stderr, "read secondary relocs for %s from %s\n", sec->name, relsec->name);
7db648
+#endif
7db648
+	  entsize = hdr->sh_entsize;
7db648
+
7db648
+	  native_relocs = bfd_malloc (hdr->sh_size);
7db648
+	  if (native_relocs == NULL)
7db648
+	    {
7db648
+	      result = FALSE;
7db648
+	      continue;
7db648
+	    }
7db648
+
7db648
+	  reloc_count = NUM_SHDR_ENTRIES (hdr);
7db648
+	  internal_relocs = (arelent *) bfd_alloc2 (abfd, reloc_count, sizeof (arelent));
7db648
+	  if (internal_relocs == NULL)
7db648
+	    {
7db648
+	      free (native_relocs);
7db648
+	      result = FALSE;
7db648
+	      continue;
7db648
+	    }
7db648
+
7db648
+	  if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
7db648
+	      || (bfd_bread (native_relocs, hdr->sh_size, abfd) != hdr->sh_size))
7db648
+	    {
7db648
+	      free (native_relocs);
7db648
+	      free (internal_relocs);
7db648
+	      result = FALSE;
7db648
+	      continue;
7db648
+	    }
7db648
+
7db648
+	  symcount = bfd_get_symcount (abfd);
7db648
+
7db648
+	  for (i = 0, internal_reloc = internal_relocs, native_reloc = native_relocs;
7db648
+	       i < reloc_count;
7db648
+	       i++, internal_reloc++, native_reloc += entsize)
7db648
+	    {
7db648
+	      ;
7db648
+	      Elf_Internal_Rela rela;
7db648
+
7db648
+	      ebd->s->swap_reloca_in (abfd, native_reloc, & rela);
7db648
+
7db648
+	      /* The address of an ELF reloc is section relative for an object
7db648
+		 file, and absolute for an executable file or shared library.
7db648
+		 The address of a normal BFD reloc is always section relative,
7db648
+		 and the address of a dynamic reloc is absolute..  */
7db648
+	      if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
7db648
+		internal_reloc->address = rela.r_offset;
7db648
+	      else
7db648
+		internal_reloc->address = rela.r_offset - sec->vma;
7db648
+
7db648
+	      if (r_sym (rela.r_info) == STN_UNDEF)
7db648
+		{
7db648
+		  /* FIXME: This and the error case below mean that we
7db648
+		     have a symbol on relocs that is not elf_symbol_type.  */
7db648
+		  internal_reloc->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
7db648
+		}
7db648
+	      else if (r_sym (rela.r_info) > symcount)
7db648
+		{
7db648
+		  _bfd_error_handler
7db648
+		    /* xgettext:c-format */
7db648
+		    (_("%pB(%pA): relocation %d has invalid symbol index %ld"),
7db648
+		     abfd, sec, i, (long) r_sym (rela.r_info));
7db648
+		  bfd_set_error (bfd_error_bad_value);
7db648
+		  internal_reloc->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
7db648
+		  result = FALSE;
7db648
+		}
7db648
+	      else
7db648
+		{
7db648
+		  asymbol **ps;
7db648
+
7db648
+		  ps = symbols + r_sym (rela.r_info) - 1;
7db648
+
7db648
+		  internal_reloc->sym_ptr_ptr = ps;
7db648
+		  /* Make sure that this symbol is not removed by strip.  */
7db648
+		  (*ps)->flags |= BSF_KEEP;
7db648
+		}
7db648
+
7db648
+	      internal_reloc->addend = rela.r_addend;
7db648
+
7db648
+	      ebd->elf_info_to_howto (abfd, internal_reloc, & rela);
7db648
+	      if (internal_reloc->howto == NULL)
7db648
+		{
7db648
+#if DEBUG_SECONDARY_RELOCS
7db648
+		  fprintf (stderr, "there is no howto associated with reloc %lx\n", rela.r_info);
7db648
+#endif
7db648
+		  result = FALSE;
7db648
+		}
7db648
+	    }
7db648
+
7db648
+	  free (native_relocs);
7db648
+	  /* Store the internal relocs.  */
7db648
+	  elf_section_data (relsec)->sec_info = internal_relocs;
7db648
+	}
7db648
+    }
7db648
+
7db648
+  return result;
7db648
+}
7db648
+
7db648
+/* Set the ELF section header fields of an output secondary reloc section.  */
7db648
+
7db648
+bfd_boolean
7db648
+_bfd_elf_copy_special_section_fields (const bfd *               ibfd ATTRIBUTE_UNUSED,
7db648
+				      bfd *                     obfd ATTRIBUTE_UNUSED,
7db648
+				      const Elf_Internal_Shdr * isection,
7db648
+				      Elf_Internal_Shdr *       osection)
7db648
+{
7db648
+  if (isection == NULL)
7db648
+    return FALSE;
7db648
+
7db648
+  if (isection->sh_type != SHT_SECONDARY_RELOC)
7db648
+    return TRUE;
7db648
+
7db648
+  asection * isec = isection->bfd_section;
7db648
+  if (isec == NULL)
7db648
+    return FALSE;
7db648
+
7db648
+  asection * osec = osection->bfd_section;
7db648
+  if (osec == NULL)
7db648
+    return FALSE;
7db648
+
7db648
+  BFD_ASSERT (elf_section_data (osec)->sec_info == NULL);
7db648
+  elf_section_data (osec)->sec_info = elf_section_data (isec)->sec_info;
7db648
+  osection->sh_type = SHT_RELA;
7db648
+  osection->sh_link = elf_onesymtab (obfd);
7db648
+  if (osection->sh_link == 0)
7db648
+    {
7db648
+      /* There is no symbol table - we are hosed...  */
7db648
+      _bfd_error_handler
7db648
+	/* xgettext:c-format */
7db648
+	(_("%pB(%pA): link section cannot be set because the output file does not have a symbol table"),
7db648
+	obfd, osec);
7db648
+      bfd_set_error (bfd_error_bad_value);
7db648
+      return FALSE;
7db648
+    }
7db648
+
7db648
+  /* Find the output section that corresponds to the isection's sh_info link.  */
7db648
+  BFD_ASSERT (isection->sh_info > 0 && isection->sh_info < elf_numsections (ibfd));
7db648
+  isection = elf_elfsections (ibfd)[isection->sh_info];
7db648
+
7db648
+  BFD_ASSERT (isection != NULL);
7db648
+  BFD_ASSERT (isection->bfd_section != NULL);
7db648
+  BFD_ASSERT (isection->bfd_section->output_section != NULL);
7db648
+  osection->sh_info = elf_section_data (isection->bfd_section->output_section)->this_idx;
7db648
+
7db648
+#if DEBUG_SECONDARY_RELOCS
7db648
+  fprintf (stderr, "update header of %s, sh_link = %u, sh_info = %u\n",
7db648
+	   osec->name, osection->sh_link, osection->sh_info);
7db648
+#endif
7db648
+
7db648
+  return TRUE;
7db648
+}
7db648
+
7db648
+/* Write out a secondary reloc section.  */
7db648
+
7db648
+bfd_boolean
7db648
+_bfd_elf_write_secondary_reloc_section (bfd *abfd, asection *sec)
7db648
+{
7db648
+  const struct elf_backend_data * const ebd = get_elf_backend_data (abfd);
7db648
+  bfd_vma addr_offset;
7db648
+  asection * relsec;
7db648
+  bfd_vma (*r_info) (bfd_vma, bfd_vma);
7db648
+
7db648
+#ifdef BFD64
7db648
+  if (bfd_arch_bits_per_address (abfd) != 32)
7db648
+    r_info = elf64_r_info;
7db648
+  else
7db648
+#endif
7db648
+    r_info = elf32_r_info;
7db648
+
7db648
+  if (sec == NULL)
7db648
+    return FALSE;
7db648
+
7db648
+  /* The address of an ELF reloc is section relative for an object
7db648
+     file, and absolute for an executable file or shared library.
7db648
+     The address of a BFD reloc is always section relative.  */
7db648
+  addr_offset = 0;
7db648
+  if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
7db648
+    addr_offset = sec->vma;
7db648
+
7db648
+  /* Discover if there are any secondary reloc sections
7db648
+     associated with SEC.  */
7db648
+  for (relsec = abfd->sections; relsec != NULL; relsec = relsec->next)
7db648
+    {
7db648
+      const struct bfd_elf_section_data * const esd = elf_section_data (relsec);
7db648
+      Elf_Internal_Shdr * const hdr = (Elf_Internal_Shdr *) & esd->this_hdr;
7db648
+
7db648
+      if (hdr->sh_type == SHT_RELA
7db648
+	  && hdr->sh_info == (unsigned) elf_section_data (sec)->this_idx)
7db648
+	{
7db648
+	  asymbol *    last_sym;
7db648
+	  int          last_sym_idx;
7db648
+	  unsigned int reloc_count;
7db648
+	  unsigned int idx;
7db648
+	  arelent *    src_irel;
7db648
+	  bfd_byte *   dst_rela;
7db648
+
7db648
+	  BFD_ASSERT (hdr->contents == NULL);
7db648
+
7db648
+	  reloc_count = hdr->sh_size / hdr->sh_entsize;
7db648
+	  BFD_ASSERT (reloc_count > 0);
7db648
+
7db648
+	  hdr->contents = bfd_alloc (abfd, hdr->sh_size);
7db648
+	  if (hdr->contents == NULL)
7db648
+	    continue;
7db648
+
7db648
+#if DEBUG_SECONDARY_RELOCS
7db648
+	  fprintf (stderr, "write %u secondary relocs for %s from %s\n", reloc_count, sec->name, relsec->name);
7db648
+#endif
7db648
+	  last_sym = NULL;
7db648
+	  last_sym_idx = 0;
7db648
+	  dst_rela = hdr->contents;
7db648
+	  src_irel = (arelent *) esd->sec_info;
7db648
+	  BFD_ASSERT (src_irel != NULL);
7db648
+
7db648
+	  for (idx = 0; idx < reloc_count; idx++, dst_rela += hdr->sh_entsize)
7db648
+	    {
7db648
+	      Elf_Internal_Rela src_rela;
7db648
+	      arelent *ptr;
7db648
+	      asymbol *sym;
7db648
+	      int n;
7db648
+
7db648
+	      ptr = src_irel + idx;
7db648
+	      sym = *ptr->sym_ptr_ptr;
7db648
+
7db648
+	      if (sym == last_sym)
7db648
+		n = last_sym_idx;
7db648
+	      else
7db648
+		{
7db648
+		  last_sym = sym;
7db648
+		  n = _bfd_elf_symbol_from_bfd_symbol (abfd, & sym);
7db648
+		  if (n < 0)
7db648
+		    {
7db648
+#if DEBUG_SECONDARY_RELOCS
7db648
+		      fprintf (stderr, "failed to find symbol %s whilst rewriting relocs\n",
7db648
+			       sym->name);
7db648
+#endif
7db648
+		      /* FIXME: Signal failure somehow.  */
7db648
+		      n = 0;
7db648
+		    }
7db648
+		  last_sym_idx = n;
7db648
+		}
7db648
+
7db648
+	      if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
7db648
+		  && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
7db648
+		  && ! _bfd_elf_validate_reloc (abfd, ptr))
7db648
+		{
7db648
+#if DEBUG_SECONDARY_RELOCS
7db648
+		  fprintf (stderr, "symbol %s is not in the output bfd\n",
7db648
+			   sym->name);
7db648
+#endif
7db648
+		  /* FIXME: Signal failure somehow.  */
7db648
+		  n = 0;
7db648
+		}
7db648
+
7db648
+	      if (ptr->howto == NULL)
7db648
+		{
7db648
+#if DEBUG_SECONDARY_RELOCS
7db648
+		  fprintf (stderr, "reloc for symbol %s does not have a howto associated with it\n",
7db648
+			   sym->name);
7db648
+#endif
7db648
+		  /* FIXME: Signal failure somehow.  */
7db648
+		  n = 0;
7db648
+		}
7db648
+
7db648
+	      src_rela.r_offset = ptr->address + addr_offset;
7db648
+	      src_rela.r_info = r_info (n, ptr->howto->type);
7db648
+	      src_rela.r_addend = ptr->addend;
7db648
+	      ebd->s->swap_reloca_out (abfd, &src_rela, dst_rela);
7db648
+	    }
7db648
+	}
7db648
+    }
7db648
+
7db648
+  return TRUE;
7db648
+}
7db648
+
7db648
+/* Preserve any OS or PROCESSOR specific section indicies.  */
7db648
+
7db648
+unsigned int
7db648
+_bfd_elf_symbol_section_index (bfd * abfd ATTRIBUTE_UNUSED,
7db648
+			       elf_symbol_type * sym)
7db648
+{
7db648
+  unsigned int shndx = sym->internal_elf_sym.st_shndx;
7db648
+
7db648
+  /* Preserve special section indicies.  */
7db648
+  return shndx >= SHN_LORESERVE ? shndx : SHN_ABS;
7db648
+}
7db648
diff -rup binutils.orig/bfd/elfcode.h binutils-2.30/bfd/elfcode.h
7db648
--- binutils.orig/bfd/elfcode.h	2020-02-12 13:31:20.334605640 +0000
7db648
+++ binutils-2.30/bfd/elfcode.h	2020-02-12 13:31:33.833507567 +0000
7db648
@@ -855,6 +855,7 @@ elf_object_p (bfd *abfd)
7db648
 void
7db648
 elf_write_relocs (bfd *abfd, asection *sec, void *data)
7db648
 {
7db648
+  const struct elf_backend_data * const bed = get_elf_backend_data (abfd);
7db648
   bfd_boolean *failedp = (bfd_boolean *) data;
7db648
   Elf_Internal_Shdr *rela_hdr;
7db648
   bfd_vma addr_offset;
7db648
@@ -969,6 +970,13 @@ elf_write_relocs (bfd *abfd, asection *s
7db648
       src_rela.r_addend = ptr->addend;
7db648
       (*swap_out) (abfd, &src_rela, dst_rela);
7db648
     }
7db648
+
7db648
+  if (bed->write_secondary_relocs != NULL)
7db648
+    if (! bed->write_secondary_relocs (abfd, sec))
7db648
+      {
7db648
+	*failedp = TRUE;
7db648
+	return;
7db648
+      }
7db648
 }
7db648
 
7db648
 /* Write out the program headers.  */
7db648
@@ -1271,7 +1279,10 @@ elf_slurp_symbol_table (bfd *abfd, asymb
7db648
 		{
7db648
 		  /* This symbol is in a section for which we did not
7db648
 		     create a BFD section.  Just use bfd_abs_section,
7db648
-		     although it is wrong.  FIXME.  */
7db648
+		     although it is wrong.  FIXME.  Note - there is
7db648
+		     code in elf.c:swap_out_syms that calls
7db648
+		     symbol_section_index() in the elf backend for
7db648
+		     cases like this.  */
7db648
 		  sym->symbol.section = bfd_abs_section_ptr;
7db648
 		}
7db648
 	    }
7db648
@@ -1501,6 +1512,7 @@ elf_slurp_reloc_table (bfd *abfd,
7db648
 		       asymbol **symbols,
7db648
 		       bfd_boolean dynamic)
7db648
 {
7db648
+  const struct elf_backend_data * const bed = get_elf_backend_data (abfd);
7db648
   struct bfd_elf_section_data * const d = elf_section_data (asect);
7db648
   Elf_Internal_Shdr *rel_hdr;
7db648
   Elf_Internal_Shdr *rel_hdr2;
7db648
@@ -1564,6 +1576,10 @@ elf_slurp_reloc_table (bfd *abfd,
7db648
 					      symbols, dynamic))
7db648
     return FALSE;
7db648
 
7db648
+  if (bed->slurp_secondary_relocs != NULL
7db648
+      && ! bed->slurp_secondary_relocs (abfd, asect, symbols))
7db648
+    return FALSE;
7db648
+
7db648
   asect->relocation = relents;
7db648
   return TRUE;
7db648
 }
7db648
diff -rup binutils.orig/bfd/elflink.c binutils-2.30/bfd/elflink.c
7db648
--- binutils.orig/bfd/elflink.c	2020-02-12 13:31:20.338605611 +0000
7db648
+++ binutils-2.30/bfd/elflink.c	2020-02-12 13:31:33.834507560 +0000
7db648
@@ -11514,6 +11514,10 @@ elf_final_link_free (bfd *obfd, struct e
7db648
     }
7db648
 }
7db648
 
7db648
+#define is_reloc_section(ESDO)			\
7db648
+  (   (ESDO)->this_hdr.sh_type == SHT_REL	\
7db648
+   || (ESDO)->this_hdr.sh_type == SHT_RELA)
7db648
+
7db648
 /* Do the final step of an ELF link.  */
7db648
 
7db648
 bfd_boolean
7db648
@@ -11685,8 +11689,7 @@ bfd_elf_final_link (bfd *abfd, struct bf
7db648
 		      && elf_symtab_shndx_list (sec->owner) != NULL)
7db648
 		    max_sym_shndx_count = sym_count;
7db648
 
7db648
-		  if (esdo->this_hdr.sh_type == SHT_REL
7db648
-		      || esdo->this_hdr.sh_type == SHT_RELA)
7db648
+		  if (is_reloc_section (esdo))
7db648
 		    /* Some backends use reloc_count in relocation sections
7db648
 		       to count particular types of relocs.  Of course,
7db648
 		       reloc sections themselves can't have relocations.  */
7db648
@@ -12290,6 +12293,9 @@ bfd_elf_final_link (bfd *abfd, struct bf
7db648
       struct bfd_elf_section_data *esdo = elf_section_data (o);
7db648
       bfd_boolean sort;
7db648
 
7db648
+      if (esdo == NULL)
7db648
+	continue;
7db648
+
7db648
       if ((o->flags & SEC_RELOC) == 0)
7db648
 	continue;
7db648
 
7db648
diff -rup binutils.orig/bfd/elfxx-target.h binutils-2.30/bfd/elfxx-target.h
7db648
--- binutils.orig/bfd/elfxx-target.h	2020-02-12 13:31:20.338605611 +0000
7db648
+++ binutils-2.30/bfd/elfxx-target.h	2020-02-12 13:31:33.834507560 +0000
7db648
@@ -737,7 +737,7 @@
7db648
 #endif
7db648
 
7db648
 #ifndef elf_backend_copy_special_section_fields
7db648
-#define elf_backend_copy_special_section_fields NULL
7db648
+#define elf_backend_copy_special_section_fields _bfd_elf_copy_special_section_fields
7db648
 #endif
7db648
 
7db648
 #ifndef elf_backend_compact_eh_encoding
7db648
@@ -745,7 +745,23 @@
7db648
 #endif
7db648
 
7db648
 #ifndef elf_backend_cant_unwind_opcode
7db648
-#define elf_backend_cant_unwind_opcode 0
7db648
+#define elf_backend_cant_unwind_opcode NULL
7db648
+#endif
7db648
+
7db648
+#ifndef elf_backend_init_secondary_reloc_section
7db648
+#define elf_backend_init_secondary_reloc_section _bfd_elf_init_secondary_reloc_section
7db648
+#endif
7db648
+
7db648
+#ifndef elf_backend_slurp_secondary_reloc_section
7db648
+#define elf_backend_slurp_secondary_reloc_section _bfd_elf_slurp_secondary_reloc_section
7db648
+#endif
7db648
+
7db648
+#ifndef elf_backend_write_secondary_reloc_section
7db648
+#define elf_backend_write_secondary_reloc_section _bfd_elf_write_secondary_reloc_section
7db648
+#endif
7db648
+
7db648
+#ifndef elf_backend_symbol_section_index
7db648
+#define elf_backend_symbol_section_index _bfd_elf_symbol_section_index
7db648
 #endif
7db648
 
7db648
 #ifndef elf_match_priority
7db648
@@ -870,6 +886,10 @@ static struct elf_backend_data elfNN_bed
7db648
   elf_backend_setup_gnu_properties,
7db648
   elf_backend_compact_eh_encoding,
7db648
   elf_backend_cant_unwind_opcode,
7db648
+  elf_backend_init_secondary_reloc_section,
7db648
+  elf_backend_slurp_secondary_reloc_section,
7db648
+  elf_backend_write_secondary_reloc_section,
7db648
+  elf_backend_symbol_section_index,
7db648
   elf_backend_static_tls_alignment,
7db648
   elf_backend_stack_align,
7db648
   elf_backend_strtab_flags,
7db648
Only in binutils-2.30/bfd: elfxx-target.h.orig