3 # Copyright (c) 2003, Pavel Roskin
4 # This script is Free Software, and it can be copied, distributed and
5 # modified under the terms of GNU General Public License, version 2.
7 # Run this script on the map with cross-reference generated by GNU ld,
8 # and it will generate a list of symbols that don't need to be global.
9 # To create the map, run something like this:
10 # make LDFLAGS=-Wl,-Map,output.map,--cref
19 print "Usage: unrefglobals.pl mapfile\n";
23 if (!open (MAP
, "$ARGV[0]")) {
24 print "Cannot open file \"$ARGV[0]\"\n";
29 my $next_line = <MAP
>;
31 last unless $next_line;
34 next unless ($line =~ m{^[A-Za-z_][A-Za-z0-9_]* +[^ /][^ ]+\.o$} or
35 $line =~ m{^[A-Za-z_][A-Za-z0-9_]* +[^ /][^ ]+\.a\([^ ]+\.o\)$});
36 if (!$next_line or ($next_line !~ /^ /)) {
37 my @arr = split (' ', $line);
38 $symbols{$arr[0]} = $arr[1];
46 foreach my $obj (sort keys %objs) {
48 foreach my $sym (sort keys %syms) {
49 print "\t$sym\n" if ($symbols{$sym} eq $obj);