① Android下怎麼使用LDD查看依賴庫
Android下沒有ldd可以使用,在進行ndk開發的時候,檢查庫的依賴項特別麻煩。有兩個解決方案:
1、將linux的的ldd移植過去。因為android也是基於linux的,所以將ldd移植過去是完全可能的,google一下吧,這不是本文的重點;
2、現成的。ndk已經提供了工具,在ubuntu下執行locate readelf,你會發現有這些輸出:
/mydroid/external/elfutils/src/readelf.c
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-readelf
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.3.1/bin/arm-eabi-readelf
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.3.1/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-readelf
/mydroid/prebuilt/darwin-x86/toolchain/arm-eabi-4.4.0/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-readelf
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin/arm-eabi-readelf
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-readelf
/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/man/man1/arm-eabi-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/bin/i686-unknown-linux-gnu-readelf
/mydroid/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/man/man1/i686-unknown-linux-gnu-readelf.1
/mydroid/prebuilt/linux-x86/toolchain/sh-4.3.3/bin/sh-linux-gnu-readelf
/usr/android/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-readelf
/usr/android/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-readelf
/usr/bin/readelf
/usr/share/man/man1/readelf.1.gz
加粗的部分就是你可以使用的工具了。
測試一下:
當你完成android的編譯後,測試如下:
root@dylan-ubuntu:/mydroid/out/target/proct/generic/system/bin# /usr/android/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-readelf -d test_pvauthorengine
Dynamic section at offset 0x20b00 contains 26 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libopencore_author.so]
0x00000001 (NEEDED) Shared library: [libopencore_common.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000020 (PREINIT_ARRAY) 0x28000
0x00000021 (PREINIT_ARRAYSZ) 0x8
0x00000019 (INIT_ARRAY) 0x28008
0x0000001b (INIT_ARRAYSZ) 8 (bytes)
0x0000001a (FINI_ARRAY) 0x28010
0x0000001c (FINI_ARRAYSZ) 8 (bytes)
0x00000004 (HASH) 0x8108
0x00000005 (STRTAB) 0x8fb0
0x00000006 (SYMTAB) 0x85a0
0x0000000a (STRSZ) 4570 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x28bf8
0x00000002 (PLTRELSZ) 1144 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0xa19c
0x00000011 (REL) 0xa18c
0x00000012 (RELSZ) 16 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000000 (NULL) 0x0
root@dylan-ubuntu:/mydroid/out/target/proct/generic/obj/lib# /usr/android/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-readelf -d libopencore_common.so
Dynamic section at offset 0xcc448 contains 36 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libutils.so]
0x00000001 (NEEDED) Shared library: [libcutils.so]
0x00000001 (NEEDED) Shared library: [libui.so]
0x00000001 (NEEDED) Shared library: [libhardware.so]
0x00000001 (NEEDED) Shared library: [libandroid_runtime.so]
0x00000001 (NEEDED) Shared library: [libdrm1.so]
0x00000001 (NEEDED) Shared library: [libmedia.so]
0x00000001 (NEEDED) Shared library: [libskia.so]
0x00000001 (NEEDED) Shared library: [libvorbisidec.so]
0x00000001 (NEEDED) Shared library: [libsonivox.so]
0x00000001 (NEEDED) Shared library: [liblog.so]
0x00000001 (NEEDED) Shared library: [libicuuc.so]
0x00000001 (NEEDED) Shared library: [libcamera_client.so]
0x00000001 (NEEDED) Shared library: [libsurfaceflinger_client.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x0000000e (SONAME) Library soname: [libopencore_common.so]
0x00000010 (SYMBOLIC) 0x0
0x00000019 (INIT_ARRAY) 0xc7000
0x0000001b (INIT_ARRAYSZ) 16 (bytes)
0x00000004 (HASH) 0xb4
0x00000005 (STRTAB) 0xc6fc
0x00000006 (SYMTAB) 0x420c
0x0000000a (STRSZ) 86133 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0xcc588
0x00000002 (PLTRELSZ) 1032 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x22144
0x00000011 (REL) 0x21774
0x00000012 (RELSZ) 2512 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffa (RELCOUNT) 4012
0x00000000 (NULL) 0x0
轉載
② linux源碼包怎麼查看依賴關系
一、可執行文件/二進制文件依賴共享庫
ldd命令用來查看可執行文件依賴的共享庫文件。
$ ldd --help
Usage: ldd [OPTION]... FILE...
--help print this help and exit
--version print version information and exit
-d, --data-relocs process data relocations
-r, --function-relocs process data and function relocations
-u, --unused print unused direct dependencies
-v, --verbose print all information
示例:
$ ldd helloworld
二、共享庫依賴共享庫關系
上面的ldd命令無法查看共享庫的依賴關系,因為共享庫本身並不是可執行文件,我們可以使用
objmp -x libhelloworld.so | grep NEEDED
其中,libhelloworld.so是你的庫名稱。
附:
readelf命令用於讀取ELF Header信息
③ Linux使用ldd命令查看程序調用了哪些動態庫
名稱 ldd - 列印共享庫的依賴關系
大綱 ldd [選項]...文件...
描述 ldd 輸出在命令行上指定的每個程序或共享庫需要的共享庫。
選項
--version
列印ldd的版本號
-v --verbose
列印所有信息,例如包括符號的版本信息
-d --data-relocs
執行符號重部署,並報告缺少的目標對象(只對ELF格式適用)
-r --function-relocs
對目標對象和函數執行重新部署,並報告缺少的目標對象和函數(只對ELF格式適用)
--help 用法信息
或者看看《linux就該這么學》,具體關於這一章地址3w(dot)linuxprobe/chapter-02(dot)html.
④ 查詢linux應用程序運行依賴哪些庫
在x86下,為了查看程序所依賴的庫,可以使用ldd命令
但如果是使用arm-linux-gcc 等交叉編譯環境編譯出來的程序,則要使用readelf命令來查看了
⑤ 查詢Linux應用程序運行依賴哪些庫
在x86下,為了查看程序所依賴的庫,可以使用ldd命令
但如果是使用arm-linux-gcc 等交叉編譯環境編譯出來的程序
⑥ Android下怎麼使用LDD查看依賴庫
Android下沒有ldd可以使用,在進行ndk開發的時候,檢查庫的依賴項特別麻煩。有兩個解決方案:
1、將linux的的ldd移植過去。因為android也是基於linux的,所以將ldd移植過去是完全可能的,google一下;
2、現成的。ndk已經提供了工具,在ubuntu下執行locate readelf,會發現有這些輸出。
⑦ linux c 段錯誤如何定位
1. 段錯誤是什麼
一句話來說,段錯誤是指訪問的內存超出了系統給這個程序所設定的內存空間,例如訪問了不存在的內存地址、訪問了系統保護的內存地址、訪問了只讀的內存地址等等情況。這里貼一個對於「段錯誤」的准確定義(參考Answers.com):
A segmentation fault (often shortened to segfault) is a particular error condition that can occur ring the operation of computer software. In short, a segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (e.g., attempts to write to a read-only location, or to overwrite part of the operating system). Systems based on processors like the Motorola 68000 tend to refer to these events as Address or Bus errors.
Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, "segmentation fault" being an example. Some operating systems still have segmentation at some logical level although paging is used as the main memory management policy.
On Unix-like operating systems, a process that accesses invalid memory receives the SIGSEGV signal. On Microsoft Windows, a process that accesses invalid memory receives the STATUS_ACCESS_VIOLATION exception.
2. 段錯誤產生的原因
2.1 訪問不存在的內存地址
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *ptr = NULL;
*ptr = 0;
}
2.2 訪問系統保護的內存地址
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *ptr = (int *)0;
*ptr = 100;
}
2.3 訪問只讀的內存地址
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
char *ptr = "test";
strcpy(ptr, "TEST");
}
2.4 棧溢出
#include<stdio.h>
#include<stdlib.h>
void main()
{
main();
}
等等其他原因。
3. 段錯誤信息的獲取
程序發生段錯誤時,提示信息很少,下面有幾種查看段錯誤的發生信息的途徑。
3.1 dmesg
dmesg可以在應用程序crash掉時,顯示內核中保存的相關信息。如下所示,通過dmesg命令可以查看發生段錯誤的程序名稱、引起段錯誤發生的內存地址、指令指針地址、堆棧指針地址、錯誤代碼、錯誤原因等。以程序2.3為例:
panfeng@ubuntu:~/segfault$ dmesg
[ 2329.479037] segfault3[2700]: segfault at 80484e0 ip 00d2906a sp bfbbec3c error 7 in libc-2.10.1.so[cb4000+13e000]
3.2 -g
使用gcc編譯程序的源碼時,加上-g參數,這樣可以使得生成的二進制文件中加入可以用於gdb調試的有用信息。以程序2.3為例:
panfeng@ubuntu:~/segfault$ gcc -g -o segfault3 segfault3.c
3.3 nm
使用nm命令列出二進制文件中的符號表,包括符號地址、符號類型、符號名等,這樣可以幫助定位在哪裡發生了段錯誤。以程序2.3為例:
panfeng@ubuntu:~/segfault$ nm segfault3
08049f20 d _DYNAMIC
08049ff4 d _GLOBAL_OFFSET_TABLE_
080484dc R _IO_stdin_used
w _Jv_RegisterClasses
08049f10 d __CTOR_END__
08049f0c d __CTOR_LIST__
08049f18 D __DTOR_END__
08049f14 d __DTOR_LIST__
080484ec r __FRAME_END__
08049f1c d __JCR_END__
08049f1c d __JCR_LIST__
0804a014 A __bss_start
0804a00c D __data_start
08048490 t __do_global_ctors_aux
08048360 t __do_global_dtors_aux
0804a010 D __dso_handle
w __gmon_start__
0804848a T __i686.get_pc_thunk.bx
08049f0c d __init_array_end
08049f0c d __init_array_start
08048420 T __libc_csu_fini
08048430 T __libc_csu_init
U __libc_start_main@@GLIBC_2.0
0804a014 A _edata
0804a01c A _end
080484bc T _fini
080484d8 R _fp_hw
080482bc T _init
08048330 T _start
0804a014 b completed.6990
0804a00c W data_start
0804a018 b dtor_idx.6992
080483c0 t frame_mmy
080483e4 T main
U memcpy@@GLIBC_2.0
3.4 ldd
使用ldd命令查看二進製程序的共享鏈接庫依賴,包括庫的名稱、起始地址,這樣可以確定段錯誤到底是發生在了自己的程序中還是依賴的共享庫中。以程序2.3為例:
panfeng@ubuntu:~/segfault$ ldd ./segfault3
linux-gate.so.1 => (0x00e08000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00675000)
/lib/ld-linux.so.2 (0x00482000)
⑧ linux下的靜態庫創建與查看,及如何查看某個可執行依賴於哪些動態庫
創建靜態庫:
ar -rcs test.a *.o
查看靜態庫:
ar -tv test.a
解壓靜態庫:
ar -x test.a
查看程序依賴的動態庫:
readelf -a xxx|grep library
如:可以看到,下面的交叉程序hello執行依賴於如下兩個動態庫。
rebi@ubuntu:~/test$ arm-none-linux-gnueabi-readelf -a hello|grep "library"
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
rebi@ubuntu:~/test$
或者:readelf -l hello 即可。
nm xxx 查看符號
其中,T表示代碼段,U表示在其它地方定義,所以需要確保必須在某個.o或庫里被定義過。