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

7ab123
commit 6911b7dcb8ea17f8b811578dd4ac1ab7bb675e7b
7ab123
Author: Alan Modra <amodra@gmail.com>
7ab123
Date:   Tue Oct 29 15:37:43 2013 +1030
7ab123
7ab123
    Add ELFv2 .localentry support.
7ab123
    
7ab123
    This defines the ELF symbol st_other field used to encode the number
7ab123
    of instructions between a function "global entry" and its "local entry",
7ab123
    and adds support related to the local entry offset.
7ab123
    
7ab123
    include/elf/
7ab123
    	* ppc64.h (STO_PPC64_LOCAL_BIT, STO_PPC64_LOCAL_MASK): Define.
7ab123
    	(ppc64_decode_local_entry, ppc64_encode_local_entry): New functions.
7ab123
    	(PPC64_LOCAL_ENTRY_OFFSET, PPC64_SET_LOCAL_ENTRY_OFFSET): Define.
7ab123
    bfd/
7ab123
    	* elf64-ppc.c (struct ppc_stub_hash_entry): Add "other".
7ab123
    	(stub_hash_newfunc): Init new ppc_stub_hash_entry field, and one
7ab123
    	we forgot, "plt_ent".
7ab123
    	(ppc64_elf_add_symbol_hook): Check ELFv1 objects don't have
7ab123
    	st_other bits only valid in ELFv2.
7ab123
    	(ppc64_elf_merge_symbol_attribute): New function.
7ab123
    	(ppc_type_of_stub): Add local_off param to test branch range.
7ab123
    	(ppc_build_one_stub): Adjust destinations for ELFv2 locals.
7ab123
    	(ppc_size_one_stub, toc_adjusting_stub_needed): Similarly.
7ab123
    	(ppc64_elf_size_stubs): Pass local_off to ppc_type_of_stub.
7ab123
    	Set "other" field.
7ab123
    	(ppc64_elf_relocate_section): Adjust destination for ELFv2 local
7ab123
    	calls.
7ab123
    gas/
7ab123
    	* config/tc-ppc.c (md_pseudo_table): Add .localentry.
7ab123
    	(ppc_elf_localentry): New function.
7ab123
    	(ppc_force_relocation): Force relocs on all branches to localenty
7ab123
    	symbols.
7ab123
    	(ppc_fix_adjustable): Don't reduce such symbols to section+offset.
7ab123
    binutils/
7ab123
    	* readelf.c (get_ppc64_symbol_other): New function.
7ab123
    	(get_symbol_other): Use it for EM_PPC64.
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
@@ -118,6 +118,7 @@ static bfd_vma opd_entry_value
7ab123
 #define elf_backend_link_output_symbol_hook   ppc64_elf_output_symbol_hook
7ab123
 #define elf_backend_special_sections	      ppc64_elf_special_sections
7ab123
 #define elf_backend_post_process_headers      _bfd_elf_set_osabi
7ab123
+#define elf_backend_merge_symbol_attribute    ppc64_elf_merge_symbol_attribute
7ab123
 
7ab123
 /* The name of the dynamic interpreter.  This is put in the .interp
7ab123
    section.  */
7ab123
@@ -3640,6 +3641,9 @@ struct ppc_stub_hash_entry {
7ab123
   /* Where this stub is being called from, or, in the case of combined
7ab123
      stub sections, the first input section in the group.  */
7ab123
   asection *id_sec;
7ab123
+
7ab123
+  /* Symbol st_other.  */
7ab123
+  unsigned char other;
7ab123
 };
7ab123
 
7ab123
 struct ppc_branch_hash_entry {
7ab123
@@ -3886,7 +3890,9 @@ stub_hash_newfunc (struct bfd_hash_entry
7ab123
       eh->target_value = 0;
7ab123
       eh->target_section = NULL;
7ab123
       eh->h = NULL;
7ab123
+      eh->plt_ent = NULL;
7ab123
       eh->id_sec = NULL;
7ab123
+      eh->other = 0;
7ab123
     }
7ab123
 
7ab123
   return entry;
7ab123
@@ -4629,7 +4635,7 @@ static bfd_boolean
7ab123
 ppc64_elf_add_symbol_hook (bfd *ibfd,
7ab123
 			   struct bfd_link_info *info,
7ab123
 			   Elf_Internal_Sym *isym,
7ab123
-			   const char **name ATTRIBUTE_UNUSED,
7ab123
+			   const char **name,
7ab123
 			   flagword *flags ATTRIBUTE_UNUSED,
7ab123
 			   asection **sec,
7ab123
 			   bfd_vma *value ATTRIBUTE_UNUSED)
7ab123
@@ -4649,9 +4655,35 @@ ppc64_elf_add_symbol_hook (bfd *ibfd,
7ab123
 	   && strcmp ((*sec)->name, ".opd") == 0)
7ab123
     isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
7ab123
 
7ab123
+  if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
7ab123
+    {
7ab123
+      if (abiversion (ibfd) == 0)
7ab123
+	set_abiversion (ibfd, 2);
7ab123
+      else if (abiversion (ibfd) == 1)
7ab123
+	{
7ab123
+	  info->callbacks->einfo (_("%P: symbol '%s' has invalid st_other"
7ab123
+				    " for ABI version 1\n"), name);
7ab123
+	  bfd_set_error (bfd_error_bad_value);
7ab123
+	  return FALSE;
7ab123
+	}
7ab123
+    }
7ab123
+
7ab123
   return TRUE;
7ab123
 }
7ab123
 
7ab123
+/* Merge non-visibility st_other attributes: local entry point.  */
7ab123
+
7ab123
+static void
7ab123
+ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry *h,
7ab123
+				  const Elf_Internal_Sym *isym,
7ab123
+				  bfd_boolean definition,
7ab123
+				  bfd_boolean dynamic)
7ab123
+{
7ab123
+  if (definition && !dynamic)
7ab123
+    h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1))
7ab123
+		| ELF_ST_VISIBILITY (h->other));
7ab123
+}
7ab123
+
7ab123
 /* This function makes an old ABI object reference to ".bar" cause the
7ab123
    inclusion of a new ABI object archive that defines "bar".
7ab123
    NAME is a symbol defined in an archive.  Return a symbol in the hash
7ab123
@@ -9586,7 +9618,8 @@ ppc_type_of_stub (asection *input_sec,
7ab123
 		  const Elf_Internal_Rela *rel,
7ab123
 		  struct ppc_link_hash_entry **hash,
7ab123
 		  struct plt_entry **plt_ent,
7ab123
-		  bfd_vma destination)
7ab123
+		  bfd_vma destination,
7ab123
+		  unsigned long local_off)
7ab123
 {
7ab123
   struct ppc_link_hash_entry *h = *hash;
7ab123
   bfd_vma location;
7ab123
@@ -9655,7 +9688,7 @@ ppc_type_of_stub (asection *input_sec,
7ab123
   if (r_type != R_PPC64_REL24)
7ab123
     max_branch_offset = 1 << 15;
7ab123
 
7ab123
-  if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
7ab123
+  if (branch_offset + max_branch_offset >= 2 * max_branch_offset - local_off)
7ab123
     /* We need a stub.  Figure out whether a long_branch or plt_branch
7ab123
        is needed later.  */
7ab123
     return ppc_stub_long_branch;
7ab123
@@ -10023,9 +10056,11 @@ ppc_build_one_stub (struct bfd_hash_entr
7ab123
     case ppc_stub_long_branch:
7ab123
     case ppc_stub_long_branch_r2off:
7ab123
       /* Branches are relative.  This is where we are going to.  */
7ab123
-      off = dest = (stub_entry->target_value
7ab123
-		    + stub_entry->target_section->output_offset
7ab123
-		    + stub_entry->target_section->output_section->vma);
7ab123
+      dest = (stub_entry->target_value
7ab123
+	      + stub_entry->target_section->output_offset
7ab123
+	      + stub_entry->target_section->output_section->vma);
7ab123
+      dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
7ab123
+      off = dest;
7ab123
 
7ab123
       /* And this is where we are coming from.  */
7ab123
       off -= (stub_entry->stub_offset
7ab123
@@ -10128,6 +10163,8 @@ ppc_build_one_stub (struct bfd_hash_entr
7ab123
       dest = (stub_entry->target_value
7ab123
 	      + stub_entry->target_section->output_offset
7ab123
 	      + stub_entry->target_section->output_section->vma);
7ab123
+      if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
7ab123
+	dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
7ab123
 
7ab123
       bfd_put_64 (htab->brlt->owner, dest,
7ab123
 		  htab->brlt->contents + br_entry->offset);
7ab123
@@ -10472,6 +10509,7 @@ ppc_size_one_stub (struct bfd_hash_entry
7ab123
       /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
7ab123
 	 variants.  */
7ab123
       bfd_vma r2off = 0;
7ab123
+      bfd_vma local_off = 0;
7ab123
 
7ab123
       off = (stub_entry->target_value
7ab123
 	     + stub_entry->target_section->output_offset
7ab123
@@ -10500,8 +10538,10 @@ ppc_size_one_stub (struct bfd_hash_entry
7ab123
 	  off -= size - 4;
7ab123
 	}
7ab123
 
7ab123
+      local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
7ab123
+
7ab123
       /* If the branch offset if too big, use a ppc_stub_plt_branch.  */
7ab123
-      if (off + (1 << 25) >= (bfd_vma) (1 << 26))
7ab123
+      if (off + (1 << 25) >= (bfd_vma) (1 << 26) - local_off)
7ab123
 	{
7ab123
 	  struct ppc_branch_hash_entry *br_entry;
7ab123
 
7ab123
@@ -11097,7 +11137,10 @@ toc_adjusting_stub_needed (struct bfd_li
7ab123
 	     need a plt_branch stub.  A plt_branch stub uses r2.  */
7ab123
 	  else if (dest - (isec->output_offset
7ab123
 			   + isec->output_section->vma
7ab123
-			   + rel->r_offset) + (1 << 25) >= (2 << 25))
7ab123
+			   + rel->r_offset) + (1 << 25)
7ab123
+		   >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
7ab123
+							     ? h->other
7ab123
+							     : sym->st_other))
7ab123
 	    {
7ab123
 	      ret = 1;
7ab123
 	      break;
7ab123
@@ -11553,6 +11596,7 @@ ppc64_elf_size_stubs (struct bfd_link_in
7ab123
 		  asection *sym_sec, *code_sec;
7ab123
 		  bfd_vma sym_value, code_value;
7ab123
 		  bfd_vma destination;
7ab123
+		  unsigned long local_off;
7ab123
 		  bfd_boolean ok_dest;
7ab123
 		  struct ppc_link_hash_entry *hash;
7ab123
 		  struct ppc_link_hash_entry *fdh;
7ab123
@@ -11629,12 +11673,16 @@ ppc64_elf_size_stubs (struct bfd_link_in
7ab123
 		    }
7ab123
 
7ab123
 		  destination = 0;
7ab123
+		  local_off = 0;
7ab123
 		  if (ok_dest)
7ab123
 		    {
7ab123
 		      sym_value += irela->r_addend;
7ab123
 		      destination = (sym_value
7ab123
 				     + sym_sec->output_offset
7ab123
 				     + sym_sec->output_section->vma);
7ab123
+		      local_off = PPC64_LOCAL_ENTRY_OFFSET (hash
7ab123
+							    ? hash->elf.other
7ab123
+							    : sym->st_other);
7ab123
 		    }
7ab123
 
7ab123
 		  code_sec = sym_sec;
7ab123
@@ -11671,7 +11719,8 @@ ppc64_elf_size_stubs (struct bfd_link_in
7ab123
 		  /* Determine what (if any) linker stub is needed.  */
7ab123
 		  plt_ent = NULL;
7ab123
 		  stub_type = ppc_type_of_stub (section, irela, &hash,
7ab123
-						&plt_ent, destination);
7ab123
+						&plt_ent, destination,
7ab123
+						local_off);
7ab123
 
7ab123
 		  if (stub_type != ppc_stub_plt_call)
7ab123
 		    {
7ab123
@@ -11771,6 +11820,7 @@ ppc64_elf_size_stubs (struct bfd_link_in
7ab123
 		    }
7ab123
 		  stub_entry->h = hash;
7ab123
 		  stub_entry->plt_ent = plt_ent;
7ab123
+		  stub_entry->other = hash ? hash->elf.other : sym->st_other;
7ab123
 		  stub_entry->addend = irela->r_addend;
7ab123
 
7ab123
 		  if (stub_entry->h != NULL)
7ab123
@@ -13105,6 +13155,10 @@ ppc64_elf_relocate_section (bfd *output_
7ab123
 		  + input_section->output_offset
7ab123
 		  + input_section->output_section->vma);
7ab123
 
7ab123
+	  relocation += PPC64_LOCAL_ENTRY_OFFSET (fdh
7ab123
+						  ? fdh->elf.other
7ab123
+						  : sym->st_other);
7ab123
+
7ab123
 	  if (stub_entry != NULL
7ab123
 	      && (stub_entry->stub_type == ppc_stub_long_branch
7ab123
 		  || stub_entry->stub_type == ppc_stub_plt_branch)
7ab123
Index: gdb-7.6.1/include/elf/ppc64.h
7ab123
===================================================================
7ab123
--- gdb-7.6.1.orig/include/elf/ppc64.h
7ab123
+++ gdb-7.6.1/include/elf/ppc64.h
7ab123
@@ -171,6 +171,53 @@ END_RELOC_NUMBERS (R_PPC64_max)
7ab123
    0 for unspecified or not using any features affected by the differences.  */
7ab123
 #define EF_PPC64_ABI	3
7ab123
 
7ab123
+/* The ELFv2 ABI uses three bits in the symbol st_other field of a
7ab123
+   function definition to specify the number of instructions between a
7ab123
+   function's global entry point and local entry point.
7ab123
+   The global entry point is used when it is necessary to set up the
7ab123
+   toc pointer (r2) for the function.  Callers must enter the global
7ab123
+   entry point with r12 set to the global entry point address.  On
7ab123
+   return from the function, r2 may have a different value to that
7ab123
+   which it had on entry.
7ab123
+   The local entry point is used when r2 is known to already be valid
7ab123
+   for the function.  There is no requirement on r12 when using the
7ab123
+   local entry point, and on return r2 will contain the same value as
7ab123
+   at entry.
7ab123
+   A value of zero in these bits means that the function has a single
7ab123
+   entry point with no requirement on r12 or r2, and that on return r2
7ab123
+   will contain the same value as at entry.
7ab123
+   Values of one and seven are reserved.  */
7ab123
+#define STO_PPC64_LOCAL_BIT		5
7ab123
+#define STO_PPC64_LOCAL_MASK		(7 << STO_PPC64_LOCAL_BIT)
7ab123
+
7ab123
+// 3 bit other field to bytes.
7ab123
+static inline unsigned int
7ab123
+ppc64_decode_local_entry(unsigned int other)
7ab123
+{
7ab123
+  return ((1 << other) >> 2) << 2;
7ab123
+}
7ab123
+
7ab123
+// bytes to field value.
7ab123
+static inline unsigned int
7ab123
+ppc64_encode_local_entry(unsigned int val)
7ab123
+{
7ab123
+  return (val >= 4 * 4
7ab123
+	  ? (val >= 8 * 4
7ab123
+	     ? (val >= 16 * 4 ? 6 : 5)
7ab123
+	     : 4)
7ab123
+	  : (val >= 2 * 4
7ab123
+	     ? 3
7ab123
+	     : (val >= 1 * 4 ? 2 : 0)));
7ab123
+}
7ab123
+
7ab123
+/* st_other to number of bytes.  */
7ab123
+#define PPC64_LOCAL_ENTRY_OFFSET(other)				\
7ab123
+  ppc64_decode_local_entry (((other) & STO_PPC64_LOCAL_MASK)	\
7ab123
+			    >> STO_PPC64_LOCAL_BIT)
7ab123
+/* number of bytes to st_other.  */
7ab123
+#define PPC64_SET_LOCAL_ENTRY_OFFSET(val)		\
7ab123
+  ppc64_encode_local_entry (val) << STO_PPC64_LOCAL_BIT
7ab123
+
7ab123
 /* Specify the start of the .glink section.  */
7ab123
 #define DT_PPC64_GLINK		DT_LOPROC
7ab123