3 # Copyright (c) 2003, Pavel Roskin
4 # This script is Free Software, and it can be copied, distributed and
5 # modified as defined in the GNU General Public License. A copy of
6 # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
8 # Run this script on the map with cross-reference generated by GNU ld,
9 # and it will generate a list of symbols that don't need to be global.
10 # To create the map, run something like this:
11 # make LDFLAGS=-Wl,-Map,output.map,--cref
20 print "Usage: unrefglobals.pl mapfile\n";
24 if (!open (MAP
, "$ARGV[0]")) {
25 print "Cannot open file \"$ARGV[0]\"\n";
30 my $next_line = <MAP
>;
32 last unless $next_line;
35 next unless ($line =~ m{^[A-Za-z_][A-Za-z0-9_]* +[^ /][^ ]+\.o$} or
36 $line =~ m{^[A-Za-z_][A-Za-z0-9_]* +[^ /][^ ]+\.a\([^ ]+\.o\)$});
37 if (!$next_line or ($next_line !~ /^ /)) {
38 my @arr = split (' ', $line);
39 $symbols{$arr[0]} = $arr[1];
47 foreach my $obj (sort keys %objs) {
49 foreach my $sym (sort keys %syms) {
50 print "\t$sym\n" if ($symbols{$sym} eq $obj);