]> ruderich.org/simon Gitweb - blhc/blhc.git/blobdiff - bin/blhc
Refactor Ada handling of format CFLAGS
[blhc/blhc.git] / bin / blhc
index accb99fbff8226aa42fb55ed423a9e32b40d3710..4a16a36ee3edeeda74fab554625a86598ae176da 100755 (executable)
--- a/bin/blhc
+++ b/bin/blhc
@@ -2,7 +2,7 @@
 
 # Build log hardening check, checks build logs for missing hardening flags.
 
-# Copyright (C) 2012-2016  Simon Ruderich
+# Copyright (C) 2012-2017  Simon Ruderich
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@ our $VERSION = '0.07';
 my $cc_regex = qr/
     (?<!\s-)               # ignore options, e.g. "-c++" [sic!] (used by swig)
     (?<!\.)                # ignore file names, e.g. "test.gcc"
-    (?:cc|gcc|g\+\+|c\+\+)
+    (?:cc|gcc|g\+\+|c\+\+|mpicc|mpicxx)
     (?:-[\d.]+)?           # version suffix, e.g. "gcc-4.6"
     /x;
 # Full regex which matches the complete compiler name. Used in a few places to
@@ -618,7 +618,7 @@ if ($option_help) {
 }
 if ($option_version) {
     print <<"EOF";
-blhc $VERSION  Copyright (C) 2012-2016  Simon Ruderich
+blhc $VERSION  Copyright (C) 2012-2017  Simon Ruderich
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -1022,14 +1022,21 @@ foreach my $file (@ARGV) {
 
     # Option or auto detected.
     if ($arch) {
-        # The following was partially copied from dpkg-dev 1.18.10
+        # The following was partially copied from dpkg-dev 1.18.15
         # (/usr/share/perl5/Dpkg/Vendor/Debian.pm, _add_hardening_flags()),
         # copyright RaphaĆ«l Hertzog <hertzog@debian.org>, Kees Cook
         # <kees@debian.org>, Canonical, Ltd. licensed under GPL version 2 or
         # later. Keep it in sync.
 
         require Dpkg::Arch;
-        my ($abi, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
+        my ($os, $cpu);
+        # Recent dpkg versions use a quadruplet for arch. Support both.
+        eval {
+            (undef, undef, $os, $cpu) = Dpkg::Arch::debarch_to_debtuple($arch);
+        };
+        if ($@) {
+            (undef, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
+        }
 
         # Disable unsupported hardening options.
         if ($os !~ /^(?:linux|kfreebsd|knetbsd|hurd)$/
@@ -1080,14 +1087,12 @@ foreach my $file (@ARGV) {
         @ldflags = (@ldflags, @def_ldflags_bindnow);
     }
 
-    # Stores normal CFLAGS when @cflags_ada are temporarily used.
-    my @cflags_backup;
-    # Ada CFLAGS, only set if ada is used.
-    my @cflags_ada;
     # Ada doesn't support format hardening flags, see #680117 for more
     # information. Filter them out if ada is used.
+    my @cflags_backup;
+    my @cflags_noformat;
     if ($ada and $harden_format) {
-        @cflags_ada = grep {
+        @cflags_noformat = grep {
             my $ok = 1;
             foreach my $flag (@def_cflags_format) {
                 $ok = 0 if $_ eq $flag;
@@ -1229,7 +1234,7 @@ LINE:
         }
 
         my $compile_cpp = 0;
-        my $compile_ada = 0;
+        my $restore_cflags = 0;
         # Assume CXXFLAGS are required when a C++ file is specified in the
         # compiler line.
         if ($compile
@@ -1239,10 +1244,10 @@ LINE:
         # Ada needs special CFLAGS, use them if only ada files are compiled.
         } elsif ($ada
                 and extension_found(\%extensions_ada, @extensions)) {
-            $compile_ada = 1;
+            $restore_cflags = 1;
             $preprocess = 0; # Ada uses no CPPFLAGS
             @cflags_backup = @cflags;
-            @cflags        = @cflags_ada;
+            @cflags        = @cflags_noformat;
         }
 
         if ($option_buildd) {
@@ -1317,7 +1322,7 @@ LINE:
         }
 
         # Restore normal CFLAGS.
-        if ($compile_ada) {
+        if ($restore_cflags) {
             @cflags = @cflags_backup;
         }
     }
@@ -1619,7 +1624,7 @@ E<lt>jari.aalto@cante.netE<gt> for their valuable input and suggestions.
 
 =head1 LICENSE AND COPYRIGHT
 
-Copyright (C) 2012-2016 by Simon Ruderich
+Copyright (C) 2012-2017 by Simon Ruderich
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by