Android 查看动态库依赖的库文件

参考:http://blog.csdn.net/renwotao2009/article/details/51398739
  最近工作过程中,遇到了一个库文件打开失败的问题,需要查看so文件依赖哪些动态库。之前看到有同事用到ldd命令,但是本地使用ldd命令来解析arm的动态库是不行的。

armwind# ldd libcameraservice.so
not a dynamic executable

答案大家是知道的,由于是arm架构,用x86的程序来解析肯定是有问题的。所以又百度了一下,发现是有对应的命令来解析,如下我是64位的arm,所以使用了aarch64-linux-android-readelf命令。

aarch64-linux-android-readelf -d libcameraservice.so

执行上面的命令就得到下面的结果

Dynamic section at offset 0xe4cf0 contains 44 entries:
Tag Type Name/Value
0x0000000000000003 (PLTGOT) 0x1069f0
0x0000000000000002 (PLTRELSZ) 41448 (bytes)
0x0000000000000017 (JMPREL) 0x5fcd0
0x0000000000000014 (PLTREL) RELA
0x0000000060000011 (Operating System specific: 60000011) 0x58c28
0x0000000060000012 (Operating System specific: 60000012) 0x70a8
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffff9 (RELACOUNT) 652
0x0000000000000006 (SYMTAB) 0x20238
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000005 (STRTAB) 0x2e5d8
0x000000000000000a (STRSZ) 155156 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x543f0
0x0000000000000001 (NEEDED) Shared library: [libui.so]
0x0000000000000001 (NEEDED) Shared library: [liblog.so]
0x0000000000000001 (NEEDED) Shared library: [libutils.so]
0x0000000000000001 (NEEDED) Shared library: [libbinder.so]
0x0000000000000001 (NEEDED) Shared library: [libcutils.so]
0x0000000000000001 (NEEDED) Shared library: [libmedia.so]
0x0000000000000001 (NEEDED) Shared library: [libmediautils.so]
0x0000000000000001 (NEEDED) Shared library: [libcamera_client.so]
0x0000000000000001 (NEEDED) Shared library: [libgui.so]
0x0000000000000001 (NEEDED) Shared library: [libhardware.so]
0x0000000000000001 (NEEDED) Shared library: [libsync.so]
0x0000000000000001 (NEEDED) Shared library: [libcamera_metadata.so]
0x0000000000000001 (NEEDED) Shared library: [libjpeg.so]
0x0000000000000001 (NEEDED) Shared library: [libmemunreachable.so]
0x0000000000000001 (NEEDED) Shared library: [libc++.so]
0x0000000000000001 (NEEDED) Shared library: [libdl.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so]
0x0000000000000001 (NEEDED) Shared library: [libm.so]
0x000000000000000e (SONAME) Library soname: [libcameraservice.so]
0x000000000000001a (FINI_ARRAY) 0xf2a60
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x0000000000000019 (INIT_ARRAY) 0x105ce8
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
0x000000000000001e (FLAGS) BIND_NOW
0x000000006ffffffb (FLAGS_1) Flags: NOW
0x000000006ffffff0 (VERSYM) 0x578c4
0x000000006ffffffc (VERDEF) 0x58bbc
0x000000006ffffffd (VERDEFNUM) 1
0x000000006ffffffe (VERNEED) 0x58bd8
0x000000006fffffff (VERNEEDNUM) 2
0x0000000000000000 (NULL) 0x0

二、程序演示

如果是x86的动态库就可以使用ldd来分析。

  • 1.编译成动态库
    例程:
#include
using namespace std;
int main() {
    cout<<"hello world" << endl;
    return 0;
}

g++ -fPIC -shared -o libarmwind.so helloWorld.cpp
使用上面的命令就可以将方法封装成一个动态库,上面把helloworld封装成了libarmwind.so.

armwind#ls -l libarmwind.so
-rwxrwxrwx 1 root root 8693 Sep 5 09:52 libarmwind.so

  • 2.使用ldd查看依赖库
    使用g++编译得到默认的a.out可执行程序。

armwind# ldd a.out
linux-vdso.so.1 => (0x00007fff061ff000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fdf4e5b0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fdf4e2b4000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fdf4e09d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdf4dcde000)
/lib64/ld-linux-x86-64.so.2 (0x00007fdf4e8d8000)


  • 3.使用readelf来查看依赖库

armwind# readelf -d libarmwind.so | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]

你可能感兴趣的:(android问题分析及解决)