reference_discarded.pl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. # Keith Ownes <kaos@sgi.com> commented:
  68. # For our future {in}sanity, add a comment that this is the ppc .opd
  69. # section, not the ia64 .opd section.
  70. # ia64 .opd should not point to discarded sections.
  71. $errorcount = 0;
  72. foreach $object (keys(%object)) {
  73. my $from;
  74. open(OBJDUMP, "objdump -r $object|") || die "cannot objdump -r $object";
  75. while (defined($line = <OBJDUMP>)) {
  76. chomp($line);
  77. if ($line =~ /RELOCATION RECORDS FOR /) {
  78. ($from = $line) =~ s/.*\[([^]]*).*/$1/;
  79. }
  80. if (($line =~ /\.text\.exit$/ ||
  81. $line =~ /\.exit\.text$/ ||
  82. $line =~ /\.data\.exit$/ ||
  83. $line =~ /\.exit\.data$/ ||
  84. $line =~ /\.exitcall\.exit$/) &&
  85. ($from !~ /\.text\.exit$/ &&
  86. $from !~ /\.exit\.text$/ &&
  87. $from !~ /\.data\.exit$/ &&
  88. $from !~ /\.opd$/ &&
  89. $from !~ /\.exit\.data$/ &&
  90. $from !~ /\.altinstructions$/ &&
  91. $from !~ /\.pdr$/ &&
  92. $from !~ /\.debug_.*$/ &&
  93. $from !~ /\.exitcall\.exit$/ &&
  94. $from !~ /\.eh_frame$/ &&
  95. $from !~ /\.stab$/)) {
  96. printf("Error: %s %s refers to %s\n", $object, $from, $line);
  97. $errorcount = $errorcount + 1;
  98. }
  99. }
  100. close(OBJDUMP);
  101. }
  102. # printf("Done\n");
  103. exit(0);