6 $Getopt::Std
::STANDARD_HELP_VERSION
++;
10 getopts
('f:s', \
%args);
18 This program parses a linker map file, especially one produced when linking an iOS executable.
20 Input is read from a map file provided as command-line argument
22 By default a list of libraries used and the size of code and data
23 linked in from each library is printed, in reverse order of size.
25 The following options are available:
26 -s Print a list of symbols instead.
27 -f 'filter' Filter which libraries are handled. The filter can be
28 a regular expression, typically several library names
29 combined with the '|' operator. Makes sense only when
34 die "The -f switch makes sense only if -s is also used\n" if defined($args{'f'}) && !defined($args{'s'});
36 die "Please provide one map file name\n" if !defined($ARGV[0]);
38 die "Just one argument please\n" if defined($ARGV[1]);
45 open(INPUT
, '<', $ARGV[0]) || die "Could not open $ARGV[0]: $!\n";
48 if ($state == 0 && m!^# Object files:!) {
50 } elsif ($state == 1 && m!^\[ *([0-9]+)\] .*/([-_a-z0-9]+\.a)\(.*!i) {
51 $libofnumber{$1} = $2;
52 } elsif ($state == 1 && m!^# Sections:!) {
54 } elsif ($state == 2 && m!^# Address\s+Size\s+File\s+Name!) {
56 } elsif ($state == 3 && m!^0x[0-9A-F]+\s+(0x[0-9A-F]+)\s+\[ *([0-9]+)\] (.*)!) {
57 my ($size,$libnum,$symbol) = ($1, $2, $3);
58 if (defined($libofnumber{$libnum})) {
59 $sizeoflib{$libofnumber{$libnum}} += hex($size);
60 if (!defined($args{'f'}) || $libofnumber{$libnum} =~ /$args{'f'}/) {
61 $sizeofsym{$symbol} = hex($size);
68 # Print symbols in reverse size order
69 foreach (sort { $sizeofsym{$b} <=> $sizeofsym{$a} } keys(%sizeofsym)) {
70 print $_, ": ", $sizeofsym{$_}, "\n";
73 # Print libraries in reverse size order
74 foreach (sort { $sizeoflib{$b} <=> $sizeoflib{$a} } keys(%sizeoflib)) {
75 print $_, ": ", $sizeoflib{$_}, "\n";