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

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