| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright © 2007-2010 Raphaël Hertzog |
|
2
|
|
|
|
|
|
|
# Copyright © 2007-2009,2012-2015,2017-2018 Guillem Jover |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
|
5
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
|
6
|
|
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
|
7
|
|
|
|
|
|
|
# (at your option) any later version. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
10
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
|
|
|
|
# GNU General Public License for more details. |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
15
|
|
|
|
|
|
|
# along with this program. If not, see . |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Dpkg::Shlibs::Objdump; |
|
18
|
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
|
14
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
58
|
|
|
20
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
54
|
|
|
21
|
2
|
|
|
2
|
|
8
|
use feature qw(state); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
168
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
34
|
use Dpkg::Gettext; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
110
|
|
|
26
|
2
|
|
|
2
|
|
10
|
use Dpkg::ErrorHandling; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1132
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
|
29
|
0
|
|
|
0
|
0
|
0
|
my $this = shift; |
|
30
|
0
|
|
0
|
|
|
0
|
my $class = ref($this) || $this; |
|
31
|
0
|
|
|
|
|
0
|
my $self = { objects => {} }; |
|
32
|
0
|
|
|
|
|
0
|
bless $self, $class; |
|
33
|
0
|
|
|
|
|
0
|
return $self; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add_object { |
|
37
|
0
|
|
|
0
|
0
|
0
|
my ($self, $obj) = @_; |
|
38
|
0
|
|
|
|
|
0
|
my $id = $obj->get_id; |
|
39
|
0
|
0
|
|
|
|
0
|
if ($id) { |
|
40
|
0
|
|
|
|
|
0
|
$self->{objects}{$id} = $obj; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
0
|
|
|
|
|
0
|
return $id; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub analyze { |
|
46
|
0
|
|
|
0
|
0
|
0
|
my ($self, $file) = @_; |
|
47
|
0
|
|
|
|
|
0
|
my $obj = Dpkg::Shlibs::Objdump::Object->new($file); |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
return $self->add_object($obj); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub locate_symbol { |
|
53
|
0
|
|
|
0
|
0
|
0
|
my ($self, $name) = @_; |
|
54
|
0
|
|
|
|
|
0
|
foreach my $obj (values %{$self->{objects}}) { |
|
|
0
|
|
|
|
|
0
|
|
|
55
|
0
|
|
|
|
|
0
|
my $sym = $obj->get_symbol($name); |
|
56
|
0
|
0
|
0
|
|
|
0
|
if (defined($sym) && $sym->{defined}) { |
|
57
|
0
|
|
|
|
|
0
|
return $sym; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
0
|
|
|
|
|
0
|
return; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get_object { |
|
64
|
0
|
|
|
0
|
0
|
0
|
my ($self, $objid) = @_; |
|
65
|
0
|
0
|
|
|
|
0
|
if ($self->has_object($objid)) { |
|
66
|
0
|
|
|
|
|
0
|
return $self->{objects}{$objid}; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
0
|
|
|
|
|
0
|
return; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub has_object { |
|
72
|
0
|
|
|
0
|
0
|
0
|
my ($self, $objid) = @_; |
|
73
|
0
|
|
|
|
|
0
|
return exists $self->{objects}{$objid}; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
use constant { |
|
77
|
2
|
|
|
|
|
2088
|
ELF_BITS_NONE => 0, |
|
78
|
|
|
|
|
|
|
ELF_BITS_32 => 1, |
|
79
|
|
|
|
|
|
|
ELF_BITS_64 => 2, |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
ELF_ORDER_NONE => 0, |
|
82
|
|
|
|
|
|
|
ELF_ORDER_2LSB => 1, |
|
83
|
|
|
|
|
|
|
ELF_ORDER_2MSB => 2, |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
ELF_MACH_SPARC => 2, |
|
86
|
|
|
|
|
|
|
ELF_MACH_MIPS => 8, |
|
87
|
|
|
|
|
|
|
ELF_MACH_SPARC64_OLD => 11, |
|
88
|
|
|
|
|
|
|
ELF_MACH_SPARC32PLUS => 18, |
|
89
|
|
|
|
|
|
|
ELF_MACH_PPC64 => 21, |
|
90
|
|
|
|
|
|
|
ELF_MACH_S390 => 22, |
|
91
|
|
|
|
|
|
|
ELF_MACH_ARM => 40, |
|
92
|
|
|
|
|
|
|
ELF_MACH_ALPHA_OLD => 41, |
|
93
|
|
|
|
|
|
|
ELF_MACH_SH => 42, |
|
94
|
|
|
|
|
|
|
ELF_MACH_SPARC64 => 43, |
|
95
|
|
|
|
|
|
|
ELF_MACH_IA64 => 50, |
|
96
|
|
|
|
|
|
|
ELF_MACH_AVR => 83, |
|
97
|
|
|
|
|
|
|
ELF_MACH_M32R => 88, |
|
98
|
|
|
|
|
|
|
ELF_MACH_MN10300 => 89, |
|
99
|
|
|
|
|
|
|
ELF_MACH_MN10200 => 90, |
|
100
|
|
|
|
|
|
|
ELF_MACH_OR1K => 92, |
|
101
|
|
|
|
|
|
|
ELF_MACH_XTENSA => 94, |
|
102
|
|
|
|
|
|
|
ELF_MACH_MICROBLAZE => 189, |
|
103
|
|
|
|
|
|
|
ELF_MACH_AVR_OLD => 0x1057, |
|
104
|
|
|
|
|
|
|
ELF_MACH_OR1K_OLD => 0x8472, |
|
105
|
|
|
|
|
|
|
ELF_MACH_ALPHA => 0x9026, |
|
106
|
|
|
|
|
|
|
ELF_MACH_M32R_CYGNUS => 0x9041, |
|
107
|
|
|
|
|
|
|
ELF_MACH_S390_OLD => 0xa390, |
|
108
|
|
|
|
|
|
|
ELF_MACH_XTENSA_OLD => 0xabc7, |
|
109
|
|
|
|
|
|
|
ELF_MACH_MICROBLAZE_OLD => 0xbaab, |
|
110
|
|
|
|
|
|
|
ELF_MACH_MN10300_CYGNUS => 0xbeef, |
|
111
|
|
|
|
|
|
|
ELF_MACH_MN10200_CYGNUS => 0xdead, |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
ELF_VERSION_NONE => 0, |
|
114
|
|
|
|
|
|
|
ELF_VERSION_CURRENT => 1, |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# List of processor flags that might influence the ABI. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
ELF_FLAG_ARM_ALIGN8 => 0x00000040, |
|
119
|
|
|
|
|
|
|
ELF_FLAG_ARM_NEW_ABI => 0x00000080, |
|
120
|
|
|
|
|
|
|
ELF_FLAG_ARM_OLD_ABI => 0x00000100, |
|
121
|
|
|
|
|
|
|
ELF_FLAG_ARM_SOFT_FLOAT => 0x00000200, |
|
122
|
|
|
|
|
|
|
ELF_FLAG_ARM_HARD_FLOAT => 0x00000400, |
|
123
|
|
|
|
|
|
|
ELF_FLAG_ARM_EABI_MASK => 0xff000000, |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
ELF_FLAG_IA64_ABI64 => 0x00000010, |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
ELF_FLAG_MIPS_ABI2 => 0x00000020, |
|
128
|
|
|
|
|
|
|
ELF_FLAG_MIPS_32BIT => 0x00000100, |
|
129
|
|
|
|
|
|
|
ELF_FLAG_MIPS_FP64 => 0x00000200, |
|
130
|
|
|
|
|
|
|
ELF_FLAG_MIPS_NAN2008 => 0x00000400, |
|
131
|
|
|
|
|
|
|
ELF_FLAG_MIPS_ABI_MASK => 0x0000f000, |
|
132
|
|
|
|
|
|
|
ELF_FLAG_MIPS_ARCH_MASK => 0xf0000000, |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
ELF_FLAG_PPC64_ABI64 => 0x00000003, |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
ELF_FLAG_SH_MACH_MASK => 0x0000001f, |
|
137
|
2
|
|
|
2
|
|
18
|
}; |
|
|
2
|
|
|
|
|
4
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# These map alternative or old machine IDs to their canonical form. |
|
140
|
|
|
|
|
|
|
my %elf_mach_map = ( |
|
141
|
|
|
|
|
|
|
ELF_MACH_ALPHA_OLD() => ELF_MACH_ALPHA, |
|
142
|
|
|
|
|
|
|
ELF_MACH_AVR_OLD() => ELF_MACH_AVR, |
|
143
|
|
|
|
|
|
|
ELF_MACH_M32R_CYGNUS() => ELF_MACH_M32R, |
|
144
|
|
|
|
|
|
|
ELF_MACH_MICROBLAZE_OLD() => ELF_MACH_MICROBLAZE, |
|
145
|
|
|
|
|
|
|
ELF_MACH_MN10200_CYGNUS() => ELF_MACH_MN10200, |
|
146
|
|
|
|
|
|
|
ELF_MACH_MN10300_CYGNUS() => ELF_MACH_MN10300, |
|
147
|
|
|
|
|
|
|
ELF_MACH_OR1K_OLD() => ELF_MACH_OR1K, |
|
148
|
|
|
|
|
|
|
ELF_MACH_S390_OLD() => ELF_MACH_S390, |
|
149
|
|
|
|
|
|
|
ELF_MACH_SPARC32PLUS() => ELF_MACH_SPARC, |
|
150
|
|
|
|
|
|
|
ELF_MACH_SPARC64_OLD() => ELF_MACH_SPARC64, |
|
151
|
|
|
|
|
|
|
ELF_MACH_XTENSA_OLD() => ELF_MACH_XTENSA, |
|
152
|
|
|
|
|
|
|
); |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# These masks will try to expose processor flags that are ABI incompatible, |
|
155
|
|
|
|
|
|
|
# and as such are part of defining the architecture ABI. If uncertain it is |
|
156
|
|
|
|
|
|
|
# always better to not mask a flag, because that preserves the historical |
|
157
|
|
|
|
|
|
|
# behavior, and we do not drop dependencies. |
|
158
|
|
|
|
|
|
|
my %elf_flags_mask = ( |
|
159
|
|
|
|
|
|
|
ELF_MACH_IA64() => ELF_FLAG_IA64_ABI64, |
|
160
|
|
|
|
|
|
|
ELF_MACH_MIPS() => ELF_FLAG_MIPS_ABI_MASK | ELF_FLAG_MIPS_ABI2, |
|
161
|
|
|
|
|
|
|
ELF_MACH_PPC64() => ELF_FLAG_PPC64_ABI64, |
|
162
|
|
|
|
|
|
|
); |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub get_format { |
|
165
|
0
|
|
|
0
|
0
|
0
|
my ($file) = @_; |
|
166
|
0
|
|
|
|
|
0
|
state %format; |
|
167
|
|
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
0
|
return $format{$file} if exists $format{$file}; |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
0
|
my $header; |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
0
|
open my $fh, '<', $file or syserr(g_('cannot read %s'), $file); |
|
173
|
0
|
|
|
|
|
0
|
my $rc = read $fh, $header, 64; |
|
174
|
0
|
0
|
|
|
|
0
|
if (not defined $rc) { |
|
|
|
0
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
0
|
syserr(g_('cannot read %s'), $file); |
|
176
|
|
|
|
|
|
|
} elsif ($rc != 64) { |
|
177
|
0
|
|
|
|
|
0
|
return; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
0
|
|
|
|
|
0
|
close $fh; |
|
180
|
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
0
|
my %elf; |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# Unpack the identifier field. |
|
184
|
0
|
|
|
|
|
0
|
@elf{qw(magic bits endian vertype osabi verabi)} = unpack 'a4C5', $header; |
|
185
|
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
0
|
return unless $elf{magic} eq "\x7fELF"; |
|
187
|
0
|
0
|
|
|
|
0
|
return unless $elf{vertype} == ELF_VERSION_CURRENT; |
|
188
|
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
0
|
my ($elf_word, $elf_endian); |
|
190
|
0
|
0
|
|
|
|
0
|
if ($elf{bits} == ELF_BITS_32) { |
|
|
|
0
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
0
|
$elf_word = 'L'; |
|
192
|
|
|
|
|
|
|
} elsif ($elf{bits} == ELF_BITS_64) { |
|
193
|
0
|
|
|
|
|
0
|
$elf_word = 'Q'; |
|
194
|
|
|
|
|
|
|
} else { |
|
195
|
0
|
|
|
|
|
0
|
return; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
0
|
0
|
|
|
|
0
|
if ($elf{endian} == ELF_ORDER_2LSB) { |
|
|
|
0
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
0
|
$elf_endian = '<'; |
|
199
|
|
|
|
|
|
|
} elsif ($elf{endian} == ELF_ORDER_2MSB) { |
|
200
|
0
|
|
|
|
|
0
|
$elf_endian = '>'; |
|
201
|
|
|
|
|
|
|
} else { |
|
202
|
0
|
|
|
|
|
0
|
return; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# Unpack the endianness and size dependent fields. |
|
206
|
0
|
|
|
|
|
0
|
my $tmpl = "x16(S2Lx[${elf_word}3]L)${elf_endian}"; |
|
207
|
0
|
|
|
|
|
0
|
@elf{qw(type mach version flags)} = unpack $tmpl, $header; |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# Canonicalize the machine ID. |
|
210
|
0
|
|
0
|
|
|
0
|
$elf{mach} = $elf_mach_map{$elf{mach}} // $elf{mach}; |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# Mask any processor flags that might not change the architecture ABI. |
|
213
|
0
|
|
0
|
|
|
0
|
$elf{flags} &= $elf_flags_mask{$elf{mach}} // 0; |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
# Repack for easy comparison, as a big-endian byte stream, so that |
|
216
|
|
|
|
|
|
|
# unpacking for output gives meaningful results. |
|
217
|
0
|
|
|
|
|
0
|
$format{$file} = pack 'C2(SL)>', @elf{qw(bits endian mach flags)}; |
|
218
|
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
0
|
return $format{$file}; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub is_elf { |
|
223
|
0
|
|
|
0
|
0
|
0
|
my $file = shift; |
|
224
|
0
|
0
|
|
|
|
0
|
open(my $file_fh, '<', $file) or syserr(g_('cannot read %s'), $file); |
|
225
|
0
|
|
|
|
|
0
|
my ($header, $result) = ('', 0); |
|
226
|
0
|
0
|
|
|
|
0
|
if (read($file_fh, $header, 4) == 4) { |
|
227
|
0
|
0
|
|
|
|
0
|
$result = 1 if ($header =~ /^\177ELF$/); |
|
228
|
|
|
|
|
|
|
} |
|
229
|
0
|
|
|
|
|
0
|
close($file_fh); |
|
230
|
0
|
|
|
|
|
0
|
return $result; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
package Dpkg::Shlibs::Objdump::Object; |
|
234
|
|
|
|
|
|
|
|
|
235
|
2
|
|
|
2
|
|
16
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
60
|
|
|
236
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
64
|
|
|
237
|
2
|
|
|
2
|
|
10
|
use feature qw(state); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
78
|
|
|
238
|
|
|
|
|
|
|
|
|
239
|
2
|
|
|
2
|
|
14
|
use Dpkg::Gettext; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
128
|
|
|
240
|
2
|
|
|
2
|
|
14
|
use Dpkg::ErrorHandling; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
182
|
|
|
241
|
2
|
|
|
2
|
|
16
|
use Dpkg::Path qw(find_command); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
96
|
|
|
242
|
2
|
|
|
2
|
|
12
|
use Dpkg::Arch qw(debarch_to_gnutriplet get_build_arch get_host_arch); |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
5422
|
|
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub new { |
|
245
|
16
|
|
|
16
|
|
12161
|
my $this = shift; |
|
246
|
16
|
|
50
|
|
|
167
|
my $file = shift // ''; |
|
247
|
16
|
|
33
|
|
|
97
|
my $class = ref($this) || $this; |
|
248
|
16
|
|
|
|
|
43
|
my $self = {}; |
|
249
|
16
|
|
|
|
|
61
|
bless $self, $class; |
|
250
|
|
|
|
|
|
|
|
|
251
|
16
|
|
|
|
|
62
|
$self->reset; |
|
252
|
16
|
50
|
|
|
|
55
|
if ($file) { |
|
253
|
0
|
|
|
|
|
0
|
$self->analyze($file); |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
|
|
256
|
16
|
|
|
|
|
4385
|
return $self; |
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub reset { |
|
260
|
24
|
|
|
24
|
|
1992
|
my $self = shift; |
|
261
|
|
|
|
|
|
|
|
|
262
|
24
|
|
|
|
|
105
|
$self->{file} = ''; |
|
263
|
24
|
|
|
|
|
88
|
$self->{id} = ''; |
|
264
|
24
|
|
|
|
|
111
|
$self->{HASH} = ''; |
|
265
|
24
|
|
|
|
|
59
|
$self->{GNU_HASH} = ''; |
|
266
|
24
|
|
|
|
|
69
|
$self->{INTERP} = 0; |
|
267
|
24
|
|
|
|
|
83
|
$self->{SONAME} = ''; |
|
268
|
24
|
|
|
|
|
65
|
$self->{NEEDED} = []; |
|
269
|
24
|
|
|
|
|
79
|
$self->{RPATH} = []; |
|
270
|
24
|
|
|
|
|
15855
|
$self->{dynsyms} = {}; |
|
271
|
24
|
|
|
|
|
102
|
$self->{flags} = {}; |
|
272
|
24
|
|
|
|
|
102
|
$self->{dynrelocs} = {}; |
|
273
|
|
|
|
|
|
|
|
|
274
|
24
|
|
|
|
|
55
|
return $self; |
|
275
|
|
|
|
|
|
|
} |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
sub _select_objdump { |
|
278
|
|
|
|
|
|
|
# Decide which objdump to call |
|
279
|
0
|
0
|
|
0
|
|
0
|
if (get_build_arch() ne get_host_arch()) { |
|
280
|
0
|
|
|
|
|
0
|
my $od = debarch_to_gnutriplet(get_host_arch()) . '-objdump'; |
|
281
|
0
|
0
|
|
|
|
0
|
return $od if find_command($od); |
|
282
|
|
|
|
|
|
|
} |
|
283
|
0
|
|
|
|
|
0
|
return 'objdump'; |
|
284
|
|
|
|
|
|
|
} |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
sub analyze { |
|
287
|
0
|
|
|
0
|
|
0
|
my ($self, $file) = @_; |
|
288
|
|
|
|
|
|
|
|
|
289
|
0
|
|
0
|
|
|
0
|
$file ||= $self->{file}; |
|
290
|
0
|
0
|
|
|
|
0
|
return unless $file; |
|
291
|
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
0
|
$self->reset; |
|
293
|
0
|
|
|
|
|
0
|
$self->{file} = $file; |
|
294
|
|
|
|
|
|
|
|
|
295
|
0
|
|
|
|
|
0
|
$self->{exec_abi} = Dpkg::Shlibs::Objdump::get_format($file); |
|
296
|
|
|
|
|
|
|
|
|
297
|
0
|
0
|
|
|
|
0
|
if (not defined $self->{exec_abi}) { |
|
298
|
0
|
|
|
|
|
0
|
warning(g_("unknown executable format in file '%s'"), $file); |
|
299
|
0
|
|
|
|
|
0
|
return; |
|
300
|
|
|
|
|
|
|
} |
|
301
|
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
0
|
state $OBJDUMP = _select_objdump(); |
|
303
|
0
|
|
|
|
|
0
|
local $ENV{LC_ALL} = 'C'; |
|
304
|
0
|
0
|
|
|
|
0
|
open(my $objdump, '-|', $OBJDUMP, '-w', '-f', '-p', '-T', '-R', $file) |
|
305
|
|
|
|
|
|
|
or syserr(g_('cannot fork for %s'), $OBJDUMP); |
|
306
|
0
|
|
|
|
|
0
|
my $ret = $self->parse_objdump_output($objdump); |
|
307
|
0
|
|
|
|
|
0
|
close($objdump); |
|
308
|
0
|
|
|
|
|
0
|
return $ret; |
|
309
|
|
|
|
|
|
|
} |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
sub parse_objdump_output { |
|
312
|
24
|
|
|
24
|
|
1030
|
my ($self, $fh) = @_; |
|
313
|
|
|
|
|
|
|
|
|
314
|
24
|
|
|
|
|
75
|
my $section = 'none'; |
|
315
|
24
|
|
|
|
|
4866
|
while (<$fh>) { |
|
316
|
13136
|
|
|
|
|
124833
|
s/\s*$//; |
|
317
|
13136
|
100
|
|
|
|
30222
|
next if length == 0; |
|
318
|
|
|
|
|
|
|
|
|
319
|
12952
|
100
|
|
|
|
44867
|
if (/^DYNAMIC SYMBOL TABLE:/) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
320
|
24
|
|
|
|
|
83
|
$section = 'dynsym'; |
|
321
|
24
|
|
|
|
|
108
|
next; |
|
322
|
|
|
|
|
|
|
} elsif (/^DYNAMIC RELOCATION RECORDS/) { |
|
323
|
12
|
|
|
|
|
31
|
$section = 'dynreloc'; |
|
324
|
12
|
|
|
|
|
39
|
$_ = <$fh>; # Skip header |
|
325
|
12
|
|
|
|
|
34
|
next; |
|
326
|
|
|
|
|
|
|
} elsif (/^Dynamic Section:/) { |
|
327
|
22
|
|
|
|
|
135
|
$section = 'dyninfo'; |
|
328
|
22
|
|
|
|
|
126
|
next; |
|
329
|
|
|
|
|
|
|
} elsif (/^Program Header:/) { |
|
330
|
20
|
|
|
|
|
48
|
$section = 'program'; |
|
331
|
20
|
|
|
|
|
70
|
next; |
|
332
|
|
|
|
|
|
|
} elsif (/^Version definitions:/) { |
|
333
|
10
|
|
|
|
|
37
|
$section = 'verdef'; |
|
334
|
10
|
|
|
|
|
37
|
next; |
|
335
|
|
|
|
|
|
|
} elsif (/^Version References:/) { |
|
336
|
20
|
|
|
|
|
54
|
$section = 'verref'; |
|
337
|
20
|
|
|
|
|
130
|
next; |
|
338
|
|
|
|
|
|
|
} |
|
339
|
|
|
|
|
|
|
|
|
340
|
12844
|
100
|
|
|
|
24153
|
if ($section eq 'dynsym') { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
341
|
10710
|
|
|
|
|
20998
|
$self->parse_dynamic_symbol($_); |
|
342
|
|
|
|
|
|
|
} elsif ($section eq 'dynreloc') { |
|
343
|
1028
|
50
|
|
|
|
2924
|
if (/^\S+\s+(\S+)\s+(.+)$/) { |
|
344
|
1028
|
|
|
|
|
4842
|
$self->{dynrelocs}{$2} = $1; |
|
345
|
|
|
|
|
|
|
} else { |
|
346
|
0
|
|
|
|
|
0
|
warning(g_("couldn't parse dynamic relocation record: %s"), $_); |
|
347
|
|
|
|
|
|
|
} |
|
348
|
|
|
|
|
|
|
} elsif ($section eq 'dyninfo') { |
|
349
|
490
|
100
|
|
|
|
2378
|
if (/^\s*NEEDED\s+(\S+)/) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
350
|
36
|
|
|
|
|
53
|
push @{$self->{NEEDED}}, $1; |
|
|
36
|
|
|
|
|
251
|
|
|
351
|
|
|
|
|
|
|
} elsif (/^\s*SONAME\s+(\S+)/) { |
|
352
|
18
|
|
|
|
|
145
|
$self->{SONAME} = $1; |
|
353
|
|
|
|
|
|
|
} elsif (/^\s*HASH\s+(\S+)/) { |
|
354
|
8
|
|
|
|
|
48
|
$self->{HASH} = $1; |
|
355
|
|
|
|
|
|
|
} elsif (/^\s*GNU_HASH\s+(\S+)/) { |
|
356
|
18
|
|
|
|
|
151
|
$self->{GNU_HASH} = $1; |
|
357
|
|
|
|
|
|
|
} elsif (/^\s*RUNPATH\s+(\S+)/) { |
|
358
|
|
|
|
|
|
|
# RUNPATH takes precedence over RPATH but is |
|
359
|
|
|
|
|
|
|
# considered after LD_LIBRARY_PATH while RPATH |
|
360
|
|
|
|
|
|
|
# is considered before (if RUNPATH is not set). |
|
361
|
0
|
|
|
|
|
0
|
my $runpath = $1; |
|
362
|
0
|
|
|
|
|
0
|
$self->{RPATH} = [ split /:/, $runpath ]; |
|
363
|
|
|
|
|
|
|
} elsif (/^\s*RPATH\s+(\S+)/) { |
|
364
|
0
|
|
|
|
|
0
|
my $rpath = $1; |
|
365
|
0
|
0
|
|
|
|
0
|
unless (scalar(@{$self->{RPATH}})) { |
|
|
0
|
|
|
|
|
0
|
|
|
366
|
0
|
|
|
|
|
0
|
$self->{RPATH} = [ split /:/, $rpath ]; |
|
367
|
|
|
|
|
|
|
} |
|
368
|
|
|
|
|
|
|
} |
|
369
|
|
|
|
|
|
|
} elsif ($section eq 'program') { |
|
370
|
288
|
100
|
|
|
|
809
|
if (/^\s*INTERP\s+/) { |
|
371
|
6
|
|
|
|
|
24
|
$self->{INTERP} = 1; |
|
372
|
|
|
|
|
|
|
} |
|
373
|
|
|
|
|
|
|
} elsif ($section eq 'none') { |
|
374
|
72
|
100
|
|
|
|
537
|
if (/^\s*.+:\s*file\s+format\s+(\S+)$/) { |
|
|
|
100
|
|
|
|
|
|
|
375
|
24
|
|
|
|
|
225
|
$self->{format} = $1; |
|
376
|
|
|
|
|
|
|
} elsif (/^architecture:\s*\S+,\s*flags\s*\S+:$/) { |
|
377
|
|
|
|
|
|
|
# Parse 2 lines of "-f" |
|
378
|
|
|
|
|
|
|
# architecture: i386, flags 0x00000112: |
|
379
|
|
|
|
|
|
|
# EXEC_P, HAS_SYMS, D_PAGED |
|
380
|
|
|
|
|
|
|
# start address 0x08049b50 |
|
381
|
24
|
|
|
|
|
125
|
$_ = <$fh>; |
|
382
|
24
|
|
|
|
|
60
|
chomp; |
|
383
|
24
|
|
|
|
|
412
|
$self->{flags}{$_} = 1 foreach (split(/,\s*/)); |
|
384
|
|
|
|
|
|
|
} |
|
385
|
|
|
|
|
|
|
} |
|
386
|
|
|
|
|
|
|
} |
|
387
|
|
|
|
|
|
|
# Update status of dynamic symbols given the relocations that have |
|
388
|
|
|
|
|
|
|
# been parsed after the symbols... |
|
389
|
24
|
|
|
|
|
160
|
$self->apply_relocations(); |
|
390
|
|
|
|
|
|
|
|
|
391
|
24
|
|
|
|
|
173
|
return $section ne 'none'; |
|
392
|
|
|
|
|
|
|
} |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
# Output format of objdump -w -T |
|
395
|
|
|
|
|
|
|
# |
|
396
|
|
|
|
|
|
|
# /lib/libc.so.6: file format elf32-i386 |
|
397
|
|
|
|
|
|
|
# |
|
398
|
|
|
|
|
|
|
# DYNAMIC SYMBOL TABLE: |
|
399
|
|
|
|
|
|
|
# 00056ef0 g DF .text 000000db GLIBC_2.2 getwchar |
|
400
|
|
|
|
|
|
|
# 00000000 g DO *ABS* 00000000 GCC_3.0 GCC_3.0 |
|
401
|
|
|
|
|
|
|
# 00069960 w DF .text 0000001e GLIBC_2.0 bcmp |
|
402
|
|
|
|
|
|
|
# 00000000 w D *UND* 00000000 _pthread_cleanup_pop_restore |
|
403
|
|
|
|
|
|
|
# 0000b788 g DF .text 0000008e Base .protected xine_close |
|
404
|
|
|
|
|
|
|
# 0000b788 g DF .text 0000008e .hidden IA__g_free |
|
405
|
|
|
|
|
|
|
# | ||||||| | | | | |
|
406
|
|
|
|
|
|
|
# | ||||||| | | Version str (.visibility) + Symbol name |
|
407
|
|
|
|
|
|
|
# | ||||||| | Alignment |
|
408
|
|
|
|
|
|
|
# | ||||||| Section name (or *UND* for an undefined symbol) |
|
409
|
|
|
|
|
|
|
# | ||||||F=Function,f=file,O=object |
|
410
|
|
|
|
|
|
|
# | |||||d=debugging,D=dynamic |
|
411
|
|
|
|
|
|
|
# | ||||I=Indirect |
|
412
|
|
|
|
|
|
|
# | |||W=warning |
|
413
|
|
|
|
|
|
|
# | ||C=constructor |
|
414
|
|
|
|
|
|
|
# | |w=weak |
|
415
|
|
|
|
|
|
|
# | g=global,l=local,!=both global/local |
|
416
|
|
|
|
|
|
|
# Size of the symbol |
|
417
|
|
|
|
|
|
|
# |
|
418
|
|
|
|
|
|
|
# GLIBC_2.2 is the version string associated to the symbol |
|
419
|
|
|
|
|
|
|
# (GLIBC_2.2) is the same but the symbol is hidden, a newer version of the |
|
420
|
|
|
|
|
|
|
# symbol exist |
|
421
|
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
my $vis_re = qr/(\.protected|\.hidden|\.internal|0x\S+)/; |
|
423
|
|
|
|
|
|
|
my $dynsym_re = qr< |
|
424
|
|
|
|
|
|
|
^ |
|
425
|
|
|
|
|
|
|
[0-9a-f]+ # Symbol size |
|
426
|
|
|
|
|
|
|
\ (.{7}) # Flags |
|
427
|
|
|
|
|
|
|
\s+(\S+) # Section name |
|
428
|
|
|
|
|
|
|
\s+[0-9a-f]+ # Alignment |
|
429
|
|
|
|
|
|
|
(?:\s+(\S+))? # Version string |
|
430
|
|
|
|
|
|
|
(?:\s+$vis_re)? # Visibility |
|
431
|
|
|
|
|
|
|
\s+(.+) # Symbol name |
|
432
|
|
|
|
|
|
|
>x; |
|
433
|
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
sub parse_dynamic_symbol { |
|
435
|
10710
|
|
|
10710
|
|
17720
|
my ($self, $line) = @_; |
|
436
|
10710
|
50
|
|
|
|
73054
|
if ($line =~ $dynsym_re) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
|
|
438
|
10710
|
|
|
|
|
41005
|
my ($flags, $sect, $ver, $vis, $name) = ($1, $2, $3, $4, $5); |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
# Special case if version is missing but extra visibility |
|
441
|
|
|
|
|
|
|
# attribute replaces it in the match |
|
442
|
10710
|
100
|
100
|
|
|
55086
|
if (defined($ver) and $ver =~ /^$vis_re$/) { |
|
443
|
22
|
|
|
|
|
34
|
$vis = $ver; |
|
444
|
22
|
|
|
|
|
36
|
$ver = ''; |
|
445
|
|
|
|
|
|
|
} |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
# Cleanup visibility field |
|
448
|
10710
|
100
|
|
|
|
19185
|
$vis =~ s/^\.// if defined($vis); |
|
449
|
|
|
|
|
|
|
|
|
450
|
10710
|
|
100
|
|
|
110914
|
my $symbol = { |
|
|
|
|
100
|
|
|
|
|
|
451
|
|
|
|
|
|
|
name => $name, |
|
452
|
|
|
|
|
|
|
version => $ver // '', |
|
453
|
|
|
|
|
|
|
section => $sect, |
|
454
|
|
|
|
|
|
|
dynamic => substr($flags, 5, 1) eq 'D', |
|
455
|
|
|
|
|
|
|
debug => substr($flags, 5, 1) eq 'd', |
|
456
|
|
|
|
|
|
|
type => substr($flags, 6, 1), |
|
457
|
|
|
|
|
|
|
weak => substr($flags, 1, 1) eq 'w', |
|
458
|
|
|
|
|
|
|
local => substr($flags, 0, 1) eq 'l', |
|
459
|
|
|
|
|
|
|
global => substr($flags, 0, 1) eq 'g', |
|
460
|
|
|
|
|
|
|
visibility => $vis // '', |
|
461
|
|
|
|
|
|
|
hidden => '', |
|
462
|
|
|
|
|
|
|
defined => $sect ne '*UND*' |
|
463
|
|
|
|
|
|
|
}; |
|
464
|
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
# Handle hidden symbols |
|
466
|
10710
|
100
|
100
|
|
|
37759
|
if (defined($ver) and $ver =~ /^\((.*)\)$/) { |
|
467
|
528
|
|
|
|
|
1156
|
$ver = $1; |
|
468
|
528
|
|
|
|
|
1096
|
$symbol->{version} = $1; |
|
469
|
528
|
|
|
|
|
1022
|
$symbol->{hidden} = 1; |
|
470
|
|
|
|
|
|
|
} |
|
471
|
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
# Register symbol |
|
473
|
10710
|
|
|
|
|
21403
|
$self->add_dynamic_symbol($symbol); |
|
474
|
|
|
|
|
|
|
} elsif ($line =~ /^[0-9a-f]+ (.{7})\s+(\S+)\s+[0-9a-f]+/) { |
|
475
|
|
|
|
|
|
|
# Same start but no version and no symbol ... just ignore |
|
476
|
|
|
|
|
|
|
} elsif ($line =~ /^REG_G\d+\s+/) { |
|
477
|
|
|
|
|
|
|
# Ignore some s390-specific output like |
|
478
|
|
|
|
|
|
|
# REG_G6 g R *UND* 0000000000000000 #scratch |
|
479
|
|
|
|
|
|
|
} else { |
|
480
|
0
|
|
|
|
|
0
|
warning(g_("couldn't parse dynamic symbol definition: %s"), $line); |
|
481
|
|
|
|
|
|
|
} |
|
482
|
|
|
|
|
|
|
} |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
sub apply_relocations { |
|
485
|
24
|
|
|
24
|
|
68
|
my $self = shift; |
|
486
|
24
|
|
|
|
|
58
|
foreach my $sym (values %{$self->{dynsyms}}) { |
|
|
24
|
|
|
|
|
981
|
|
|
487
|
|
|
|
|
|
|
# We want to mark as undefined symbols those which are currently |
|
488
|
|
|
|
|
|
|
# defined but that depend on a copy relocation |
|
489
|
10710
|
100
|
|
|
|
24328
|
next if not $sym->{defined}; |
|
490
|
9768
|
50
|
|
|
|
21178
|
next if not exists $self->{dynrelocs}{$sym->{name}}; |
|
491
|
0
|
0
|
|
|
|
0
|
if ($self->{dynrelocs}{$sym->{name}} =~ /^R_.*_COPY$/) { |
|
492
|
0
|
|
|
|
|
0
|
$sym->{defined} = 0; |
|
493
|
|
|
|
|
|
|
} |
|
494
|
|
|
|
|
|
|
} |
|
495
|
|
|
|
|
|
|
} |
|
496
|
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
sub add_dynamic_symbol { |
|
498
|
10714
|
|
|
10714
|
|
16091
|
my ($self, $symbol) = @_; |
|
499
|
10714
|
|
|
|
|
16056
|
$symbol->{objid} = $symbol->{soname} = $self->get_id(); |
|
500
|
10714
|
100
|
|
|
|
20795
|
$symbol->{soname} =~ s{^.*/}{} unless $self->{SONAME}; |
|
501
|
10714
|
100
|
|
|
|
16823
|
if ($symbol->{version}) { |
|
502
|
10174
|
|
|
|
|
85378
|
$self->{dynsyms}{$symbol->{name} . '@' . $symbol->{version}} = $symbol; |
|
503
|
|
|
|
|
|
|
} else { |
|
504
|
540
|
|
|
|
|
3875
|
$self->{dynsyms}{$symbol->{name} . '@Base'} = $symbol; |
|
505
|
|
|
|
|
|
|
} |
|
506
|
|
|
|
|
|
|
} |
|
507
|
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
sub get_id { |
|
509
|
10714
|
|
|
10714
|
|
14898
|
my $self = shift; |
|
510
|
10714
|
|
66
|
|
|
45852
|
return $self->{SONAME} || $self->{file}; |
|
511
|
|
|
|
|
|
|
} |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
sub get_symbol { |
|
514
|
38
|
|
|
38
|
|
22986
|
my ($self, $name) = @_; |
|
515
|
38
|
100
|
|
|
|
178
|
if (exists $self->{dynsyms}{$name}) { |
|
516
|
32
|
|
|
|
|
128
|
return $self->{dynsyms}{$name}; |
|
517
|
|
|
|
|
|
|
} |
|
518
|
6
|
50
|
|
|
|
36
|
if ($name !~ /@/) { |
|
519
|
6
|
50
|
|
|
|
40
|
if (exists $self->{dynsyms}{$name . '@Base'}) { |
|
520
|
6
|
|
|
|
|
36
|
return $self->{dynsyms}{$name . '@Base'}; |
|
521
|
|
|
|
|
|
|
} |
|
522
|
|
|
|
|
|
|
} |
|
523
|
0
|
|
|
|
|
0
|
return; |
|
524
|
|
|
|
|
|
|
} |
|
525
|
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
sub get_exported_dynamic_symbols { |
|
527
|
35
|
|
|
35
|
|
1424
|
my $self = shift; |
|
528
|
22973
|
100
|
100
|
|
|
120059
|
return grep { $_->{defined} && $_->{dynamic} && !$_->{local} } |
|
529
|
35
|
|
|
|
|
102
|
values %{$self->{dynsyms}}; |
|
|
35
|
|
|
|
|
3053
|
|
|
530
|
|
|
|
|
|
|
} |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
sub get_undefined_dynamic_symbols { |
|
533
|
2
|
|
|
2
|
|
1306
|
my $self = shift; |
|
534
|
4480
|
100
|
|
|
|
9998
|
return grep { (!$_->{defined}) && $_->{dynamic} } |
|
535
|
2
|
|
|
|
|
6
|
values %{$self->{dynsyms}}; |
|
|
2
|
|
|
|
|
270
|
|
|
536
|
|
|
|
|
|
|
} |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
sub get_needed_libraries { |
|
539
|
2
|
|
|
2
|
|
6
|
my $self = shift; |
|
540
|
2
|
|
|
|
|
2
|
return @{$self->{NEEDED}}; |
|
|
2
|
|
|
|
|
14
|
|
|
541
|
|
|
|
|
|
|
} |
|
542
|
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
sub is_executable { |
|
544
|
8
|
|
|
8
|
|
24
|
my $self = shift; |
|
545
|
|
|
|
|
|
|
return (exists $self->{flags}{EXEC_P} && $self->{flags}{EXEC_P}) || |
|
546
|
8
|
|
33
|
|
|
110
|
(exists $self->{INTERP} && $self->{INTERP}); |
|
547
|
|
|
|
|
|
|
} |
|
548
|
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
sub is_public_library { |
|
550
|
8
|
|
|
8
|
|
188
|
my $self = shift; |
|
551
|
|
|
|
|
|
|
return exists $self->{flags}{DYNAMIC} && $self->{flags}{DYNAMIC} |
|
552
|
8
|
|
33
|
|
|
170
|
&& exists $self->{SONAME} && $self->{SONAME}; |
|
553
|
|
|
|
|
|
|
} |
|
554
|
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
1; |