Subject: bug#12714: [PATCH] build: do not redefine _FORTIFY_SOURCE

From: Mike Frysinger <[email-masked]>
Date: Tue, 23 Oct 2012 15:50:42 -0400

On Tuesday 23 October 2012 15:26:14 Jim Meyering wrote:
> Mike Frysinger wrote:
> > If the active compiler or flags have already defined _FORTIFY_SOURCE,
> > don't go overriding that.  Otherwise we get a lot of spew about the
> > flag being redefined.
> > 
> > * configure.ac (FORTIFY_SOURCE): Check if _FORTIFY_SOURCE is defined.
> > ---
> > 
> >  configure.ac | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/configure.ac b/configure.ac
> > index e5e05be..6504144 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -170,7 +170,7 @@ if test "$gl_gcc_warnings" = yes; then
> > 
> >    AH_VERBATIM([FORTIFY_SOURCE],
> >    [/* Enable compile-time and run-time bounds-checking, and some
> >    warnings,
> >    
> >        without upsetting glibc 2.15+. */
> > 
> > -   #if defined __OPTIMIZE__ && __OPTIMIZE__
> > +   #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
> > 
> >     # define _FORTIFY_SOURCE 2
> >     #endif
> >    
> >    ])
> 
> Thanks.  Please adjust the log (or just tell us and we'll adjust it)
> so that we know which compiler motivates this change.

Ubuntu will enable _FORTIFY_SOURCE by default.  not sure about Debian.  Gentoo 
has been doing it for a while.

in the past, we could just default it to 2 (in which case this wouldn't 
normally trigger a warning), but as the comment states here, newer glibc is 
picky and will error out if you have -D_FORTIFY_SOURCE=2 -O0.  so we had to 
update the default to read:
	_FORTIFY_SOURCE=((defined __OPTIMIZE__ && __OPTIMIZE__ > 0) ? 2 : 0)

in which case this code triggers lots of false warnings.

however, that isn't the only way to trigger this.  if the user themselves do:
	CPPFLAGS=-D_FORTIFY_SOURCE=1 ./configure
it'll cause warnings.
-mike