Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFI Load Failure on ARM #1137

Closed
cadwallion opened this issue Oct 16, 2013 · 11 comments
Closed

FFI Load Failure on ARM #1137

cadwallion opened this issue Oct 16, 2013 · 11 comments

Comments

@cadwallion
Copy link

JRuby Version: 1.7.5 (1.9.3p392) 2013-10-07 74e9291 on Java HotSpot(TM) Client VM 1.7.0_40-b43 [linux-arm]
RVM Version: 1.23.7 (stable)
OS Version: Linux raspberrypi 3.6.11+ #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013 armv6l GNU/Linux

I have been developing a JRuby-based version of my application on my MacBook Pro without issues. I loaded the working branch onto my Raspberry Pi and startup results in the following error:

root@raspberrypi:~/brewby# jruby -J-Xmx200m bin/brewby start --config ~/.testbrewbyrc --recipe examples/brewby_recipe.rb
LoadError: Could not load FFI Provider: (NotImplementedError) FFI not available: null
 See http://jira.codehaus.org/browse/JRUBY-4583
  require at org/jruby/RubyKernel.java:1082
   (root) at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/ffi/ffi.rb:69
  require at org/jruby/RubyKernel.java:1082
   (root) at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/ffi.rb:1
  require at org/jruby/RubyKernel.java:1082
   (root) at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/ffi.rb:1
  require at org/jruby/RubyKernel.java:1082
   (root) at /usr/local/rvm/gems/jruby-1.7.5/gems/ffi-ncurses-0.4.0/lib/ffi-ncurses.rb:1
  require at org/jruby/RubyKernel.java:1082
   (root) at /usr/local/rvm/gems/jruby-1.7.5/gems/ffi-ncurses-0.4.0/lib/ffi-ncurses.rb:16
  require at org/jruby/RubyKernel.java:1082
   (root) at /home/pi/brewery/brewby/lib/brewby/view.rb:1
  require at org/jruby/RubyKernel.java:1082
   (root) at bin/brewby:5

FFI was working on the Raspberry Pi using MRI 1.9.3. Any assistance would be appreciated.

@cadwallion
Copy link
Author

As a test case, I created a file that does nothing but require 'ffi-ncurses' and it results in the same error.

require 'ffi-ncurses'
root@raspberrypi:~/brewby# jruby -J-Xmx200m test_case.rb
LoadError: Could not load FFI Provider: (NotImplementedError) FFI not available: null
 See http://jira.codehaus.org/browse/JRUBY-4583
  require at org/jruby/RubyKernel.java:1082
  require at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:53
   (root) at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/ffi/ffi.rb:69
  require at org/jruby/RubyKernel.java:1082
   (root) at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
  require at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:53
  require at org/jruby/RubyKernel.java:1082
   (root) at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/ffi.rb:1
   (root) at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
  require at org/jruby/RubyKernel.java:1082
  require at /usr/local/rvm/rubies/jruby-1.7.5/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:53
   (root) at test_case.rb:1

@ghost
Copy link

ghost commented Oct 17, 2013

Its probably not recognising the cpu.

What is the result of running this jruby command on the box?

jruby -rjava -e 'p java.lang.System.get_property("os.arch")'

@cadwallion
Copy link
Author

Pretty straightforward output:

root@raspberrypi:~# jruby -rjava -e 'p java.lang.System.get_property("os.arch")'
"arm"

@ghost
Copy link

ghost commented Oct 20, 2013

@cadwallion Can you checkout the jffi source from https://github.com/jnr/jffi (preferably on the Pi), and run:

ant jar && java -jar dist/jffi-complete.jar

If you don't have ant on the dest machine, you can run it on your mac, then just copy the jar over.

That should display some basic diagnostics, and more importantly, dump out all errors it encountered when trying trying to load the stub library.

@cadwallion
Copy link
Author

Certainly, here's the output:

root@raspberrypi:~/jffi# ant jar && java -jar dist/jffi-complete.jar
Buildfile: /root/jffi/build.xml

-pre-init:

-init-vars:
    [mkdir] Created dir: /root/jffi/build/jni

-post-init:

-init:

-pre-jar:

-pre-compile:

-do-compile:
    [mkdir] Created dir: /root/jffi/build/classes
    [javac] Compiling 42 source files to /root/jffi/build/classes
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
    [javac] /root/jffi/src/main/java/com/kenai/jffi/MemoryIO.java:847: warning: Unsafe is internal proprietary API and may be removed in a future release
    [javac]         protected static sun.misc.Unsafe unsafe = sun.misc.Unsafe.class.cast(getUnsafe());
    [javac]                                  ^
    [javac] /root/jffi/src/main/java/com/kenai/jffi/MemoryIO.java:847: warning: Unsafe is internal proprietary API and may be removed in a future release
    [javac]         protected static sun.misc.Unsafe unsafe = sun.misc.Unsafe.class.cast(getUnsafe());
    [javac]                                                           ^
    [javac] Note: /root/jffi/src/main/java/com/kenai/jffi/ClosureMagazine.java uses or overrides a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 3 warnings

-generate-version-source:
     [echo] Generating Version.java
    [mkdir] Created dir: /root/jffi/build/java/com/kenai/jffi

-generate-version:
    [javac] Compiling 1 source file to /root/jffi/build/classes
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
    [javac] 1 warning

-compile-java:

-generate-native-headers:

-build-native-library:
     [exec] Configuring libffi for arm-linux
     [exec] configure: error: in `/root/jffi/build/jni/libffi-arm-linux':
     [exec] configure: error: C compiler cannot create executables
     [exec] See `config.log' for more details
     [exec] make: *** [/root/jffi/build/jni/libffi-arm-linux/.libs/libffi_convenience.a] Error 77

BUILD FAILED
/root/jffi/build.xml:325: exec returned: 2

Total time: 53 seconds

@ghost
Copy link

ghost commented Oct 21, 2013

Do you have the full dev toolchain installed?

There should be a config.log in /root/jffi/build/jni/libffi-arm-linux/ that tells you the problem it was having.

@cadwallion
Copy link
Author

Yup, here's the output:

root@raspberrypi:~/jffi/build/jni/libffi-arm-linux# cat config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by libffi configure 3.0.10, which was
generated by GNU Autoconf 2.68.  Invocation command line was

  $ /root/jffi/jni/libffi/configure --disable-static --with-pic=yes --disable-dependency-tracking

## --------- ##
## Platform. ##
## --------- ##

hostname = raspberrypi
uname -m = armv6l
uname -r = 3.6.11+
uname -s = Linux
uname -v = #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013

/usr/bin/uname -p = unknown
/bin/uname -X     = unknown

/bin/arch              = unknown
/usr/bin/arch -k       = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo      = unknown
/bin/machine           = unknown
/usr/bin/oslevel       = unknown
/bin/universe          = unknown

PATH: /usr/local/rvm/gems/ruby-1.9.3-p362/bin
PATH: /usr/local/rvm/gems/ruby-1.9.3-p362@global/bin
PATH: /usr/local/rvm/rubies/ruby-1.9.3-p362/bin
PATH: /usr/local/rvm/bin
PATH: /usr/local/sbin
PATH: /usr/local/bin
PATH: /usr/sbin
PATH: /usr/bin
PATH: /sbin
PATH: /bin


## ----------- ##
## Core tests. ##
## ----------- ##

configure:2550: checking build system type
configure:2564: result: armv6l-unknown-linux-gnueabi
configure:2584: checking host system type
configure:2597: result: armv6l-unknown-linux-gnueabi
configure:2617: checking target system type
configure:2630: result: armv6l-unknown-linux-gnueabi
configure:2722: checking for gsed
configure:2753: result: sed
configure:2781: checking for a BSD-compatible install
configure:2849: result: /usr/bin/install -c
configure:2860: checking whether build environment is sane
configure:2910: result: yes
configure:3048: checking for a thread-safe mkdir -p
configure:3087: result: /bin/mkdir -p
configure:3100: checking for gawk
configure:3116: found /usr/bin/gawk
configure:3127: result: gawk
configure:3138: checking whether make sets $(MAKE)
configure:3160: result: yes
configure:3299: checking for gcc
configure:3326: result:  cc -m32
configure:3555: checking for C compiler version
configure:3564:  cc -m32  --version >&5
cc (Debian 4.6.3-12+rpi1) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

configure:3575: $? = 0
configure:3564:  cc -m32  -v >&5
Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-12+rpi1' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-12+rpi1)
configure:3575: $? = 0
configure:3564:  cc -m32  -V >&5
cc: error: unrecognized option '-V'
cc: fatal error: no input files
compilation terminated.
configure:3575: $? = 4
configure:3564:  cc -m32  -qversion >&5
cc: error: unrecognized option '-qversion'
cc: fatal error: no input files
compilation terminated.
configure:3575: $? = 4
configure:3595: checking whether the C compiler works
configure:3617:  cc -m32  -DFFI_MMAP_EXEC_WRIT -O2 -fno-omit-frame-pointer -fno-strict-aliasing -DNDEBUG   conftest.c  >&5
cc1: error: unrecognized command line option '-m32'
configure:3621: $? = 1
configure:3659: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libffi"
| #define PACKAGE_TARNAME "libffi"
| #define PACKAGE_VERSION "3.0.10"
| #define PACKAGE_STRING "libffi 3.0.10"
| #define PACKAGE_BUGREPORT "http://sourceware.org/libffi.html"
| #define PACKAGE_URL ""
| #define PACKAGE "libffi"
| #define VERSION "3.0.10"
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:3664: error: in `/root/jffi/build/jni/libffi-arm-linux':
configure:3666: error: C compiler cannot create executables
See `config.log' for more details

## ---------------- ##
## Cache variables. ##
## ---------------- ##

ac_cv_build=armv6l-unknown-linux-gnueabi
ac_cv_env_CCASFLAGS_set=
ac_cv_env_CCASFLAGS_value=
ac_cv_env_CCAS_set=
ac_cv_env_CCAS_value=
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_CPP_set=
ac_cv_env_CPP_value=
ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=
ac_cv_env_host_alias_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_host=armv6l-unknown-linux-gnueabi
ac_cv_path_ax_enable_builddir_sed=sed
ac_cv_path_install='/usr/bin/install -c'
ac_cv_path_mkdir=/bin/mkdir
ac_cv_prog_AWK=gawk
ac_cv_prog_ac_ct_CC=' cc -m32 '
ac_cv_prog_make_make_set=yes
ac_cv_target=armv6l-unknown-linux-gnueabi

## ----------------- ##
## Output variables. ##
## ----------------- ##

ACLOCAL='${SHELL} /root/jffi/jni/libffi/missing --run aclocal-1.11'
ALLOCA=''
ALPHA_FALSE=''
ALPHA_TRUE=''
AMDEPBACKSLASH=''
AMDEP_FALSE=''
AMDEP_TRUE=''
AMTAR='${SHELL} /root/jffi/jni/libffi/missing --run tar'
AM_LTLDFLAGS=''
AM_RUNTESTFLAGS=''
AR=''
ARM_FALSE=''
ARM_TRUE=''
AUTOCONF='${SHELL} /root/jffi/jni/libffi/missing --run autoconf'
AUTOHEADER='${SHELL} /root/jffi/jni/libffi/missing --run autoheader'
AUTOMAKE='${SHELL} /root/jffi/jni/libffi/missing --run automake-1.11'
AVR32_FALSE=''
AVR32_TRUE=''
AWK='gawk'
CC=' cc -m32 '
CCAS=''
CCASDEPMODE=''
CCASFLAGS=''
CCDEPMODE=''
CFLAGS='-DFFI_MMAP_EXEC_WRIT -O2 -fno-omit-frame-pointer -fno-strict-aliasing -DNDEBUG'
CPP=''
CPPFLAGS=''
CYGPATH_W='echo'
DEFS=''
DEPDIR=''
DLLTOOL=''
DSYMUTIL=''
DUMPBIN=''
ECHO_C=''
ECHO_N='-n'
ECHO_T=''
EGREP=''
EXEEXT=''
FFI_DEBUG_FALSE=''
FFI_DEBUG_TRUE=''
FFI_EXEC_TRAMPOLINE_TABLE=''
FFI_EXEC_TRAMPOLINE_TABLE_FALSE=''
FFI_EXEC_TRAMPOLINE_TABLE_TRUE=''
FGREP=''
FRV_FALSE=''
FRV_TRUE=''
GREP=''
HAVE_LONG_DOUBLE=''
IA64_FALSE=''
IA64_TRUE=''
INSTALL_DATA='${INSTALL} -m 644'
INSTALL_PROGRAM='${INSTALL}'
INSTALL_SCRIPT='${INSTALL}'
INSTALL_STRIP_PROGRAM='$(install_sh) -c -s'
LD='ld -m32 '
LDFLAGS=''
LIBFFI_CRIS_FALSE=''
LIBFFI_CRIS_TRUE=''
LIBOBJS=''
LIBS=''
LIBTOOL=''
LIPO=''
LN_S=''
LTLIBOBJS=''
M32R_FALSE=''
M32R_TRUE=''
M68K_FALSE=''
M68K_TRUE=''
MAINT=''
MAINTAINER_MODE_FALSE=''
MAINTAINER_MODE_TRUE=''
MAKEINFO='${SHELL} /root/jffi/jni/libffi/missing --run makeinfo'
MANIFEST_TOOL=''
MIPS_FALSE=''
MIPS_TRUE=''
MKDIR_P='/bin/mkdir -p'
MOXIE_FALSE=''
MOXIE_TRUE=''
NM=''
NMEDIT=''
OBJDUMP=''
OBJEXT=''
OTOOL64=''
OTOOL=''
PA64_HPUX_FALSE=''
PA64_HPUX_TRUE=''
PACKAGE='libffi'
PACKAGE_BUGREPORT='http://sourceware.org/libffi.html'
PACKAGE_NAME='libffi'
PACKAGE_STRING='libffi 3.0.10'
PACKAGE_TARNAME='libffi'
PACKAGE_URL=''
PACKAGE_VERSION='3.0.10'
PATH_SEPARATOR=':'
PA_HPUX_FALSE=''
PA_HPUX_TRUE=''
PA_LINUX_FALSE=''
PA_LINUX_TRUE=''
POWERPC_AIX_FALSE=''
POWERPC_AIX_TRUE=''
POWERPC_DARWIN_FALSE=''
POWERPC_DARWIN_TRUE=''
POWERPC_FALSE=''
POWERPC_FREEBSD_FALSE=''
POWERPC_FREEBSD_TRUE=''
POWERPC_TRUE=''
PRTDIAG=''
RANLIB=''
S390_FALSE=''
S390_TRUE=''
SED=''
SET_MAKE=''
SH64_FALSE=''
SH64_TRUE=''
SHELL='/bin/bash'
SH_FALSE=''
SH_TRUE=''
SPARC_FALSE=''
SPARC_TRUE=''
STRIP=''
TARGET=''
TARGETDIR=''
TESTSUBDIR_FALSE=''
TESTSUBDIR_TRUE=''
VERSION='3.0.10'
X86_64_FALSE=''
X86_64_TRUE=''
X86_DARWIN_FALSE=''
X86_DARWIN_TRUE=''
X86_FALSE=''
X86_FREEBSD_FALSE=''
X86_FREEBSD_TRUE=''
X86_TRUE=''
X86_WIN32_FALSE=''
X86_WIN32_TRUE=''
X86_WIN64_FALSE=''
X86_WIN64_TRUE=''
ac_ct_AR=''
ac_ct_CC=' cc -m32 '
ac_ct_DUMPBIN=''
am__EXEEXT_FALSE=''
am__EXEEXT_TRUE=''
am__fastdepCCAS_FALSE=''
am__fastdepCCAS_TRUE=''
am__fastdepCC_FALSE=''
am__fastdepCC_TRUE=''
am__include=''
am__isrc=' -I$(srcdir)'
am__leading_dot='.'
am__quote=''
am__tar='${AMTAR} chof - "$$tardir"'
am__untar='${AMTAR} xf -'
ax_enable_builddir_sed='sed'
bindir='${exec_prefix}/bin'
build='armv6l-unknown-linux-gnueabi'
build_alias=''
build_cpu='armv6l'
build_os='linux-gnueabi'
build_vendor='unknown'
datadir='${datarootdir}'
datarootdir='${prefix}/share'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
dvidir='${docdir}'
exec_prefix='NONE'
host='armv6l-unknown-linux-gnueabi'
host_alias=''
host_cpu='armv6l'
host_os='linux-gnueabi'
host_vendor='unknown'
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
install_sh='${SHELL} /root/jffi/jni/libffi/install-sh'
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mandir='${datarootdir}/man'
mkdir_p='/bin/mkdir -p'
oldincludedir='/usr/include'
pdfdir='${docdir}'
prefix='NONE'
program_transform_name='s,x,x,'
psdir='${docdir}'
sbindir='${exec_prefix}/sbin'
sharedstatedir='${prefix}/com'
sys_symbol_underscore=''
sysconfdir='${prefix}/etc'
target='armv6l-unknown-linux-gnueabi'
target_alias=''
target_cpu='armv6l'
target_os='linux-gnueabi'
target_vendor='unknown'
toolexecdir=''
toolexeclibdir=''

## ----------- ##
## confdefs.h. ##
## ----------- ##

/* confdefs.h */
#define PACKAGE_NAME "libffi"
#define PACKAGE_TARNAME "libffi"
#define PACKAGE_VERSION "3.0.10"
#define PACKAGE_STRING "libffi 3.0.10"
#define PACKAGE_BUGREPORT "http://sourceware.org/libffi.html"
#define PACKAGE_URL ""
#define PACKAGE "libffi"
#define VERSION "3.0.10"

configure: exit 77

@ghost
Copy link

ghost commented Oct 21, 2013

Ok, that seems to be due the '-m32' that is put in by the jni makefile.

Can you update your jffi tree and try building again?

@cadwallion
Copy link
Author

This got much further along, successfully building but then erroring after the Hello World. Since the output is getting pretty long, I threw it in a gist here: https://gist.github.com/cadwallion/7081956

@headius headius modified the milestones: JRuby 1.7.12, JRuby 1.7.10 Feb 21, 2014
@enebo
Copy link
Member

enebo commented Feb 22, 2014

There appears to be something wrong with jffi unpacking to /tmp. If you explicitly copy to /usr/lib/libjffi-1.2.so then this jffi-complete.jar runs:

pi@raspberrypi ~/jffi $ java -jar dist/jffi-complete.jar
jffi jar version=1.2.8
jffi stub version=1.2.8
memory fault protection enabled=false
stub arch=arm
JNI version=0x10006

I seem to be able to make files on my pi in /tmp so I don't know anything more currently. I am also able to load this:

pi@raspberrypi ~/jruby $ ./bin/jruby -Xnative.verbose=true -e "p File.stat('.')"
Successfully loaded native POSIX impl.
#<File::Stat dev=0xb306, ino=134219, mode=040755, nlink=9, uid=1000, gid=1000, rdev=0x0, size=4096, blksize=4096, blocks=0, atime=1969-12-31 18:00:00 -0600, mtime=1969-12-31 18:00:00 -0600, ctime=2001-07-23 21:24:42 -0500>

So it is definitely something wrong with the magic unpacking which happens....The workaround for now is to cp libjffi-1.2.so to /usr/lib.

@enebo
Copy link
Member

enebo commented May 11, 2016

I am resolving this here because I know there is an issue open for this in jnr/ffi-30.

@enebo enebo closed this as completed May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants