Unsatsified Link with libstlposrt_shared.so in Activity (_ZNSt12__node_alloc11_M_allocateERj)

96 views
Skip to first unread message

nolo...@gmail.com

unread,
Aug 31, 2014, 3:22:45 PM8/31/14
to andro...@googlegroups.com
I'm building a library that depends on `libcryptopp.so`. `libcryptopp.so` depends on `libstlport_shared.so`. The Java class that uses them looks like so:

    public class PRNG {
       
        static {
            System.loadLibrary("stlport_shared");
            System.loadLibrary("cryptopp");
            System.loadLibrary("prng");
        }
        ...
    }

When the activity launches, logcat claims `libstlport_shared.so` is loaded:

    D/dalvikvm( 2105): Trying to load lib /data/data/com.deltoid.prng/lib/libstlport_shared.so 0x410a5d58
    D/dalvikvm( 2105): Added shared lib /data/data/com.deltoid.prng/lib/libstlport_shared.so 0x410a5d58
    D/dalvikvm( 2105): No JNI_OnLoad found in /data/data/com.deltoid.prng/lib/libstlport_shared.so 0x410a5d58, skipping init
    ...

Next, `libcryptopp.so` is loaded. However, it results in an unsatisfied link error:

    ...
    D/dalvikvm( 2105): Trying to load lib /data/data/com.deltoid.prng/lib/libcryptopp.so 0x410a5d58
    W/dalvikvm( 2105): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/deltoid/prng/PRNG;
    ...
    E/AndroidRuntime( 2105):     at dalvik.system.NativeStart.main(Native Method)
    E/AndroidRuntime( 2105): Caused by: java.lang.UnsatisfiedLinkError:
                                                  Cannot load library: reloc_library[1285]:
                                                  86 cannot locate '_ZNSt12__node_alloc11_M_allocateERj'...
    E/AndroidRuntime( 2105):
    E/AndroidRuntime( 2105):     at java.lang.Runtime.loadLibrary(Runtime.java:370)

***Here's the bewildering thing***. I experienced the unsatisfied link of `'_ZNSt12__node_alloc11_M_allocateERj'` before. It happened on the command line during non-GUI testing (see[0] and [1]). The solution was to:

    shell@android:/data/local/tmp $ export LD_PRELOAD=`pwd`/libstlport_shared.so
    shell@android:/data/local/tmp $ echo $LD_PRELOAD                              
    /data/local/tmp/libstlport_shared.so

***Question***: Why am I getting an unsatisfied link error even though the library that provides the function is loaded?

Thanks in advance

****************************************

[0] "__ZNSt12__node_alloc11_M_allocateERj missing symbol?", https://groups.google.com/forum/#!topic/android-ndk/PeXmQiT-xEo
[1] "Crypto++'s "Android (Command Line)", http://www.cryptopp.com/wiki/Android_%28Command_Line%29

****************************************

Here's the full logcat of the session.

    I/ActivityManager(  182): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.deltoid.prng/.MainActivity} from pid 474
    D/dalvikvm( 2105): Late-enabling CheckJNI
    I/ActivityManager(  182): Start proc com.deltoid.prng for activity com.deltoid.prng/.MainActivity: pid=2105 uid=10082 gids={}
    D/WindowManager(  182): adjustConfigurationLw, config:{1.0 0mcc0mnc (no locale) layoutdir=0 sw800dp w1280dp h752dp xlrg land ?uimode ?night finger -keyb/v/h -nav/v} mLidOpen:-1 mHasDockFeature:true mHasHallSensorFeature:true config.hardKeyboardHidden:2
    D/OpenGLRenderer(  474): Flushing caches (mode 1)
    D/dalvikvm( 2105): Trying to load lib /data/data/com.deltoid.prng/lib/libstlport_shared.so 0x410a5d58
    D/dalvikvm( 2105): Added shared lib /data/data/com.deltoid.prng/lib/libstlport_shared.so 0x410a5d58
    D/dalvikvm( 2105): No JNI_OnLoad found in /data/data/com.deltoid.prng/lib/libstlport_shared.so 0x410a5d58, skipping init
    D/dalvikvm( 2105): Trying to load lib /data/data/com.deltoid.prng/lib/libcryptopp.so 0x410a5d58
    W/dalvikvm( 2105): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/deltoid/prng/PRNG;
    D/AndroidRuntime( 2105): Shutting down VM
    W/dalvikvm( 2105): threadid=1: thread exiting with uncaught exception (group=0x40a421f8)
    E/AndroidRuntime( 2105): FATAL EXCEPTION: main
    E/AndroidRuntime( 2105): java.lang.ExceptionInInitializerError
    E/AndroidRuntime( 2105):     at com.deltoid.prng.MainActivity.onCreate(MainActivity.java:21)
    E/AndroidRuntime( 2105):     at android.app.Activity.performCreate(Activity.java:4465)
    E/AndroidRuntime( 2105):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    E/AndroidRuntime( 2105):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
    E/AndroidRuntime( 2105):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
    E/AndroidRuntime( 2105):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
    E/AndroidRuntime( 2105):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
    E/AndroidRuntime( 2105):     at android.os.Handler.dispatchMessage(Handler.java:99)
    E/AndroidRuntime( 2105):     at android.os.Looper.loop(Looper.java:137)
    E/AndroidRuntime( 2105):     at android.app.ActivityThread.main(ActivityThread.java:4424)
    E/AndroidRuntime( 2105):     at java.lang.reflect.Method.invokeNative(Native Method)
    E/AndroidRuntime( 2105):     at java.lang.reflect.Method.invoke(Method.java:511)
    E/AndroidRuntime( 2105):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    E/AndroidRuntime( 2105):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    E/AndroidRuntime( 2105):     at dalvik.system.NativeStart.main(Native Method)
    E/AndroidRuntime( 2105): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1285]:    86 cannot locate '_ZNSt12__node_alloc11_M_allocateERj'...
    E/AndroidRuntime( 2105):
    E/AndroidRuntime( 2105):     at java.lang.Runtime.loadLibrary(Runtime.java:370)
    E/AndroidRuntime( 2105):     at java.lang.System.loadLibrary(System.java:535)
    E/AndroidRuntime( 2105):     at com.deltoid.prng.PRNG.<clinit>(PRNG.java:7)
    E/AndroidRuntime( 2105):     ... 15 more
    W/ActivityManager(  182):   Force finishing activity com.deltoid.prng/.MainActivity
    D/OpenGLRenderer(  474): Flushing caches (mode 0)
    W/ActivityManager(  182): Activity pause timeout for ActivityRecord{410bc170 com.deltoid.prng/.MainActivity}

nolo...@gmail.com

unread,
Sep 1, 2014, 2:42:10 AM9/1/14
to andro...@googlegroups.com
I was able to track this down to a missing dependency.

Below, when the shared object was built, I used --sysroot to include the header and library paths. I also specified libstlport_shared.so in $(LDLIBS). However, the command to build the shared object did not include $(LDFLAGS) and $(LDLIBS) (someone else wrote the makefile).

Readelf showed it was missing:

    $ arm-linux-androideabi-readelf -d libcryptopp.so

    Dynamic section at offset 0x34472c contains 26 entries:
     Tag        Type                         Name/Value
     0x00000003 (PLTGOT)                     0x346e30
     0x00000002 (PLTRELSZ)                   904 (bytes)
     ...
     0x00000001 (NEEDED)                     Shared library: [libstdc++.so]
     0x00000001 (NEEDED)                     Shared library: [libm.so]
     0x00000001 (NEEDED)                     Shared library: [libc.so]
     0x00000001 (NEEDED)                     Shared library: [libdl.so]
    ...

********

$ make static dynamic
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -pipe -fPIC -DCRYPTOPP_DISABLE_ASM
--sysroot=/opt/android-ndk-r9/platforms/android-14/arch-arm
-I/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/ -c 3way.cpp
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -pipe -fPIC -DCRYPTOPP_DISABLE_ASM
--sysroot=/opt/android-ndk-r9/platforms/android-14/arch-arm
-I/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/ -c adler32.cpp
arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -pipe -fPIC -DCRYPTOPP_DISABLE_ASM
--sysroot=/opt/android-ndk-r9/platforms/android-14/arch-arm
-I/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/ -c algebra.cpp
...

arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -pipe -fPIC -DCRYPTOPP_DISABLE_ASM
--sysroot=/opt/android-ndk-r9/platforms/android-14/arch-arm
-I/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/ -shared -o libcryptopp.so
3way.o adler32.o algebra.o algparam.o arc4.o asn.o authenc.o base32.o base64.o
... wait.o wake.o whrlpool.o xtr.o xtrcrypt.o zdeflate.o zinflate.o zlib.o
...

When I added /opt/android-ndk-r9/sources/cxx-stl/stlport/libs/armeabi/libstlport_shared.so to the command that built the shared object, the problem went away.
Reply all
Reply to author
Forward
0 new messages