3 # reference_discarded.pl (C) Keith Owens 2001 <kaos@ocs.com.au>
5 # Released under GPL V2.
7 # List dangling references to vmlinux discarded sections.
10 die($0 . " takes no arguments\n") if($#ARGV >= 0);
20 # printf("Finding objects, ");
21 open(OBJDUMP_LIST
, "find . -name '*.o' | xargs objdump -h |") || die "getting objdump list failed";
22 while (defined($line = <OBJDUMP_LIST
>)) {
24 if ($line =~ /:\s+file format/) {
25 ($object = $line) =~ s/:.*//;
26 $object{$object}->{'module'} = 0;
27 $object{$object}->{'size'} = 0;
28 $object{$object}->{'off'} = 0;
30 if ($line =~ /^\s*\d+\s+\.modinfo\s+/) {
31 $object{$object}->{'module'} = 1;
33 if ($line =~ /^\s*\d+\s+\.comment\s+/) {
34 ($object{$object}->{'size'}, $object{$object}->{'off'}) = (split(' ', $line))[2,5];
38 # printf("%d objects, ", scalar keys(%object));
40 foreach $object (keys(%object)) {
41 if ($object{$object}->{'module'}) {
43 delete($object{$object});
46 # printf("ignoring %d module(s)\n", $ignore);
48 # Ignore conglomerate objects, they have been built from multiple objects and we
49 # only care about the individual objects. If an object has more than one GCC:
50 # string in the comment section then it is conglomerate. This does not filter
51 # out conglomerates that consist of exactly one object, can't be helped.
53 # printf("Finding conglomerates, ");
55 foreach $object (keys(%object)) {
56 if (exists($object{$object}->{'off'})) {
57 my ($off, $size, $comment, $l);
58 $off = hex($object{$object}->{'off'});
59 $size = hex($object{$object}->{'size'});
60 open(OBJECT
, "<$object") || die "cannot read $object";
61 seek(OBJECT
, $off, 0) || die "seek to $off in $object failed";
62 $l = read(OBJECT
, $comment, $size);
63 die "read $size bytes from $object .comment failed" if ($l != $size);
65 if ($comment =~ /GCC\:.*GCC\:/m || $object =~ /built-in\.o/) {
67 delete($object{$object});
71 # printf("ignoring %d conglomerate(s)\n", $ignore);
73 # printf("Scanning objects\n");
75 foreach $object (keys(%object)) {
77 open(OBJDUMP
, "objdump -r $object|") || die "cannot objdump -r $object";
78 while (defined($line = <OBJDUMP
>)) {
80 if ($line =~ /RELOCATION RECORDS FOR /) {
81 ($from = $line) =~ s/.*\[([^]]*).*/$1/;
83 if (($line =~ /\.text\.exit$/ ||
84 $line =~ /\.exit\.text$/ ||
85 $line =~ /\.data\.exit$/ ||
86 $line =~ /\.exit\.data$/ ||
87 $line =~ /\.exitcall\.exit$/) &&
88 ($from !~ /\.text\.exit$/ &&
89 $from !~ /\.exit\.text$/ &&
90 $from !~ /\.data\.exit$/ &&
91 $from !~ /\.exit\.data$/ &&
92 $from !~ /\.altinstructions$/ &&
94 $from !~ /\.debug_.*$/ &&
95 $from !~ /\.exitcall\.exit$/ &&
96 $from !~ /\.eh_frame$/ &&
97 $from !~ /\.stab$/)) {
98 printf("Error: %s %s refers to %s\n", $object, $from, $line);
99 $errorcount = $errorcount + 1;