public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libgcj/9078: libffi: problems with uint8 on powerpc
@ 2002-12-28  3:16 Matthias Klose
  0 siblings, 0 replies; 5+ messages in thread
From: Matthias Klose @ 2002-12-28  3:16 UTC (permalink / raw)
  To: gcc-gnats, debian-gcc


>Number:         9078
>Category:       libgcj
>Synopsis:       libffi: problems with uint8 on powerpc
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 28 03:16:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     David Paul BELANGER <dbelan2@CS.McGill.CA>
>Release:        3.2.1 (Debian) (Debian unstable)
>Organization:
The Debian Project
>Environment:
System: Debian GNU/Linux (unstable)
Architecture: i686
host: i386-linux
>Description:
[ Reported to the Debian BTS as report #173074.
  Please CC 173074@bugs.debian.org on replies.
  Log of report can be found at http://bugs.debian.org/173074 ]
	

[ category libgcj, as there is no explicit libffi category]

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

>How-To-Repeat:
	
>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libgcj/9078: libffi: problems with uint8 on powerpc
@ 2003-03-17  3:19 jsturm
  0 siblings, 0 replies; 5+ messages in thread
From: jsturm @ 2003-03-17  3:19 UTC (permalink / raw)
  To: 173074, dbelan2, gcc-bugs, gcc-prs, java-prs, jsturm

Synopsis: libffi: problems with uint8 on powerpc

State-Changed-From-To: feedback->closed
State-Changed-By: jsturm
State-Changed-When: Mon Mar 17 03:19:44 2003
State-Changed-Why:
    Closed in Debian BTS.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9078


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libgcj/9078: libffi: problems with uint8 on powerpc
@ 2003-03-16 17:16 Matthias Klose
  0 siblings, 0 replies; 5+ messages in thread
From: Matthias Klose @ 2003-03-16 17:16 UTC (permalink / raw)
  To: jsturm; +Cc: gcc-prs

The following reply was made to PR libgcj/9078; it has been noted by GNATS.

From: Matthias Klose <doko@cs.tu-berlin.de>
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
Date: Sun, 16 Mar 2003 18:02:34 +0100

 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libgcj/9078: libffi: problems with uint8 on powerpc
@ 2002-12-29  8:13 jsturm
  0 siblings, 0 replies; 5+ messages in thread
From: jsturm @ 2002-12-29  8:13 UTC (permalink / raw)
  To: 173074, dbelan2, gcc-bugs, gcc-prs, java-prs, jsturm, nobody

Synopsis: libffi: problems with uint8 on powerpc

Responsible-Changed-From-To: unassigned->jsturm
Responsible-Changed-By: jsturm
Responsible-Changed-When: Sun Dec 29 08:13:07 2002
Responsible-Changed-Why:
    I'll handle it.
State-Changed-From-To: open->feedback
State-Changed-By: jsturm
State-Changed-When: Sun Dec 29 08:13:07 2002
State-Changed-Why:
    Response sent via email.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9078


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libgcj/9078: libffi: problems with uint8 on powerpc
@ 2002-12-29  8:06 Jeff Sturm
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Sturm @ 2002-12-29  8:06 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR libgcj/9078; it has been noted by GNATS.

From: Jeff Sturm <jsturm@one-point.com>
To: 173074@bugs.debian.org
Cc: gcc-gnats@gcc.gnu.org, <debian-gcc@lists.debian.org>,
   <gcc-prs@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>, <java-prs@gcc.gnu.org>,
   David Paul BELANGER <dbelan2@CS.McGill.CA>
Subject: Re: libgcj/9078: libffi: problems with uint8 on powerpc
Date: Sun, 29 Dec 2002 11:04:41 -0500 (EST)

 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
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-03-17  3:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-28  3:16 libgcj/9078: libffi: problems with uint8 on powerpc Matthias Klose
2002-12-29  8:06 Jeff Sturm
2002-12-29  8:13 jsturm
2003-03-16 17:16 Matthias Klose
2003-03-17  3:19 jsturm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).