From 1e107c19fd86533a6e0eb426904d6e48b6876844 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 29 Mar 2012 17:06:20 +0200 Subject: [PATCH] Ignore compiler lines with no files with extensions. This prevents many false positives and shouldn't cause any false negatives. Also update $file_extension_regex to exclude ',', ';' and ':' from the file extension which prevents additional false positives. --- bin/blhc | 22 ++++++++++------------ t/logs/configure | 10 ++++++++++ t/logs/good | 2 ++ t/logs/make | 6 ++++++ t/tests.t | 6 +++++- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/bin/blhc b/bin/blhc index b4d87e4..4a1c0b1 100755 --- a/bin/blhc +++ b/bin/blhc @@ -144,7 +144,7 @@ my $file_extension_regex = qr/ \s \S+ # Filename without extension. \. - ([^\\.\s]+) # File extension. + ([^\\.,;:\s]+) # File extension. (?=\s|\\) # At end of word. Can't use \b because some files have non # word characters at the end and because \b matches double # extensions (like .cpp.o). Works always as all lines are @@ -572,23 +572,21 @@ FILE: foreach my $file (@ARGV) { } # Ignore lines with no compiler commands. - next if $line !~ /\b$cc_regex(?:\s|\\)/o and not $non_verbose; + next if not $non_verbose + and not $line =~ /\b$cc_regex(?:\s|\\)/o; + # Ignore lines with no filenames with extensions. May miss + # some non-verbose builds (e.g. "gcc -o test" [sic!]), but + # shouldn't be a problem as the log will most likely contain + # other non-verbose commands which are detected. + next if not $non_verbose + and not $line =~ /$file_extension_regex/o; # Ignore false positives. # # `./configure` output. next if not $non_verbose and $line =~ /^(?:checking|(?:C|c)onfigure:) /; - next if $line =~ /^\s*(?:Host\s+)?(?:C\s+)? - (?:C|c)ompiler[\s.]*:?\s+ - $cc_regex_full - (?:\s-std=[a-z0-9:+]+)?\s*$ - /xo - or $line =~ /^\s*(?:- )?(?:HOST_)?(?:CC|CXX)\s*=\s*$cc_regex_full\s*$/o - or $line =~ /^\s*-- Check for working (?:C|CXX) compiler: / - or $line =~ /^\s*(?:echo )?Using [A-Z_]+\s*=\s*/; - # `make` output. - next if $line =~ /^Making [a-z]+ in \S+/; # e.g. "[...] in c++" + next if $line =~ /^\s*(?:- )?(?:HOST_)?(?:CC|CXX)\s*=\s*$cc_regex_full\s*$/o; # Check if additional hardening options were used. Used to # ensure they are used for the complete build. diff --git a/t/logs/configure b/t/logs/configure index 623c563..b390ba8 100644 --- a/t/logs/configure +++ b/t/logs/configure @@ -29,6 +29,8 @@ Host C compiler gcc Compiler: s390x-linux-gnu-gcc Compiler: sparc-linux-gnu-gcc + C++ Compiler...: g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wall -D_FORTIFY_SOURCE=2 + - General Compile FLAGS - CC = mpicc - CXX = g++ @@ -68,6 +70,12 @@ Configuration: -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Check for working CXX compiler: /usr/bin/c++ -- works +-- Use g++ visibility support..... YES + + setting CPP to "sparc-linux-gnu-gcc -E" + +Looking for compiler... gcc is executable. +Looking for compiler... cc is executable. configure: using CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fPIC configure: using LDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -Wl,--as-needed @@ -83,6 +91,8 @@ Using ALL_CFLAGS=-D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffe echo Using LDFLAGS="-Wl,-z,relro -Wl,--as-needed -fPIE -pie -Wall" Using LDFLAGS=-Wl,-z,relro -Wl,--as-needed -fPIE -pie -Wall ++ CC=cc CFLAGS=-g -O2 -Wformat -Wformat-security -Werror=format-security -Wall -Wformat LDFLAGS=-Wl,-z,relro -Wl,-z,now -Wl,--as-needed + CC = cc CC=gcc diff --git a/t/logs/good b/t/logs/good index 74057f5..180a64d 100644 --- a/t/logs/good +++ b/t/logs/good @@ -31,3 +31,5 @@ gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-securit gcc -E -D_FORTIFY_SOURCE=2 test.c gcc -Wl,-z,relro -o test test.cpp.o + +command --cc test diff --git a/t/logs/make b/t/logs/make index 1b5b31e..57584da 100644 --- a/t/logs/make +++ b/t/logs/make @@ -4,3 +4,9 @@ dpkg-buildpackage: source package test Making all in c++ Making install in c++ + +make CC="gcc -Wall -Wextra" CFLAGS="-fPIE" + +CC=gcc /usr/bin/program + +/usr/bin/make CC=g++ DBGFLAGS="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wl,-z,relro -Wl,--as-needed" diff --git a/t/tests.t b/t/tests.t index 949ed88..69da465 100644 --- a/t/tests.t +++ b/t/tests.t @@ -19,7 +19,7 @@ use strict; use warnings; -use Test::More tests => 102; +use Test::More tests => 104; sub is_blhc { @@ -591,6 +591,10 @@ is_blhc 'buildd-verbose-build', '--buildd', 4, 'W-compiler-flags-hidden 1 (of 5) hidden '; +is_blhc 'make', '--buildd', 1, + 'W-no-compiler-commands +'; + # multiple files -- 2.45.2