Fix PR gdb/23835: Don't redefine _FORTIFY_SOURCE if it's already defined
authorSergio Durigan Junior <sergiodj@redhat.com>
Tue, 30 Oct 2018 21:37:03 +0000 (17:37 -0400)
committerSergio Durigan Junior <sergiodj@redhat.com>
Wed, 31 Oct 2018 21:42:43 +0000 (17:42 -0400)
Gentoo has a local GCC patch which always defines _FORTIFY_SOURCE=2.
This causes a build problem when building GDB there, because
"common/common-defs.h" also defines _FORTIFY_SOURCE=2:

    CXX    gdb.o
  In file included from ../../gdb/defs.h:28:0,
   from ../../gdb/gdb.c:19:
  ../../gdb/common/common-defs.h:71:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
   #define _FORTIFY_SOURCE 2

  <built-in>: note: this is the location of the previous definition
  cc1plus: all warnings being treated as errors
  make[2]: *** [Makefile:1619: gdb.o] Error 1

Even though it is questionable whether Gentoo's approach is the
correct one:

  https://jira.mongodb.org/browse/SERVER-29982
  https://bugs.gentoo.org/621036

it is still possible for GDB to be a bit more robust here and make
sure it just defines _FORTIFY_SOURCE if it hasn't been defined
already.  This patch does that.

Tested by rebuilding and making sure the macro was defined.

gdb/ChangeLog:
2018-10-31  Sergio Durigan Junior  <sergiodj@redhat.com>

PR gdb/23835
* common/common-defs.h: Don't redefine _FORTIFY_SOURCE if it's
already defined.

gdb/ChangeLog
gdb/common/common-defs.h

index 112785e920900f7cfaab7ea8f3ebd73810a53d46..6d9816e7044b8adfba8ff709ad850ac326dcb383 100644 (file)
@@ -1,3 +1,9 @@
+2018-10-31  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       PR gdb/23835
+       * common/common-defs.h: Don't redefine _FORTIFY_SOURCE if it's
+       already defined.
+
 2018-10-31  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>
 
        * ppc-linux-nat.c: Include nat/linux-ptrace.h.
index 58445b161105f7c74a454f00703077508b8b0f05..86f7c1ab9ae2e0cfc6d34c7751d664c2081bebda 100644 (file)
    enable it here in order to try to catch these problems earlier;
    plus this seems like a reasonable safety measure.  The check for
    optimization is required because _FORTIFY_SOURCE only works when
-   optimization is enabled.  */
+   optimization is enabled.  If _FORTIFY_SOURCE is already defined,
+   then we don't do anything.  */
 
-#if defined __OPTIMIZE__ && __OPTIMIZE__ > 0
+#if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__ > 0
 #define _FORTIFY_SOURCE 2
 #endif
 
This page took 0.035437 seconds and 4 git commands to generate.