選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

sortobjdump.pl 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. # Sort the symbol table portion of the output of objdump -ht by
  5. # section, then by symbol value, then by size. Used to enhance the
  6. # linker maps produced by "make bin/%.map" by also showing the values
  7. # of all non-global symbols.
  8. my %section_idx = ( "*ABS*" => ".", "*UND*" => "_" );
  9. my %lines;
  10. while ( <> ) {
  11. if ( /^\s+(\d+)\s+([\.\*]\S+)\s+[0-9a-fA-F]+\s+[0-9a-fA-F]/ ) {
  12. # It's a header line containing a section definition; extract the
  13. # section index and store it. Also print the header line.
  14. print;
  15. ( my $index, my $section ) = ( $1, $2 );
  16. $section_idx{$section} = sprintf ( "%02d", $index );
  17. } elsif ( /^([0-9a-fA-F]+)\s.*?\s([\.\*]\S+)\s+([0-9a-fA-F]+)\s+(\S+)/ ) {
  18. # It's a symbol line - store it in the hash, indexed by
  19. # "<section_index>:<value>:<size>:<end_tag>". <end_tag> is "0" if
  20. # the symbol name is of the form xxx_end, "1" otherwise; this is
  21. # done so that table end markers show up before any other symbols
  22. # with the same value.
  23. ( my $value, my $section, my $size, my $name ) = ( $1, $2, $3, $4 );
  24. die "Unrecognised section \"$section\"\n"
  25. unless exists $section_idx{$section};
  26. my $section_idx = $section_idx{$section};
  27. my $end = ( $name =~ /_end$/ ) ? "0" : "1";
  28. my $key = $section_idx.":".$value.":".$size.":".$end;
  29. $lines{$key} ||= '';
  30. $lines{$key} .= $_;
  31. } else {
  32. # It's a generic header line: just print it.
  33. print;
  34. }
  35. }
  36. print $lines{$_} foreach sort keys %lines;