From patchwork Thu Feb 13 16:18:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 320115 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 EED8A2C007A for ; Fri, 14 Feb 2014 03:19:39 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=uh9YpTqqiE1EiWY/ kXknr4Pu7CqkCQMllBRDYb/I/EzYUqCgjhKiNJhPnV2DSfhbOTrHgZWH1E3F4qcM k+lXyfUQDbfax16Y9W5f+ryYCJG1lRF88FBMHrbDrcO2qqQGBI2KDGbmuLHZNq/F 1xksfLpHs2RCE9SZAAVisIeoF5c= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=lEaaYtPO2BdmCzLK073QVA LKYmk=; b=LFAvWAN9t3yFVMAlxSlfYxmfo9ODJfpboZ2rITyYqGferfwM3/5wbN J6ChnH4bNX5rDN9CNQ8MiPYNoYfFv8CFEnbicEKXA3v0U95szHLTiVRMaihb2Jeg kIP2FhfXmFA5dJHx/O31DrBhupXZhN5sC7vjyeNPuQ+xF6WaGCxew= Received: (qmail 5881 invoked by alias); 13 Feb 2014 16:19:22 -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 5829 invoked by uid 89); 13 Feb 2014 16:19:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 13 Feb 2014 16:19:20 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id ADA2C26E20C4 for ; Thu, 13 Feb 2014 17:19:17 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x7DTBKMayAbG for ; Thu, 13 Feb 2014 17:19:17 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 8696626E1FED for ; Thu, 13 Feb 2014 17:19:17 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Fix PR libffi/60073 Date: Thu, 13 Feb 2014 17:18:47 +0100 Message-ID: <1627069.1KANd3nG1O@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.29-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 This adds proper variadic support to the SPARC port of libffi, thus fixing a regression in the testsuite in 64-bit mode, and fixes a small inaccuracy in the documentation. Tested on SPARC/Solaris and SPARC64/Solaris, applied on the mainline. 2014-02-13 Eric Botcazou PR libffi/60073 * src/sparc/ffitarget.h (FFI_TARGET_SPECIFIC_VARIADIC): Define. (FFI_EXTRA_CIF_FIELDS): Likewise. (FFI_NATIVE_RAW_API): Move around. * src/sparc/ffi.c (ffi_prep_cif_machdep_core): New function from... (ffi_prep_cif_machdep): ...here. Call ffi_prep_cif_machdep_core. (ffi_prep_cif_machdep_var): New function. (ffi_closure_sparc_inner_v9): Do not pass anonymous FP arguments in FP registers. * doc/libffi.texi (Introduction): Fix inaccuracy. Index: src/sparc/ffitarget.h =================================================================== --- src/sparc/ffitarget.h (revision 207685) +++ src/sparc/ffitarget.h (working copy) @@ -58,16 +58,17 @@ typedef enum ffi_abi { } ffi_abi; #endif +#define FFI_TARGET_SPECIFIC_VARIADIC 1 +#define FFI_EXTRA_CIF_FIELDS unsigned int nfixedargs + /* ---- Definitions for closures ----------------------------------------- */ #define FFI_CLOSURES 1 -#define FFI_NATIVE_RAW_API 0 - #ifdef SPARC64 #define FFI_TRAMPOLINE_SIZE 24 #else #define FFI_TRAMPOLINE_SIZE 16 #endif +#define FFI_NATIVE_RAW_API 0 #endif - Index: src/sparc/ffi.c =================================================================== --- src/sparc/ffi.c (revision 207685) +++ src/sparc/ffi.c (working copy) @@ -249,7 +249,7 @@ int ffi_prep_args_v9(char *stack, extend } /* Perform machine dependent cif processing */ -ffi_status ffi_prep_cif_machdep(ffi_cif *cif) +static ffi_status ffi_prep_cif_machdep_core(ffi_cif *cif) { int wordsize; @@ -334,6 +334,19 @@ ffi_status ffi_prep_cif_machdep(ffi_cif return FFI_OK; } +ffi_status ffi_prep_cif_machdep(ffi_cif *cif) +{ + cif->nfixedargs = cif->nargs; + return ffi_prep_cif_machdep_core (cif); +} + +ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs, + unsigned int ntotalargs) +{ + cif->nfixedargs = nfixedargs; + return ffi_prep_cif_machdep_core (cif); +} + int ffi_v9_layout_struct(ffi_type *arg, int off, char *ret, char *intg, char *flt) { ffi_type **ptr = &arg->elements[0]; @@ -604,8 +617,7 @@ ffi_closure_sparc_inner_v9(ffi_closure * /* Copy the caller's structure return address so that the closure returns the data directly to the caller. */ - if (cif->flags == FFI_TYPE_VOID - && cif->rtype->type == FFI_TYPE_STRUCT) + if (cif->flags == FFI_TYPE_VOID && cif->rtype->type == FFI_TYPE_STRUCT) { rvalue = (void *) gpr[0]; /* Skip the structure return address. */ @@ -619,6 +631,10 @@ ffi_closure_sparc_inner_v9(ffi_closure * /* Grab the addresses of the arguments from the stack frame. */ for (i = 0; i < cif->nargs; i++) { + /* If the function is variadic, FP arguments are passed in FP + registers only if the corresponding parameter is named. */ + const int named = (i < cif->nfixedargs); + if (arg_types[i]->type == FFI_TYPE_STRUCT) { if (arg_types[i]->size > 16) @@ -633,7 +649,9 @@ ffi_closure_sparc_inner_v9(ffi_closure * 0, (char *) &gpr[argn], (char *) &gpr[argn], - (char *) &fpr[argn]); + named + ? (char *) &fpr[argn] + : (char *) &gpr[argn]); avalue[i] = &gpr[argn]; argn += ALIGN(arg_types[i]->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG; } @@ -649,6 +667,7 @@ ffi_closure_sparc_inner_v9(ffi_closure * argn++; #endif if (i < fp_slot_max + && named && (arg_types[i]->type == FFI_TYPE_FLOAT || arg_types[i]->type == FFI_TYPE_DOUBLE #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE @@ -662,7 +681,7 @@ ffi_closure_sparc_inner_v9(ffi_closure * } /* Invoke the closure. */ - (closure->fun) (cif, rvalue, avalue, closure->user_data); + closure->fun (cif, rvalue, avalue, closure->user_data); /* Tell ffi_closure_sparc how to perform return type promotions. */ return cif->rtype->type; Index: doc/libffi.texi =================================================================== --- doc/libffi.texi (revision 207685) +++ doc/libffi.texi (working copy) @@ -63,14 +63,14 @@ section entitled ``GNU General Public Li @node Introduction @chapter What is libffi? -Compilers for high level languages generate code that follow certain +Compilers for high-level languages generate code that follow certain conventions. These conventions are necessary, in part, for separate compilation to work. One such convention is the @dfn{calling convention}. The calling convention is a set of assumptions made by the compiler about where function arguments will be found on entry to a function. A calling convention also specifies where the return -value for a function is found. The calling convention is also -sometimes called the @dfn{ABI} or @dfn{Application Binary Interface}. +value for a function is found. The calling convention is part of +what is called the @dfn{ABI} or @dfn{Application Binary Interface}. @cindex calling convention @cindex ABI @cindex Application Binary Interface