[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#173074: marked as done ([PR libgcj/9078] libffi: problems with uint8 on powerpc)



Your message dated Sun, 16 Mar 2003 18:02:34 +0100
with message-id <15988.44586.196724.492991@gargle.gargle.HOWL>
and subject line libgcj/9078: libffi: problems with uint8 on powerpc
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 14 Dec 2002 19:43:16 +0000
>From dbelan2@cs.mcgill.ca Sat Dec 14 13:43:16 2002
Return-path: <dbelan2@cs.mcgill.ca>
Received: from relay10.cs.mcgill.ca [132.206.3.88] 
	by master.debian.org with esmtp (Exim 3.12 1 (Debian))
	id 18NIBv-0002Hf-00; Sat, 14 Dec 2002 13:43:15 -0600
Received: from pinto.cs.mcgill.ca (pinto.CS.McGill.CA [132.206.3.79])
	by relay10.cs.mcgill.ca (Postfix) with ESMTP id 72560536F9B
	for <submit@bugs.debian.org>; Sat, 14 Dec 2002 14:43:15 -0500 (EST)
Received: from pinto.cs.mcgill.ca (dbelan2@localhost [127.0.0.1])
	by pinto.cs.mcgill.ca (8.12.3/8.12.3/Debian -4) with ESMTP id gBEJhFWA013919
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=FAIL)
	for <submit@bugs.debian.org>; Sat, 14 Dec 2002 14:43:15 -0500
Received: (from dbelan2@localhost)
	by pinto.cs.mcgill.ca (8.12.3/8.12.3/Debian -4) id gBEJhFhV013917
	for submit@bugs.debian.org; Sat, 14 Dec 2002 14:43:15 -0500
Date: Sat, 14 Dec 2002 14:43:15 -0500
From: David Paul BELANGER <dbelan2@CS.McGill.CA>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: problems with uint8 on powerpc
Message-ID: <20021214194315.GA13810@pinto.cs.mcgill.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.4i
Delivered-To: submit@bugs.debian.org
X-Spam-Status: No, hits=-4.6 required=5.0
	tests=SPAM_PHRASE_00_01,USER_AGENT,USER_AGENT_MUTT
	version=2.41
X-Spam-Level: 

Package: libffi2
Version: 1:3.2.1-0pre3
Severity: normal

ffi_type_uint8 and other arguments shorter than one word are
not passed in correctly to the function called by ffi_call.

Also, returns values are not passed correctly.  For example, instead of
finding the returned byte value where the pointer points to, it is found
at an offset of 3 from the pointer.

This is related to the fact that the powerpc is a big endian machine and
somewhere, bytes need to be moved.

I have included code and output I get on my powerpc machine.

Thanks,
David

-----

#include <stdio.h>
#include <ffi.h>


unsigned char identity(unsigned char c) {
  printf("identity: %d\n", c);
  return c;
}


int main(void) {
  ffi_cif cif;
  ffi_type *args[1];
  void *values[1];
  int b;
  unsigned char result;
  int i;

  args[0] = &ffi_type_uint;
  /*
   * args[0] = &ffi_type_uint8;  - if this type is specified,
   * function always receives 0.
   */


  b = 24;
  values[0] = &b;


  if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
		   &ffi_type_uint8, args) != FFI_OK) {
    printf("error\n");
    return 1;
  }


  ffi_call(&cif, identity, &result, values);

  printf("at result: %d\n", result);
  printf("at result + 3: %d\n", *(&result + 3));

  /*
  for (i = 0; i < sizeof(result); i++) {
    printf("byte %d = %d\n", i, *((unsigned char *) &result));
  }
  */

  return 0;
}

-----
output:

identity: 24
at result: 0
at result + 3: 24

-----


David


-- System Information
Debian Release: testing/unstable
Architecture: powerpc
Kernel: Linux ibou 2.4.20-rc1-ben0 #3 Thu Nov 14 22:24:15 EST 2002 ppc
Locale: LANG=C, LC_CTYPE=C

Versions of packages libffi2 depends on:
ii  gcc-3.2-base               1:3.2.1-0pre3 The GNU Compiler Collection (base 
ii  libc6                      2.2.5-14.3    GNU C Library: Shared libraries an





---------------------------------------
Received: (at 173074-done) by bugs.debian.org; 16 Mar 2003 17:06:43 +0000
>From doko@cs.tu-berlin.de Sun Mar 16 11:06:42 2003
Return-path: <doko@cs.tu-berlin.de>
Received: from mail.cs.tu-berlin.de [130.149.17.13] (root)
	by master.debian.org with esmtp (Exim 3.12 1 (Debian))
	id 18ubas-00023h-00; Sun, 16 Mar 2003 11:06:42 -0600
Received: from bolero.cs.tu-berlin.de (daemon@bolero.cs.tu-berlin.de [130.149.19.1])
	by mail.cs.tu-berlin.de (8.9.3/8.9.3) with ESMTP id SAA10340;
	Sun, 16 Mar 2003 18:02:34 +0100 (MET)
Received: (from doko@localhost)
	by bolero.cs.tu-berlin.de (8.11.6+Sun/8.9.3) id h2GH2YD16529;
	Sun, 16 Mar 2003 18:02:34 +0100 (MET)
From: Matthias Klose <doko@cs.tu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <15988.44586.196724.492991@gargle.gargle.HOWL>
Date: Sun, 16 Mar 2003 18:02:34 +0100
To: Jeff Sturm <jsturm@one-point.com>
Cc: 173074-done@bugs.debian.org, gcc-gnats@gcc.gnu.org, <gcc-prs@gcc.gnu.org>,
        <gcc-bugs@gcc.gnu.org>, <java-prs@gcc.gnu.org>,
        David Paul BELANGER <dbelan2@CS.McGill.CA>,
        "Prof. Etienne M. Gagnon" <etienne.gagnon@uqam.ca>
Subject: Re: libgcj/9078: libffi: problems with uint8 on powerpc
In-Reply-To: <Pine.LNX.4.44.0212290941030.5493-100000@ops2.one-point.com>
References: <E18SEr1-0007ft-00@tango.net.local>
	<Pine.LNX.4.44.0212290941030.5493-100000@ops2.one-point.com>
X-Mailer: VM 7.03 under 21.4 (patch 6) "Common Lisp" XEmacs Lucid
Delivered-To: 173074-done@bugs.debian.org
X-Spam-Status: No, hits=-1.3 required=4.0
	tests=IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_00_01
	version=2.44
X-Spam-Level: 

Ok, closing the Debian report. Leave the gnats entry to Jeff.

Prof. Etienne M. Gagnon writes:
> On Sun, Mar 16, 2003 at 05:15:47PM +0100, Matthias Klose wrote:
> > hmm, you didn't open this report. Sure I can close it?
> 
> Yes, I am sure.  The bug was opened by of the developers of the
> SableVM project, and he forwarded to me the information in the Debian
> BTS and in the upstream BTS.  Based on that information, I went back
> into the SableVM source code and fixed the bug.  It was definitely not
> a libffi bug (yet one has to very carfully read the libffi
> documentation to notice the inconsistency in the treatment of function
> arguments and return values).


Jeff Sturm writes:
> On Sat, 28 Dec 2002, Matthias Klose wrote:
> > ffi_type_uint8 and other arguments shorter than one word are
> > not passed in correctly to the function called by ffi_call.
> 
> For an ffi_type_uint8, ffi_call expects the corresponding value
> pointer to be a (unsigned char *).  So this is correct usage:
> 
>     int b = 24;
>     args[0] = &ffi_type_uint;
>     values[0] = &b;
> 
> Also correct would be:
> 
>     unsigned char b = 24;
>     args[0] = &ffi_type_uint8;
>     values[0] = &b;
> 
> > Also, returns values are not passed correctly.  For example, instead of
> > finding the returned byte value where the pointer points to, it is found
> > at an offset of 3 from the pointer.
> 
> Return values are handled a little differently than arguments.
> libffi/README says:
> 
>     RVALUE is a pointer to a chunk of memory that is to hold the
>         result of the function call. Currently, it must be
>         at least one word in size (except for the n32 version
>         under Irix 6.x, which must be a pointer to an 8 byte
>         aligned value (a long long). It must also be at least
>         word aligned (depending on the return type, and the
>         system's alignment requirements). If RTYPE is
>         &ffi_type_void, this is ignored. If RVALUE is NULL,
>         the return value is discarded.
> 
> So this cannot work:
> 
>     unsigned char result;
>     if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
>   		   &ffi_type_uint8, args) != FFI_OK) {
> 
> You could use "unsigned int result" on a 32-bit target, or use ffi_arg
> which is typedef'ed to work correctly on 32 or 64-bit targets:
> 
>     ffi_arg result;
>     if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
>                    &ffi_type_uint8, args) != FFI_OK) {
> 
> With those changes your example should be portable to any target supported
> by libffi.
> 
> Jeff
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-gcc-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: