From patchwork Wed Sep 11 11:38:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 274260 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 801502C00FA for ; Wed, 11 Sep 2013 21:39:00 +1000 (EST) 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=XZRsNOIIj78BVZzU/ fXqhBbLJK0fqBPXz+D6YBuPfESzu1hk2zkbI887yC/LfIKev9NcHcO9hdSjld4ZX HpPCzknYOY8jMZ8SWW+F/oapotE81KUwhMWJetmnh5cpfQSpbQcSiDyOb1J3v5Gt eYQBYkteQFlM+M0Ob21pUh7XmY= 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=6FE5NBOjh47tGFW2lnbV5T2 YYLU=; b=GANNmW9zjyggnWiUQQYtDfH7KOIbs5i+qZiwmak0rmorS9nc12+9ZEP B2rK5VoTLJYz6Zn87lfdVnF2IXqwO37/Oa2gqEEnLhEV9JUw2t6ZG9Y3bTL28orf nsCakfhrznAZYImq375b9Sog495i1fhW2qf9gwCzeiNJPThPFwx4= Received: (qmail 18666 invoked by alias); 11 Sep 2013 11:38:54 -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 18643 invoked by uid 89); 11 Sep 2013 11:38:54 -0000 Received: from mail-pd0-f178.google.com (HELO mail-pd0-f178.google.com) (209.85.192.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 11 Sep 2013 11:38:54 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=ALL_TRUSTED, AWL, BAYES_00, FREEMAIL_FROM autolearn=unavailable version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-pd0-f178.google.com Received: by mail-pd0-f178.google.com with SMTP id w10so9090559pde.37 for ; Wed, 11 Sep 2013 04:38:52 -0700 (PDT) X-Received: by 10.66.142.193 with SMTP id ry1mr3136987pab.150.1378899531897; Wed, 11 Sep 2013 04:38:51 -0700 (PDT) Received: from bubble.grove.modra.org ([101.166.26.37]) by mx.google.com with ESMTPSA id sy2sm29282670pbc.16.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Sep 2013 04:38:51 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 2A7FAEA0077; Wed, 11 Sep 2013 21:08:46 +0930 (CST) Date: Wed, 11 Sep 2013 21:08:46 +0930 From: Alan Modra To: gcc-patches@gcc.gnu.org, libffi-discuss@sourceware.org Cc: Bill Schmidt , dje@gcc.gnu.org Subject: Re: [PATCH, PowerPC] Fix PR57949 (ABI alignment issue) Message-ID: <20130911113845.GF2643@bubble.grove.modra.org> Mail-Followup-To: gcc-patches@gcc.gnu.org, libffi-discuss@sourceware.org, Bill Schmidt , dje@gcc.gnu.org References: <1376494321.17852.17.camel@oc8801110288.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1376494321.17852.17.camel@oc8801110288.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On Wed, Aug 14, 2013 at 10:32:01AM -0500, Bill Schmidt wrote: > This fixes a long-standing problem with GCC's implementation of the > PPC64 ELF ABI. If a structure contains a member requiring 128-bit > alignment, and that structure is passed as a parameter, the parameter > currently receives only 64-bit alignment. This is an error, and is > incompatible with correct code generated by the IBM XL compilers. This caused multiple failures in the libffi testsuite: libffi.call/cls_align_longdouble.c libffi.call/cls_align_longdouble_split.c libffi.call/cls_align_longdouble_split2.c libffi.call/nested_struct5.c Fixed by making the same alignment adjustment in libffi to structures passed by value. Bill, I think your patch needs to go on all active gcc branches as otherwise we'll need different versions of libffi for the next gcc releases. The following was bootstrapped and regression checked powerpc64-linux. OK for mainline, and the 4.7 and 4.8 branches when/if Bill's patch goes in there? * src/powerpc/ffi.c (ffi_prep_args64): Align FFI_TYPE_STRUCT. (ffi_closure_helper_LINUX64): Likewise. Index: libffi/src/powerpc/ffi.c =================================================================== --- libffi/src/powerpc/ffi.c (revision 202428) +++ libffi/src/powerpc/ffi.c (working copy) @@ -462,6 +462,7 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long double **d; } p_argv; unsigned long gprvalue; + unsigned long align; stacktop.c = (char *) stack + bytes; gpr_base.ul = stacktop.ul - ASM_NEEDS_REGISTERS64 - NUM_GPR_ARG_REGISTERS64; @@ -532,6 +533,10 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long #endif case FFI_TYPE_STRUCT: + align = (*ptr)->alignment; + if (align > 16) + align = 16; + next_arg.ul = ALIGN (next_arg.ul, align); words = ((*ptr)->size + 7) / 8; if (next_arg.ul >= gpr_base.ul && next_arg.ul + words > gpr_end.ul) { @@ -1349,6 +1354,7 @@ ffi_closure_helper_LINUX64 (ffi_closure *closure, long i, avn; ffi_cif *cif; ffi_dblfl *end_pfr = pfr + NUM_FPR_ARG_REGISTERS64; + unsigned long align; cif = closure->cif; avalue = alloca (cif->nargs * sizeof (void *)); @@ -1399,6 +1405,10 @@ ffi_closure_helper_LINUX64 (ffi_closure *closure, break; case FFI_TYPE_STRUCT: + align = arg_types[i]->alignment; + if (align > 16) + align = 16; + pst = ALIGN (pst, align); #ifndef __LITTLE_ENDIAN__ /* Structures with size less than eight bytes are passed left-padded. */