This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Android and libffi


Hi,

I'm working on an Android application where I want to execute the
following closure example :

/* Acts like puts with the file given at time of enclosure. */
void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[],
                  FILE *stream)
{
    *ret = fputs(*(char **)args[0], stream);
    __android_log_write(ANDROID_LOG_DEBUG, "testffi", "hello");
}

int test_ffi()
{
    ffi_cif cif;
    ffi_type *args[1];
    ffi_closure *closure;

    int (*bound_puts)(char *);
    int rc;

    /* Allocate closure and bound_puts */
    closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);

    if (closure)
    {
        /* Initialize the argument info vectors */
        args[0] = &ffi_type_pointer;

        /* Initialize the cif */
        if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
                         &ffi_type_uint, args) == FFI_OK)
        {
            /* Initialize the closure, setting stream to stdout */
            if (ffi_prep_closure_loc(closure, &cif, puts_binding,
                                     stdout, bound_puts) == FFI_OK)
            {
                rc = bound_puts("Hello World!");
                /* rc now holds the result of the call to fputs */
            }
        }
    }

    /* Deallocate both closure, and bound_puts */
    ffi_closure_free(closure);

    return 0;
}

I'm using jni to execute native code. When executing this example I
get Fatal signal 11 (SIGSEGV), code 2, fault addr 0xb4b16478 on line
"rc = bound_puts("Hello World!");"

The first line on the stacktrace is: #0  0xa185a0a0 in ?? () which is
triggered from line "rc = bound_puts("Hello World!");"

I'm using the arm-linux-androideabi-4.9 toolchain from the Android NDK
r10e-linux-x86_64.

Used the following script to crosscompile libffi for arm:
#!/bin/sh
export PATH=/home/bla/workspace/toolchain/bin:$PATH
export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16"
cd libffi
mkdir build-android
./autogen.sh
cd build-android
../configure --prefix=/home/bla/workspace/setups/libffi-install
--host=arm-linux-androideabi --disable-shared --enable-static
make
make install

This works without any errors.

I'm using this Android.mk in my application for libffi:

include $(CLEAR_VARS)
LOCAL_MODULE := ffi
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libffi.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)


I can't find the problem, i've cloned libffi from the github page and
tried all the older versions (tags).

Can anyone help me out with this problem or tell me what I'm doing wrong?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]