From 23020a59781f2a07a8d56053972d14c6d3cae2b3 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 7 Jul 2012 19:27:04 +0200 Subject: [PATCH] Ignore missing -Wformat -Werror=format-security for Ada files. Thanks to Nicolas Boulenguez for reporting this. See http://bugs.debian.org/680117 for details. --- MANIFEST | 1 + bin/blhc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++--- t/logs/ada | 16 +++++++++++++ t/tests.t | 15 ++++++++++++- 4 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 t/logs/ada diff --git a/MANIFEST b/MANIFEST index 1ef6dac..adebaab 100644 --- a/MANIFEST +++ b/MANIFEST @@ -6,6 +6,7 @@ META.json META.yml NEWS README +t/logs/ada t/logs/arch-amd64 t/logs/arch-avr32 t/logs/arch-i386 diff --git a/bin/blhc b/bin/blhc index 75888b8..e03ac28 100755 --- a/bin/blhc +++ b/bin/blhc @@ -81,6 +81,12 @@ my @source_no_preprocess_compile_cpp = ( # Objective-C++ qw( mii ), ); +my @source_no_preprocess_compile_ada = ( + # Ada body + qw( adb ), + # If you add another file, fix use of @source_no_preprocess_compile_ada + # below (search for $compile_ada). +); my @source_no_preprocess_compile = ( # C qw( i ), @@ -90,8 +96,8 @@ my @source_no_preprocess_compile = ( qw( mi ), # Fortran qw( f for ftn f90 f95 f03 f08 ), - # Ada body - qw( adb ), + # Ada + @source_no_preprocess_compile_ada, ); my @source_no_preprocess_no_compile = ( # Assembly @@ -287,6 +293,20 @@ my $option_color; # FUNCTIONS +# Only works for single-level arrays with no undef values. Thanks to perlfaq4. +sub array_equal { + my ($first_ref, $second_ref) = @_; + + return 0 if scalar @{$first_ref} != scalar @{$second_ref}; + + my $length = scalar @{$first_ref}; + for (my $i = 0; $i < $length; $i++) { + return 0 if $first_ref->[$i] ne $second_ref->[$i]; + } + + return 1; +} + sub error_flags { my ($message, $missing_flags_ref, $flag_renames_ref, $line) = @_; @@ -640,6 +660,11 @@ 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 used + # for performance reasons. + my $ada = 0; + while (my $line = <$fh>) { # Detect architecture automatically unless overridden. For buildd logs # only, doesn't use the dpkg-buildpackage header. Necessary to ignore @@ -699,6 +724,11 @@ foreach my $file (@ARGV) { } next FILE; } + + # Ada compiler. + if ($line =~ /\bgnat\b/) { + $ada = 1; + } } # We skip over unimportant lines at the beginning of the log to @@ -905,6 +935,22 @@ foreach my $file (@ARGV) { @ldflags = (@ldflags, @def_ldflags_bindnow); } + # Stores normal CFLAGS when @cflags_ada are temporarily used. + my @cflags_backup; + # Ada CFLAGS. + my @cflags_ada = @cflags; + # Ada doesn't support format hardening flags, see #680117 for more + # information. Filter them out if ada is used. + if ($ada and $harden_format) { + @cflags_ada = 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 # as long as @def_cppflags_fortify contains only one variable. @@ -1029,13 +1075,22 @@ LINE: } } + my $compile_cpp = 0; + my $compile_ada = 0; # Assume CXXFLAGS are required when a C++ file is specified in the # compiler line. - my $compile_cpp = 0; if ($compile 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 $compile + and array_equal(\@extensions, + \@source_no_preprocess_compile_ada)) { + $compile_ada = 1; + @cflags_backup = @cflags; + @cflags = @cflags_ada; } if ($option_buildd) { @@ -1100,6 +1155,11 @@ LINE: $statistics{link_missing}++; } } + + # Restore normal CFLAGS. + if ($compile_ada) { + @cflags = @cflags_backup; + } } } diff --git a/t/logs/ada b/t/logs/ada new file mode 100644 index 0000000..bc801c2 --- /dev/null +++ b/t/logs/ada @@ -0,0 +1,16 @@ +Build-Depends: ..., gnat, gnat-4.6, ... + +dpkg-buildpackage: source package ada package + + +gcc-4.6 -c -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security test.c +gcc-4.6 -c -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -gnatn -gnatw.eH test-a.adb +gcc-4.6 -c -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -gnatn -gnatw.eH test-b.adb +gcc-4.6 -c -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -gnatn -gnatw.eH test-c.adb +gcc-4.6 -c -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -gnatn -gnatw.eH test-d.ads + +/usr/bin/gcc-4.6 -shared -lgnat-4.6 -o libtest.so.2 test-a.o test-b.o test-c.o -Wl,-z,relro -Wl,--as-needed +/usr/bin/gcc-4.6 -shared -lgnat-4.6 -o libtest.so.2 test-a.o test-b.o test-c.o -Wl,--as-needed + +gcc -c -g -O2 test.c +gcc -g -O2 test.c diff --git a/t/tests.t b/t/tests.t index 0811ef7..0e1833e 100644 --- a/t/tests.t +++ b/t/tests.t @@ -19,7 +19,7 @@ use strict; use warnings; -use Test::More tests => 194; +use Test::More tests => 196; sub is_blhc { @@ -748,6 +748,19 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): g++-4.6 -Wl,-z,defs -o tes '; +# ada + +is_blhc 'ada', '', 8, + 'CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc-4.6 -c -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security test.c +LDFLAGS missing (-Wl,-z,relro): /usr/bin/gcc-4.6 -shared -lgnat-4.6 -o libtest.so.2 test-a.o test-b.o test-c.o -Wl,--as-needed +CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): gcc -c -g -O2 test.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c -g -O2 test.c +CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): gcc -g -O2 test.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 test.c +LDFLAGS missing (-Wl,-z,relro): gcc -g -O2 test.c +'; + + # libtool is_blhc 'libtool', '--bindnow', 8, -- 2.43.2