From 49ca3dc4499ac634f791803c1ad25d38b491b055 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 14 Oct 2003 23:04:01 +0000 Subject: [PATCH] New file - find unreferenced global symbols in cross-reference linker maps. --- maint/unrefglobals.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 maint/unrefglobals.pl diff --git a/maint/unrefglobals.pl b/maint/unrefglobals.pl new file mode 100755 index 000000000..139630816 --- /dev/null +++ b/maint/unrefglobals.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +# Run this script on the map with cross-reference generated by GNU ld, +# and it will generate a list of symbols that don't need to be global. +# To create the map, run something like this: +# make LDFLAGS=-Wl,-Map,mc.map,--cref + +use strict; + +if ($#ARGV != 0) { + print "Usage: unrefglobals.pl mapfile\n"; + exit 1; +} + +if (!open (MAP, "$ARGV[0]")) { + print "Cannot open file \"$ARGV[0]\"\n"; + exit 1; +} + +my $line; +my $next_line = ; +while (1) { + last unless $next_line; + $line = $next_line; + $next_line = ; + next unless ($line =~ /^[A-Za-z_][A-Za-z0-9_]* +[^ ]+\.o$/ or + $line =~ /^[A-Za-z_][A-Za-z0-9_]* +[^ ]+\.a\([^ ]+\.o\)$/); + if (!$next_line or ($next_line !~ /^ /)) { + print $line; + } +} + +close(MAP);