Blame SOURCES/ltrace-0.7.91-ppc64le-support.patch

8d9cfe
From eea4ad2cce289753aaa35b4e0258a76d8f8f367c Mon Sep 17 00:00:00 2001
8d9cfe
From: Thierry Fauck <thierry@linux.vnet.ibm.com>
8d9cfe
Date: Tue, 13 May 2014 07:48:24 -0400
8d9cfe
Subject: [PATCH] Support for powerpc64 arch ppc64el
8d9cfe
8d9cfe
Signed-off-by: Thierry Fauck <thierry@linux.vnet.ibm.com>
8d9cfe
8d9cfe
	Add support for ppc64le proc and ELF ABIv2.
8d9cfe
	Provides support for irelative and wchar
8d9cfe
---
8d9cfe
 ltrace-elf.c                           |    2 +-
8d9cfe
 ltrace-elf.h                           |    1 +
8d9cfe
 sysdeps/linux-gnu/ppc/arch.h           |   35 ++++-
8d9cfe
 sysdeps/linux-gnu/ppc/fetch.c          |  244 +++++++++++++++++++++++++++++---
8d9cfe
 sysdeps/linux-gnu/ppc/plt.c            |   98 ++++++++++++--
8d9cfe
 sysdeps/linux-gnu/ppc/trace.c          |   10 ++
8d9cfe
 testsuite/ltrace.main/system_calls.exp |    2 +-
8d9cfe
 7 files changed, 356 insertions(+), 36 deletions(-)
8d9cfe
8d9cfe
diff --git a/ltrace-elf.c b/ltrace-elf.c
8d9cfe
index 8997518..f638342 100644
8d9cfe
--- a/ltrace-elf.c
8d9cfe
+++ b/ltrace-elf.c
8d9cfe
@@ -859,7 +859,7 @@ populate_plt(struct process *proc, const char *filename,
8d9cfe
 	return 0;
8d9cfe
 }
8d9cfe
 
8d9cfe
-static void
8d9cfe
+void
8d9cfe
 delete_symbol_chain(struct library_symbol *libsym)
8d9cfe
 {
8d9cfe
 	while (libsym != NULL) {
8d9cfe
diff --git a/ltrace-elf.h b/ltrace-elf.h
8d9cfe
index db4ffe9..4a824c4 100644
8d9cfe
--- a/ltrace-elf.h
8d9cfe
+++ b/ltrace-elf.h
8d9cfe
@@ -166,6 +166,7 @@ int elf_read_next_uleb128(Elf_Data *data, GElf_Xword *offset, uint64_t *retp);
8d9cfe
 /* Return whether there's AMOUNT more bytes after OFFSET in DATA.  */
8d9cfe
 int elf_can_read_next(Elf_Data *data, GElf_Xword offset, GElf_Xword amount);
8d9cfe
 
8d9cfe
+void delete_symbol_chain(struct library_symbol *);
8d9cfe
 #if __WORDSIZE == 32
8d9cfe
 #define PRI_ELF_ADDR		PRIx32
8d9cfe
 #define GELF_ADDR_CAST(x)	(void *)(uint32_t)(x)
8d9cfe
diff --git a/sysdeps/linux-gnu/ppc/arch.h b/sysdeps/linux-gnu/ppc/arch.h
8d9cfe
index bf9b5dc..7918a13 100644
8d9cfe
--- a/sysdeps/linux-gnu/ppc/arch.h
8d9cfe
+++ b/sysdeps/linux-gnu/ppc/arch.h
8d9cfe
@@ -23,8 +23,8 @@
8d9cfe
 #define LTRACE_PPC_ARCH_H
8d9cfe
 
8d9cfe
 #include <gelf.h>
8d9cfe
+#include <stdbool.h>
8d9cfe
 
8d9cfe
-#define BREAKPOINT_VALUE { 0x7f, 0xe0, 0x00, 0x08 }
8d9cfe
 #define BREAKPOINT_LENGTH 4
8d9cfe
 #define DECR_PC_AFTER_BREAK 0
8d9cfe
 
8d9cfe
@@ -34,8 +34,33 @@
8d9cfe
 #ifdef __powerpc64__ // Says 'ltrace' is 64 bits, says nothing about target.
8d9cfe
 #define LT_ELFCLASS2	ELFCLASS64
8d9cfe
 #define LT_ELF_MACHINE2	EM_PPC64
8d9cfe
-#define ARCH_SUPPORTS_OPD
8d9cfe
-#endif
8d9cfe
+
8d9cfe
+# ifdef __LITTLE_ENDIAN__
8d9cfe
+# define BREAKPOINT_VALUE { 0x08, 0x00, 0xe0, 0x7f }
8d9cfe
+# define ARCH_ENDIAN_LITTLE
8d9cfe
+# else
8d9cfe
+# define BREAKPOINT_VALUE { 0x7f, 0xe0, 0x00, 0x08 }
8d9cfe
+# define ARCH_SUPPORTS_OPD
8d9cfe
+# define ARCH_ENDIAN_BIG
8d9cfe
+# endif
8d9cfe
+
8d9cfe
+# if _CALL_ELF != 2
8d9cfe
+# define ARCH_SUPPORTS_OPD
8d9cfe
+# define STACK_FRAME_OVERHEAD 112
8d9cfe
+#  ifndef EF_PPC64_ABI
8d9cfe
+#  define EF_PPC64_ABI 3
8d9cfe
+#  endif
8d9cfe
+# else /* _CALL_ELF == 2 ABIv2 */
8d9cfe
+# define STACK_FRAME_OVERHEAD 32
8d9cfe
+# endif /* CALL_ELF */
8d9cfe
+
8d9cfe
+#else
8d9cfe
+#define BREAKPOINT_VALUE { 0x7f, 0xe0, 0x00, 0x08 }
8d9cfe
+#define ARCH_ENDIAN_BIG
8d9cfe
+# ifndef EF_PPC64_ABI
8d9cfe
+# define EF_PPC64_ABI 3
8d9cfe
+# endif
8d9cfe
+#endif 	/* __powerpc64__ */
8d9cfe
 
8d9cfe
 #define ARCH_HAVE_SW_SINGLESTEP
8d9cfe
 #define ARCH_HAVE_ADD_PLT_ENTRY
8d9cfe
@@ -43,7 +68,6 @@
8d9cfe
 #define ARCH_HAVE_TRANSLATE_ADDRESS
8d9cfe
 #define ARCH_HAVE_DYNLINK_DONE
8d9cfe
 #define ARCH_HAVE_FETCH_ARG
8d9cfe
-#define ARCH_ENDIAN_BIG
8d9cfe
 #define ARCH_HAVE_SIZEOF
8d9cfe
 #define ARCH_HAVE_ALIGNOF
8d9cfe
 
8d9cfe
@@ -56,7 +80,8 @@ struct arch_ltelf_data {
8d9cfe
 	Elf_Data *opd_data;
8d9cfe
 	GElf_Addr opd_base;
8d9cfe
 	GElf_Xword opd_size;
8d9cfe
-	int secure_plt;
8d9cfe
+	bool secure_plt : 1;
8d9cfe
+	bool elfv2_abi  : 1;
8d9cfe
 
8d9cfe
 	Elf_Data *reladyn;
8d9cfe
 	size_t reladyn_count;
8d9cfe
diff --git a/sysdeps/linux-gnu/ppc/fetch.c b/sysdeps/linux-gnu/ppc/fetch.c
8d9cfe
index ed38336..c9381c3 100644
8d9cfe
--- a/sysdeps/linux-gnu/ppc/fetch.c
8d9cfe
+++ b/sysdeps/linux-gnu/ppc/fetch.c
8d9cfe
@@ -30,9 +30,11 @@
8d9cfe
 #include "ptrace.h"
8d9cfe
 #include "proc.h"
8d9cfe
 #include "value.h"
8d9cfe
+#include "ltrace-elf.h"
8d9cfe
 
8d9cfe
 static int allocate_gpr(struct fetch_context *ctx, struct process *proc,
8d9cfe
-			struct arg_type_info *info, struct value *valuep);
8d9cfe
+			struct arg_type_info *info, struct value *valuep,
8d9cfe
+			size_t off, bool is_hfa_type);
8d9cfe
 
8d9cfe
 /* Floating point registers have the same width on 32-bit as well as
8d9cfe
  * 64-bit PPC, but <ucontext.h> presents a different API depending on
8d9cfe
@@ -62,7 +64,10 @@ struct fetch_context {
8d9cfe
 		gregs64_t r64;
8d9cfe
 	} regs;
8d9cfe
 	struct fpregs_t fpregs;
8d9cfe
-
8d9cfe
+	int vgreg;
8d9cfe
+	int struct_size;
8d9cfe
+	int struct_hfa_size;
8d9cfe
+	int struct_hfa_count;
8d9cfe
 };
8d9cfe
 
8d9cfe
 static int
8d9cfe
@@ -74,7 +79,8 @@ fetch_context_init(struct process *proc, struct fetch_context *context)
8d9cfe
 	if (proc->e_machine == EM_PPC)
8d9cfe
 		context->stack_pointer = proc->stack_pointer + 8;
8d9cfe
 	else
8d9cfe
-		context->stack_pointer = proc->stack_pointer + 112;
8d9cfe
+		context->stack_pointer = proc->stack_pointer
8d9cfe
+			+ STACK_FRAME_OVERHEAD;
8d9cfe
 
8d9cfe
 	/* When ltrace is 64-bit, we might use PTRACE_GETREGS to
8d9cfe
 	 * obtain 64-bit as well as 32-bit registers.  But if we do it
8d9cfe
@@ -118,6 +124,11 @@ arch_fetch_arg_init(enum tof type, struct process *proc,
8d9cfe
 		return NULL;
8d9cfe
 	}
8d9cfe
 
8d9cfe
+	context->vgreg = context->greg;
8d9cfe
+	context->struct_size = 0;
8d9cfe
+	context->struct_hfa_size = 0;
8d9cfe
+	context->struct_hfa_count = 0;
8d9cfe
+
8d9cfe
 	/* Aggregates or unions of any length, and character strings
8d9cfe
 	 * of length longer than 8 bytes, will be returned in a
8d9cfe
 	 * storage buffer allocated by the caller. The caller will
8d9cfe
@@ -125,8 +136,20 @@ arch_fetch_arg_init(enum tof type, struct process *proc,
8d9cfe
 	 * in r3, causing the first explicit argument to be passed in
8d9cfe
 	 * r4.  */
8d9cfe
 	context->ret_struct = ret_info->type == ARGTYPE_STRUCT;
8d9cfe
-	if (context->ret_struct)
8d9cfe
+	if (context->ret_struct) {
8d9cfe
+#if _CALL_ELF == 2
8d9cfe
+		/* if R3 points to stack, parameters will be in R4.  */
8d9cfe
+		uint64_t pstack_end = ptrace(PTRACE_PEEKTEXT, proc->pid,
8d9cfe
+					proc->stack_pointer, 0);
8d9cfe
+		if (((arch_addr_t)context->regs.r64[3] > proc->stack_pointer)
8d9cfe
+		    && (context->regs.r64[3] < pstack_end)) {
8d9cfe
+			context->greg++;
8d9cfe
+			context->stack_pointer += 8;
8d9cfe
+		}
8d9cfe
+#else
8d9cfe
 		context->greg++;
8d9cfe
+#endif
8d9cfe
+	}
8d9cfe
 
8d9cfe
 	return context;
8d9cfe
 }
8d9cfe
@@ -144,7 +167,8 @@ arch_fetch_arg_clone(struct process *proc,
8d9cfe
 
8d9cfe
 static int
8d9cfe
 allocate_stack_slot(struct fetch_context *ctx, struct process *proc,
8d9cfe
-		    struct arg_type_info *info, struct value *valuep)
8d9cfe
+		    struct arg_type_info *info, struct value *valuep,
8d9cfe
+		    bool is_hfa_type)
8d9cfe
 {
8d9cfe
 	size_t sz = type_sizeof(proc, info);
8d9cfe
 	if (sz == (size_t)-1)
8d9cfe
@@ -154,7 +178,14 @@ allocate_stack_slot(struct fetch_context *ctx, struct process *proc,
8d9cfe
 	size_t off = 0;
8d9cfe
 	if (proc->e_machine == EM_PPC && a < 4)
8d9cfe
 		a = 4;
8d9cfe
+#if _CALL_ELF == 2
8d9cfe
+	else if (proc->e_machine == EM_PPC64 && sz == 4 && is_hfa_type)
8d9cfe
+		a = 4;
8d9cfe
+	else
8d9cfe
+		a = 8;
8d9cfe
+#else
8d9cfe
 	else if (proc->e_machine == EM_PPC64 && a < 8)
8d9cfe
+#endif
8d9cfe
 		a = 8;
8d9cfe
 
8d9cfe
 	/* XXX Remove the two double casts when arch_addr_t
8d9cfe
@@ -164,7 +195,7 @@ allocate_stack_slot(struct fetch_context *ctx, struct process *proc,
8d9cfe
 
8d9cfe
 	if (valuep != NULL)
8d9cfe
 		value_in_inferior(valuep, ctx->stack_pointer + off);
8d9cfe
-	ctx->stack_pointer += sz;
8d9cfe
+	ctx->stack_pointer += a;
8d9cfe
 
8d9cfe
 	return 0;
8d9cfe
 }
8d9cfe
@@ -216,19 +247,34 @@ align_small_int(unsigned char *buf, size_t w, size_t sz)
8d9cfe
 
8d9cfe
 static int
8d9cfe
 allocate_gpr(struct fetch_context *ctx, struct process *proc,
8d9cfe
-	     struct arg_type_info *info, struct value *valuep)
8d9cfe
+	     struct arg_type_info *info, struct value *valuep,
8d9cfe
+	     size_t off, bool is_hfa_type)
8d9cfe
 {
8d9cfe
 	if (ctx->greg > 10)
8d9cfe
-		return allocate_stack_slot(ctx, proc, info, valuep);
8d9cfe
+		return allocate_stack_slot(ctx, proc, info, valuep, is_hfa_type);
8d9cfe
 
8d9cfe
-	int reg_num = ctx->greg++;
8d9cfe
-	if (valuep == NULL)
8d9cfe
-		return 0;
8d9cfe
+	int reg_num = ctx->greg;
8d9cfe
 
8d9cfe
 	size_t sz = type_sizeof(proc, info);
8d9cfe
 	if (sz == (size_t)-1)
8d9cfe
 		return -1;
8d9cfe
 	assert(sz == 1 || sz == 2 || sz == 4 || sz == 8);
8d9cfe
+#if _CALL_ELF == 2
8d9cfe
+	/* Consume the stack slot corresponding to this arg.  */
8d9cfe
+	if ((sz + off) >= 8)
8d9cfe
+		ctx->greg++;
8d9cfe
+
8d9cfe
+	if (is_hfa_type)
8d9cfe
+		ctx->stack_pointer += sz;
8d9cfe
+	else
8d9cfe
+		ctx->stack_pointer += 8;
8d9cfe
+#else
8d9cfe
+	ctx->greg++;
8d9cfe
+#endif
8d9cfe
+
8d9cfe
+	if (valuep == NULL)
8d9cfe
+		return 0;
8d9cfe
+
8d9cfe
 	if (value_reserve(valuep, sz) == NULL)
8d9cfe
 		return -1;
8d9cfe
 
8d9cfe
@@ -240,13 +286,14 @@ allocate_gpr(struct fetch_context *ctx, struct process *proc,
8d9cfe
 	u.i64 = read_gpr(ctx, proc, reg_num);
8d9cfe
 	if (proc->e_machine == EM_PPC)
8d9cfe
 		align_small_int(u.buf, 8, sz);
8d9cfe
-	memcpy(value_get_raw_data(valuep), u.buf, sz);
8d9cfe
+	memcpy(value_get_raw_data(valuep), u.buf + off, sz);
8d9cfe
 	return 0;
8d9cfe
 }
8d9cfe
 
8d9cfe
 static int
8d9cfe
 allocate_float(struct fetch_context *ctx, struct process *proc,
8d9cfe
-	       struct arg_type_info *info, struct value *valuep)
8d9cfe
+	       struct arg_type_info *info, struct value *valuep,
8d9cfe
+	       size_t off, bool is_hfa_type)
8d9cfe
 {
8d9cfe
 	int pool = proc->e_machine == EM_PPC64 ? 13 : 8;
8d9cfe
 	if (ctx->freg <= pool) {
8d9cfe
@@ -257,8 +304,12 @@ allocate_float(struct fetch_context *ctx, struct process *proc,
8d9cfe
 		} u = { .d = ctx->fpregs.fpregs[ctx->freg] };
8d9cfe
 
8d9cfe
 		ctx->freg++;
8d9cfe
+
8d9cfe
+		if (!is_hfa_type)
8d9cfe
+			ctx->vgreg++;
8d9cfe
+
8d9cfe
 		if (proc->e_machine == EM_PPC64)
8d9cfe
-			allocate_gpr(ctx, proc, info, NULL);
8d9cfe
+			allocate_gpr(ctx, proc, info, NULL, off, is_hfa_type);
8d9cfe
 
8d9cfe
 		size_t sz = sizeof(double);
8d9cfe
 		if (info->type == ARGTYPE_FLOAT) {
8d9cfe
@@ -272,8 +323,128 @@ allocate_float(struct fetch_context *ctx, struct process *proc,
8d9cfe
 		memcpy(value_get_raw_data(valuep), u.buf, sz);
8d9cfe
 		return 0;
8d9cfe
 	}
8d9cfe
-	return allocate_stack_slot(ctx, proc, info, valuep);
8d9cfe
+	return allocate_stack_slot(ctx, proc, info, valuep, is_hfa_type);
8d9cfe
+}
8d9cfe
+
8d9cfe
+#if _CALL_ELF == 2
8d9cfe
+static int
8d9cfe
+allocate_hfa(struct fetch_context *ctx, struct process *proc,
8d9cfe
+	     struct arg_type_info *info, struct value *valuep,
8d9cfe
+	     enum arg_type hfa_type, size_t hfa_count)
8d9cfe
+{
8d9cfe
+	size_t sz = type_sizeof(proc, info);
8d9cfe
+	if (sz == (size_t)-1)
8d9cfe
+		return -1;
8d9cfe
+
8d9cfe
+	ctx->struct_hfa_size += sz;
8d9cfe
+
8d9cfe
+	/* There are two changes regarding structure return types:
8d9cfe
+	 * * heterogeneous float/vector structs are returned
8d9cfe
+	 *   in (multiple) FP/vector registers,
8d9cfe
+	 *   instead of via implicit reference.
8d9cfe
+	 * * small structs (up to 16 bytes) are return
8d9cfe
+	 *   in one or two GPRs, instead of via implicit reference.
8d9cfe
+	 *
8d9cfe
+	 * Other structures (larger than 16 bytes, not heterogeneous)
8d9cfe
+	 * are still returned via implicit reference (i.e. a pointer
8d9cfe
+	 * to memory where to return the struct being passed in r3).
8d9cfe
+	 * Of course, whether or not an implicit reference pointer
8d9cfe
+	 * is present will shift the remaining arguments,
8d9cfe
+	 * so you need to get this right for ELFv2 in order
8d9cfe
+	 * to get the arguments correct.
8d9cfe
+	 * If an actual parameter is known to correspond to an HFA
8d9cfe
+	 * formal parameter, each element is passed in the next
8d9cfe
+	 * available floating-point argument register starting at fp1
8d9cfe
+	 * until the fp13. The remaining elements of the aggregate are
8d9cfe
+	 * passed on the stack.  */
8d9cfe
+	size_t slot_off = 0;
8d9cfe
+
8d9cfe
+	unsigned char *buf = value_reserve(valuep, sz);
8d9cfe
+	if (buf == NULL)
8d9cfe
+		return -1;
8d9cfe
+
8d9cfe
+	struct arg_type_info *hfa_info = type_get_simple(hfa_type);
8d9cfe
+	size_t hfa_sz = type_sizeof(proc, hfa_info);
8d9cfe
+
8d9cfe
+	if (hfa_count > 8)
8d9cfe
+		ctx->struct_hfa_count += hfa_count;
8d9cfe
+
8d9cfe
+	while (hfa_count > 0 && ctx->freg <= 13) {
8d9cfe
+		int rc;
8d9cfe
+		struct value tmp;
8d9cfe
+
8d9cfe
+		value_init(&tmp, proc, NULL, hfa_info, 0);
8d9cfe
+
8d9cfe
+		/* Hetereogeneous struct - get value on GPR or stack.  */
8d9cfe
+		if (((hfa_type == ARGTYPE_FLOAT
8d9cfe
+		    || hfa_type == ARGTYPE_DOUBLE)
8d9cfe
+		      && hfa_count <= 8))
8d9cfe
+			rc = allocate_float(ctx, proc, hfa_info, &tmp,
8d9cfe
+						slot_off, true);
8d9cfe
+		else
8d9cfe
+			rc = allocate_gpr(ctx, proc, hfa_info, &tmp,
8d9cfe
+						slot_off, true);
8d9cfe
+
8d9cfe
+		memcpy(buf, value_get_data(&tmp, NULL), hfa_sz);
8d9cfe
+
8d9cfe
+		slot_off += hfa_sz;
8d9cfe
+		buf += hfa_sz;
8d9cfe
+		hfa_count--;
8d9cfe
+		if (slot_off == 8) {
8d9cfe
+			slot_off = 0;
8d9cfe
+			ctx->vgreg++;
8d9cfe
+		}
8d9cfe
+
8d9cfe
+		value_destroy(&tmp);
8d9cfe
+		if (rc < 0)
8d9cfe
+			return -1;
8d9cfe
+	}
8d9cfe
+	if (hfa_count == 0)
8d9cfe
+		return 0;
8d9cfe
+
8d9cfe
+	/* if no remaining FP, GPR corresponding to slot is used
8d9cfe
+	* Mostly it is in part of r10.  */
8d9cfe
+	if (ctx->struct_hfa_size <= 64 && ctx->vgreg == 10) {
8d9cfe
+		while (ctx->vgreg <= 10) {
8d9cfe
+			struct value tmp;
8d9cfe
+			value_init(&tmp, proc, NULL, hfa_info, 0);
8d9cfe
+			union {
8d9cfe
+				uint64_t i64;
8d9cfe
+				unsigned char buf[0];
8d9cfe
+			} u;
8d9cfe
+
8d9cfe
+			u.i64 = read_gpr(ctx, proc, ctx->vgreg);
8d9cfe
+
8d9cfe
+			memcpy(buf, u.buf + slot_off, hfa_sz);
8d9cfe
+			slot_off += hfa_sz;
8d9cfe
+			buf += hfa_sz;
8d9cfe
+			hfa_count--;
8d9cfe
+			ctx->stack_pointer += hfa_sz;
8d9cfe
+			if (slot_off >= 8 ) {
8d9cfe
+				slot_off = 0;
8d9cfe
+				ctx->vgreg++;
8d9cfe
+			}
8d9cfe
+			value_destroy(&tmp);
8d9cfe
+		}
8d9cfe
+	}
8d9cfe
+
8d9cfe
+	if (hfa_count == 0)
8d9cfe
+		return 0;
8d9cfe
+
8d9cfe
+	/* Remaining values are on stack */
8d9cfe
+	while (hfa_count) {
8d9cfe
+		struct value tmp;
8d9cfe
+		value_init(&tmp, proc, NULL, hfa_info, 0);
8d9cfe
+
8d9cfe
+		value_in_inferior(&tmp, ctx->stack_pointer);
8d9cfe
+		memcpy(buf, value_get_data(&tmp, NULL), hfa_sz);
8d9cfe
+		ctx->stack_pointer += hfa_sz;
8d9cfe
+		buf += hfa_sz;
8d9cfe
+		hfa_count--;
8d9cfe
+	}
8d9cfe
+	return 0;
8d9cfe
 }
8d9cfe
+#endif
8d9cfe
 
8d9cfe
 static int
8d9cfe
 allocate_argument(struct fetch_context *ctx, struct process *proc,
8d9cfe
@@ -287,13 +458,25 @@ allocate_argument(struct fetch_context *ctx, struct process *proc,
8d9cfe
 
8d9cfe
 	case ARGTYPE_FLOAT:
8d9cfe
 	case ARGTYPE_DOUBLE:
8d9cfe
-		return allocate_float(ctx, proc, info, valuep);
8d9cfe
+		return allocate_float(ctx, proc, info, valuep,
8d9cfe
+					8 - type_sizeof(proc,info), false);
8d9cfe
 
8d9cfe
 	case ARGTYPE_STRUCT:
8d9cfe
 		if (proc->e_machine == EM_PPC) {
8d9cfe
 			if (value_pass_by_reference(valuep) < 0)
8d9cfe
 				return -1;
8d9cfe
 		} else {
8d9cfe
+#if _CALL_ELF == 2
8d9cfe
+			struct arg_type_info *hfa_info;
8d9cfe
+			size_t hfa_size;
8d9cfe
+			hfa_info = type_get_hfa_type(info, &hfa_size);
8d9cfe
+			if (hfa_info != NULL ) {
8d9cfe
+				size_t sz = type_sizeof(proc, info);
8d9cfe
+				ctx->struct_size += sz;
8d9cfe
+				return allocate_hfa(ctx, proc, info, valuep,
8d9cfe
+						hfa_info->type, hfa_size);
8d9cfe
+			}
8d9cfe
+#endif
8d9cfe
 			/* PPC64: Fixed size aggregates and unions passed by
8d9cfe
 			 * value are mapped to as many doublewords of the
8d9cfe
 			 * parameter save area as the value uses in memory.
8d9cfe
@@ -326,6 +509,10 @@ allocate_argument(struct fetch_context *ctx, struct process *proc,
8d9cfe
 	size_t sz = type_sizeof(proc, valuep->type);
8d9cfe
 	if (sz == (size_t)-1)
8d9cfe
 		return -1;
8d9cfe
+
8d9cfe
+	if (ctx->ret_struct)
8d9cfe
+		ctx->struct_size += sz;
8d9cfe
+
8d9cfe
 	size_t slots = (sz + width - 1) / width;  /* Round up.  */
8d9cfe
 	unsigned char *buf = value_reserve(valuep, slots * width);
8d9cfe
 	if (buf == NULL)
8d9cfe
@@ -346,9 +533,11 @@ allocate_argument(struct fetch_context *ctx, struct process *proc,
8d9cfe
 		struct arg_type_info *fp_info
8d9cfe
 			= type_get_fp_equivalent(valuep->type);
8d9cfe
 		if (fp_info != NULL)
8d9cfe
-			rc = allocate_float(ctx, proc, fp_info, &val;;
8d9cfe
+			rc = allocate_float(ctx, proc, fp_info, &val,
8d9cfe
+					8-type_sizeof(proc,info), false);
8d9cfe
 		else
8d9cfe
-			rc = allocate_gpr(ctx, proc, long_info, &val;;
8d9cfe
+			rc = allocate_gpr(ctx, proc, long_info, &val,
8d9cfe
+					0, false);
8d9cfe
 
8d9cfe
 		if (rc >= 0) {
8d9cfe
 			memcpy(ptr, value_get_data(&val, NULL), width);
8d9cfe
@@ -363,6 +552,7 @@ allocate_argument(struct fetch_context *ctx, struct process *proc,
8d9cfe
 			return rc;
8d9cfe
 	}
8d9cfe
 
8d9cfe
+#ifndef __LITTLE_ENDIAN__
8d9cfe
 	/* Small values need post-processing.  */
8d9cfe
 	if (sz < width) {
8d9cfe
 		switch (info->type) {
8d9cfe
@@ -394,6 +584,7 @@ allocate_argument(struct fetch_context *ctx, struct process *proc,
8d9cfe
 			break;
8d9cfe
 		}
8d9cfe
 	}
8d9cfe
+#endif
8d9cfe
 
8d9cfe
 	return 0;
8d9cfe
 }
8d9cfe
@@ -411,7 +602,22 @@ arch_fetch_retval(struct fetch_context *ctx, enum tof type,
8d9cfe
 		  struct process *proc, struct arg_type_info *info,
8d9cfe
 		  struct value *valuep)
8d9cfe
 {
8d9cfe
+	if (fetch_context_init(proc, ctx) < 0)
8d9cfe
+		return -1;
8d9cfe
+
8d9cfe
+#if _CALL_ELF == 2
8d9cfe
+	void *ptr = (void *)(ctx->regs.r64[1]+32);
8d9cfe
+	uint64_t val = ptrace(PTRACE_PEEKTEXT, proc->pid, ptr, 0);
8d9cfe
+
8d9cfe
+	if (ctx->ret_struct
8d9cfe
+	   && ((ctx->struct_size > 64
8d9cfe
+	      || ctx->struct_hfa_count > 8
8d9cfe
+	      || (ctx->struct_hfa_size == 0 && ctx->struct_size > 56)
8d9cfe
+	      || (ctx->regs.r64[3] == ctx->regs.r64[1]+32)
8d9cfe
+	      || (ctx->regs.r64[3] == val )))) {
8d9cfe
+#else
8d9cfe
 	if (ctx->ret_struct) {
8d9cfe
+#endif
8d9cfe
 		assert(info->type == ARGTYPE_STRUCT);
8d9cfe
 
8d9cfe
 		uint64_t addr = read_gpr(ctx, proc, 3);
8d9cfe
@@ -424,8 +630,6 @@ arch_fetch_retval(struct fetch_context *ctx, enum tof type,
8d9cfe
 		return 0;
8d9cfe
 	}
8d9cfe
 
8d9cfe
-	if (fetch_context_init(proc, ctx) < 0)
8d9cfe
-		return -1;
8d9cfe
 	return allocate_argument(ctx, proc, info, valuep);
8d9cfe
 }
8d9cfe
 
8d9cfe
diff --git a/sysdeps/linux-gnu/ppc/plt.c b/sysdeps/linux-gnu/ppc/plt.c
8d9cfe
index 332daa8..45ed7fb 100644
8d9cfe
--- a/sysdeps/linux-gnu/ppc/plt.c
8d9cfe
+++ b/sysdeps/linux-gnu/ppc/plt.c
8d9cfe
@@ -136,7 +136,11 @@
8d9cfe
  */
8d9cfe
 
8d9cfe
 #define PPC_PLT_STUB_SIZE 16
8d9cfe
-#define PPC64_PLT_STUB_SIZE 8 //xxx
8d9cfe
+#if _CALL_ELF != 2
8d9cfe
+#define PPC64_PLT_STUB_SIZE 8
8d9cfe
+#else
8d9cfe
+#define PPC64_PLT_STUB_SIZE 4
8d9cfe
+#endif
8d9cfe
 
8d9cfe
 static inline int
8d9cfe
 host_powerpc64()
8d9cfe
@@ -186,8 +190,13 @@ ppc32_delayed_symbol(struct library_symbol *libsym)
8d9cfe
 	if ((insn1 & BRANCH_MASK) == B_INSN
8d9cfe
 	    || ((insn2 & BRANCH_MASK) == B_INSN
8d9cfe
 		/* XXX double cast  */
8d9cfe
+#ifdef __LITTLE_ENDIAN__
8d9cfe
+		&& (ppc_branch_dest(libsym->enter_addr + 4, insn1)
8d9cfe
+		    == (arch_addr_t) (long) libsym->lib->arch.pltgot_addr)))
8d9cfe
+#else
8d9cfe
 		&& (ppc_branch_dest(libsym->enter_addr + 4, insn2)
8d9cfe
 		    == (arch_addr_t) (long) libsym->lib->arch.pltgot_addr)))
8d9cfe
+#endif
8d9cfe
 	{
8d9cfe
 		mark_as_resolved(libsym, libsym->arch.resolved_value);
8d9cfe
 	}
8d9cfe
@@ -206,7 +215,7 @@ arch_dynlink_done(struct process *proc)
8d9cfe
 				"couldn't read PLT value for %s(%p): %s\n",
8d9cfe
 				libsym->name, libsym->enter_addr,
8d9cfe
 				strerror(errno));
8d9cfe
-			return;
8d9cfe
+				return;
8d9cfe
 		}
8d9cfe
 
8d9cfe
 		if (proc->e_machine == EM_PPC)
8d9cfe
@@ -227,8 +236,14 @@ reloc_is_irelative(int machine, GElf_Rela *rela)
8d9cfe
 {
8d9cfe
 	bool irelative = false;
8d9cfe
 	if (machine == EM_PPC64) {
8d9cfe
-#ifdef R_PPC64_JMP_IREL
8d9cfe
+#ifdef __LITTLE_ENDIAN__
8d9cfe
+# ifdef R_PPC64_IRELATIVE
8d9cfe
+		irelative = GELF_R_TYPE(rela->r_info) == R_PPC64_IRELATIVE;
8d9cfe
+# endif
8d9cfe
+#else
8d9cfe
+# ifdef R_PPC64_JMP_IREL
8d9cfe
 		irelative = GELF_R_TYPE(rela->r_info) == R_PPC64_JMP_IREL;
8d9cfe
+# endif
8d9cfe
 #endif
8d9cfe
 	} else {
8d9cfe
 		assert(machine == EM_PPC);
8d9cfe
@@ -285,6 +300,7 @@ arch_translate_address_dyn(struct process *proc,
8d9cfe
 			   arch_addr_t addr, arch_addr_t *ret)
8d9cfe
 {
8d9cfe
 	if (proc->e_machine == EM_PPC64) {
8d9cfe
+#if _CALL_ELF != 2
8d9cfe
 		uint64_t value;
8d9cfe
 		if (proc_read_64(proc, addr, &value) < 0) {
8d9cfe
 			fprintf(stderr,
8d9cfe
@@ -296,6 +312,7 @@ arch_translate_address_dyn(struct process *proc,
8d9cfe
 		 * arch_addr_t becomes integral type.  */
8d9cfe
 		*ret = (arch_addr_t)(uintptr_t)value;
8d9cfe
 		return 0;
8d9cfe
+#endif
8d9cfe
 	}
8d9cfe
 
8d9cfe
 	*ret = addr;
8d9cfe
@@ -306,7 +323,8 @@ int
8d9cfe
 arch_translate_address(struct ltelf *lte,
8d9cfe
 		       arch_addr_t addr, arch_addr_t *ret)
8d9cfe
 {
8d9cfe
-	if (lte->ehdr.e_machine == EM_PPC64) {
8d9cfe
+	if (lte->ehdr.e_machine == EM_PPC64
8d9cfe
+	    && !lte->arch.elfv2_abi) {
8d9cfe
 		/* XXX The double cast should be removed when
8d9cfe
 		 * arch_addr_t becomes integral type.  */
8d9cfe
 		GElf_Xword offset
8d9cfe
@@ -430,7 +448,16 @@ reloc_copy_if_irelative(GElf_Rela *rela, void *data)
8d9cfe
 int
8d9cfe
 arch_elf_init(struct ltelf *lte, struct library *lib)
8d9cfe
 {
8d9cfe
+
8d9cfe
+	/* Check for ABIv2 in ELF header processor specific flag.  */
8d9cfe
+#ifndef EF_PPC64_ABI
8d9cfe
+	assert (! (lte->ehdr.e_flags & 3 ) == 2)
8d9cfe
+#else
8d9cfe
+	lte->arch.elfv2_abi=((lte->ehdr.e_flags & EF_PPC64_ABI) == 2) ;
8d9cfe
+#endif
8d9cfe
+
8d9cfe
 	if (lte->ehdr.e_machine == EM_PPC64
8d9cfe
+	    && !lte->arch.elfv2_abi
8d9cfe
 	    && load_opd_data(lte, lib) < 0)
8d9cfe
 		return -1;
8d9cfe
 
8d9cfe
@@ -599,7 +626,7 @@ read_plt_slot_value(struct process *proc, GElf_Addr addr, GElf_Addr *valp)
8d9cfe
 	uint64_t l;
8d9cfe
 	/* XXX double cast.  */
8d9cfe
 	if (proc_read_64(proc, (arch_addr_t)(uintptr_t)addr, &l) < 0) {
8d9cfe
-		fprintf(stderr, "ptrace .plt slot value @%#" PRIx64": %s\n",
8d9cfe
+		debug(DEBUG_EVENT, "ptrace .plt slot value @%#" PRIx64": %s",
8d9cfe
 			addr, strerror(errno));
8d9cfe
 		return -1;
8d9cfe
 	}
8d9cfe
@@ -616,7 +643,7 @@ unresolve_plt_slot(struct process *proc, GElf_Addr addr, GElf_Addr value)
8d9cfe
 	 * pointers intact.  Hence the only adjustment that we need to
8d9cfe
 	 * do is to IP.  */
8d9cfe
 	if (ptrace(PTRACE_POKETEXT, proc->pid, addr, value) < 0) {
8d9cfe
-		fprintf(stderr, "failed to unresolve .plt slot: %s\n",
8d9cfe
+		debug(DEBUG_EVENT, "failed to unresolve .plt slot: %s",
8d9cfe
 			strerror(errno));
8d9cfe
 		return -1;
8d9cfe
 	}
8d9cfe
@@ -629,9 +656,48 @@ arch_elf_add_func_entry(struct process *proc, struct ltelf *lte,
8d9cfe
 			arch_addr_t addr, const char *name,
8d9cfe
 			struct library_symbol **ret)
8d9cfe
 {
8d9cfe
-	if (lte->ehdr.e_machine != EM_PPC || lte->ehdr.e_type == ET_DYN)
8d9cfe
+#ifndef PPC64_LOCAL_ENTRY_OFFSET
8d9cfe
+	assert(! lte->arch.elfv2_abi);
8d9cfe
+#else
8d9cfe
+	/* With ABIv2 st_other field contains an offset.  */
8d9cfe
+	 if (lte->arch.elfv2_abi)
8d9cfe
+		addr += PPC64_LOCAL_ENTRY_OFFSET(sym->st_other);
8d9cfe
+#endif
8d9cfe
+
8d9cfe
+	int st_info = GELF_ST_TYPE(sym->st_info);
8d9cfe
+
8d9cfe
+	if ((lte->ehdr.e_machine != EM_PPC && sym->st_other == 0)
8d9cfe
+	    || lte->ehdr.e_type == ET_DYN
8d9cfe
+	    || (st_info == STT_FUNC && ! sym->st_other))
8d9cfe
 		return PLT_DEFAULT;
8d9cfe
 
8d9cfe
+	if (st_info == STT_FUNC) {
8d9cfe
+		/* Put the default symbol to the chain.
8d9cfe
+		 * The addr has already been updated with
8d9cfe
+		 * symbol offset  */
8d9cfe
+		char *full_name = strdup(name);
8d9cfe
+		if (full_name == NULL) {
8d9cfe
+			fprintf(stderr, "couldn't copy name of %s: %s\n",
8d9cfe
+			name, strerror(errno));
8d9cfe
+			free(full_name);
8d9cfe
+			return PLT_FAIL;
8d9cfe
+		}
8d9cfe
+		struct library_symbol *libsym = malloc(sizeof *libsym);
8d9cfe
+		if (libsym == NULL
8d9cfe
+		    || library_symbol_init(libsym, addr, full_name, 1,
8d9cfe
+					   LS_TOPLT_NONE) < 0) {
8d9cfe
+			free(libsym);
8d9cfe
+			delete_symbol_chain(libsym);
8d9cfe
+			libsym = NULL;
8d9cfe
+			fprintf(stderr, "Couldn't add symbol %s"
8d9cfe
+				"for tracing.\n", name);
8d9cfe
+		}
8d9cfe
+		full_name = NULL;
8d9cfe
+		libsym->next = *ret;
8d9cfe
+		*ret = libsym;
8d9cfe
+		return PLT_OK;
8d9cfe
+	}
8d9cfe
+
8d9cfe
 	bool ifunc = false;
8d9cfe
 #ifdef STT_GNU_IFUNC
8d9cfe
 	ifunc = GELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC;
8d9cfe
@@ -761,9 +827,15 @@ arch_elf_add_plt_entry(struct process *proc, struct ltelf *lte,
8d9cfe
 	assert(plt_slot_addr >= lte->plt_addr
8d9cfe
 	       || plt_slot_addr < lte->plt_addr + lte->plt_size);
8d9cfe
 
8d9cfe
+	/* Should avoid to do read if dynamic linker hasn't run yet
8d9cfe
+	 * or allow -1 a valid return code.  */
8d9cfe
 	GElf_Addr plt_slot_value;
8d9cfe
-	if (read_plt_slot_value(proc, plt_slot_addr, &plt_slot_value) < 0)
8d9cfe
-		goto fail;
8d9cfe
+	if (read_plt_slot_value(proc, plt_slot_addr, &plt_slot_value) < 0) {
8d9cfe
+		if (!lte->arch.elfv2_abi)
8d9cfe
+			goto fail;
8d9cfe
+		else
8d9cfe
+			return PPC_PLT_UNRESOLVED;
8d9cfe
+	}
8d9cfe
 
8d9cfe
 	struct library_symbol *libsym = malloc(sizeof(*libsym));
8d9cfe
 	if (libsym == NULL) {
8d9cfe
@@ -997,8 +1069,12 @@ ppc_plt_bp_continue(struct breakpoint *bp, struct process *proc)
8d9cfe
 			return;
8d9cfe
 		}
8d9cfe
 
8d9cfe
+#if _CALL_ELF == 2
8d9cfe
+		continue_after_breakpoint(proc, bp);
8d9cfe
+#else
8d9cfe
 		jump_to_entry_point(proc, bp);
8d9cfe
 		continue_process(proc->pid);
8d9cfe
+#endif
8d9cfe
 		return;
8d9cfe
 
8d9cfe
 	case PPC64_PLT_STUB:
8d9cfe
@@ -1123,7 +1199,11 @@ arch_library_symbol_init(struct library_symbol *libsym)
8d9cfe
 	/* We set type explicitly in the code above, where we have the
8d9cfe
 	 * necessary context.  This is for calls from ltrace-elf.c and
8d9cfe
 	 * such.  */
8d9cfe
+#if _CALL_ELF == 2
8d9cfe
+	libsym->arch.type = PPC_PLT_UNRESOLVED;
8d9cfe
+#else
8d9cfe
 	libsym->arch.type = PPC_DEFAULT;
8d9cfe
+#endif
8d9cfe
 	return 0;
8d9cfe
 }
8d9cfe
 
8d9cfe
diff --git a/sysdeps/linux-gnu/ppc/trace.c b/sysdeps/linux-gnu/ppc/trace.c
8d9cfe
index ee9a6b5..5aab538 100644
8d9cfe
--- a/sysdeps/linux-gnu/ppc/trace.c
8d9cfe
+++ b/sysdeps/linux-gnu/ppc/trace.c
8d9cfe
@@ -65,9 +65,15 @@ syscall_p(struct process *proc, int status, int *sysnum)
8d9cfe
 	if (WIFSTOPPED(status)
8d9cfe
 	    && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) {
8d9cfe
 		long pc = (long)get_instruction_pointer(proc);
8d9cfe
+#ifndef __LITTLE_ENDIAN__
8d9cfe
 		int insn =
8d9cfe
 		    (int)ptrace(PTRACE_PEEKTEXT, proc->pid, pc - sizeof(long),
8d9cfe
 				0);
8d9cfe
+#else
8d9cfe
+		int insn =
8d9cfe
+		    (int)ptrace(PTRACE_PEEKTEXT, proc->pid, pc - sizeof(int),
8d9cfe
+				0);
8d9cfe
+#endif
8d9cfe
 
8d9cfe
 		if (insn == SYSCALL_INSN) {
8d9cfe
 			*sysnum =
8d9cfe
diff -up ltrace-0.7.91/sysdeps/linux-gnu/ppc/trace.c\~ ltrace-0.7.91/sysdeps/linux-gnu/ppc/trace.c
8d9cfe
--- ltrace-0.7.91/sysdeps/linux-gnu/ppc/trace.c~	2014-08-08 14:05:58.000000000 +0200
8d9cfe
+++ ltrace-0.7.91/sysdeps/linux-gnu/ppc/trace.c	2014-08-08 14:07:55.000000000 +0200
8d9cfe
@@ -133,7 +133,11 @@ arch_sw_singlestep(struct process *proc,
8d9cfe
 			return SWS_FAIL;
8d9cfe
 		uint32_t insn;
8d9cfe
 #ifdef __powerpc64__
8d9cfe
+# ifdef __LITTLE_ENDIAN__
8d9cfe
+		insn = (uint32_t) l;
8d9cfe
+# else
8d9cfe
 		insn = l >> 32;
8d9cfe
+# endif
8d9cfe
 #else
8d9cfe
 		insn = l;
8d9cfe
 #endif
8d9cfe
diff -up ltrace-0.7.91/configure\~ ltrace-0.7.91/configure
8d9cfe
--- ltrace-0.7.91/configure~	2014-08-08 14:09:12.000000000 +0200
8d9cfe
+++ ltrace-0.7.91/configure	2014-08-08 14:18:30.000000000 +0200
8d9cfe
@@ -2555,7 +2555,7 @@ case "${host_cpu}" in
8d9cfe
     arm*|sa110)		HOST_CPU="arm" ;;
8d9cfe
     cris*)		HOST_CPU="cris" ;;
8d9cfe
     mips*)		HOST_CPU="mips" ;;
8d9cfe
-    powerpc|powerpc64)	HOST_CPU="ppc" ;;
8d9cfe
+    powerpc|powerpc64|powerpc64le)	HOST_CPU="ppc" ;;
8d9cfe
     sun4u|sparc64)	HOST_CPU="sparc" ;;
8d9cfe
     s390x)		HOST_CPU="s390" ;;
8d9cfe
     i?86|x86_64)	HOST_CPU="x86" ;;
8d9cfe
@@ -12094,7 +12094,7 @@ if test x"$enable_libunwind" = xyes; the
8d9cfe
       arm*|sa110)         UNWIND_ARCH="arm" ;;
8d9cfe
       i?86)               UNWIND_ARCH="x86" ;;
8d9cfe
       powerpc)            UNWIND_ARCH="ppc32" ;;
8d9cfe
-      powerpc64)          UNWIND_ARCH="ppc64" ;;
8d9cfe
+      powerpc64|powerpc64le)          UNWIND_ARCH="ppc64" ;;
8d9cfe
       mips*)              UNWIND_ARCH="mips" ;;
8d9cfe
       *)                  UNWIND_ARCH="${host_cpu}" ;;
8d9cfe
   esac