Define _FORTIFY_SOURCE in common-defs.h
Commit Message
This defines _FORTIFY_SOURCE in common-defs.h. This seems like a
sensible safety measure, and also it may help avoid build problems
with -Wunused-result on distros that already define _FORTIFY_SOURCE by
default.
Tested by the buildbot.
gdb/ChangeLog
2018-08-10 Tom Tromey <tom@tromey.com>
* common/common-defs.h (_FORTIFY_SOURCE): Define.
---
gdb/ChangeLog | 4 ++++
gdb/common/common-defs.h | 12 ++++++++++++
2 files changed, 16 insertions(+)
Comments
On 2018-08-10 17:24, Tom Tromey wrote:
> This defines _FORTIFY_SOURCE in common-defs.h. This seems like a
> sensible safety measure, and also it may help avoid build problems
> with -Wunused-result on distros that already define _FORTIFY_SOURCE by
> default.
I rarely build with optimization enabled, so I wouldn't notice, but at
least it will help reproduce this kind of problem.
Thanks,
Simon
@@ -1,3 +1,7 @@
+2018-08-10 Tom Tromey <tom@tromey.com>
+
+ * common/common-defs.h (_FORTIFY_SOURCE): Define.
+
2018-08-10 Keith Seitz <keiths@redhat.com>
* compile/compile-c-support.c (add_code_header, add_code_footer):
@@ -59,6 +59,18 @@
#define __STDC_LIMIT_MACROS 1
#define __STDC_FORMAT_MACROS 1
+/* Some distros enable _FORTIFY_SOURCE by default, which on occasion
+ has caused build failures with -Wunused-result when a patch is
+ developed on a distro that does not enable _FORTIFY_SOURCE. We
+ 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. */
+
+#if defined __OPTIMIZE__ && __OPTIMIZE__ > 0
+#define _FORTIFY_SOURCE 2
+#endif
+
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>