Trying to link my app against compiled openssl

1,250 views
Skip to first unread message

Cadu Silvestre

unread,
Feb 11, 2011, 1:27:24 PM2/11/11
to android-ndk
Gentlemen,

I have a C/C++ linux app which I need to port to Android via NDK. The
app uses openssl.

I was looking for an Android-mk build option to link native openssl
against my application, and I thought LOCAL_LDLIBS was the one, but I
realized it is not, as only application listed in STABLE-APIS.html are
available and openssl is not there.

Using a x64 machine I was able to compile the whole droid platform. I
got the following openssl binaries:

/android/mydroid/out/host/linux-x86/lib/libcrypto.so
/android/mydroid/out/host/linux-x86/lib/libssl.so

So, my first unsuccessful idea was to force my libcrypto.so in
LOCAL_LDLIBS:

/android/mydroid/out/host/linux-x86/lib/libcrypto.so: could not read
symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [/android/cap/obj/local/armeabi/libSCore.so] Error 1

At this time, I realized I'd compiled the whole NDK for nothing...

Thus, as far as I could gather from ANDROID-MK docs, the remaing
option was LOCAL_SHARED_LIBRARIES:

LOCAL_SHARED_LIBRARIES += libcrypto.so

But then, I got several undefined symbols, as it didn't really link
against the library, just embeds the dependency information into the
generated app. Using the LOCAL_ALLOW_UNDEFINED_SYMBOLS option, I got
rid of the undefined symbols, and my hope is that when running my
application in the device, it will look for libcrypto.so into the
library's repository and load it to the symbol table(at least this is
the only usage I could come up to this LOCAL_ALLOW_UNDEFINED_SYMBOLS
option).

I have a long road to start testing the application, and I'd really
appreciate your help on telling me if this is the right way to create
a native application which uses openssl in android.

Thanks in advance, guys.

alan

unread,
Feb 11, 2011, 4:48:34 PM2/11/11
to andro...@googlegroups.com
i'm pretty sure that that won't work. for full compatibility you must compile openssl with the ndk and include your build with your application. you might also need to change the name of the openssl libraries to ensure there are no conflicts with the system libraries

Cadu Silvestre

unread,
Feb 14, 2011, 5:47:03 AM2/14/11
to android-ndk
Hi Alan,\

I understand when you say it won't work but would you please tell me
why? Also, why they would put that flag LOCAL_ALLOW_UNDEFINED_SYMBOLS
within makefile options?

Also, there are two points I can't see how to manage:

1) "compile openssl with the ndk and include your build with your
application"? Openssl is already compiled with NDK, now how can I
include it in my app if as the way I'm trying is somehow wrong?

2) To change the name of a linux library is not that simple. There is
something called SONAME (http://en.wikipedia.org/wiki/Soname), and you
need to change the makefiles to make this happen. I've done this
several times with regular makefiles, but with android makefiles I
don't know how to do it.

Thanks!

alan

unread,
Feb 14, 2011, 8:19:26 AM2/14/11
to andro...@googlegroups.com
any library that is not included in the ndk should not be used by applications. it is guaranteed that any library included in the ndk will have a compatible library on any device so that your application can load an use that library. libssl.so may exist on most (but not necessarily all) devices but it may be a different library compiled from a different version of the source with different options. if you link against libssl.so pulled from a device then your app should work on that device and any other device using exactly the same firmware (not just the same version 2.1, 2.2 etc but exactly the same).
there probably legitimate uses for LOCAL_ALLOW_UNDEFINED_SYMBOLS but just using it to force something to link isn't one!
to include a prebuilt library see prebuilts.html in the documentation.
are you building libssl with android make files? if so simply change LOCAL_MODULE. if you are not using android make files then i'm sure there's probably an option on configure to specify the library name.
"/android/mydroid/out/host/linux-x86/lib/libcrypto.so: could not read symbols: File in wrong format" means that the library hasn't been compiled correctly for android, maybe some part of the build was done using a system tool rather than an android one

Cadu Silvestre

unread,
Feb 14, 2011, 2:17:05 PM2/14/11
to android-ndk
Hi Alan,

Again, thanks for your quick answers - you're really helping me on
that.

I've tried the PREBUILD u mentioned - but I got the same error when
using LD:

C:/Android/Projects/CAP/obj/local/armeabi/libcrypto.so: could not read
symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [/android/Projects/MyProj/obj/local/armeabi/libSCore.so]
Error 1

You said "means that the library hasn't been compiled correctly for
android, maybe some part of the build was done using a system tool
rather than an android one".

I built that library using http://android.git.kernel.org/ code from
one week ago, and used regular android makefiles in a x64 machine.

I did nothing but go to the repository directory and type "make -j4".
My build options were:

============================================
PLATFORM_VERSION_CODENAME=AOSP
PLATFORM_VERSION=AOSP
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv5te
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=OPENMASTER
============================================

Am I doing something wrong?

Cheers.

Do I have to do anything different?

alan

unread,
Feb 15, 2011, 4:01:35 AM2/15/11
to andro...@googlegroups.com
there is a big difference between android platform sdk builds and android ndk builds. if you build using the platform sdk then your build will only work on a custom platform built by you. for your libraries to work with the ndk they must be compiled with the ndk (i.e ndk-build not make)

Cadu Silvestre

unread,
Feb 15, 2011, 8:59:05 AM2/15/11
to android-ndk
True!

My bad. It was really stupid to get a .so in the linux-x86 SDK dir and
think that it would work.

I fixed that stupid mistake and here what I got:

SharedLibrary : libSEMyProjL.so
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,-
soname,libSEMyProjL.so -shared --sysroot=/android/android-ndk-r5/
platforms/android-5/arch-arm /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/SEMyProjLCore.o /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/SEMyProjLEngine.o /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/SEMyProjLServices.o /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/JSEMyProjL.o /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/BrandAbstractCCD.o /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/BrandAbstraction.o /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/BrandAbstractMchip.o /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/BrandAbstractVSDC.o /android/MyProj/obj/local/armeabi/objs/
SEMyProjL/SEALConfig.o /android/MyProj/obj/local/armeabi/libSCore.a /
android/MyProj/obj/local/armeabi/libstdc++.a /android/MyProj/obj/local/
armeabi/libcrypto.so /android/MyProj/obj/local/armeabi/libssl.so /
android/MyProj/obj/local/armeabi/libz.so /android/android-ndk-r5/
platforms/android-5/arch-arm/usr/lib/libc.so /android/android-ndk-r5/
platforms/android-5/arch-arm/usr/lib/libstdc++.so /android/android-ndk-
r5/platforms/android-5/arch-arm/usr/lib/libm.so -Wl,--no-undefined -
Wl,-z,noexecstack -L/android/android-ndk-r5/platforms/android-5/arch-
arm/usr/lib -lstdc++ -Wl,-rpath-link=/android/android-ndk-r5/platforms/
android-5/arch-arm/usr/lib -lsupc++ -o /android/MyProj/obj/local/
armeabi/libSEMyProjL.so
Install : libSEMyProjL.so => libs/armeabi/libSEMyProjL.so
mkdir -p /android/MyProj/libs/armeabi
install -p /android/MyProj/obj/local/armeabi/libSEMyProjL.so /android/
MyProj/libs/armeabi/libSEMyProjL.so
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded /
android/MyProj/libs/armeabi/libSEMyProjL.so
Install : libcrypto.so => libs/armeabi/libcrypto.so
mkdir -p /android/MyProj/libs/armeabi
install -p /android/MyProj/obj/local/armeabi/libcrypto.so /android/
MyProj/libs/armeabi/libcrypto.so
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded /
android/MyProj/libs/armeabi/libcrypto.so
Executable : openssl
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,--gc-sections -
Wl,-z,nocopyreloc --sysroot=/android/android-ndk-r5/platforms/
android-5/arch-arm /android/MyProj/obj/local/armeabi/objs/openssl/
app_rand.o /android/MyProj/obj/local/armeabi/objs/openssl/apps.o /
android/MyProj/obj/local/armeabi/objs/openssl/asn1pars.o /android/
MyProj/obj/local/armeabi/objs/openssl/ca.o /android/MyProj/obj/local/
armeabi/objs/openssl/ciphers.o /android/MyProj/obj/local/armeabi/objs/
openssl/crl.o /android/MyProj/obj/local/armeabi/objs/openssl/crl2p7.o /
android/MyProj/obj/local/armeabi/objs/openssl/dgst.o /android/MyProj/
obj/local/armeabi/objs/openssl/dh.o /android/MyProj/obj/local/armeabi/
objs/openssl/dhparam.o /android/MyProj/obj/local/armeabi/objs/openssl/
dsa.o /android/MyProj/obj/local/armeabi/objs/openssl/dsaparam.o /
android/MyProj/obj/local/armeabi/objs/openssl/ecparam.o /android/
MyProj/obj/local/armeabi/objs/openssl/ec.o /android/MyProj/obj/local/
armeabi/objs/openssl/enc.o /android/MyProj/obj/local/armeabi/objs/
openssl/engine.o /android/MyProj/obj/local/armeabi/objs/openssl/
errstr.o /android/MyProj/obj/local/armeabi/objs/openssl/gendh.o /
android/MyProj/obj/local/armeabi/objs/openssl/gendsa.o /android/MyProj/
obj/local/armeabi/objs/openssl/genpkey.o /android/MyProj/obj/local/
armeabi/objs/openssl/genrsa.o /android/MyProj/obj/local/armeabi/objs/
openssl/nseq.o /android/MyProj/obj/local/armeabi/objs/openssl/ocsp.o /
android/MyProj/obj/local/armeabi/objs/openssl/openssl.o /android/
MyProj/obj/local/armeabi/objs/openssl/passwd.o /android/MyProj/obj/
local/armeabi/objs/openssl/pkcs12.o /android/MyProj/obj/local/armeabi/
objs/openssl/pkcs7.o /android/MyProj/obj/local/armeabi/objs/openssl/
pkcs8.o /android/MyProj/obj/local/armeabi/objs/openssl/pkey.o /android/
MyProj/obj/local/armeabi/objs/openssl/pkeyparam.o /android/MyProj/obj/
local/armeabi/objs/openssl/pkeyutl.o /android/MyProj/obj/local/armeabi/
objs/openssl/prime.o /android/MyProj/obj/local/armeabi/objs/openssl/
rand.o /android/MyProj/obj/local/armeabi/objs/openssl/req.o /android/
MyProj/obj/local/armeabi/objs/openssl/rsa.o /android/MyProj/obj/local/
armeabi/objs/openssl/rsautl.o /android/MyProj/obj/local/armeabi/objs/
openssl/s_cb.o /android/MyProj/obj/local/armeabi/objs/openssl/
s_client.o /android/MyProj/obj/local/armeabi/objs/openssl/s_server.o /
android/MyProj/obj/local/armeabi/objs/openssl/s_socket.o /android/
MyProj/obj/local/armeabi/objs/openssl/s_time.o /android/MyProj/obj/
local/armeabi/objs/openssl/sess_id.o /android/MyProj/obj/local/armeabi/
objs/openssl/smime.o /android/MyProj/obj/local/armeabi/objs/openssl/
speed.o /android/MyProj/obj/local/armeabi/objs/openssl/spkac.o /
android/MyProj/obj/local/armeabi/objs/openssl/verify.o /android/MyProj/
obj/local/armeabi/objs/openssl/version.o /android/MyProj/obj/local/
armeabi/objs/openssl/x509.o /android/MyProj/obj/local/armeabi/
libssl.so /android/MyProj/obj/local/armeabi/libcrypto.so /android/
android-ndk-r5/platforms/android-5/arch-arm/usr/lib/libc.so /android/
android-ndk-r5/platforms/android-5/arch-arm/usr/lib/libstdc++.so /
android/android-ndk-r5/platforms/android-5/arch-arm/usr/lib/libm.so -
Wl,--no-undefined -Wl,-z,noexecstack -Wl,-rpath-link=/android/android-
ndk-r5/platforms/android-5/arch-arm/usr/lib -lsupc++ -o /android/
MyProj/obj/local/armeabi/openssl
Install : openssl => libs/armeabi/openssl
mkdir -p /android/MyProj/libs/armeabi
install -p /android/MyProj/obj/local/armeabi/openssl /android/MyProj/
libs/armeabi/openssl
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded /
android/MyProj/libs/armeabi/openssl
Install : libssl.so => libs/armeabi/libssl.so
mkdir -p /android/MyProj/libs/armeabi
install -p /android/MyProj/obj/local/armeabi/libssl.so /android/MyProj/
libs/armeabi/libssl.so
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded /
android/MyProj/libs/armeabi/libssl.so
Executable : ssltest
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -Wl,--gc-sections -
Wl,-z,nocopyreloc --sysroot=/android/android-ndk-r5/platforms/
android-5/arch-arm /android/MyProj/obj/local/armeabi/objs/ssltest/
ssltest.o /android/MyProj/obj/local/armeabi/libssl.so /android/
MyProj/obj/local/armeabi/libcrypto.so /android/android-ndk-r5/
platforms/android-5/arch-arm/usr/lib/libc.so /android/android-ndk-r5/
platforms/android-5/arch-arm/usr/lib/libstdc++.so /android/android-ndk-
r5/platforms/android-5/arch-arm/usr/lib/libm.so -Wl,--no-undefined -
Wl,-z,noexecstack -Wl,-rpath-link=/android/android-ndk-r5/platforms/
android-5/arch-arm/usr/lib -lsupc++ -o /android/MyProj/obj/local/
armeabi/ssltest
Install : ssltest => libs/armeabi/ssltest
mkdir -p /android/MyProj/libs/armeabi
install -p /android/MyProj/obj/local/armeabi/ssltest /android/MyProj/
libs/armeabi/ssltest
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded /
android/MyProj/libs/armeabi/ssltest
Install : libz.so => libs/armeabi/libz.so
mkdir -p /android/MyProj/libs/armeabi
install -p /android/MyProj/obj/local/armeabi/libz.so /android/MyProj/
libs/armeabi/libz.so
/android/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded /
android/MyProj/libs/armeabi/libz.so

Which means I'm successfully compiling openssl and libz with ndk-build
besides linking them with my library.

My target library is the libSEMyProjL.so (it has my JNI symbols) and
here it goes its Android.mk LOCAL_SHARED_LIBRARIES line:

LOCAL_SHARED_LIBRARIES := libcrypto libssl libz

Which is reflected when it's being linked:

/android/MyProj/obj/local/armeabi/libSCore.a /android/MyProj/obj/
local/armeabi/libstdc++.a /android/MyProj/obj/local/armeabi/
libcrypto.so /android/MyProj/obj/local/armeabi/libssl.so /android/
MyProj/obj/local/armeabi/libz.so /android/android-ndk-r5/platforms/
android-5/arch-arm/usr/lib/libc.so /android/android-ndk-r5/platforms/
android-5/arch-arm/usr/lib/libstdc++.so /android/android-ndk-r5/
platforms/android-5/arch-arm/usr/lib/libm.so -Wl,--no-undefined -Wl,-
z,noexecstack -L/android/android-ndk-r5/platforms/android-5/arch-arm/
usr/lib -lstdc++ -Wl,-rpath-link=/android/android-ndk-r5/platforms/
android-5/arch-arm/usr/lib -lsupc++ -o /android/MyProj/obj/local/
armeabi/libSEMyProjL.so

But when I try to load it on the EMULATOR:

static {
System.loadLibrary("libSEMyProjL");
}

Thread [<3> main] (Suspended (exception UnsatisfiedLinkError))
Runtime.loadLibrary(String, ClassLoader) line: 489
System.loadLibrary(String) line: 557
SEMyProjLInterface.<clinit>() line: 12
MyProjHandler.<init>(int, EditText, Context, Activity) line: 42
MyProj.onCreate(Bundle) line: 72
Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord,
Intent) line: 2521
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord,
Intent) line: 2574
ActivityThread.access$2400(ActivityThread, ActivityThread
$ActivityRecord, Intent) line: 121
ActivityThread$H.handleMessage(Message) line: 1925
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 136
ActivityThread.main(String[]) line: 4425
Method.invokeNative(Object, Object[], Class, Class[], Class, int,
boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 860
ZygoteInit.main(String[]) line: 618
NativeStart.main(String[]) line: not available [native method]


Do you have a clue?

Is there any Android LDD like to check what dependencies are not being
satisfied?


Thanks!

Cadu Silvestre

unread,
Feb 15, 2011, 9:13:52 AM2/15/11
to android-ndk
I forgot to add two important points:

1 - In my MyProj.apk\lib\armeabi\ I have:

libcrypto.so, libssl.so, libz.so and libSEMyProjL

2 - I've also tested on the phone and I got the same exception.

Cheers!
> ...
>
> read more »

alan

unread,
Feb 15, 2011, 9:42:43 AM2/15/11
to andro...@googlegroups.com
you need to change the name of libcrypto.so and libssl.so or they will conflict with system libraries

alan

unread,
Feb 15, 2011, 9:44:39 AM2/15/11
to andro...@googlegroups.com
you also have to manually load all required shared libraries before loading you r shared library. your java should therefore look like:
   static {
     System.loadLibrary("crypto");
     System.loadLibrary("ssl");
     System.loadLibrary("SEMyProjL");
    }
(also note the lack of "lib")

Cadu Silvestre

unread,
Feb 15, 2011, 1:29:12 PM2/15/11
to android-ndk
Alan,

Many many thanks for your help untill now - I wouldn't make it this
quick without your quick and accurate answers.

Here where I am now...

I did compiled my openssl with different LOCAL_MODULE names (I found
out that changing it we also change soname, which is great). So, I was
able to load all dependencies:

System.loadLibrary("myz");
System.loadLibrary("mycrypto");
System.loadLibrary("myssl");

But when loading my library in my specific device(MB502) Emulator:

System.loadLibrary("SEMyProjL");

02-15 18:17:39.527: DEBUG/dalvikvm(1151): Trying to load lib /data/
data/br.com.smartcon.sconMyProj/lib/libSEMyProjL.so 0x43a40f70
02-15 18:17:39.678: INFO/DEBUG(27): *** *** *** *** *** *** *** ***
*** *** *** *** *** *** *** ***
02-15 18:17:39.687: INFO/DEBUG(27): Build fingerprint: 'generic/
motodev/motodev/:2.1-update1/ERE27/eng.cdwq67.20100629.113345:eng/
release-keys'
02-15 18:17:39.687: INFO/DEBUG(27): pid: 1151, tid: 1151 >>>
br.com.smartcon.sconMyProj <<<
02-15 18:17:39.687: INFO/DEBUG(27): signal 4 (SIGILL), fault addr
81100000
02-15 18:17:39.697: INFO/DEBUG(27): r0 8112e9e0 r1 8111c84c r2
8111c7ca r3 00000000
02-15 18:17:39.697: INFO/DEBUG(27): r4 8112988c r5 8112e9e0 r6
00000004 r7 00000000
02-15 18:17:39.697: INFO/DEBUG(27): r8 bee2b820 r9 41155ddc 10
00000360 fp 4104ebe0
02-15 18:17:39.697: INFO/DEBUG(27): ip 811298c8 sp bee2b648 lr
8111c804 pc 81100000 cpsr a0000010
02-15 18:17:39.837: INFO/DEBUG(27): #00 pc 00000000 /data/
data/br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:17:39.837: INFO/DEBUG(27): #01 pc 0001c800 /data/
data/br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:17:39.847: INFO/DEBUG(27): #02 pc b00001fc /system/
bin/linker
02-15 18:17:39.847: INFO/DEBUG(27): #03 pc b00002bc /system/
bin/linker
02-15 18:17:39.847: INFO/DEBUG(27): #04 pc b00018a4 /system/
bin/linker
02-15 18:17:39.857: INFO/DEBUG(27): #05 pc b0001b70 /system/
bin/linker
02-15 18:17:39.857: INFO/DEBUG(27): #06 pc b0001552 /system/
bin/linker
02-15 18:17:39.867: INFO/DEBUG(27): #07 pc b0001cbc /system/
bin/linker
02-15 18:17:39.867: INFO/DEBUG(27): #08 pc 0003d08c /system/
lib/libdvm.so
02-15 18:17:39.878: INFO/DEBUG(27): #09 pc 0005458a /system/
lib/libdvm.so
02-15 18:17:39.887: INFO/DEBUG(27): #10 pc 0001ff70 /system/
lib/libdvm.so
02-15 18:17:39.887: INFO/DEBUG(27): #11 pc 00018ef8 /system/
lib/libdvm.so
02-15 18:17:39.897: INFO/DEBUG(27): #12 pc 0004daf0 /system/
lib/libdvm.so
02-15 18:17:39.897: INFO/DEBUG(27): #13 pc 0004db22 /system/
lib/libdvm.so
02-15 18:17:39.907: INFO/DEBUG(27): #14 pc 0005867e /system/
lib/libdvm.so
02-15 18:17:39.907: INFO/DEBUG(27): #15 pc 0002430c /system/
lib/libdvm.so
02-15 18:17:39.917: INFO/DEBUG(27): #16 pc 00018ef8 /system/
lib/libdvm.so
02-15 18:17:39.927: INFO/DEBUG(27): #17 pc 0004d7dc /system/
lib/libdvm.so
02-15 18:17:39.927: INFO/DEBUG(27): #18 pc 00055294 /system/
lib/libdvm.so
02-15 18:17:39.937: INFO/DEBUG(27): #19 pc 00014018 /system/
lib/libdvm.so
02-15 18:17:39.947: INFO/DEBUG(27): #20 pc 00019acc /system/
lib/libdvm.so
02-15 18:17:39.957: INFO/DEBUG(27): #21 pc 00018ebc /system/
lib/libdvm.so
02-15 18:17:39.967: INFO/DEBUG(27): #22 pc 0004daf0 /system/
lib/libdvm.so
02-15 18:17:39.967: INFO/DEBUG(27): #23 pc 0003a9b8 /system/
lib/libdvm.so
02-15 18:17:39.977: INFO/DEBUG(27): #24 pc 0002c096 /system/
lib/libdvm.so
02-15 18:17:39.977: INFO/DEBUG(27): #25 pc 00029184 /system/
lib/libandroid_runtime.so
02-15 18:17:39.987: INFO/DEBUG(27): #26 pc 00029e68 /system/
lib/libandroid_runtime.so
02-15 18:17:39.987: INFO/DEBUG(27): #27 pc 00008cae /system/
bin/app_process
02-15 18:17:39.997: INFO/DEBUG(27): #28 pc 0000c316 /system/
lib/libc.so
02-15 18:17:39.997: INFO/DEBUG(27): #29 pc b00018aa /system/
bin/linker
02-15 18:17:40.007: INFO/DEBUG(27): code around lr:
02-15 18:17:40.007: INFO/DEBUG(27): 8111c7f4 e59f1040 e1a00005
e08f1001 ebffbf1f
02-15 18:17:40.007: INFO/DEBUG(27): 8111c804 e2700001 33a00000
e5c50004 e59f3028
02-15 18:17:40.017: INFO/DEBUG(27): 8111c814 e59f0028 e7942003
e59f3024 e08f0000
02-15 18:17:40.017: INFO/DEBUG(27): stack:
02-15 18:17:40.027: INFO/DEBUG(27): bee2b608 8110c168 /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:17:40.027: INFO/DEBUG(27): bee2b60c 81109d2f /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:17:40.027: INFO/DEBUG(27): bee2b610 0001b315 [heap]
02-15 18:17:40.037: INFO/DEBUG(27): bee2b614 b0000647 /system/
bin/linker
02-15 18:17:40.037: INFO/DEBUG(27): bee2b618 00000000
02-15 18:17:40.037: INFO/DEBUG(27): bee2b61c b00041d9 /system/
bin/linker
02-15 18:17:40.037: INFO/DEBUG(27): bee2b620 ffffffff
02-15 18:17:40.037: INFO/DEBUG(27): bee2b624 00000000
02-15 18:17:40.037: INFO/DEBUG(27): bee2b628 81128000 /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:17:40.047: INFO/DEBUG(27): bee2b62c b0016674
02-15 18:17:40.047: INFO/DEBUG(27): bee2b630 b001343c
02-15 18:17:40.047: INFO/DEBUG(27): bee2b634 b00133b0
02-15 18:17:40.057: INFO/DEBUG(27): bee2b638 ffffffff
02-15 18:17:40.057: INFO/DEBUG(27): bee2b63c 81109d2f /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:17:40.057: INFO/DEBUG(27): bee2b640 df002777
02-15 18:17:40.067: INFO/DEBUG(27): bee2b644 e3a070ad
02-15 18:17:40.077: INFO/DEBUG(27): #01 bee2b648 8112874c /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:17:40.087: INFO/DEBUG(27): bee2b64c 00000001
02-15 18:17:40.087: INFO/DEBUG(27): bee2b650 00000004
02-15 18:17:40.096: INFO/DEBUG(27): bee2b654 b00001ff /system/
bin/linker

The VM crashes oO

And the same happened on my generic device emulator:

02-15 18:25:29.569: DEBUG/dalvikvm(226): Trying to load lib /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so 0x43d0bf90
02-15 18:25:29.721: INFO/DEBUG(28): *** *** *** *** *** *** *** ***
*** *** *** *** *** *** *** ***
02-15 18:25:29.729: INFO/DEBUG(28): Build fingerprint: 'generic/sdk/
generic/:2.1-update1/ECLAIR/35983:eng/test-keys'
02-15 18:25:29.729: INFO/DEBUG(28): pid: 226, tid: 226 >>>
br.com.smartcon.sconMyProj <<<
02-15 18:25:29.739: INFO/DEBUG(28): signal 4 (SIGILL), fault addr
80e00000
02-15 18:25:29.739: INFO/DEBUG(28): r0 80e2e9e0 r1 80e1c84c r2
80e1c7ca r3 00000000
02-15 18:25:29.739: INFO/DEBUG(28): r4 80e2988c r5 80e2e9e0 r6
00000004 r7 00000000
02-15 18:25:29.739: INFO/DEBUG(28): r8 bea45850 r9 41151894 10
00000354 fp 4104bbe0
02-15 18:25:29.749: INFO/DEBUG(28): ip 80e298c8 sp bea45678 lr
80e1c804 pc 80e00000 cpsr a0000010
02-15 18:25:29.869: INFO/DEBUG(28): #00 pc 00000000 /data/
data/br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:25:29.869: INFO/DEBUG(28): #01 pc 0001c800 /data/
data/br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:25:29.879: INFO/DEBUG(28): #02 pc b00001fc /system/
bin/linker
02-15 18:25:29.879: INFO/DEBUG(28): #03 pc b00002bc /system/
bin/linker
02-15 18:25:29.889: INFO/DEBUG(28): #04 pc b00018a4 /system/
bin/linker
02-15 18:25:29.889: INFO/DEBUG(28): #05 pc b0001b70 /system/
bin/linker
02-15 18:25:29.899: INFO/DEBUG(28): #06 pc b0001552 /system/
bin/linker
02-15 18:25:29.899: INFO/DEBUG(28): #07 pc b0001cbc /system/
bin/linker
02-15 18:25:29.899: INFO/DEBUG(28): #08 pc 0003cdfc /system/
lib/libdvm.so
02-15 18:25:29.909: INFO/DEBUG(28): #09 pc 0005416a /system/
lib/libdvm.so
02-15 18:25:29.909: INFO/DEBUG(28): #10 pc 0001fd2c /system/
lib/libdvm.so
02-15 18:25:29.919: INFO/DEBUG(28): #11 pc 00018d98 /system/
lib/libdvm.so
02-15 18:25:29.919: INFO/DEBUG(28): #12 pc 0004d6d0 /system/
lib/libdvm.so
02-15 18:25:29.929: INFO/DEBUG(28): #13 pc 0004d702 /system/
lib/libdvm.so
02-15 18:25:29.939: INFO/DEBUG(28): #14 pc 00058232 /system/
lib/libdvm.so
02-15 18:25:29.939: INFO/DEBUG(28): #15 pc 000240c8 /system/
lib/libdvm.so
02-15 18:25:29.949: INFO/DEBUG(28): #16 pc 00018d98 /system/
lib/libdvm.so
02-15 18:25:29.949: INFO/DEBUG(28): #17 pc 0004d3bc /system/
lib/libdvm.so
02-15 18:25:29.949: INFO/DEBUG(28): #18 pc 00054e74 /system/
lib/libdvm.so
02-15 18:25:29.959: INFO/DEBUG(28): #19 pc 00013f58 /system/
lib/libdvm.so
02-15 18:25:29.959: INFO/DEBUG(28): #20 pc 00019888 /system/
lib/libdvm.so
02-15 18:25:29.969: INFO/DEBUG(28): #21 pc 00018d5c /system/
lib/libdvm.so
02-15 18:25:29.969: INFO/DEBUG(28): #22 pc 0004d6d0 /system/
lib/libdvm.so
02-15 18:25:29.979: INFO/DEBUG(28): #23 pc 0003a72c /system/
lib/libdvm.so
02-15 18:25:29.979: INFO/DEBUG(28): #24 pc 0002be52 /system/
lib/libdvm.so
02-15 18:25:29.989: INFO/DEBUG(28): #25 pc 00026f7c /system/
lib/libandroid_runtime.so
02-15 18:25:29.999: INFO/DEBUG(28): #26 pc 00027c60 /system/
lib/libandroid_runtime.so
02-15 18:25:29.999: INFO/DEBUG(28): #27 pc 00008cae /system/
bin/app_process
02-15 18:25:30.009: INFO/DEBUG(28): #28 pc 0000c2c6 /system/
lib/libc.so
02-15 18:25:30.009: INFO/DEBUG(28): #29 pc b00018aa /system/
bin/linker
02-15 18:25:30.019: INFO/DEBUG(28): code around lr:
02-15 18:25:30.019: INFO/DEBUG(28): 80e1c7f4 e59f1040 e1a00005
e08f1001 ebffbf1f
02-15 18:25:30.019: INFO/DEBUG(28): 80e1c804 e2700001 33a00000
e5c50004 e59f3028
02-15 18:25:30.019: INFO/DEBUG(28): 80e1c814 e59f0028 e7942003
e59f3024 e08f0000
02-15 18:25:30.019: INFO/DEBUG(28): stack:
02-15 18:25:30.029: INFO/DEBUG(28): bea45638 80e0c168 /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:25:30.029: INFO/DEBUG(28): bea4563c 80e09d2f /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:25:30.039: INFO/DEBUG(28): bea45640 0001b315 [heap]
02-15 18:25:30.039: INFO/DEBUG(28): bea45644 b0000647 /system/
bin/linker
02-15 18:25:30.039: INFO/DEBUG(28): bea45648 00000000
02-15 18:25:30.049: INFO/DEBUG(28): bea4564c b00041d9 /system/
bin/linker
02-15 18:25:30.049: INFO/DEBUG(28): bea45650 ffffffff
02-15 18:25:30.049: INFO/DEBUG(28): bea45654 00000000
02-15 18:25:30.049: INFO/DEBUG(28): bea45658 80e28000 /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:25:30.049: INFO/DEBUG(28): bea4565c b0016674
02-15 18:25:30.049: INFO/DEBUG(28): bea45660 b0012ec4
02-15 18:25:30.049: INFO/DEBUG(28): bea45664 b0012e38
02-15 18:25:30.059: INFO/DEBUG(28): bea45668 ffffffff
02-15 18:25:30.059: INFO/DEBUG(28): bea4566c 80e09d2f /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:25:30.069: INFO/DEBUG(28): bea45670 df002777
02-15 18:25:30.069: INFO/DEBUG(28): bea45674 e3a070ad
02-15 18:25:30.069: INFO/DEBUG(28): #01 bea45678 80e2874c /data/data/
br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:25:30.069: INFO/DEBUG(28): bea4567c 00000001
02-15 18:25:30.069: INFO/DEBUG(28): bea45680 00000004
02-15 18:25:30.069: INFO/DEBUG(28): bea45684 b00001ff /system/
bin/linker
02-15 18:25:30.839: DEBUG/Zygote(30): Process 226 terminated by signal
(4)


MyProj is a complex C++ code, involving exceptions, dynamic castings
and hundreds of objects (no namespaces or STL stuff).

Any clue?

Thanks!

alan

unread,
Feb 15, 2011, 1:36:03 PM2/15/11
to andro...@googlegroups.com
these are the interesting lines from the crash dump:


02-15 18:25:29.869: INFO/DEBUG(28):          #00  pc 00000000  /data/data/br.com.smartcon.sconMyProj/lib/libSEMyProjL.so
02-15 18:25:29.869: INFO/DEBUG(28):          #01  pc 0001c800  /data/data/br.com.smartcon.sconMyProj/lib/libSEMyProjL.s0

something at address 0x1c800 in your library tried to set the program counter (pc) to 0. this is illegal so an illegal instruction signal is thrown (SIGILL). what this means is that 1c800 likely tried to invoke a function pointer which was set to 0 eg:

funcPtr f = NULL;
f();

would produce the same error.
if you load your library into addr2line (use the library from obj not from libs) and enter 1c800 it should tell you the relevant line of code

Cadu Silvestre

unread,
Feb 15, 2011, 2:25:22 PM2/15/11
to android-ndk
Ok, let me understand the problem...

Why thee is a PC walking on my DLL if I haven't called anything from
it?

Is there any DllLoad like I have to implement or something like that?

I checked where that address is pointing and look what I've got:

/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/
eh_globals.cc:110

Am I compiling against the wrong version of listdc++ or something like
that?

alan

unread,
Feb 15, 2011, 3:05:12 PM2/15/11
to andro...@googlegroups.com
all sorts of stuff is called when the dll is loaded. are you using stl? if so are you using more than one, e.g. stlport and gnu_stl?

Cadu Silvestre

unread,
Feb 17, 2011, 8:23:45 AM2/17/11
to android-ndk
I'm not using STL at all - at least that what I suppose.

This is my Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libSEMyProjL

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../extern/include/ \
$(LOCAL_PATH)/../extern/include/
openssl/

LOCAL_CFLAGS += -Werror -fexceptions

LOCAL_SHARED_LIBRARIES := libmycrypto libmyssl libmyz

LOCAL_SRC_FILES := APDU.cpp \
BaseAppletServices.cpp \
BaseServices.cpp \
Crypto.cpp \
HSMAbstractionFactory.cpp \
HSMAbstractionSWSim.cpp \
KernelBase.cpp \
MULTOS.cpp \
Objects.cpp \
TLV.cpp

include $(BUILD_SHARED_LIBRARY)


But I really didn't understand why "all sorts of stuff is called when
the dll is loaded". That doesn't really make sense to me!

Thanks,

alan

unread,
Feb 17, 2011, 10:43:26 AM2/17/11
to andro...@googlegroups.com
to use "-fexceptions" you must use gnu-stl.
when you load a shared library all static initializers are called automatically, e.g. if in your code you write:
static MyClass myClass;
you are asking for a instance of MyClass to be created when the library is first loaded. Various parts of system libraries will be doing the same thing so even if you have no static initializers yourself some will still be run when your library loads.

Cadu Silvestre

unread,
Feb 17, 2011, 12:14:53 PM2/17/11
to android-ndk
Alan,

It worked!

Thousand thanks for your contribution. I'm gonna rate all your posts
to five stars - you gave me the directions to make it.
Reply all
Reply to author
Forward
0 new messages