This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi 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]

Re: [gofrontend-dev] Re: [PATCH 00/13] Go closures, libffi, and the static chain


On Thu, Dec 11, 2014 at 11:56:00AM -0800, Richard Henderson wrote:
> On 12/11/2014 04:25 AM, Dominik Vogt wrote:
> > Update:  If I disable the custom s390x code and switch to the
> > implementation just using libffi for reflection calls, the same
> > crash occurs with the testing/quick libgo test case.  The called
> > function sees a bogus value written by the synamic linker as the
> > closure pointer, for example with this line in the test code:
> > 
> >   CheckEqual(fComplex64, fComplex64, nil)

>  Is the s390 port somehow putting the address of a plt entry here?

Digging through the test program with the debugger reveals that
the register corruption is not caused by dynamic linking.
Instead, libgo lacks a patch that is necessary for complex
support.  Without that, ffi_prep_args treats _Complex like a
struct with two elements (which it is not on s390[x]) and messes
up the layout of the stack arguments, eventually loading the wrong
values into the registers when the test function is called.  It
turns out that the bad value in r0 was just a red herring in this
case.

I'm not sure I've posted the missing patch anywhere yet, so it's
attached to this message.  At the moment it enables
FFI_TYPE_COMPLEX only for s390[x], but eventually this should be
used unconditionally.

--

(This still leaves the dynamic linking issue if we do not use
libffi for reflection calls with x86* and s390[x].  Is the plan to
remove the platform specific abi code for the few platforms that
have it?  I see no way to make them work with the static chain
patch anyway.)

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany
>From 84235d9e7ba8a55dea182adc4007bfab6a35fb1f Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@de.ibm.com>
Date: Wed, 29 Oct 2014 09:08:01 +0100
Subject: [PATCH] libgo: Enable complex number support from libffi.

---
 libgo/runtime/go-ffi.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libgo/runtime/go-ffi.c b/libgo/runtime/go-ffi.c
index 21879b9..42462d0 100644
--- a/libgo/runtime/go-ffi.c
+++ b/libgo/runtime/go-ffi.c
@@ -150,11 +150,26 @@ go_complex_to_ffi (ffi_type *float_type)
   ffi_type *ret;
 
   ret = (ffi_type *) __go_alloc (sizeof (ffi_type));
+  /* Use libffi with complex type support for targets that have it.  This should
+     be the case for all targets eventually, so the #else branch should then be
+     removed.  */
+#if defined (__s390__) && defined (FFI_TYPE_COMPLEX)
+  ret->type = FFI_TYPE_COMPLEX;
+  ret->size = 2 * float_type->size;
+  ret->alignment = float_type->alignment;
+  ret->elements = (ffi_type **) __go_alloc (2 * sizeof (ffi_type *));
+  ret->elements[0] = float_type;
+  ret->elements[1] = NULL;
+#else
+  /* Warning: This works only on platforms that define C _Complex types like
+     structures in their Abi.  */
   ret->type = FFI_TYPE_STRUCT;
   ret->elements = (ffi_type **) __go_alloc (3 * sizeof (ffi_type *));
   ret->elements[0] = float_type;
   ret->elements[1] = float_type;
   ret->elements[2] = NULL;
+#endif
+
   return ret;
 }
 
@@ -184,6 +199,9 @@ go_type_to_ffi (const struct __go_type_descriptor *descriptor)
 #ifdef __alpha__
       runtime_throw("the libffi library does not support Complex64 type with "
 		    "reflect.Call or runtime.SetFinalizer");
+#elif defined(__s390__) && !defined(FFI_TYPE_COMPLEX)
+      runtime_throw("the libffi library does not support Complex64 type with "
+		    "reflect.Call or runtime.SetFinalizer");
 #else
       if (sizeof (float) == 4)
 	return go_complex_to_ffi (&ffi_type_float);
@@ -193,6 +211,9 @@ go_type_to_ffi (const struct __go_type_descriptor *descriptor)
 #ifdef __alpha__
       runtime_throw("the libffi library does not support Complex128 type with "
 		    "reflect.Call or runtime.SetFinalizer");
+#elif defined(__s390__) && !defined(FFI_TYPE_COMPLEX)
+      runtime_throw("the libffi library does not support Complex128 type with "
+		    "reflect.Call or runtime.SetFinalizer");
 #else
       if (sizeof (double) == 8)
 	return go_complex_to_ffi (&ffi_type_double);
-- 
1.8.4.2


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