Linux on PowerPC failure #38

Closed
plicease opened this Issue Feb 5, 2014 · 10 comments

Projects

None yet

2 participants

Contributor
plicease commented Feb 5, 2014

This appears to be an endianness or casting issue because only short and char are having problems:

figment% prove -bv t/03-simple-returns.t 
t/03-simple-returns.t .. 
cc -I/home/ollisg/dev/FFI-Raw/.build/MuIgwMLoDk/t -I/home/ollisg/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1/ppc64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O1 -o ./t/03-simple-returns.o ./t/03-simple-returns.c
cc -shared -O1 -L/usr/local/lib -fstack-protector -o ./t/03-simple-returns.so ./t/03-simple-returns.o
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
ok 10
not ok 11

#   Failed test at t/03-simple-returns.t line 51.
#          got: '0'
#     expected: '102'
not ok 12

#   Failed test at t/03-simple-returns.t line 52.
#          got: '0'
#     expected: '102'
not ok 13

#   Failed test at t/03-simple-returns.t line 55.
#          got: '0'
#     expected: '-103'
not ok 14

#   Failed test at t/03-simple-returns.t line 56.
#          got: '0'
#     expected: '-103'
ok 15 # TODO failing
ok 16 # TODO failing
ok 17
ok 18
ok 19
ok 20
1..20
# Looks like you failed 4 tests of 20.
Dubious, test returned 4 (wstat 1024, 0x400)
Failed 4/20 subtests 
    (2 TODO tests unexpectedly succeeded)

Test Summary Report
-------------------
t/03-simple-returns.t (Wstat: 1024 Tests: 20 Failed: 4)
  Failed tests:  11-14
  TODO passed:   15-16
  Non-zero exit status: 4
Files=1, Tests=20,  1 wallclock secs ( 0.08 usr  0.02 sys +  0.38 cusr  0.06 csys =  0.54 CPU)
Result: FAIL

I can reproduce with both the system libffi and the bundled libffi.

Owner
ghedo commented Feb 8, 2014

I expanded the 03-simple-returns tests a bit, can you please run that on ppc64 again? Maybe it'll provide a bit more information (I've also fixed the return of unsigned types, but I think that's not relevant to this problem).

Contributor
plicease commented Feb 8, 2014
figment% prove -bv t/02-simple-args.t t/03-simple-returns.t 
t/02-simple-args.t ..... 
cc -I/home/ollisg/dev/FFI-Raw/.build/tcZtqE7hFD/t -I/home/ollisg/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1/ppc64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O1 -o ./t/02-simple-args.o ./t/02-simple-args.c
cc -shared -O1 -L/usr/local/lib -fstack-protector -o ./t/02-simple-args.so ./t/02-simple-args.o
ok - got passed int64 -9223372036854775808
ok - got passed uint64 18446744073709551615
ok - got passed long -2147483648
ok - got passed ulong 4294967295
ok - got passed int -2147483648
ok - got passed uint 4294967295
ok - got passed short -32768
ok - got passed ushort 65535
ok - got passed char 0
not ok - got passed uchar 0
ok - got passed short 10
ok - got passed short 20
ok - got passed int 101
ok - got passed short 102
ok - got passed char 103
ok - got passed int 101
ok - got passed short 102
ok - got passed char 103
ok - got passed double -6.9
ok - got passed double -6.9
ok - got passed float 4.2
ok - got passed float 4.2
ok - passed a string
ok - passed a string
1..24
Failed 1/24 subtests 
t/03-simple-returns.t .. 
cc -I/home/ollisg/dev/FFI-Raw/.build/tcZtqE7hFD/t -I/home/ollisg/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1/ppc64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O1 -o ./t/03-simple-returns.o ./t/03-simple-returns.c
cc -shared -O1 -L/usr/local/lib -fstack-protector -o ./t/03-simple-returns.so ./t/03-simple-returns.o
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
ok 10
ok 11
ok 12
not ok 13

#   Failed test at t/03-simple-returns.t line 55.
#          got: '-1'
#     expected: '-32768'
not ok 14

#   Failed test at t/03-simple-returns.t line 56.
#          got: '-1'
#     expected: '-32768'
not ok 15

#   Failed test at t/03-simple-returns.t line 59.
#          got: '0'
#     expected: '65535'
not ok 16

#   Failed test at t/03-simple-returns.t line 60.
#          got: '0'
#     expected: '65535'
ok 17
ok 18
not ok 19

#   Failed test at t/03-simple-returns.t line 67.
#          got: '0'
#     expected: '255'
not ok 20

#   Failed test at t/03-simple-returns.t line 68.
#          got: '0'
#     expected: '255'
ok 21 # TODO failing
ok 22 # TODO failing
ok 23
ok 24
ok 25
ok 26
1..26
# Looks like you failed 6 tests of 26.
Dubious, test returned 6 (wstat 1536, 0x600)
Failed 6/26 subtests 
    (2 TODO tests unexpectedly succeeded)

Test Summary Report
-------------------
t/02-simple-args.t   (Wstat: 0 Tests: 24 Failed: 1)
  Failed test:  10
t/03-simple-returns.t (Wstat: 1536 Tests: 26 Failed: 6)
  Failed tests:  13-16, 19-20
  TODO passed:   21-22
  Non-zero exit status: 6
Files=2, Tests=50,  1 wallclock secs ( 0.08 usr  0.02 sys +  0.80 cusr  0.12 csys =  1.02 CPU)
Result: FAIL

Only showing the tests that failed.

The kernel is ppc64, but I believe the userland is 32bit.

Contributor
plicease commented Feb 8, 2014

I'm seeing the same behavior in this really simple C program, might this be a bug in libffi?

figment% more test.c 
#include <stdio.h>
#include <ffi.h>

short test_sint16(short in)
{
  printf("in = %hd\n", in);
  return 103;
}

int main()
{
  ffi_cif cif;
  ffi_type *args[1];
  void *values[1];
  short foo;
  short rc;

  args[0] = &ffi_type_sint16;
  values[0] = &foo;

  if(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_sint16, args) == FFI_OK)
  {
    foo = 102;
    ffi_call(&cif, test_sint16, &rc, values);
    printf("rc = %hd\n", rc);
  }
}
figment% gcc test.c -lffi
test.c: In function ‘main’:
test.c:24:5: warning: passing argument 2 of ‘ffi_call’ from incompatible pointer type [enabled by default]
/usr/include/powerpc-linux-gnu/ffi.h:403:6: note: expected ‘void (*)(void)’ but argument is of type ‘short int (*)(short int)’
figment% ./a.out 
in = 102
rc = 0
Owner
ghedo commented Feb 8, 2014

Yeah, I guess that's possible too. Try running libffi's test suite (./configure && make check, you'll probably need to install dejagnu).

Contributor
plicease commented Feb 8, 2014

all the tests pass.

@ghedo ghedo added a commit that referenced this issue Feb 9, 2014
@ghedo ghedo Raw.xs: correctly handle return values on big endian
Closes: #38
23f86ab
Owner
ghedo commented Feb 9, 2014

I think I got this (by copying what python's ctypes does). Can you please try again with git master?

Contributor
plicease commented Feb 9, 2014

I think we are getting closer! master dumps core, because FFI_CALL was trying to free the adjusted rather than the original pointer, this fixs that:

plicease/p5-FFI-Raw@5c540d3

Still getting this failure in 02-simple-args.t, which I think is a failure in a test you added since I opened this ticket:

figment% prove -bv t/02-simple-args.t
t/02-simple-args.t .. 
cc -I/home/ollisg/dev/FFI-Raw/.build/aDe2Chct5i/t -I/home/ollisg/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1/ppc64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O1 -o ./t/02-simple-args.o ./t/02-simple-args.c
cc -shared -O1 -L/usr/local/lib -fstack-protector -o ./t/02-simple-args.so ./t/02-simple-args.o
ok - got passed int64 -9223372036854775808
ok - got passed uint64 18446744073709551615
ok - got passed long -2147483648
ok - got passed ulong 4294967295
ok - got passed int -2147483648
ok - got passed uint 4294967295
ok - got passed short -32768
ok - got passed ushort 65535
ok - got passed char 0
not ok - got passed uchar 0
ok - got passed short 10
ok - got passed short 20
ok - got passed int 101
ok - got passed short 102
ok - got passed char 103
ok - got passed int 101
ok - got passed short 102
ok - got passed char 103
ok - got passed double -6.9
ok - got passed double -6.9
ok - got passed float 4.2
ok - got passed float 4.2
ok - passed a string
ok - passed a string
1..24
Failed 1/24 subtests 

Test Summary Report
-------------------
t/02-simple-args.t (Wstat: 0 Tests: 24 Failed: 1)
  Failed test:  10
Files=1, Tests=24,  1 wallclock secs ( 0.06 usr  0.02 sys +  0.42 cusr  0.06 csys =  0.56 CPU)
Result: FAIL

I have to run, but I may be able to look into it tonight.

Owner
ghedo commented Feb 9, 2014

Yeah, the handling of unsigned parameters was wrong (just like the one for unsigned returns). It should be fixed now (I also merged your patch).

Contributor
plicease commented Feb 9, 2014

works!

@plicease plicease closed this Feb 9, 2014
Contributor
plicease commented Feb 9, 2014

btw- this also fixes raspian (raspbery pi + debian port).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment