Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 634190 - =dev-ruby/ffi-1.9.18 fails test on ia64 (tests returning structs): FFI::Struct by value return using pre-set values: Failure/Error: expect(s[:s8]).to eq(0x7f)
Summary: =dev-ruby/ffi-1.9.18 fails test on ia64 (tests returning structs): FFI::Struc...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: IA64 Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://github.com/libffi/libffi/pull...
Whiteboard:
Keywords: TESTFAILURE
Depends on:
Blocks:
 
Reported: 2017-10-13 17:32 UTC by Sergei Trofimovich (RETIRED)
Modified: 2018-02-17 19:42 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
dev-ruby-ffi-1.9.18-ia64-build.log (dev-ruby-ffi-1.9.18-ia64-build.log,45.18 KB, text/x-log)
2017-10-13 17:32 UTC, Sergei Trofimovich (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich (RETIRED) gentoo-dev 2017-10-13 17:32:53 UTC
Created attachment 498552 [details]
dev-ruby-ffi-1.9.18-ia64-build.log

It's not a regression. Attached build.log.

Failures:

  1) FFI::Struct  by value return using pre-set values
     Failure/Error: expect(s[:s8]).to eq(0x7f)

       expected: 127
            got: 0

       (compared using ==)
     # ./spec/ffi/struct_spec.rb:648:in `block (2 levels) in <top (required)>'

  2) FFI::Struct  by value return using passed in values
     Failure/Error: expect(s[:s8]).to eq(123)

       expected: 123
            got: 0

       (compared using ==)
     # ./spec/ffi/struct_spec.rb:654:in `block (2 levels) in <top (required)>'

  3) FFI::Struct  by value parameter, returning struct by value
     Failure/Error: expect(ret[:s8]).to eq(s[:s8])

       expected: 18
            got: 0

       (compared using ==)
     # ./spec/ffi/struct_spec.rb:707:in `block (2 levels) in <top (required)>'

  4) FFI::Struct  by value varargs returning a struct
     Failure/Error: expect(s[:len]).to eq(string.length)

       expected: 4
            got: 6291471

       (compared using ==)
     # ./spec/ffi/struct_spec.rb:714:in `block (2 levels) in <top (required)>'

Finished in 2.21 seconds (files took 18.06 seconds to load)
4845 examples, 4 failures

Failed examples:

rspec ./spec/ffi/struct_spec.rb:646 # FFI::Struct  by value return using pre-set values
rspec ./spec/ffi/struct_spec.rb:652 # FFI::Struct  by value return using passed in values
rspec ./spec/ffi/struct_spec.rb:701 # FFI::Struct  by value parameter, returning struct by value
rspec ./spec/ffi/struct_spec.rb:711 # FFI::Struct  by value varargs returning a struct
Comment 1 Sergei Trofimovich (RETIRED) gentoo-dev 2017-10-13 17:33:27 UTC
# emerge --info
python-exec: Invalid impl in /etc/python-exec/python-exec.conf: python3.2
Portage 2.3.8 (python 3.4.5-final-0, default/linux/ia64/13.0, gcc-5.4.0, glibc-2.23-r4, 3.14.14-gentoo ia64)
=================================================================
System uname: Linux-3.14.14-gentoo-ia64-Dual-Core_Intel-R-_Itanium-R-_Processor_9040-with-gentoo-2.4.1
KiB Mem:    16660784 total,   5586112 free
KiB Swap:    1999184 total,   1890368 free
Timestamp of repository gentoo: Fri, 13 Oct 2017 02:45:02 +0000
Head commit of repository gentoo: c2f6aa1371c7a50616dabdc606481cf3a44989c4
sh bash 4.3_p48-r1
ld GNU ld (Gentoo 2.28.1 p1.0) 2.28.1
app-shells/bash:          4.3_p48-r1::gentoo
dev-lang/perl:            5.24.1-r2::gentoo
dev-lang/python:          2.7.12::gentoo, 3.4.5::gentoo
dev-util/cmake:           3.7.2::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.4.1-r2::gentoo
sys-apps/openrc:          0.32.1::gentoo
sys-apps/sandbox:         2.10-r4::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69::gentoo
sys-devel/automake:       1.15-r2::gentoo
sys-devel/binutils:       2.26.1::gentoo, 2.28-r2::gentoo, 2.28.1::gentoo
sys-devel/gcc:            5.4.0-r3::gentoo
sys-devel/gcc-config:     1.8-r1::gentoo
sys-devel/libtool:        2.4.6-r3::gentoo
sys-devel/make:           4.2.1::gentoo
sys-kernel/linux-headers: 4.4::gentoo (virtual/os-headers)
sys-libs/glibc:           2.23-r4::gentoo
Repositories:

gentoo
    location: /bound/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

ACCEPT_KEYWORDS="ia64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="ia64-unknown-linux-gnu"
CFLAGS="-O2 -pipe -fdiagnostics-show-option -frecord-gcc-switches"
CHOST="ia64-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt /var/bind"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php7.0/ext-active/ /etc/php/cgi-php7.0/ext-active/ /etc/php/cli-php7.0/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -pipe"
DISTDIR="/bound/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync multilib-strict news parallel-fetch preserve-libs protect-owned sandbox sfperms strict stricter test unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="ru_RU.UTF-8"
LC_ALL=""
LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu"
MAKEOPTS="-j5 -l5"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X acl berkdb bzip2 cli corefonts cracklib crypt cxx dbus dri fortran gdbm ia64 iconv ipv6 jpeg modules ncurses nls nptl openmp pam pcre png readline session sqlite ssl tcpd text truetype unicode xattr zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-6" POSTGRES_TARGETS="postgres9_5" PYTHON_SINGLE_TARGET="python3_4" PYTHON_TARGETS="python2_7 python3_4" RUBY_TARGETS="ruby22" USERLAND="GNU" VIDEO_CARDS="fbdev glint mach64 mga nv r128 radeon savage tdfx vesa dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 2 Sergei Trofimovich (RETIRED) gentoo-dev 2017-10-13 19:19:09 UTC
It looks liek a problem either in ffi<->libffi boundary or a problem in libffi itself.

IA64 passes the whole 'struct { char s8; int s32; }' in a single register. Might be relevant.
Comment 3 Sergei Trofimovich (RETIRED) gentoo-dev 2017-10-13 21:26:13 UTC
=dev-libs/libffi-3.2.1 has quite a few failures on ia64:

# FEATURES=test emerge -v1 dev-libs/libffi
                === libffi Summary ===

    # of expected passes            1530
    # of unexpected failures        290

I'll bounce this bug to toolchain@ first and get back to ruby@
library if we'll find evidence of problems on dev-ruby/ffi side.
Comment 4 Larry the Git Cow gentoo-dev 2017-10-14 19:57:00 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=75b2c980d16c2b137f21e9f6a0a3f1de6ddd7769

commit 75b2c980d16c2b137f21e9f6a0a3f1de6ddd7769
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2017-10-14 19:51:14 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2017-10-14 19:56:54 +0000

    dev-libs/libffi: ia64: fix small struct handling, bug #634190
    
    After FFI_TYPE_COMPLEX was added to libffi ia64 dispatch table
    was off-by-one in IA-64 specific handling of return values.
    
    Bug: https://bugs.gentoo.org/634190
    Package-Manager: Portage-2.3.10, Repoman-2.3.3

 .../libffi/files/libffi-3.2.1-complex-ia64.patch   | 41 ++++++++++++++++++++++
 dev-libs/libffi/libffi-3.2.1.ebuild                |  1 +
 2 files changed, 42 insertions(+)}
Comment 5 Sergei Trofimovich (RETIRED) gentoo-dev 2017-10-14 20:06:34 UTC
=dev-ruby/ffi-1.9.18 got better but still fails one callback test:

Failures:

  1) Callback returning struct by value
     Failure/Error: expect(ret[:s8]).to eq(s[:s8])
     
       expected: 18
            got: 88
     
       (compared using ==)
     # ./spec/ffi/callback_spec.rb:275:in `block (2 levels) in <top (required)>'

Finished in 2.63 seconds (files took 18.51 seconds to load)
4845 examples, 1 failure

I'll poke a it a bit later.
Comment 6 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-13 07:56:33 UTC
I think it's a libffi bug. Reproducer [1] looks like that:

    $ gcc a.c -o a `pkg-config --cflags --libs libffi` -Wall -ggdb3 && ./a
    make_s=0x2000000800011900
    calling make_s_via_cb(0x2000000800011900)
    calling make_s
    result = {
     .s32 = 0xfffffc00
     .f32 = -nan
     .s8  = 0x3e
    }

On other arches it returns

    make_s=0x55af819bc95a
    calling make_s_via_cb(0x55af819bc95a)
    calling make_s
    result = {
     .s32 = 0x1234
     .f32 = 7.000000
     .s8  = 0x78
    }

ia64 does not handle small return structs properly (there is support for it in libffi, I guess it's broken for floats).

[1]:
// The test originally discovered in ruby's bindings
// for ffi in https://bugs.gentoo.org/634190
// There a structure is returned from callback
//
// Simple in-place test:
//     gcc a.c -o a `pkg-config --cflags --libs libffi` -Wall -ggdb3 && ./a
#include <ffi.h>
#include <stdio.h>

struct s {
    int s32;
    float f32;
    signed char s8;
};

struct s make_s(void) {
    printf ("calling make_s\n");
    struct s r = {
        .s32 = 0x1234,
        .f32 = 7.0,
        .s8  = 0x78,
    };
    return r;
}

struct s make_s_via_cb(struct s (*f)(void)) {
    printf ("calling make_s_via_cb(%p)\n", f);
    return f();
}

int main() {
    ffi_cif cif;
    struct s r;

    ffi_type* s_fields[] = {
        &ffi_type_sint,
        &ffi_type_float,
        &ffi_type_schar,
        NULL,
    };
    ffi_type rtype = {
        .size      = 0,
        .alignment = 0,
        .type      = FFI_TYPE_STRUCT,
        .elements  = s_fields,
    };
    ffi_type *atypes[] = {
        &ffi_type_pointer,
        NULL,
    };

    void * arg0 = &make_s;
    void * in_args[] = {
        &arg0,
        NULL,
    };

    // below we emulate normal call:
    // r = make_s_via_cb(&make_s);

    printf ("make_s=%p\n", make_s);
    ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &rtype, atypes);
    ffi_call(&cif, FFI_FN(make_s_via_cb), &r, in_args);

    printf("result = {\n");
    printf(" .s32 = 0x%x\n", r.s32);
    printf(" .f32 = %f\n", r.f32);
    printf(" .s8  = 0x%x\n", r.s8);
    printf("}\n");
}
Comment 7 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-13 08:09:03 UTC
Shorter example without callback complication:

guppy ~ # gcc b.c -o b `pkg-config --cflags --libs libffi` -Wall -ggdb3 && ./b
result = {
 .s32 = 0x0
 .f32 = 0.000000
 .s8  = 0x0
}

guppy ~ # cat b.c
// The test originally discovered in ruby's bindings
// for ffi in https://bugs.gentoo.org/634190
//
// Simple in-place test:
//     gcc b.c -o b `pkg-config --cflags --libs libffi` -Wall -ggdb3 && ./b
#include <ffi.h>
#include <stdio.h>

struct s { int s32; float f32; signed char s8; };

struct s make_s(void) {
    struct s r = { .s32 = 0x1234, .f32 = 7.0, .s8  = 0x78, };
    return r;
}

int main() {
    ffi_cif cif;
    struct s r;

    ffi_type* s_fields[] = { &ffi_type_sint, &ffi_type_float, &ffi_type_schar, NULL, };
    ffi_type rtype = {
        .size      = 0,
        .alignment = 0,
        .type      = FFI_TYPE_STRUCT,
        .elements  = s_fields,
    };

    // below we emulate normal call:
    // r = make_s();

    ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &rtype, NULL);
    ffi_call(&cif, FFI_FN(make_s), &r, NULL);

    printf("result = {\n");
    printf(" .s32 = 0x%x\n", r.s32);
    printf(" .f32 = %f\n", r.f32);
    printf(" .s8  = 0x%x\n", r.s8);
    printf("}\n");
}
Comment 8 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-17 19:14:35 UTC
And we have a candidate fix for libffi: https://github.com/libffi/libffi/pull/407
Comment 9 Larry the Git Cow gentoo-dev 2018-02-17 19:42:01 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4e5016fe999d1e38f3ba606c977bcea43451ac05

commit 4e5016fe999d1e38f3ba606c977bcea43451ac05
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-02-17 19:41:37 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-02-17 19:41:54 +0000

    dev-libs/libffi: fix small struct handling on ia64, bug #634190
    
    Bug: https://github.com/libffi/libffi/pull/407
    Closes: https://bugs.gentoo.org/634190
    Package-Manager: Portage-2.3.24, Repoman-2.3.6

 .../files/libffi-3.2.1-ia64-small-struct.patch     | 74 ++++++++++++++++++++++
 dev-libs/libffi/libffi-3.2.1-r2.ebuild             | 70 ++++++++++++++++++++
 2 files changed, 144 insertions(+)