2 # objdump-info -- lintian collection script
4 # The original shell script version of this script is
5 # Copyright (C) 1998 Christian Schwarz
7 # This version, including support for etch's binutils, is
8 # Copyright (C) 2008 Adam D. Barratt
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, you can find it on the World Wide
22 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
23 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
29 unless (-f "fields/package") {
30 print STDERR "error: collection script called in wrong directory!\n";
36 open (FILES, '<', "file-info")
37 or fail("cannot open file-info: $!");
39 open (OUT, '>', "objdump-info")
40 or fail("cannot open objdump-info: $!");
42 open(PIPE, '-|', "dpkg-query -W -f='\${Version}\n' binutils")
43 or fail("unable to run dpkg-query: $!");
44 my $binutils_version = <PIPE>;
45 chomp $binutils_version;
49 or fail ("unable to chdir to unpacked: $!\n");
52 if (m/^(.+?):\s.*ELF/) {
55 print OUT "-- $bin\n";
57 system("head $bin | grep -q 'packed.*with.*UPX'");
58 print OUT "objdump: $bin: Packed with UPX" if $? == 0;
60 if (open(PIPE, '-|', "readelf -l $bin 2>&1")) {
67 system("objdump -T $bin >/dev/null 2>&1");
69 # Seems happy so slurp the full output
70 if (open(PIPE, '-|', "objdump --headers --private-headers -T $bin 2>&1")) {
76 } elsif ($binutils_version !~ m/^2\.17/) {
77 # etch's binutils (2.17) can't read 64-bit binaries on 32-bit
78 # platforms so we special-case that below
80 # Otherwise we allow the two specific errors "Invalid operation" and
81 # "File format not recognized" as the checks scripts handle them
83 # From the original script:
84 # If the objdump error is "Invalid operation", we handle it later
85 # in the check script, since this is the expected output (for now)
86 # on detached debugging information in /usr/lib/debug.
89 if (open(PIPE, '-|', "objdump --headers --private-headers -T $bin 2>&1")) {
91 $failed = 0 if m/Invalid operation$/;
92 $failed = 0 if m/File format not recognized$/;
101 # We're using etch's binutils so attempt to build an output file
102 # in the expected format without using objcopy; we lose some
103 # data but none that our later checks actually use
107 if (system("readelf -l $bin 2>&1 | grep -q 'Error: Not an ELF file'") == 0) {
108 print OUT "objdump: $bin: File format not recognized\n";
110 } elsif (open(PIPE, '-|', "readelf -W -l -t -d -V $bin")) {
116 if (m/^Program Headers:/) {
119 } elsif (m/^Section Headers:/) {
122 } elsif (m/^Dynamic section at offset .*:/) {
125 } elsif (m/^Version symbols section /) {
129 } elsif (m/^\s*(\S+)\s*(?:(?:\S+\s+){4})\S+\s(...)/
130 and $section eq 'PH') {
131 my ($header, $flags) = ($1, $2);
132 $header =~ s/^GNU_//g;
133 next if $header eq 'Type';
136 $newflags .= ($flags =~ m/R/) ? 'r' : '-';
137 $newflags .= ($flags =~ m/W/) ? 'w' : '-';
138 $newflags .= ($flags =~ m/E/) ? 'x' : '-';
140 $program_headers{$header} = $newflags;
142 print OUT " $header off 0x0 X 0x0 X 0x0\n flags $newflags\n";
143 } elsif (m/^\s*\[(\d+)\]\s*(\S+)(?:\s|\Z)/
144 and $section eq 'SH') {
146 } elsif (m/^\s*0x(?:[0-9A-F]+)\s+\((.*?)\)\s+(\S.*)\Z/i
147 and $section eq 'DS') {
148 my ($type, $value) = ($1, $2);
150 $value =~ s/^(?:Shared library|Library soname): \[(.*)\]/$1/;
151 print OUT " $type $value\n";
152 } elsif (m/^\s*[0-9A-F]+:\s*(\S+)\s*\((\S+)\)\s/i
153 and $section eq 'VS') {
154 while (m/\s(\S+)\s*\((\S+)\)(\s|\Z)/gc) {
155 my ($vernum, $verstring) = ($1, $2);
156 push @symbol_versions, $verstring;
158 } elsif (m/^There is no dynamic section in this file/
159 and exists $program_headers{DYNAMIC}) {
160 # The headers declare a dynamic section but it's
161 # empty. Generate the same error as objdump,
162 # the checks scripts special-case the string.
163 print OUT "\n\nobjdump: $bin: Invalid operation\n";
169 if (open(PIPE, '-|', "readelf -W -s -D $bin")) {
170 print OUT "DYNAMIC SYMBOL TABLE:\n";
173 last if m/^Symbol table of/;
175 if (m/^\s*(\d+)\s+\d+:\s*[0-9a-f]+\s+\d+\s+(?:(?:\S+\s+){3})(\S+)\s+(.*)\Z/) {
176 my ($symnum, $seg, $sym, $ver) = ($1, $2, $3, '');
178 if ($sym =~ m/^(.*)@(.*)$/) {
182 $ver = $symbol_versions[$symnum];
184 if ($ver eq '*local*' or $ver eq '*global*') {
193 if ($seg =~ m/^\d+$/ and defined $sections[$seg]) {
194 $seg = $sections[$seg];
197 print OUT "00 XX $seg 000000 $ver $sym\n";
213 print STDERR "internal error: $_[0]\n";
215 print STDERR "internal error: $!\n";
217 print STDERR "internal error.\n";