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

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