public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Define _FORTIFY_SOURCE in common-defs.h
Date: Fri, 10 Aug 2018 21:24:00 -0000	[thread overview]
Message-ID: <20180810212402.19814-1-tom@tromey.com> (raw)

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(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e046b64b5c6..810431f2bfe 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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):
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index 80f1ff4f560..58445b16110 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -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>
-- 
2.17.1

             reply	other threads:[~2018-08-10 21:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 21:24 Tom Tromey [this message]
2018-08-10 21:33 ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180810212402.19814-1-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).