From 8f1ee1b36556cffee3f73d8af385fab9f6891470 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Fri, 14 May 2004 20:19:35 -0700 Subject: [PATCH] [PATCH] make buildcheck From: Arjan van de Ven the patch below adds a "make buildcheck" target which checks for the "uses exit in init" bug using Keith Owen's script. In the future other similar sanity checks can be added to this target, but even just this one has been quite useful already. I use it in the kernel rpm build process for example, and I'm sure the OSDL build testers can/want to use it too. From: Keith Owens They commented out the progress print statements, I prefer to have them present but no big deal. The licence is missing. --- Makefile | 3 + scripts/reference_discarded.pl | 109 +++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 scripts/reference_discarded.pl diff --git a/Makefile b/Makefile index 3fd255e574107..33d147403b8fe 100644 --- a/Makefile +++ b/Makefile @@ -1059,6 +1059,9 @@ versioncheck: -name '*.[hcS]' -type f -print | sort \ | xargs $(PERL) -w scripts/checkversion.pl +buildcheck: + $(PERL) scripts/reference_discarded.pl + endif #ifeq ($(config-targets),1) endif #ifeq ($(mixed-targets),1) diff --git a/scripts/reference_discarded.pl b/scripts/reference_discarded.pl new file mode 100644 index 0000000000000..9d01ec5f30b7b --- /dev/null +++ b/scripts/reference_discarded.pl @@ -0,0 +1,109 @@ +#!/usr/bin/perl -w +# +# reference_discarded.pl (C) Keith Owens 2001 +# +# Released under GPL V2. +# +# List dangling references to vmlinux discarded sections. + +use strict; +die($0 . " takes no arguments\n") if($#ARGV >= 0); + +my %object; +my $object; +my $line; +my $ignore; +my $errorcount; + +$| = 1; + +# printf("Finding objects, "); +open(OBJDUMP_LIST, "find . -name '*.o' | xargs objdump -h |") || die "getting objdump list failed"; +while (defined($line = )) { + chomp($line); + if ($line =~ /:\s+file format/) { + ($object = $line) =~ s/:.*//; + $object{$object}->{'module'} = 0; + $object{$object}->{'size'} = 0; + $object{$object}->{'off'} = 0; + } + if ($line =~ /^\s*\d+\s+\.modinfo\s+/) { + $object{$object}->{'module'} = 1; + } + if ($line =~ /^\s*\d+\s+\.comment\s+/) { + ($object{$object}->{'size'}, $object{$object}->{'off'}) = (split(' ', $line))[2,5]; + } +} +close(OBJDUMP_LIST); +# printf("%d objects, ", scalar keys(%object)); +$ignore = 0; +foreach $object (keys(%object)) { + if ($object{$object}->{'module'}) { + ++$ignore; + delete($object{$object}); + } +} +# printf("ignoring %d module(s)\n", $ignore); + +# Ignore conglomerate objects, they have been built from multiple objects and we +# only care about the individual objects. If an object has more than one GCC: +# string in the comment section then it is conglomerate. This does not filter +# out conglomerates that consist of exactly one object, can't be helped. + +# printf("Finding conglomerates, "); +$ignore = 0; +foreach $object (keys(%object)) { + if (exists($object{$object}->{'off'})) { + my ($off, $size, $comment, $l); + $off = hex($object{$object}->{'off'}); + $size = hex($object{$object}->{'size'}); + open(OBJECT, "<$object") || die "cannot read $object"; + seek(OBJECT, $off, 0) || die "seek to $off in $object failed"; + $l = read(OBJECT, $comment, $size); + die "read $size bytes from $object .comment failed" if ($l != $size); + close(OBJECT); + if ($comment =~ /GCC\:.*GCC\:/m) { + ++$ignore; + delete($object{$object}); + } + } +} +# printf("ignoring %d conglomerate(s)\n", $ignore); + +# printf("Scanning objects\n"); +$errorcount = 0; +foreach $object (keys(%object)) { + my $from; + open(OBJDUMP, "objdump -r $object|") || die "cannot objdump -r $object"; + while (defined($line = )) { + chomp($line); + if ($line =~ /RELOCATION RECORDS FOR /) { + ($from = $line) =~ s/.*\[([^]]*).*/$1/; + } + if (($line =~ /\.text\.exit$/ || + $line =~ /\.exit\.text$/ || + $line =~ /\.data\.exit$/ || + $line =~ /\.exit\.data$/ || + $line =~ /\.exitcall\.exit$/) && + ($from !~ /\.text\.exit$/ && + $from !~ /\.exit\.text$/ && + $from !~ /\.data\.exit$/ && + $from !~ /\.exit\.data$/ && + $from !~ /\.altinstructions$/ && + $from !~ /\.debug_info$/ && + $from !~ /\.debug_aranges$/ && + $from !~ /\.debug_ranges$/ && + $from !~ /\.debug_line$/ && + $from !~ /\.debug_frame$/ && + $from !~ /\.exitcall\.exit$/ && + $from !~ /\.eh_frame$/ && + $from !~ /\.stab$/)) { + printf("Error: %s %s refers to %s\n", $object, $from, $line); + $errorcount = $errorcount + 1; + } + } + close(OBJDUMP); +} +# printf("Done\n"); + +exit($errorcount); -- 2.53.0