reference_discarded.pl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/perl -w
  2. #
  3. # reference_discarded.pl (C) Keith Owens 2001 <kaos@ocs.com.au>
  4. #
  5. # Released under GPL V2.
  6. #
  7. # List dangling references to vmlinux discarded sections.
  8. use strict;
  9. die($0 . " takes no arguments\n") if($#ARGV >= 0);
  10. my %object;
  11. my $object;
  12. my $line;
  13. my $ignore;
  14. my $errorcount;
  15. $| = 1;
  16. # printf("Finding objects, ");
  17. open(OBJDUMP_LIST, "find . -name '*.o' | xargs objdump -h |") || die "getting objdump list failed";
  18. while (defined($line = <OBJDUMP_LIST>)) {
  19. chomp($line);
  20. if ($line =~ /:\s+file format/) {
  21. ($object = $line) =~ s/:.*//;
  22. $object{$object}->{'module'} = 0;
  23. $object{$object}->{'size'} = 0;
  24. $object{$object}->{'off'} = 0;
  25. }
  26. if ($line =~ /^\s*\d+\s+\.modinfo\s+/) {
  27. $object{$object}->{'module'} = 1;
  28. }
  29. if ($line =~ /^\s*\d+\s+\.comment\s+/) {
  30. ($object{$object}->{'size'}, $object{$object}->{'off'}) = (split(' ', $line))[2,5];
  31. }
  32. }
  33. close(OBJDUMP_LIST);
  34. # printf("%d objects, ", scalar keys(%object));
  35. $ignore = 0;
  36. foreach $object (keys(%object)) {
  37. if ($object{$object}->{'module'}) {
  38. ++$ignore;
  39. delete($object{$object});
  40. }
  41. }
  42. # printf("ignoring %d module(s)\n", $ignore);
  43. # Ignore conglomerate objects, they have been built from multiple objects and we
  44. # only care about the individual objects. If an object has more than one GCC:
  45. # string in the comment section then it is conglomerate. This does not filter
  46. # out conglomerates that consist of exactly one object, can't be helped.
  47. # printf("Finding conglomerates, ");
  48. $ignore = 0;
  49. foreach $object (keys(%object)) {
  50. if (exists($object{$object}->{'off'})) {
  51. my ($off, $size, $comment, $l);
  52. $off = hex($object{$object}->{'off'});
  53. $size = hex($object{$object}->{'size'});
  54. open(OBJECT, "<$object") || die "cannot read $object";
  55. seek(OBJECT, $off, 0) || die "seek to $off in $object failed";
  56. $l = read(OBJECT, $comment, $size);
  57. die "read $size bytes from $object .comment failed" if ($l != $size);
  58. close(OBJECT);
  59. if ($comment =~ /GCC\:.*GCC\:/m || $object =~ /built-in\.o/) {
  60. ++$ignore;
  61. delete($object{$object});
  62. }
  63. }
  64. }
  65. # printf("ignoring %d conglomerate(s)\n", $ignore);
  66. # printf("Scanning objects\n");
  67. $errorcount = 0;
  68. foreach $object (keys(%object)) {
  69. my $from;
  70. open(OBJDUMP, "objdump -r $object|") || die "cannot objdump -r $object";
  71. while (defined($line = <OBJDUMP>)) {
  72. chomp($line);
  73. if ($line =~ /RELOCATION RECORDS FOR /) {
  74. ($from = $line) =~ s/.*\[([^]]*).*/$1/;
  75. }
  76. if (($line =~ /\.text\.exit$/ ||
  77. $line =~ /\.exit\.text$/ ||
  78. $line =~ /\.data\.exit$/ ||
  79. $line =~ /\.exit\.data$/ ||
  80. $line =~ /\.exitcall\.exit$/) &&
  81. ($from !~ /\.text\.exit$/ &&
  82. $from !~ /\.exit\.text$/ &&
  83. $from !~ /\.data\.exit$/ &&
  84. $from !~ /\.exit\.data$/ &&
  85. $from !~ /\.altinstructions$/ &&
  86. $from !~ /\.pdr$/ &&
  87. $from !~ /\.debug_info$/ &&
  88. $from !~ /\.debug_aranges$/ &&
  89. $from !~ /\.debug_ranges$/ &&
  90. $from !~ /\.debug_line$/ &&
  91. $from !~ /\.debug_frame$/ &&
  92. $from !~ /\.exitcall\.exit$/ &&
  93. $from !~ /\.eh_frame$/ &&
  94. $from !~ /\.stab$/)) {
  95. printf("Error: %s %s refers to %s\n", $object, $from, $line);
  96. $errorcount = $errorcount + 1;
  97. }
  98. }
  99. close(OBJDUMP);
  100. }
  101. # printf("Done\n");
  102. exit(0);