Subject: bug#17793: closed (Re: bug#17793: Gentoo gcc 4.8.3 build problem: -fstack-protector [also, Re: bug#17754])

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 17 Jun 2014 19:30:10 +0000

Your bug report

#17793: Gentoo gcc 4.8.3 build problem: -fstack-protector [also, Re: bug#17754]

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
17793: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17793
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#17793: Gentoo gcc 4.8.3 build problem: -fstack-protector [also, Re: bug#17754]
From: Paul Eggert <[email-masked]>
To: behoffski <[email-masked]>, [email-masked]
Date: Tue, 17 Jun 2014 12:28:54 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

behoffski wrote:

>          In file included from mbsstr.c:32:0:
>          str-kmp.h: In function 'knuth_morris_pratt':
>          str-kmp.h:35:1: error: stack protector not protecting local
> variables: variable length buffer [-Werror=stack-protector]
>           knuth_morris_pratt (const UNIT *haystack,
>           ^

These warnings don't indicate any bugs in the code; they're merely about 
incomplete run-time checking in the underlying implementation.  I was 
particularly amused by a refusal to compile a function on the grounds 
that its code doesn't use the stack!

So let's just disable the warnings.  I pushed the attached patch.

> Valgrind and -fsanitize=address are incompatible

Thanks, I didn't know that.  Too bad, but understandable.  Neither tool 
dominates the other, so I guess we'll have to use them separately.
From 8ade09bf8173b39e42ef3dcbcf75721809541d69 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Tue, 17 Jun 2014 12:09:16 -0700
Subject: [PATCH] build: avoid -Wstack-protector

This allows the use of --enable-gcc-warnings on Gentoo and Ubuntu.
See: http://bugs.gnu.org/17793
* configure.ac (WERROR_CFLAGS): Avoid -Wstack-protector.

This can be worked around, but the cure is worse than the disease.
---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configure.ac b/configure.ac
index 7ac2937..3315855 100644
--- a/configure.ac
+++ b/configure.ac
@@ -117,6 +117,7 @@ if test "$gl_gcc_warnings" = yes; then
   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
   nw="$nw -Wpadded"                 # Our structs are not padded
   nw="$nw -Wvla"                    # warnings in gettext.h
+  nw="$nw -Wstack-protector"        # generates false alarms for useful code
   nw="$nw -Wswitch-default"         # Too many warnings for now
   nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
   nw="$nw -Winline"                 # streq.h's streq4, streq6 and strcaseeq6
-- 
1.9.3

Subject: Gentoo gcc 4.8.3 build problem: -fstack-protector [also, Re: bug#17754]
From: behoffski <[email-masked]>
To: [email-masked]
Date: Tue, 17 Jun 2014 20:16:37 +0930
List-Id: <debbugs-submit.debbugs.gnu.org>

G'day,

[Re: bug#17754: There is a bugfix in 4.8.3 regarding code flow analysis
that covers the reported case.  Now that Gentoo has added gcc 4.8.3 to
its package database, I've rebuilt, and the compiler now correctly
detects that the variable will always be initialised before it is used.
The unwanted behaviour in gcc 4.8.2 was part of the new "-Og" feature.]

----

New potential portability problem:  When Gentoo released their
repackaged gcc 4.8.3 (in the last 48 hours or so), they also released a
warning NEWS item regarding gcc 4.8.3 defaulting to -fstack-protector,
and gcc 4.9 onwards defaulting to -fstack-protector-strong:

         2014-06-15-gcc48_ssp
           Title                     GCC 4.8.3 defaults to -fstack-protector
           Author                    Ryan Hill <[email-masked]>
           Posted                    2014-06-15
           Revision                  1

         Beginning with GCC 4.8.3, Stack Smashing Protection (SSP) will be
         enabled by default.  The 4.8 series will enable -fstack-protector
         while 4.9 and later enable -fstack-protector-strong. [...]

         [...] these features [...] can be disabled with -fno-stack-protector.

I've just installed gcc 4.8.3, and have found that the -fstack-protector
feature results in a compilation error in lib/mbsstr.c:

         In file included from mbsstr.c:32:0:
         str-kmp.h: In function 'knuth_morris_pratt':
         str-kmp.h:35:1: error: stack protector not protecting local variables: variable length buffer [-Werror=stack-protector]
          knuth_morris_pratt (const UNIT *haystack,
          ^
         mbsstr.c: In function 'knuth_morris_pratt_multibyte':
         mbsstr.c:40:1: error: stack protector not protecting local variables: variable length buffer [-Werror=stack-protector]
          knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
          ^
         cc1: all warnings being treated as errors

Re-running './configure CFLAGS="-Og -fsanitize=address -fno-stack-protector"
results in a clean build, and "make check" passes.

On a slightly-related note, Valgrind and -fsanitize=address are incompatible
(overlapping memory space usage).  Configuring with
"CFLAGS=-Og -fno-stack-protector" (no "-fsanitize=address") lets "make check"
run successfully  with Jim's Valgrind scripts referencing built images in
grep/src/.vg-tmp/.

cheers,

behoffski (Brenton Hoff)
Programmer, Grouse Software