[Mono-bugs] [Bug 60331][Nor] New - PowerPC JIT generates ba for branches between basic blocks

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 17 Jun 2004 02:09:25 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by pcbeard@mac.com.

http://bugzilla.ximian.com/show_bug.cgi?id=60331

--- shadow/60331	2004-06-17 02:09:25.000000000 -0400
+++ shadow/60331.tmp.9330	2004-06-17 02:09:25.000000000 -0400
@@ -0,0 +1,66 @@
+Bug#: 60331
+Product: Mono: Runtime
+Version: unspecified
+OS: Mac OS X 10.3
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: pcbeard@mac.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: PowerPC JIT generates ba for branches between basic blocks
+
+In mini-ppc.c, the function ppc_patch() as written converts any kind of branch instruction with 
+opcode==28, into a branch absolute, if the target of the branch can be reached by this form. 
+This has bad behavior in terms of ahead of time compilation, because it means branches 
+between basic blocks can have this form if the code is generated low or high enough in memory. 
+However, the way aot.c is written, no relocation patches are maintained for the 
+MONO_PATCH_INFO_BB type of patches, so the resulting ahead of time compiled binary is most 
+likely unusable.
+
+Here is a relatively simple change to ppc_patch() that appears to fix the problem:
+
+Index: mini-ppc.c
+===========================================================
+========
+RCS file: /mono/mono/mono/mini/mini-ppc.c,v
+retrieving revision 1.67
+diff -u -r1.67 mini-ppc.c
+--- mini-ppc.c	27 May 2004 13:11:09 -0000	1.67
++++ mini-ppc.c	17 Jun 2004 04:46:41 -0000
+@@ -2160,17 +2160,19 @@
+ 
+ 	//g_print ("patching 0x%08x (0x%08x) to point to 0x%08x\n", code, ins, target);
+ 	if (prim == 18) {
+-		if ((glong)target >= 0){
+-			if ((glong)target <= 33554431){
+-				ins = (18 << 26) | ((guint32) target) | (ins & 1) | 2;
+-				*(guint32*)code = ins;
+-				return;
+-			} 
+-		} else {
+-			if ((glong)target >= -33554432){
+-				ins = (18 << 26) | (((guint32)target) & ~0xfc000000) | (ins & 1) | 2;
+-				*(guint32*)code = ins;
+-				return;
++		if (ins & 0x2) { // XXX_PCB test for AA
++			if ((glong)target >= 0){
++				if ((glong)target <= 33554431){
++					ins = (18 << 26) | ((guint32) target) | (ins & 1) | 2;
++					*(guint32*)code = ins;
++					return;
++				} 
++			} else {
++				if ((glong)target >= -33554432){
++					ins = (18 << 26) | (((guint32)target) & ~0xfc000000) | (ins & 1) | 2;
++					*(guint32*)code = ins;
++					return;
++				}
+ 			}
+ 		}