您的位置:首页 > 编程语言 > Go语言

ldd(1) is good but objdump(1) is better(转)

2011-07-08 10:20 225 查看
Micro post to know shared libraries needed by a ELF binary. We can know them using the common ldd(1) :

(sbz@atemi:~)[0:0] % ldd /usr/local/bin/irssi
/usr/local/bin/irssi:
libgmodule-2.0.so.0 => /usr/local/lib/libgmodule-2.0.so.0 (0x33d29000)
libglib-2.0.so.0 => /usr/local/lib/libglib-2.0.so.0 (0x33d2d000)
libintl.so.8 => /usr/local/lib/libintl.so.8 (0x33ddf000)
libiconv.so.3 => /usr/local/lib/libiconv.so.3 (0x33de8000)
libpcre.so.0 => /usr/local/lib/libpcre.so.0 (0x33edf000)
libssl.so.5 => /usr/lib/libssl.so.5 (0x33f11000)
libcrypto.so.5 => /lib/libcrypto.so.5 (0x33f5b000)
libncurses.so.5.7 => /usr/local/lib/libncurses.so.5.7 (0x340b5000)
libc.so.7 => /lib/libc.so.7 (0x340d2000)
libtinfo.so.5.7 => /usr/local/lib/libtinfo.so.5.7 (0x341d5000)

But using objdump(1) is more funny:

(sbz@atemi:~)[0:0] % objdump -x /usr/local/bin/irssi |grep NEEDED
NEEDED libgmodule-2.0.so.0
NEEDED libglib-2.0.so.0
NEEDED libintl.so.8
NEEDED libiconv.so.3
NEEDED libpcre.so.0
NEEDED libssl.so.5
NEEDED libcrypto.so.5
NEEDED libncurses.so.5.7
NEEDED libc.so.7
NEEDED libtinfo.so.5.7

But how it works ?? Just because ELF binary contains a section .dynamic with entries NEEDED used by the dynamic linker.
To get alls the sections, we need to use readelf(1) or use info files in gdb(1):

(sbz@atemi:~)[0:0] % readelf -S /usr/local/bin/irssi
There are 26 section headers, starting at offset 0xb3ee0:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 08048114 000114 000015 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 0804812c 00012c 000018 00 A 0 0 4
[ 3] .hash HASH 08048144 000144 002644 04 A 4 0 4
[ 4] .dynsym DYNSYM 0804a788 002788 005880 10 A 5 1 4
[ 5] .dynstr STRTAB 08050008 008008 005945 00 A 0 0 1
[ 6] .gnu.version VERSYM 0805594e 00d94e 000b10 02 A 4 0 2
[ 7] .gnu.version_r VERNEED 08056460 00e460 000020 00 A 5 1 4
[ 8] .rel.dyn REL 08056480 00e480 000048 08 A 4 0 4
[ 9] .rel.plt REL 080564c8 00e4c8 000a88 08 A 4 b 4
[10] .init PROGBITS 08056f50 00ef50 000011 00 AX 0 0 4
[11] .plt PROGBITS 08056f64 00ef64 001520 04 AX 0 0 4
[12] .text PROGBITS 08058490 010490 087ab4 00 AX 0 0 16
[13] .fini PROGBITS 080dff44 097f44 00000c 00 AX 0 0 4
[14] .rodata PROGBITS 080dff60 097f60 0141c6 00 A 0 0 32
[15] .eh_frame_hdr PROGBITS 080f4128 0ac128 000014 00 A 0 0 4
[16] .data PROGBITS 080f5140 0ac140 005d20 00 WA 0 0 32
[17] .eh_frame PROGBITS 080fae60 0b1e60 00003c 00 A 0 0 4
[18] .dynamic DYNAMIC 080fae9c 0b1e9c 000118 08 WA 5 0 4
[19] .ctors PROGBITS 080fafb4 0b1fb4 000008 00 WA 0 0 4
[20] .dtors PROGBITS 080fafbc 0b1fbc 000008 00 WA 0 0 4
[21] .jcr PROGBITS 080fafc4 0b1fc4 000004 00 WA 0 0 4
[22] .got PROGBITS 080fafc8 0b1fc8 000550 04 WA 0 0 4
[23] .bss NOBITS 080fb520 0b2520 00180c 00 WA 0 0 32
[24] .comment PROGBITS 00000000 0b2520 0018f4 00 0 0 1
[25] .shstrtab STRTAB 00000000 0b3e14 0000cc 00 0 0 1

We will dump them with a gdb(1) batch command:
(sbz@atemi:~)[0:0] % cat >/tmp/bla <<EOF
info files
EOF
(sbz@atemi:~)[0:0] % gdb --batch --command=/tmp/bla /usr/local/bin/irssi
(no debugging symbols found)...Symbols from "/usr/local/bin/irssi".
Local exec file:
`/usr/local/bin/irssi', file type elf32-i386-freebsd.
Entry point: 0x8058490
0x08048114 - 0x08048129 is .interp
0x0804812c - 0x08048144 is .note.ABI-tag
0x08048144 - 0x0804a788 is .hash
0x0804a788 - 0x08050008 is .dynsym
0x08050008 - 0x0805594d is .dynstr
0x0805594e - 0x0805645e is .gnu.version
0x08056460 - 0x08056480 is .gnu.version_r
0x08056480 - 0x080564c8 is .rel.dyn
0x080564c8 - 0x08056f50 is .rel.plt
0x08056f50 - 0x08056f61 is .init
0x08056f64 - 0x08058484 is .plt
0x08058490 - 0x080dff44 is .text
0x080dff44 - 0x080dff50 is .fini
0x080dff60 - 0x080f4126 is .rodata
0x080f4128 - 0x080f413c is .eh_frame_hdr
0x080f5140 - 0x080fae60 is .data
0x080fae60 - 0x080fae9c is .eh_frame
0x080fae9c - 0x080fafb4 is .dynamic
0x080fafb4 - 0x080fafbc is .ctors
0x080fafbc - 0x080fafc4 is .dtors
0x080fafc4 - 0x080fafc8 is .jcr
0x080fafc8 - 0x080fb518 is .got
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: