Linux 查看程序依赖

一般用两个命令 lddobjdump

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[broly@localhost ~]$ 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

For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
[broly@localhost ~]$ ldd /bin/ls
linux-vdso.so.1 => (0x00007ffff9ced000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f60fc8fa000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007f60fc6f5000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007f60fc4eb000)
libc.so.6 => /lib64/libc.so.6 (0x00007f60fc12a000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f60fbec9000)
liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f60fbca3000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f60fba9f000)
/lib64/ld-linux-x86-64.so.2 (0x00007f60fcb28000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f60fb89a000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f60fb67d000)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
[broly@localhost ~]$ objdump --help
Usage: objdump <option(s)> <file(s)>
Display information from object <file(s)>.
At least one of the following switches must be given:
-a, --archive-headers Display archive header information
-f, --file-headers Display the contents of the overall file header
-p, --private-headers Display object format specific file header conten ts
-P, --private=OPT,OPT... Display object format specific contents
-h, --[section-]headers Display the contents of the section headers
-x, --all-headers Display the contents of all headers
-d, --disassemble Display assembler contents of executable sections
-D, --disassemble-all Display assembler contents of all sections
-S, --source Intermix source code with disassembly
-s, --full-contents Display the full contents of all sections request ed
-g, --debugging Display debug information in object file
-e, --debugging-tags Display debug information using ctags style
-G, --stabs Display (in raw form) any STABS info in the file
-W[lLiaprmfFsoRt] or
--dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=fra mes,
=frames-interp,=str,=loc,=Ranges,=pubtypes,
=gdb_index,=trace_info,=trace_abbrev,=trace_aranges,
=addr,=cu_index]
Display DWARF info in the file
-t, --syms Display the contents of the symbol table(s)
-T, --dynamic-syms Display the contents of the dynamic symbol table
-r, --reloc Display the relocation entries in the file
-R, --dynamic-reloc Display the dynamic relocation entries in the fil e
@<file> Read options from <file>
-v, --version Display this program's version number
-i, --info List object formats and architectures supported
-H, --help Display this information

The following switches are optional:
-b, --target=BFDNAME Specify the target object format as BFDNAME
-m, --architecture=MACHINE Specify the target architecture as MACHINE
-j, --section=NAME Only display information for section NAME
-M, --disassembler-options=OPT Pass text OPT on to the disassembler
-EB --endian=big Assume big endian format when disassembling
-EL --endian=little Assume little endian format when disassembl ing
--file-start-context Include context from start of file (with -S )
-I, --include=DIR Add DIR to search list for source files
-l, --line-numbers Include line numbers and filenames in outpu t
-F, --file-offsets Include file offsets when displaying inform ation
-C, --demangle[=STYLE] Decode mangled/processed symbol names
The STYLE, if specified, can be `auto', `g nu',
`lucid', `arm', `hp', `edg', `gnu-v3', `ja va'
or `gnat'
-w, --wide Format output for more than 80 columns
-z, --disassemble-zeroes Do not skip blocks of zeroes when disassemb ling
--start-address=ADDR Only process data whose address is >= ADDR
--stop-address=ADDR Only process data whose address is <= ADDR
--prefix-addresses Print complete address alongside disassembl y
--[no-]show-raw-insn Display hex alongside symbolic disassembly
--insn-width=WIDTH Display WIDTH bytes on a single line for -d
--adjust-vma=OFFSET Add OFFSET to all displayed section address es
--special-syms Include special symbols in symbol dumps
--prefix=PREFIX Add PREFIX to absolute paths for -S
--prefix-strip=LEVEL Strip initial directory names for -S
--dwarf-depth=N Do not display DIEs at depth N or greater
--dwarf-start=N Display DIEs starting with N, at the same depth
or deeper
--dwarf-check Make additional dwarf internal consistency chec ks.

objdump: supported targets: elf64-x86-64 elf32-i386 elf32-x86-64 a.out-i386- linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32 -little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
objdump: supported architectures: i386 i386:x86-64 i386:x64-32 i8086 i386:in tel i386:x86-64:intel i386:x64-32:intel l1om l1om:intel k1om k1om:intel plug in

The following i386/x86-64 specific disassembler options are supported for us e
with the -M switch (multiple options should be separated by commas):
x86-64 Disassemble in 64bit mode
i386 Disassemble in 32bit mode
i8086 Disassemble in 16bit mode
att Display instruction in AT&T syntax
intel Display instruction in Intel syntax
att-mnemonic
Display instruction in AT&T mnemonic
intel-mnemonic
Display instruction in Intel mnemonic
addr64 Assume 64bit address size
addr32 Assume 32bit address size
addr16 Assume 16bit address size
data32 Assume 32bit data size
data16 Assume 16bit data size
suffix Always display instruction suffix in AT&T syntax
Report bugs to <http://bugzilla.redhat.com/bugzilla/>.
[broly@localhost ~]$ objdump -p /bin/ls

/bin/ls: file format elf64-x86-64

Program Header:
PHDR off 0x0000000000000040 vaddr 0x0000000000400040 paddr 0x0000000000400040 align 2**3
filesz 0x00000000000001f8 memsz 0x00000000000001f8 flags r-x
INTERP off 0x0000000000000238 vaddr 0x0000000000400238 paddr 0x0000000000400238 align 2**0
filesz 0x000000000000001c memsz 0x000000000000001c flags r--
LOAD off 0x0000000000000000 vaddr 0x0000000000400000 paddr 0x0000000000400000 align 2**21
filesz 0x00000000000193fc memsz 0x00000000000193fc flags r-x
LOAD off 0x000000000001a310 vaddr 0x000000000061a310 paddr 0x000000000061a310 align 2**21
filesz 0x00000000000012f0 memsz 0x0000000000002010 flags rw-
DYNAMIC off 0x000000000001ada8 vaddr 0x000000000061ada8 paddr 0x000000000061ada8 align 2**3
filesz 0x0000000000000200 memsz 0x0000000000000200 flags rw-
NOTE off 0x0000000000000254 vaddr 0x0000000000400254 paddr 0x0000000000400254 align 2**2
filesz 0x0000000000000044 memsz 0x0000000000000044 flags r--
EH_FRAME off 0x0000000000016650 vaddr 0x0000000000416650 paddr 0x0000000000416650 align 2**2
filesz 0x0000000000000744 memsz 0x0000000000000744 flags r--
STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**4
filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
RELRO off 0x000000000001a310 vaddr 0x000000000061a310 paddr 0x000000000061a310 align 2**0
filesz 0x0000000000000cf0 memsz 0x0000000000000cf0 flags r--

Dynamic Section:
NEEDED libselinux.so.1
NEEDED libcap.so.2
NEEDED libacl.so.1
NEEDED libc.so.6
INIT 0x0000000000402228
FINI 0x000000000041295c
INIT_ARRAY 0x000000000061a310
INIT_ARRAYSZ 0x0000000000000008
FINI_ARRAY 0x000000000061a318
FINI_ARRAYSZ 0x0000000000000008
GNU_HASH 0x0000000000400298
STRTAB 0x0000000000400f30
SYMTAB 0x00000000004002d0
STRSZ 0x00000000000005bc
SYMENT 0x0000000000000018
DEBUG 0x0000000000000000
PLTGOT 0x000000000061b000
PLTRELSZ 0x0000000000000ac8
PLTREL 0x0000000000000007
JMPREL 0x0000000000401760
RELA 0x0000000000401688
RELASZ 0x00000000000000d8
RELAENT 0x0000000000000018
VERNEED 0x00000000004015f8
VERNEEDNUM 0x0000000000000002
VERSYM 0x00000000004014ec

Version References:
required from libacl.so.1:
0x05822450 0x00 07 ACL_1.0
required from libc.so.6:
0x06969194 0x00 08 GLIBC_2.14
0x0d696914 0x00 06 GLIBC_2.4
0x06969197 0x00 05 GLIBC_2.17
0x09691974 0x00 04 GLIBC_2.3.4
0x09691a75 0x00 03 GLIBC_2.2.5
0x0d696913 0x00 02 GLIBC_2.3

信息比较多的时候就用 grep 筛选一下。