diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 112785e9209..6d9816e7044 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index 58445b16110..86f7c1ab9ae 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -65,9 +65,10 @@
    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