From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23717 invoked by alias); 26 Oct 2013 12:32:39 -0000 Mailing-List: contact libffi-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libffi-discuss-owner@sourceware.org Received: (qmail 23701 invoked by uid 89); 26 Oct 2013 12:32:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-HELO: mail-pa0-f49.google.com Received: from mail-pa0-f49.google.com (HELO mail-pa0-f49.google.com) (209.85.220.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 26 Oct 2013 12:32:36 +0000 Received: by mail-pa0-f49.google.com with SMTP id lj1so5212629pab.22 for ; Sat, 26 Oct 2013 05:32:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=CNtnP2G+/uyryDSI25K4Vsn34yNX/FLreUMn8TyaJqg=; b=Y0LV5pEBfMod0kDKvVkq+DDOm0RBJBoz6PrZLDCCzevpouOSAZyqdde9FMfKoD2+OM +6SPSin+xDte8xR449MtOoxJ4Vw+aABkWHTwwZxeNrWZ2sp/8chVKCjSTTZp8JmGgLBj MSqKPYVgfQVNl0ARK9Qv/zE8MX5HnWLKBS6+GXtnUSudIzuK9xRnvh5i0KF4K3nwq9hq GkItB0d7lRp+NF9VcOoC+tE9b+I6wQvy9XdywugmH3XpoEox0MuK10wMFyAcTU4CKIjs lCco1D2dzAN8OAo3J0txAxkKaaXSWHeqyYo0RbQjImLruGwUogjccDS1snX1luhZea3W BO2w== X-Gm-Message-State: ALoCoQkwd5COsMPkQDJPzAHE2/N+xsZgRckqgWn0gBeJNrX7FLjoFevp+7dDprw2QZiGhmEs+IDP MIME-Version: 1.0 X-Received: by 10.66.154.1 with SMTP id vk1mr15720973pab.85.1382790754942; Sat, 26 Oct 2013 05:32:34 -0700 (PDT) Received: by 10.70.96.228 with HTTP; Sat, 26 Oct 2013 05:32:34 -0700 (PDT) In-Reply-To: <87fvrrzvws.fsf@netris.org> References: <87fvrrzvws.fsf@netris.org> Date: Sat, 26 Oct 2013 12:32:00 -0000 Message-ID: Subject: Re: [PATCH] Fix handling of uint32_t arguments on the MIPS N32 ABI. From: Anthony Green To: Mark H Weaver Cc: "libffi-discuss@sourceware.org" Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2013/txt/msg00193.txt.bz2 Thanks Mark. I've committed this change. https://github.com/atgreen/libffi/commit/d3372c54ce7117e80d389ba875dc5b6b2213c71e AG On Wed, Oct 23, 2013 at 2:25 PM, Mark H Weaver wrote: > Hello all, > > A failing glib test on MIPS N32 has alerted me to a bug in the handling > of unsigned 32-bit integers in libffi. The MIPSpro N32 ABI Handbook [*] > states: > > "32-bit integer (int) parameters are always sign-extended when passed > in registers, whether of signed or unsigned type. [This issue does > not arise in the o32-bit ABI.]" (chapter 2, page 6) > > [*] http://techpubs.sgi.com/library/manuals/2000/007-2816-005/pdf/007-2816-005.pdf > > and indeed GCC generates code that assumes this. > For example, GCC 4.7.3 compiles: > > --8<---------------cut here---------------start------------->8--- > #include > #include > > void > do_test (uint32_t a) > { > if (a != 4294967253U) > exit (1); > } > --8<---------------cut here---------------end--------------->8--- > > as follows (with extraneous cruft stripped): > > --8<---------------cut here---------------start------------->8--- > do_test: > li $2,-43 # 0xffffffffffffffd5 > beq $4,$2,.L5 > nop > > addiu $sp,$sp,-16 > sd $31,8($sp) > jal exit > li $4,1 # 0x1 > > .L5: > j $31 > nop > --8<---------------cut here---------------end--------------->8--- > > However, the current libffi code zero-extends 32-bit unsigned integers, > which violates this N32 FFI requirement. > > See below for a patch to fix this problem. I've tested this patch on > the preliminary port of GNU Guix to MIPS N32, which uses a minimally > patched GNU toolchain targetting mips64el-linux-gnu. > > Without this patch, glib-2.38.0 fails its test suite, specifically the > gobject/test/signal.c test, which uses libffi to pass a large 32-bit > unsigned integer to a test function that checks the received value. > With this patch, glib-2.38.0 passes its test suite. > > Comments and suggestions welcome. > > Regards, > Mark > > > Signed-off-by: Mark H Weaver > --- > ChangeLog | 5 +++++ > src/mips/ffi.c | 7 +++++++ > 2 files changed, 12 insertions(+), 0 deletions(-) > > diff --git a/ChangeLog b/ChangeLog > index eceef84..e7e5d94 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,8 @@ > +2013-10-23 Mark H Weaver > + > + * src/mips/ffi.c: Fix handling of uint32_t arguments on the > + MIPS N32 ABI. > + > 2013-10-13 Sandra Loosemore > > * README: Add Nios II to table of supported platforms. > diff --git a/src/mips/ffi.c b/src/mips/ffi.c > index 03121e3..5d0dd70 100644 > --- a/src/mips/ffi.c > +++ b/src/mips/ffi.c > @@ -170,7 +170,14 @@ static void ffi_prep_args(char *stack, > break; > > case FFI_TYPE_UINT32: > +#ifdef FFI_MIPS_N32 > + /* The N32 ABI requires that 32-bit integers > + be sign-extended to 64-bits, regardless of > + whether they are signed or unsigned. */ > + *(ffi_arg *)argp = *(SINT32 *)(* p_argv); > +#else > *(ffi_arg *)argp = *(UINT32 *)(* p_argv); > +#endif > break; > > /* This can only happen with 64bit slots. */ > -- > 1.7.5.4 >