This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] libffi-MIPS: Fix ffi closure support for n64 ABI.


Closure support in libffi for the MIPS64/n64 ABI is broken because it is
using the 32 bit add instruction in several places to do pointer
manipulation.  In most cases this causes the calculated pointer value to
have its upper 32 bits clobbered.

I am still trying to understand how I didn't catch this when I was doing
the initial development of the n64 support.  My best (but untested)
theory is that the machine I did the original testing on (linux-2.6.18
on R4400 Indy) just happened to give the desired results for the
undefined operation I was using and my new test machine (linux 2.6.23 on
R5000 O2) does not.  The operation is undefined because the source
register must be either all 0s or all 1s in the upper 32 bits when using
32 bit arithmetic.

In any event the patch uses the 64 bit add instruction so that the upper
32 bits of the pointers are not clobbered by sign extension.

Tested on mips64-linux-gnu both n32 and n64 ABIs

OK to commit?

2007-12-05  David Daney  <ddaney@avtrex.com>

    * src/mips/n32.S (ffi_closure_N32): Use 64-bit add instruction on
    pointer values.


Index: src/mips/n32.S
===================================================================
--- src/mips/n32.S	(revision 130154)
+++ src/mips/n32.S	(working copy)
@@ -417,9 +417,9 @@ ffi_closure_N32:
 	# Call ffi_closure_mips_inner_N32 to do the real work.
 	LA	t9, ffi_closure_mips_inner_N32
 	move	a0, $12	 # Pointer to the ffi_closure
-	addu	a1, $sp, V0_OFF2
-	addu	a2, $sp, A0_OFF2
-	addu	a3, $sp, F12_OFF2
+	ADDU	a1, $sp, V0_OFF2
+	ADDU	a2, $sp, A0_OFF2
+	ADDU	a3, $sp, F12_OFF2
 	jalr	t9
 
 	# Return flags are in v0

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]