3 # Copyright (c) 2003, Pavel Roskin
4 # The Midnight Commander is free software: you can redistribute it
5 # and/or modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation, either version 3 of the License,
7 # or (at your option) any later version.
9 # The Midnight Commander 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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Run this script on the map with cross-reference generated by GNU ld,
18 # and it will generate a list of symbols that don't need to be global.
19 # To create the map, run something like this:
20 # make LDFLAGS=-Wl,-Map,output.map,--cref
29 print "Usage: unrefglobals.pl mapfile\n";
33 if (!open (MAP
, "$ARGV[0]")) {
34 print "Cannot open file \"$ARGV[0]\"\n";
39 my $next_line = <MAP
>;
41 last unless $next_line;
44 next unless ($line =~ m{^[A-Za-z_][A-Za-z0-9_]* +[^ /][^ ]+\.o$} or
45 $line =~ m{^[A-Za-z_][A-Za-z0-9_]* +[^ /][^ ]+\.a\([^ ]+\.o\)$});
46 if (!$next_line or ($next_line !~ /^ /)) {
47 my @arr = split (' ', $line);
48 $symbols{$arr[0]} = $arr[1];
56 foreach my $obj (sort keys %objs) {
58 foreach my $sym (sort keys %syms) {
59 print "\t$sym\n" if ($symbols{$sym} eq $obj);