File basic_changes_powerpc_be.patch of Package mono-core

commit 8332185abf23e2f27a536e6b7a08310aba8564fb
Author: Bill Seurer <seurer@linux.vnet.ibm.com>
Date:   Tue Aug 18 09:36:23 2015 -0500

[ppc] Basic changes to allow mono to build and run on power BE
patch adapted to current mono 4.2.1.102

The patch of tramp-ppc.c was not from above commit
but is also required to avoid ppc64 build segfault.

Signed-off-by: Michel Normand <normand@linux.vnet.ibm.com>
---
 mono/mini/mini-ppc.c         |   10 ++++++++--
 mono/mini/mini-trampolines.c |    5 ++++-
 mono/mini/tramp-ppc.c        |    4 ++++
 mono/sgen/sgen-archdep.h     |    4 ++--
 4 files changed, 18 insertions(+), 5 deletions(-)

Index: mono-4.2.1/mono/mini/mini-ppc.c
===================================================================
--- mono-4.2.1.orig/mono/mini/mini-ppc.c
+++ mono-4.2.1/mono/mini/mini-ppc.c
@@ -1086,7 +1086,10 @@ get_call_info (MonoGenericSharingContext
 				cinfo->args [n].size = size;
 
 				/* It was 7, now it is 8 in LinuxPPC */
-				if (fr <= PPC_LAST_FPARG_REG) {
+				if (fr <= PPC_LAST_FPARG_REG
+				// For non-native vararg calls the parms must go in storage
+					&& !(!sig->pinvoke && (sig->call_convention == MONO_CALL_VARARG))
+				       ) {
 					cinfo->args [n].regtype = RegTypeFP;
 					cinfo->args [n].reg = fr;
 					fr ++;
@@ -1177,7 +1180,10 @@ get_call_info (MonoGenericSharingContext
 		case MONO_TYPE_R8:
 			cinfo->args [n].size = 8;
 			/* It was 7, now it is 8 in LinuxPPC */
-			if (fr <= PPC_LAST_FPARG_REG) {
+			if (fr <= PPC_LAST_FPARG_REG
+			// For non-native vararg calls the parms must go in storage
+				&& !(!sig->pinvoke && (sig->call_convention == MONO_CALL_VARARG))
+			       ) {
 				cinfo->args [n].regtype = RegTypeFP;
 				cinfo->args [n].reg = fr;
 				fr ++;
Index: mono-4.2.1/mono/mini/mini-trampolines.c
===================================================================
--- mono-4.2.1.orig/mono/mini/mini-trampolines.c
+++ mono-4.2.1/mono/mini/mini-trampolines.c
@@ -1066,7 +1066,10 @@ mono_delegate_trampoline (mgreg_t *regs,
 				}
 			}
 		}
-	} else {
+	// If "delegate->method_ptr" is null mono_get_addr_from_ftnptr will fail if
+	// ftnptrs are being used.  "method" would end up null on archtitectures without
+	// ftnptrs so we can just skip this.
+	} else if (delegate->method_ptr) {
 		ji = mono_jit_info_table_find (domain, mono_get_addr_from_ftnptr (delegate->method_ptr));
 		if (ji)
 			method = jinfo_get_method (ji);
Index: mono-4.2.1/mono/sgen/sgen-archdep.h
===================================================================
--- mono-4.2.1.orig/mono/sgen/sgen-archdep.h
+++ mono-4.2.1/mono/sgen/sgen-archdep.h
@@ -88,8 +88,8 @@
 	} while (0)
 
 /* MS_BLOCK_SIZE must be a multiple of the system pagesize, which for some
-   archs is 64k.  */
-#if defined(TARGET_POWERPC64) && _CALL_ELF == 2
+   architectures is 64k.  */
+#if defined(TARGET_POWERPC64)
 #define ARCH_MIN_MS_BLOCK_SIZE	(64*1024)
 #define ARCH_MIN_MS_BLOCK_SIZE_SHIFT	16
 #endif
Index: mono-4.2.1/mono/mini/tramp-ppc.c
===================================================================
--- mono-4.2.1.orig/mono/mini/tramp-ppc.c
+++ mono-4.2.1/mono/mini/tramp-ppc.c
@@ -625,8 +625,12 @@ mono_arch_get_nullified_class_init_tramp
 
 	g_assert (code - buf <= tramp_size);
 
+	if (info)
 	*info = mono_tramp_info_create ("nullified_class_init_trampoline", buf, code - buf, NULL, NULL);
 
+	/* It is expected to be a function descriptor on power pre-v2 ABI */
+	buf = mono_create_ftnptr (mono_domain_get (), buf);
+
 	return buf;
 }