From: Simon Ruderich Date: Sat, 31 Aug 2019 08:44:44 +0000 (+0200) Subject: Fix format CFLAGS for Ada/Fortran with some build logs X-Git-Tag: 0.10~4 X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=eaa4bece3aca1798ffe5a13030cca3dfbdd4ce0c;p=blhc%2Fblhc.git Fix format CFLAGS for Ada/Fortran with some build logs No longer check for "gnat" and "gfortran" packages as dependency. Instead, apply the special handling unconditionally. This might be slightly slower but permits running blhc on Ada/Fortran build logs which provide no information about dependencies (e.g. when running just dpkg-buildpackage). --- diff --git a/MANIFEST b/MANIFEST index 80e56d2..b4b05d3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -50,6 +50,7 @@ t/logs/dpkg-buildpackage-architecture-old t/logs/empty t/logs/false-positives t/logs/fortran +t/logs/fortran-no-build-deps t/logs/g++ t/logs/gcc t/logs/good diff --git a/NEWS b/NEWS index 188dcc5..814d1c7 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,10 @@ Version 0.XX by Ross Vandegrift, patch from Mathieu Parent (Debian bug #929503). - Fix false positive in non-verbose check for python setuptools; reported by Simon McVittie (Debian Bug #930993). +- Fix special handling of format CFLAGS for Ada/Fortran with build logs not + generated pbuilder/sbuild (pbuilder and sbuild provide build dependencies + but other do not); reported by Christoph Berg and Rafael Laboissière (Debian + bug #924387). Version 0.09 diff --git a/bin/blhc b/bin/blhc index 0892cad..446ffb3 100755 --- a/bin/blhc +++ b/bin/blhc @@ -792,13 +792,6 @@ foreach my $file (@ARGV) { my $harden_bindnow = $option_bindnow; # defaults to 0 my $harden_pie = $option_pie; # defaults to 0 - # Does this build log use ada? Ada also uses gcc as compiler but uses - # different CFLAGS. But only perform ada checks if an ada compiler is used - # for performance reasons. - my $ada = 0; - # Fortran also requires different CFLAGS. - my $fortran = 0; - # Number of parallel jobs to prevent false positives when detecting # non-verbose builds. As not all jobs declare the number of parallel jobs # use a large enough default. @@ -907,15 +900,6 @@ foreach my $file (@ARGV) { } next FILE; } - - # Ada compiler. - if ($line =~ /\bgnat\b/) { - $ada = 1; - } - # Fortran compiler. - if ($line =~ /\bgfortran\b/) { - $fortran = 1; - } } # This flags is not always available, but if it is use it. @@ -1213,19 +1197,15 @@ foreach my $file (@ARGV) { } # Ada doesn't support format hardening flags, see #680117 for more - # information. Same for fortran. Filter them out if either language is - # used. + # information. Same for fortran. my @cflags_backup; - my @cflags_noformat; - if (($ada or $fortran) and $harden_format) { - @cflags_noformat = grep { + my @cflags_noformat = grep { my $ok = 1; foreach my $flag (@def_cflags_format) { $ok = 0 if $_ eq $flag; } $ok; } @cflags; - } # Hack to fix cppflags_fortify_broken() if --ignore-flag # -D_FORTIFY_SOURCE=2 is used to ignore missing fortification. Only works @@ -1367,16 +1347,14 @@ LINE: and extension_found(\%extensions_compile_cpp, @extensions)) { $compile = 0; $compile_cpp = 1; - # Ada needs special CFLAGS, use them if only ada files are compiled. - } elsif ($ada - and extension_found(\%extensions_ada, @extensions)) { + # Ada needs special CFLAGS + } elsif (extension_found(\%extensions_ada, @extensions)) { $restore_cflags = 1; $preprocess = 0; # Ada uses no CPPFLAGS @cflags_backup = @cflags; @cflags = @cflags_noformat; - # Same for fortran. - } elsif ($fortran - and extension_found(\%extensions_fortran, @extensions)) { + # Same for fortran + } elsif (extension_found(\%extensions_fortran, @extensions)) { $restore_cflags = 1; @cflags_backup = @cflags; @cflags = @cflags_noformat; diff --git a/t/logs/fortran-no-build-deps b/t/logs/fortran-no-build-deps new file mode 100644 index 0000000..48a05e5 --- /dev/null +++ b/t/logs/fortran-no-build-deps @@ -0,0 +1,16 @@ +dpkg-buildpackage: source package fortran package + +gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -Wl,-z,relro -o balls balls.f +gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -c -o quadric.o quadric.f +gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -c -o suv.o suv.f +gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 \ +rastep.f quadric.o suv.o -Wl,-z,relro \ +-o rastep +gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -c -o render.o render.f +gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -fstack-protector-strong -o balls-without-ldflags balls.f + +mpifort -cpp -DDOUB -g -O2 -fdebug-prefix-map=/«PKGBUILDDIR»=. -c -o transform.o transform.f90 + +# correct +gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -Wl,-z,relro -fstack-protector-strong -o balls balls.f +mpifort -cpp -DDOUB -g -O2 -fdebug-prefix-map=/«PKGBUILDDIR»=. -fstack-protector-strong -c -o paste.o paste.f90 diff --git a/t/tests.t b/t/tests.t index 2e2b9d7..76e90e7 100644 --- a/t/tests.t +++ b/t/tests.t @@ -19,7 +19,7 @@ use strict; use warnings; -use Test::More tests => 238; +use Test::More tests => 240; sub is_blhc { @@ -787,6 +787,16 @@ LDFLAGS missing (-Wl,-z,relro): gfortran -g -w -O2 -Wtabs -ffixed-line-length-13 CFLAGS missing (-fstack-protector-strong): mpifort -cpp -DDOUB -g -O2 -fdebug-prefix-map=/«PKGBUILDDIR»=. -c -o transform.o transform.f90 '; +is_blhc 'fortran-no-build-deps', '', 8, + 'CFLAGS missing (-fstack-protector-strong): gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -Wl,-z,relro -o balls balls.f +CFLAGS missing (-fstack-protector-strong): gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -c -o quadric.o quadric.f +CFLAGS missing (-fstack-protector-strong): gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -c -o suv.o suv.f +CFLAGS missing (-fstack-protector-strong): gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 \ rastep.f quadric.o suv.o -Wl,-z,relro \ -o rastep +CFLAGS missing (-fstack-protector-strong): gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -c -o render.o render.f +LDFLAGS missing (-Wl,-z,relro): gfortran -g -w -O2 -Wtabs -ffixed-line-length-132 -fstack-protector-strong -o balls-without-ldflags balls.f +CFLAGS missing (-fstack-protector-strong): mpifort -cpp -DDOUB -g -O2 -fdebug-prefix-map=/«PKGBUILDDIR»=. -c -o transform.o transform.f90 +'; + # libtool