This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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/RFA] libffi SH patch


Hi,

New libffi testsuite reveals several bugs in the SH implementation
of libffi. With the appended patch, all failures in libffi tests
go away and no new regressions on libjava tests.
OK for the mainline?

Regards,
	kaz
--
2003-09-18  Kaz Kojima  <kkojima@gcc.gnu.org>

	* src/sh/ffi.c (ffi_prep_args): Take account into the alignement
	for the register size.
	(ffi_closure_helper_SYSV): Handle the structure return value
	address correctly.
	(ffi_closure_helper_SYSV): Return the appropriate type when
	the registers are used for the structure return value.
	* src/sh/sysv.S (ffi_closure_SYSV): Fix the stack layout for
	the 64-bit return value.  Update copyright years.

diff -u3prN ORIG/gcc/libffi/src/sh/ffi.c LOCAL/gcc/libffi/src/sh/ffi.c
--- ORIG/gcc/libffi/src/sh/ffi.c	Thu Aug 14 08:09:36 2003
+++ LOCAL/gcc/libffi/src/sh/ffi.c	Tue Sep 16 17:42:30 2003
@@ -220,7 +220,7 @@ void ffi_prep_args(char *stack, extended
 	    greg += n;
 #endif
 	  memcpy (argp, *p_argv, z);
-	  argp += z;
+	  argp += n * sizeof (int);
 	}
     }
 
@@ -315,7 +315,7 @@ void ffi_prep_args(char *stack, extended
 	    }
 #endif
 	  memcpy (argp, *p_argv, z);
-	  argp += z;
+	  argp += n * sizeof (int);
 	}
     }
 
@@ -533,10 +533,10 @@ ffi_closure_helper_SYSV (ffi_closure *cl
 
   /* Copy the caller's structure return value address so that the closure
      returns the data directly to the caller.  */
-  if (cif->rtype->type == FFI_TYPE_STRUCT)
+  if (cif->rtype->type == FFI_TYPE_STRUCT && STRUCT_VALUE_ADDRESS_WITH_ARG)
     {
       rvalue = *pgr++;
-      ireg = STRUCT_VALUE_ADDRESS_WITH_ARG ? 1 : 0;
+      ireg = 1;
     }
   else
     ireg = 0;
@@ -717,6 +717,6 @@ ffi_closure_helper_SYSV (ffi_closure *cl
 
   (closure->fun) (cif, rvalue, avalue, closure->user_data);
 
-  /* Tell ffi_closure_osf how to perform return type promotions.  */
-  return cif->rtype->type;
+  /* Tell ffi_closure_SYSV how to perform return type promotions.  */
+  return return_type (cif->rtype);
 }
diff -u3prN ORIG/gcc/libffi/src/sh/sysv.S LOCAL/gcc/libffi/src/sh/sysv.S
--- ORIG/gcc/libffi/src/sh/sysv.S	Tue Dec 17 03:22:48 2002
+++ LOCAL/gcc/libffi/src/sh/sysv.S	Thu Sep 18 21:53:13 2003
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------
-   sysv.S - Copyright (c) 2002 Kaz Kojima
+   sysv.S - Copyright (c) 2002, 2003 Kaz Kojima
    
    SuperH Foreign Function Interface 
 
@@ -505,21 +505,22 @@ ENTRY(ffi_closure_SYSV)
 	   ...
 	   32 bytes (floating register parameters, SH-4 only)
 	   16 bytes (register parameters)
-	    4 bytes (result)
+	    8 bytes (result)
+	    4 bytes (pad)
 	    4 bytes (5th arg)
 	   <- new stack pointer
 	*/
 .LCFI8:
 #if defined(__SH4__)
-	add	#-56,r15
+	add	#-64,r15
 #else
-	add	#-24,r15
+	add	#-32,r15
 #endif
 .LCFI9:
 	mov	r15,r14
 .LCFIA:
 	mov	r14,r1
-	add	#24,r1
+	add	#32,r1
 	mov.l	r7,@-r1
 	mov.l	r6,@-r1
 	mov.l	r5,@-r1
@@ -528,7 +529,7 @@ ENTRY(ffi_closure_SYSV)
 
 #if defined(__SH4__)
 	mov	r14,r1
-	add	#56,r1
+	add	#64,r1
 #ifdef __LITTLE_ENDIAN__
 	fmov.s	fr10,@-r1
 	fmov.s	fr11,@-r1
@@ -552,14 +553,14 @@ ENTRY(ffi_closure_SYSV)
 #endif
 
 	mov	r14,r1
-	add	#4,r1
+	add	#8,r1
 	mov	r1,r5
 
 	mov	r14,r1
 #if defined(__SH4__)
-	add	#64,r1
+	add	#72,r1
 #else
-	add	#32,r1
+	add	#40,r1
 #endif
 	mov.l	r1,@r14
 
@@ -574,7 +575,7 @@ ENTRY(ffi_closure_SYSV)
 	mov.w	@r0,r0
 	mov	r14,r2
 	braf	r0
-	 add	#4,r2
+	 add	#8,r2
 0:
 	.align 2
 L_helper:
@@ -664,9 +665,9 @@ L_case_uh:
 
 L_case_v:
 #if defined(__SH4__)
-	add	#56,r15
+	add	#64,r15
 #else
-	add	#24,r15
+	add	#32,r15
 #endif
 	lds.l	@r15+,pr
 	rts
@@ -757,9 +758,9 @@ __FRAME_BEGIN__:
 	.4byte	.LCFI9-.LCFI8
 	.byte	0xe	/* DW_CFA_def_cfa_offset */
 #if defined(__SH4__)
-	.byte	8+56	/* uleb128 8+56 */
+	.byte	8+64	/* uleb128 8+64 */
 #else
-	.byte	8+24	/* uleb128 8+24 */
+	.byte	8+32	/* uleb128 8+32 */
 #endif
 	.byte	0x91	/* DW_CFA_offset, column 0x11 */
         .byte	0x2


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