From patchwork Fri Dec 12 12:06:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominik Vogt X-Patchwork-Id: 420445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 01D131400E7 for ; Fri, 12 Dec 2014 23:06:48 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=oJyAnuyBIUIv+nIJT /qRxJdJJ5duA/Ub+DMyvVQsooOYdrJMVtOiBd/mSP71qZcodw/3gkvJYY/GQXqyw J9JVCUe7V9bh8oC4dneq+vxHy9KnROjNGTI6/14WVEskkcnyuGq4JYaaqdP4IFeU nJNiXgyTogbi+Esb541OzArx6E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=kRe3MYV5ctdLiRlu/gJ+QZe scxw=; b=udLD3mMx8LX1pVQfJZ1ECTzO9DC/1ieLQso/Puzc+HI4/awXRAfe6Wf vlU7yfOGkIrRtBdqh1TD1XlBSGO9BWEmWVcL3a7eOnVKNNUPUHx9hUDRto0AVS4v N8irEdK24ZbNK5/uPBUkAvkcSpzb9g2Lim+F+K+qjTUqUXXMhFD4= Received: (qmail 28990 invoked by alias); 12 Dec 2014 12:06:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 28978 invoked by uid 89); 12 Dec 2014 12:06:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e06smtp16.uk.ibm.com Received: from e06smtp16.uk.ibm.com (HELO e06smtp16.uk.ibm.com) (195.75.94.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 12 Dec 2014 12:06:38 +0000 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 12 Dec 2014 12:06:35 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 12 Dec 2014 12:06:33 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 24BF32190041 for ; Fri, 12 Dec 2014 12:06:04 +0000 (GMT) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sBCC6XDb58589192 for ; Fri, 12 Dec 2014 12:06:33 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sBCC6W2F026094 for ; Fri, 12 Dec 2014 05:06:32 -0700 Received: from bl3ahm9f.de.ibm.com (sig-9-84-42-139.evts.de.ibm.com [9.84.42.139]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id sBCC6VwR026072 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Fri, 12 Dec 2014 05:06:32 -0700 Received: from dvogt by bl3ahm9f.de.ibm.com with local (Exim 4.76) (envelope-from ) id 1XzOzP-0008Ly-4G; Fri, 12 Dec 2014 13:06:31 +0100 Date: Fri, 12 Dec 2014 13:06:30 +0100 From: Dominik Vogt To: libffi-discuss@sourceware.org, gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Re: [gofrontend-dev] Re: [PATCH 00/13] Go closures, libffi, and the static chain Message-ID: <20141212120630.GA32026@linux.vnet.ibm.com> Reply-To: libffi-discuss@sourceware.org Mail-Followup-To: libffi-discuss@sourceware.org, gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com References: <1412973773-3942-1-git-send-email-rth@redhat.com> <20141211090623.GA30484@linux.vnet.ibm.com> <20141211092144.GE4283@bubble.grove.modra.org> <20141211103106.GA9789@linux.vnet.ibm.com> <20141211122519.GA26215@linux.vnet.ibm.com> <5489F6D0.8020009@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5489F6D0.8020009@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14121212-0025-0000-0000-000002D975DB 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 ^_^ ^_^ From 84235d9e7ba8a55dea182adc4007bfab6a35fb1f Mon Sep 17 00:00:00 2001 From: Dominik Vogt 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