Blame SOURCES/gdb-rhbz1125820-ppc64le-enablement-08of37.patch

01917d
commit ee67d69a3ff0eed25d98c5e97ed6c3ede8069edc
01917d
Author: Alan Modra <amodra@gmail.com>
01917d
Date:   Tue Oct 29 15:06:09 2013 +1030
01917d
01917d
    Add .abiversion related support for ELFv2
01917d
    
01917d
    Defines bits in ELF e_flags to differentiate ELFv2 objects from ELFv2,
01917d
    adds .abiversion directive to explicitly choose the ABI, and code to
01917d
    check and automatically select ABI.
01917d
    
01917d
    include/elf/
01917d
    	* ppc64.h (EF_PPC64_ABI): Define.
01917d
    bfd/
01917d
    	* elf64-ppc.c (abiversion, set_abiversion): New functions.
01917d
    	(ppc64_elf_get_synthetic_symtab): Handle ELFv2 objects without .opd.
01917d
    	(struct ppc_link_hash_table): Add opd_abi.
01917d
    	(ppc64_elf_check_relocs): Check no .opd with ELFv2.
01917d
    	(ppc64_elf_merge_private_bfd_data): New function.
01917d
    	(ppc64_elf_print_private_bfd_data): New function.
01917d
    	(ppc64_elf_tls_setup): Set htab->opd_abi.
01917d
    	(ppc64_elf_size_dynamic_sections): Don't emit OPD related dynamic
01917d
    	tags for ELFv2.
01917d
    	(ppc_build_one_stub): Use R_PPC64_IRELATIVE for ELFv2 ifunc.
01917d
    	(ppc64_elf_finish_dynamic_symbol): Likewise
01917d
    binutils/
01917d
    	* readelf.c (get_machine_flags): Display ABI version for EM_PPC64.
01917d
    gas/
01917d
    	* config/tc-ppc.c: Include elf/ppc64.h.
01917d
    	(ppc_abiversion): New variable.
01917d
    	(md_pseudo_table): Add .abiversion.
01917d
    	(ppc_elf_abiversion, ppc_elf_end): New functions.
01917d
    	* config/tc-ppc.h (md_end): Define.
01917d
01917d
Index: gdb-7.6.1/bfd/elf64-ppc.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/bfd/elf64-ppc.c
01917d
+++ gdb-7.6.1/bfd/elf64-ppc.c
01917d
@@ -81,7 +81,8 @@ static bfd_vma opd_entry_value
01917d
 #define bfd_elf64_mkobject		      ppc64_elf_mkobject
01917d
 #define bfd_elf64_bfd_reloc_type_lookup	      ppc64_elf_reloc_type_lookup
01917d
 #define bfd_elf64_bfd_reloc_name_lookup	      ppc64_elf_reloc_name_lookup
01917d
-#define bfd_elf64_bfd_merge_private_bfd_data  _bfd_generic_verify_endian_match
01917d
+#define bfd_elf64_bfd_merge_private_bfd_data  ppc64_elf_merge_private_bfd_data
01917d
+#define bfd_elf64_bfd_print_private_bfd_data  ppc64_elf_print_private_bfd_data
01917d
 #define bfd_elf64_new_section_hook	      ppc64_elf_new_section_hook
01917d
 #define bfd_elf64_bfd_link_hash_table_create  ppc64_elf_link_hash_table_create
01917d
 #define bfd_elf64_bfd_link_hash_table_free    ppc64_elf_link_hash_table_free
01917d
@@ -2836,6 +2837,19 @@ get_opd_info (asection * sec)
01917d
     return &ppc64_elf_section_data (sec)->u.opd;
01917d
   return NULL;
01917d
 }
01917d
+
01917d
+static inline int
01917d
+abiversion (bfd *abfd)
01917d
+{
01917d
+  return elf_elfheader (abfd)->e_flags & EF_PPC64_ABI;
01917d
+}
01917d
+
01917d
+static inline void
01917d
+set_abiversion (bfd *abfd, int ver)
01917d
+{
01917d
+  elf_elfheader (abfd)->e_flags &= ~EF_PPC64_ABI;
01917d
+  elf_elfheader (abfd)->e_flags |= ver & EF_PPC64_ABI;
01917d
+}
01917d
 
01917d
 /* Parameters for the qsort hook.  */
01917d
 static bfd_boolean synthetic_relocatable;
01917d
@@ -2982,15 +2996,19 @@ ppc64_elf_get_synthetic_symtab (bfd *abf
01917d
   long count;
01917d
   char *names;
01917d
   long symcount, codesecsym, codesecsymend, secsymend, opdsymend;
01917d
-  asection *opd;
01917d
+  asection *opd = NULL;
01917d
   bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
01917d
   asymbol **syms;
01917d
+  int abi = abiversion (abfd);
01917d
 
01917d
   *ret = NULL;
01917d
 
01917d
-  opd = bfd_get_section_by_name (abfd, ".opd");
01917d
-  if (opd == NULL)
01917d
-    return 0;
01917d
+  if (abi < 2)
01917d
+    {
01917d
+      opd = bfd_get_section_by_name (abfd, ".opd");
01917d
+      if (opd == NULL && abi == 1)
01917d
+	return 0;
01917d
+    }
01917d
 
01917d
   symcount = static_count;
01917d
   if (!relocatable)
01917d
@@ -3159,20 +3177,18 @@ ppc64_elf_get_synthetic_symtab (bfd *abf
01917d
   else
01917d
     {
01917d
       bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
01917d
-      bfd_byte *contents;
01917d
+      bfd_byte *contents = NULL;
01917d
       size_t size;
01917d
       long plt_count = 0;
01917d
       bfd_vma glink_vma = 0, resolv_vma = 0;
01917d
       asection *dynamic, *glink = NULL, *relplt = NULL;
01917d
       arelent *p;
01917d
 
01917d
-      if (!bfd_malloc_and_get_section (abfd, opd, &contents))
01917d
+      if (opd != NULL && !bfd_malloc_and_get_section (abfd, opd, &contents))
01917d
 	{
01917d
+	free_contents_and_exit:
01917d
 	  if (contents)
01917d
-	    {
01917d
-	    free_contents_and_exit:
01917d
-	      free (contents);
01917d
-	    }
01917d
+	    free (contents);
01917d
 	  count = -1;
01917d
 	  goto done;
01917d
 	}
01917d
@@ -3772,6 +3788,9 @@ struct ppc_link_hash_table
01917d
   /* Alignment of PLT call stubs.  */
01917d
   unsigned int plt_stub_align:4;
01917d
 
01917d
+  /* Set if we're linking code with function descriptors.  */
01917d
+  unsigned int opd_abi:1;
01917d
+
01917d
   /* Set if PLT call stubs should load r11.  */
01917d
   unsigned int plt_static_chain:1;
01917d
 
01917d
@@ -4959,6 +4978,15 @@ ppc64_elf_check_relocs (bfd *abfd, struc
01917d
 	 information about the associated function section.  */
01917d
       bfd_size_type amt;
01917d
 
01917d
+      if (abiversion (abfd) == 0)
01917d
+	set_abiversion (abfd, 1);
01917d
+      else if (abiversion (abfd) == 2)
01917d
+	{
01917d
+	  info->callbacks->einfo (_("%P: .opd not allowed in ABI version %d\n"),
01917d
+				  abiversion (abfd));
01917d
+	  bfd_set_error (bfd_error_bad_value);
01917d
+	  return FALSE;
01917d
+	}
01917d
       amt = sec->size * sizeof (*opd_sym_map) / 8;
01917d
       opd_sym_map = bfd_zalloc (abfd, amt);
01917d
       if (opd_sym_map == NULL)
01917d
@@ -5518,6 +5546,78 @@ ppc64_elf_check_relocs (bfd *abfd, struc
01917d
   return TRUE;
01917d
 }
01917d
 
01917d
+/* Merge backend specific data from an object file to the output
01917d
+   object file when linking.  */
01917d
+
01917d
+static bfd_boolean
01917d
+ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
01917d
+{
01917d
+  unsigned long iflags, oflags;
01917d
+
01917d
+  if ((ibfd->flags & BFD_LINKER_CREATED) != 0)
01917d
+    return TRUE;
01917d
+
01917d
+  if (!is_ppc64_elf (ibfd) || !is_ppc64_elf (obfd))
01917d
+    return TRUE;
01917d
+
01917d
+  if (!_bfd_generic_verify_endian_match (ibfd, obfd))
01917d
+    return FALSE;
01917d
+
01917d
+  iflags = elf_elfheader (ibfd)->e_flags;
01917d
+  oflags = elf_elfheader (obfd)->e_flags;
01917d
+
01917d
+  if (!elf_flags_init (obfd) || oflags == 0)
01917d
+    {
01917d
+      elf_flags_init (obfd) = TRUE;
01917d
+      elf_elfheader (obfd)->e_flags = iflags;
01917d
+    }
01917d
+  else if (iflags == oflags || iflags == 0)
01917d
+    ;
01917d
+  else if (iflags & ~EF_PPC64_ABI)
01917d
+    {
01917d
+      (*_bfd_error_handler)
01917d
+	(_("%B uses unknown e_flags 0x%lx"), ibfd, iflags);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      return FALSE;
01917d
+    }
01917d
+  else
01917d
+    {
01917d
+      (*_bfd_error_handler)
01917d
+	(_("%B: ABI version %ld is not compatible with ABI version %ld output"),
01917d
+	 ibfd, iflags, oflags);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      return FALSE;
01917d
+    }
01917d
+
01917d
+  /* Merge Tag_compatibility attributes and any common GNU ones.  */
01917d
+  _bfd_elf_merge_object_attributes (ibfd, obfd);
01917d
+
01917d
+  return TRUE;
01917d
+}
01917d
+
01917d
+static bfd_boolean
01917d
+ppc64_elf_print_private_bfd_data (bfd *abfd, void *ptr)
01917d
+{
01917d
+  /* Print normal ELF private data.  */
01917d
+  _bfd_elf_print_private_bfd_data (abfd, ptr);
01917d
+
01917d
+  if (elf_elfheader (abfd)->e_flags != 0)
01917d
+    {
01917d
+      FILE *file = ptr;
01917d
+
01917d
+      /* xgettext:c-format */
01917d
+      fprintf (file, _("private flags = 0x%lx:"),
01917d
+	       elf_elfheader (abfd)->e_flags);
01917d
+
01917d
+      if ((elf_elfheader (abfd)->e_flags & EF_PPC64_ABI) != 0)
01917d
+	fprintf (file, _(" [abiv%ld]"),
01917d
+		 elf_elfheader (abfd)->e_flags & EF_PPC64_ABI);
01917d
+      fputc ('\n', file);
01917d
+    }
01917d
+
01917d
+  return TRUE;
01917d
+}
01917d
+
01917d
 /* OFFSET in OPD_SEC specifies a function descriptor.  Return the address
01917d
    of the code entry point, and its section.  */
01917d
 
01917d
@@ -7504,6 +7604,9 @@ ppc64_elf_tls_setup (struct bfd_link_inf
01917d
   if (htab == NULL)
01917d
     return NULL;
01917d
 
01917d
+  if (abiversion (info->output_bfd) == 1)
01917d
+    htab->opd_abi = 1;
01917d
+
01917d
   if (*no_multi_toc)
01917d
     htab->do_multi_toc = 0;
01917d
   else if (!htab->do_multi_toc)
01917d
@@ -9127,7 +9230,7 @@ readonly_dynrelocs (struct elf_link_hash
01917d
 /* Set the sizes of the dynamic sections.  */
01917d
 
01917d
 static bfd_boolean
01917d
-ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
01917d
+ppc64_elf_size_dynamic_sections (bfd *output_bfd,
01917d
 				 struct bfd_link_info *info)
01917d
 {
01917d
   struct ppc_link_hash_table *htab;
01917d
@@ -9439,7 +9542,7 @@ ppc64_elf_size_dynamic_sections (bfd *ou
01917d
 	    return FALSE;
01917d
 	}
01917d
 
01917d
-      if (NO_OPD_RELOCS)
01917d
+      if (NO_OPD_RELOCS && abiversion (output_bfd) <= 1)
01917d
 	{
01917d
 	  if (!add_dynamic_entry (DT_PPC64_OPD, 0)
01917d
 	      || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
01917d
@@ -10202,7 +10305,10 @@ ppc_build_one_stub (struct bfd_hash_entr
01917d
 	  bfd_byte *rl;
01917d
 
01917d
 	  rela.r_offset = dest;
01917d
-	  rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
01917d
+	  if (htab->opd_abi)
01917d
+	    rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
01917d
+	  else
01917d
+	    rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
01917d
 	  rela.r_addend = (stub_entry->target_value
01917d
 			   + stub_entry->target_section->output_offset
01917d
 			   + stub_entry->target_section->output_section->vma);
01917d
@@ -14012,7 +14118,10 @@ ppc64_elf_finish_dynamic_symbol (bfd *ou
01917d
 	    rela.r_offset = (htab->iplt->output_section->vma
01917d
 			     + htab->iplt->output_offset
01917d
 			     + ent->plt.offset);
01917d
-	    rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
01917d
+	    if (htab->opd_abi)
01917d
+	      rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
01917d
+	    else
01917d
+	      rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
01917d
 	    rela.r_addend = (h->root.u.def.value
01917d
 			     + h->root.u.def.section->output_offset
01917d
 			     + h->root.u.def.section->output_section->vma
01917d
--- a/include/elf/ppc64.h
01917d
+++ b/include/elf/ppc64.h
01917d
@@ -173,6 +173,13 @@ END_RELOC_NUMBERS (R_PPC64_max)
01917d
   (((R) >= R_PPC64_TLS && (R) <= R_PPC64_DTPREL16_HIGHESTA)		\
01917d
    || ((R) >= R_PPC64_TPREL16_HIGH && (R) <= R_PPC64_DTPREL16_HIGHA))
01917d
 
01917d
+
01917d
+/* e_flags bits specifying ABI.
01917d
+   1 for original function descriptor using ABI,
01917d
+   2 for revised ABI without function descriptors,
01917d
+   0 for unspecified or not using any features affected by the differences.  */
01917d
+#define EF_PPC64_ABI	3
01917d
+
01917d
 /* Specify the start of the .glink section.  */
01917d
 #define DT_PPC64_GLINK		DT_LOPROC
01917d