X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=bin%2Fblhc;h=62ddb86a6076f986eb6fdeffec5b84e71b6f8731;hb=17f9869280cd3b89f8a6a1dd172d03a0871bf786;hp=ad98dc594355431609fa8a91fc83309f5605d7a6;hpb=f2db9f24cb7bc4d7ce9bf169bd06dd7ec5e17a1d;p=blhc%2Fblhc.git diff --git a/bin/blhc b/bin/blhc index ad98dc5..62ddb86 100755 --- a/bin/blhc +++ b/bin/blhc @@ -172,8 +172,7 @@ my @def_cflags_pie = ( '-fPIE', ); my @def_cxxflags = ( - '-g', - '-O(?:2|3)', + @def_cflags, ); # @def_cxxflags_* is the same as @def_cflags_*. my @def_cppflags = (); @@ -203,6 +202,21 @@ my %flag_renames = ( '-Wl,(-z,)?now' => '-Wl,-z,now', ); +# Statistics of missing flags and non-verbose build commands. Used for +# $option_buildd. +my %statistics = ( + preprocess => 0, + preprocess_missing => 0, + compile => 0, + compile_missing => 0, + compile_cpp => 0, + compile_cpp_missing => 0, + link => 0, + link_missing => 0, + commands => 0, + commands_nonverbose => 0, +); + # Use colored (ANSI) output? my $option_color; @@ -318,7 +332,7 @@ sub is_non_verbose_build { if (defined $file) { # Get filename, we can't use the complete path as only parts of it are # used in the real compiler command. - $file =~ m{/([a-zA-Z0-9._-]+)$}; + $file =~ m{/([^/\s]+)$}; $file = $1; if ($next_line =~ /\Q$file\E/ and $next_line =~ /$cc_regex/o) { @@ -471,7 +485,11 @@ FILE: foreach my $file (@ARGV) { # If hardening wrapper is used (wraps calls to gcc and adds hardening # flags automatically) we can't perform any checks, abort. if ($line =~ /^Build-Depends: .*\bhardening-wrapper\b/) { - error_hardening_wrapper(); + if (not $option_buildd) { + error_hardening_wrapper(); + } else { + print "I-hardening-wrapper-used\n"; + } $exit |= 1 << 4; next FILE; } @@ -589,6 +607,10 @@ FILE: foreach my $file (@ARGV) { next FILE; } + if ($option_buildd) { + $statistics{commands} += scalar @input; + } + # Option or auto detected. if ($option_arch) { # The following was partially copied from dpkg-dev 1.16.1.2 @@ -646,7 +668,11 @@ FILE: foreach my $file (@ARGV) { my $skip = 0; if (is_non_verbose_build($line, $input[$i + 1], \$skip)) { - error_non_verbose_build($line); + if (not $option_buildd) { + error_non_verbose_build($line); + } else { + $statistics{commands_nonverbose}++; + } $exit |= 1 << 2; next; } @@ -656,6 +682,9 @@ FILE: foreach my $file (@ARGV) { # Remove everything until and including the compiler command. Makes # checks easier and faster. $line =~ s/^.*?$cc_regex//o; + # "([...] test.c)" is not detected as 'test.c' - fix this by removing + # the brace and similar characters. + $line =~ s/['")]+$//; # Skip unnecessary tests when only preprocessing. my $flag_preprocess = 0; @@ -712,6 +741,13 @@ FILE: foreach my $file (@ARGV) { $compile_cpp = 1; } + if ($option_buildd) { + $statistics{preprocess}++ if $preprocess; + $statistics{compile}++ if $compile; + $statistics{compile_cpp}++ if $compile_cpp; + $statistics{link}++ if $link; + } + # Check hardening flags. my @missing; if ($compile and not all_flags_used($line, \@missing, @cflags) @@ -721,7 +757,11 @@ FILE: foreach my $file (@ARGV) { and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie) # Assume dpkg-buildflags returns the correct flags. and not $line =~ /`dpkg-buildflags --get CFLAGS`/) { - error_flags('CFLAGS missing', \@missing, \%flag_renames, $input[$i]); + if (not $option_buildd) { + error_flags('CFLAGS missing', \@missing, \%flag_renames, $input[$i]); + } else { + $statistics{compile_missing}++; + } $exit |= 1 << 3; } elsif ($compile_cpp and not all_flags_used($line, \@missing, @cflags) # Libraries linked with -fPIC don't have to (and can't) be @@ -730,13 +770,21 @@ FILE: foreach my $file (@ARGV) { and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie) # Assume dpkg-buildflags returns the correct flags. and not $line =~ /`dpkg-buildflags --get CXXFLAGS`/) { - error_flags('CXXFLAGS missing', \@missing, \%flag_renames, $input[$i]); + if (not $option_buildd) { + error_flags('CXXFLAGS missing', \@missing, \%flag_renames, $input[$i]); + } else { + $statistics{compile_cpp_missing}++; + } $exit |= 1 << 3; } if ($preprocess and not all_flags_used($line, \@missing, @cppflags) # Assume dpkg-buildflags returns the correct flags. and not $line =~ /`dpkg-buildflags --get CPPFLAGS`/) { - error_flags('CPPFLAGS missing', \@missing, \%flag_renames, $input[$i]); + if (not $option_buildd) { + error_flags('CPPFLAGS missing', \@missing, \%flag_renames, $input[$i]); + } else { + $statistics{preprocess_missing}++; + } $exit |= 1 << 3; } if ($link and not all_flags_used($line, \@missing, @ldflags) @@ -744,12 +792,53 @@ FILE: foreach my $file (@ARGV) { and not pic_pie_conflict($line, $harden_pie, \@missing, @def_ldflags_pie) # Assume dpkg-buildflags returns the correct flags. and not $line =~ /`dpkg-buildflags --get LDFLAGS`/) { - error_flags('LDFLAGS missing', \@missing, \%flag_renames, $input[$i]); + if (not $option_buildd) { + error_flags('LDFLAGS missing', \@missing, \%flag_renames, $input[$i]); + } else { + $statistics{link_missing}++; + } $exit |= 1 << 3; } } } +# Print statistics for buildd mode, only output in this mode. +if ($option_buildd) { + my @warning; + + if ($statistics{preprocess_missing}) { + push @warning, sprintf "CPPFLAGS %d (of %d)", + $statistics{preprocess_missing}, + $statistics{preprocess}; + } + if ($statistics{compile_missing}) { + push @warning, sprintf "CFLAGS %d (of %d)", + $statistics{compile_missing}, + $statistics{compile}; + } + if ($statistics{compile_cpp_missing}) { + push @warning, sprintf "CXXFLAGS %d (of %d)", + $statistics{compile_cpp_missing}, + $statistics{compile_cpp}; + } + if ($statistics{link_missing}) { + push @warning, sprintf "LDFLAGS %d (of %d)", + $statistics{link_missing}, + $statistics{link}; + } + if (scalar @warning) { + local $" = ', '; # array join string + print "W-dpkg-buildflags-missing @warning missing\n"; + } + + if ($statistics{commands_nonverbose}) { + printf "W-compiler-flags-hidden %d (of %d) hidden\n", + $statistics{commands_nonverbose}, + $statistics{commands}, + } +} + + exit $exit;