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

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