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

01917d
commit d4094b6a8883ae481c7644c5a210254efe92e9ad
01917d
Author: Ulrich Weigand <ulrich.weigand@de.ibm.com>
01917d
Date:   Tue Feb 4 18:40:16 2014 +0100
01917d
01917d
    PowerPC64 ELFv2 ABI: no function descriptors
01917d
    
01917d
    This implements the most significant difference with the ELFv2 ABI:
01917d
    we no longer use function descriptors.  The patch consists mostly
01917d
    of switching off code to deal with descriptors :-)
01917d
    
01917d
    In addition, when calling an inferior function, we no longer need
01917d
    to provide its TOC in r2.  Instead, ELFv2 code expects to be called
01917d
    with r12 pointing to the code address itself.
01917d
    
01917d
    gdb/ChangeLog:
01917d
    
01917d
    	* ppc-linux-tdep.c (ppc_linux_init_abi): Only call
01917d
    	set_gdbarch_convert_from_func_ptr_addr and
01917d
    	set_gdbarch_elf_make_msymbol_special for ELFv1.
01917d
    	* ppc-sysv-tdep.c (ppc64_sysv_abi_push_param): Only handle
01917d
    	function descriptors on ELFv1.
01917d
    	(ppc64_sysv_abi_push_dummy_call): Likewise.  On ELFv2,
01917d
    	set up r12 at function entry.
01917d
01917d
Index: gdb-7.6.1/gdb/ppc-linux-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/ppc-linux-tdep.c
01917d
+++ gdb-7.6.1/gdb/ppc-linux-tdep.c
01917d
@@ -1331,13 +1331,16 @@ ppc_linux_init_abi (struct gdbarch_info
01917d
   
01917d
   if (tdep->wordsize == 8)
01917d
     {
01917d
-      /* Handle PPC GNU/Linux 64-bit function pointers (which are really
01917d
-	 function descriptors).  */
01917d
-      set_gdbarch_convert_from_func_ptr_addr
01917d
-	(gdbarch, ppc64_convert_from_func_ptr_addr);
01917d
+      if (tdep->elf_abi == POWERPC_ELF_V1)
01917d
+	{
01917d
+	  /* Handle PPC GNU/Linux 64-bit function pointers (which are really
01917d
+	     function descriptors).  */
01917d
+	  set_gdbarch_convert_from_func_ptr_addr
01917d
+	    (gdbarch, ppc64_convert_from_func_ptr_addr);
01917d
 
01917d
-      set_gdbarch_elf_make_msymbol_special (gdbarch,
01917d
-					    ppc64_elf_make_msymbol_special);
01917d
+	  set_gdbarch_elf_make_msymbol_special
01917d
+	    (gdbarch, ppc64_elf_make_msymbol_special);
01917d
+	}
01917d
 
01917d
       /* Shared library handling.  */
01917d
       set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
01917d
Index: gdb-7.6.1/gdb/ppc-sysv-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/ppc-sysv-tdep.c
01917d
+++ gdb-7.6.1/gdb/ppc-sysv-tdep.c
01917d
@@ -1351,8 +1351,9 @@ ppc64_sysv_abi_push_param (struct gdbarc
01917d
 	  word = unpack_long (type, val);
01917d
 
01917d
 	  /* Convert any function code addresses into descriptors.  */
01917d
-	  if (TYPE_CODE (type) == TYPE_CODE_PTR
01917d
-	      || TYPE_CODE (type) == TYPE_CODE_REF)
01917d
+	  if (tdep->elf_abi == POWERPC_ELF_V1
01917d
+	      && (TYPE_CODE (type) == TYPE_CODE_PTR
01917d
+		  || TYPE_CODE (type) == TYPE_CODE_REF))
01917d
 	    {
01917d
 	      struct type *target_type
01917d
 		= check_typedef (TYPE_TARGET_TYPE (type));
01917d
@@ -1552,24 +1553,32 @@ ppc64_sysv_abi_push_dummy_call (struct g
01917d
      breakpoint.  */
01917d
   regcache_cooked_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
01917d
 
01917d
-  /* Use the func_addr to find the descriptor, and use that to find
01917d
-     the TOC.  If we're calling via a function pointer, the pointer
01917d
-     itself identifies the descriptor.  */
01917d
-  {
01917d
-    struct type *ftype = check_typedef (value_type (function));
01917d
-    CORE_ADDR desc_addr = value_as_address (function);
01917d
-
01917d
-    if (TYPE_CODE (ftype) == TYPE_CODE_PTR
01917d
-	|| convert_code_addr_to_desc_addr (func_addr, &desc_addr))
01917d
-      {
01917d
-	/* The TOC is the second double word in the descriptor.  */
01917d
-	CORE_ADDR toc =
01917d
-	  read_memory_unsigned_integer (desc_addr + tdep->wordsize,
01917d
-					tdep->wordsize, byte_order);
01917d
-	regcache_cooked_write_unsigned (regcache,
01917d
-					tdep->ppc_gp0_regnum + 2, toc);
01917d
-      }
01917d
-  }
01917d
+  /* In the ELFv1 ABI, use the func_addr to find the descriptor, and use
01917d
+     that to find the TOC.  If we're calling via a function pointer,
01917d
+     the pointer itself identifies the descriptor.  */
01917d
+  if (tdep->elf_abi == POWERPC_ELF_V1)
01917d
+    {
01917d
+      struct type *ftype = check_typedef (value_type (function));
01917d
+      CORE_ADDR desc_addr = value_as_address (function);
01917d
+
01917d
+      if (TYPE_CODE (ftype) == TYPE_CODE_PTR
01917d
+	  || convert_code_addr_to_desc_addr (func_addr, &desc_addr))
01917d
+	{
01917d
+	  /* The TOC is the second double word in the descriptor.  */
01917d
+	  CORE_ADDR toc =
01917d
+	    read_memory_unsigned_integer (desc_addr + tdep->wordsize,
01917d
+					  tdep->wordsize, byte_order);
01917d
+
01917d
+	  regcache_cooked_write_unsigned (regcache,
01917d
+					  tdep->ppc_gp0_regnum + 2, toc);
01917d
+	}
01917d
+    }
01917d
+
01917d
+  /* In the ELFv2 ABI, we need to pass the target address in r12 since
01917d
+     we may be calling a global entry point.  */
01917d
+  if (tdep->elf_abi == POWERPC_ELF_V2)
01917d
+    regcache_cooked_write_unsigned (regcache,
01917d
+				    tdep->ppc_gp0_regnum + 12, func_addr);
01917d
 
01917d
   return sp;
01917d
 }