3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # A wrapper for nm that produces output listing symbol size.
13 my($prev_module) = "";
15 my($prev_symbol) = "";
17 open(NM_OUTPUT
, "nm -fnol $ARGV[0] | c++filt |") or die "nm failed to run on $ARGV[0]\n";
23 if ($line =~ /^([^:]+):\s*([0-9a-f]{8}) (\w) (.+)$/)
30 #Skip absolute addresses, there should be only a few
31 if ('a' eq lc $kind) {
32 if ('trampoline_size' ne $symbol) {
33 warn "Encountered unknown absolutely addressed symbol '$symbol' in $module";
38 # we expect the input to have been piped through c++filt to
39 # demangle symbols. For some reason, it doesn't always demangle
40 # all of them, so push still-mangled symbols back through c++filt again.
41 if ($symbol =~ /^(_[_Z].+)/)
43 # warn "Trying again to unmangle $1\n";
44 $symbol = `c++filt '$1'`;
46 # warn "Unmangling again to $symbol\n";
49 my($prev_size) = hex($addr) - hex($prev_addr);
50 # print "Outputting line $line\n";
52 # always print one behind, because only now do we know its size
53 if ($prev_module ne "") {
54 printf "%s:%08x %s %s\n", $prev_module, $prev_size, $prev_kind, $prev_symbol;
58 $prev_module = $module;
60 $prev_symbol = $symbol;
64 # warn " Discaring line $line\n";
68 # we don't know how big the last symbol is, so always show 4.
69 if ($prev_module ne "") {
70 printf "%s:%08x %s %s\n", $prev_module, 4, $prev_kind, $prev_symbol;