X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=bin%2Fblhc;h=af644d3597621d2ad04de3bac77f7d78be1b01a7;hb=0f1a49d52e94c258e444548c34903d27346d8a52;hp=72a2c4294ec2d6c04b1e54ff263a2452c2060e63;hpb=9e0473a48cbaa821c36fb9c456c25b203d46c87c;p=blhc%2Fblhc.git diff --git a/bin/blhc b/bin/blhc index 72a2c42..af644d3 100755 --- a/bin/blhc +++ b/bin/blhc @@ -183,7 +183,12 @@ my $file_extension_regex = qr/ # real regexps below for better execution speed). my @def_cflags = ( '-g', - '-O(?:2|3)', + '-O(?:2|3)', # keep at index 1, search for @def_cflags_debug to change it +); +my @def_cflags_debug = ( + # These flags indicate a debug build which disables checks for -O2. + '-O0', + '-Og', ); my @def_cflags_format = ( '-Wformat(?:=2)?', # -Wformat=2 implies -Wformat, accept it too @@ -248,6 +253,7 @@ my @flag_refs = ( # References to all used flags. my @flag_refs_all = ( @flag_refs, + \@def_cflags_debug, \@def_cppflags_fortify_bad, \@def_ldflags_pic, ); @@ -460,7 +466,7 @@ sub is_non_verbose_build { return 0 if $line =~ /^\s*C\+\+.+?:\s+(?:yes|no)\s*$/; return 0 if $line =~ /^\s*C\+\+ Library: stdc\+\+$/; # "Compiling" non binary files. - return 0 if $line =~ /^\s*Compiling \S+\.(?:py|el)['"]?(?:\.\.\.)?$/; + return 0 if $line =~ /^\s*Compiling \S+\.(?:py|el)['"]?\s*(?:\.\.\.)?$/; # "Compiling" with no file name. if ($line =~ /^\s*[Cc]ompiling\s+(.+?)(?:\.\.\.)?$/) { # $file_extension_regex may need spaces around the filename. @@ -495,7 +501,7 @@ sub is_non_verbose_build { return 1; } -# Remove @flags from $flag_refs_ref, and $flag_renames_ref. +# Remove @flags from $flag_refs_ref, uses $flag_renames_ref as reference. sub remove_flags { my ($flag_refs_ref, $flag_renames_ref, @flags) = @_; @@ -953,7 +959,7 @@ foreach my $file (@ARGV) { # Option or auto detected. if ($arch) { - # The following was partially copied from dpkg-dev 1.17.1 + # The following was partially copied from dpkg-dev 1.17.11 # (/usr/share/perl5/Dpkg/Vendor/Debian.pm, add_hardening_flags()), # copyright Raphaël Hertzog , Kees Cook # , Canonical, Ltd. licensed under GPL version 2 or @@ -967,8 +973,7 @@ foreach my $file (@ARGV) { $cpu =~ /^(?:hppa|mips|mipsel|avr32)$/) { $harden_pie = 0; } - if ($cpu =~ /^(?:ia64|alpha|mips|mipsel|hppa|arm64)$/ - or $arch eq 'arm') { + if ($cpu =~ /^(?:ia64|alpha|mips|mipsel|hppa)$/ or $arch eq 'arm') { $harden_stack = 0; } if ($cpu =~ /^(?:ia64|hppa|avr32)$/) { @@ -1174,6 +1179,13 @@ LINE: $statistics{link}++ if $link; } + # Check if there are flags indicating a debug build. If that's true, + # skip the check for -O2. This prevents fortification, but that's fine + # for a debug build. + if (any_flags_used($line, @def_cflags_debug)) { + remove_flags([\@cflags], \%flag_renames, $def_cflags[1]); + } + # Check hardening flags. my @missing; if ($compile and not all_flags_used($line, \@missing, @cflags)