From: Pedro Alves <palves@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/5] Poison non-POD memset & non-trivially-copyable memcpy/memmove
Date: Tue, 25 Apr 2017 10:02:00 -0000 [thread overview]
Message-ID: <83f0f951-ce42-1b71-e970-816a92c8478f@redhat.com> (raw)
In-Reply-To: <c0efc486-6d2e-f1f9-b7f4-b0b42220d927@redhat.com>
On 04/25/2017 10:24 AM, Pedro Alves wrote:
> On 04/25/2017 09:24 AM, Yao Qi wrote:
>> Pedro Alves <palves@redhat.com> writes:
>>
>> Hi Pedro,
>>
>>> +/* True if "T *" is relocatable. I.e., copyable with memcpy/memmove.
>>> + I.e., T is either trivially copyable, or void. */
>>> +template<typename T>
>>> +struct IsRelocatable
>>> + : gdb::Or<std::is_void<T>,
>>> + std::is_trivially_copyable<T>>
>>> +{};
>>
>> This breaks the build with gcc 4.8,
>>
>> In file included from ../../binutils-gdb/gdb/common/common-defs.h:85:0,
>> from ../../binutils-gdb/gdb/defs.h:28,
>> from ../../binutils-gdb/gdb/gdb.c:19:
>> ../../binutils-gdb/gdb/common/poison.h:66:6: error: âis_trivially_copyableâ is not a member of âstdâ
>> std::is_trivially_copyable<T>>
>> ^
>>
>
> Sorry, I thought I had tested gcc 4.8, but clearly I did not. I'll fix it
> as soon as I have a chance, probably by disabling the poisoning on
> older compilers.
Like this. I went ahead and pushed it.
From debed3db4887483552103da36d180967ef0dca5f Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Tue, 25 Apr 2017 10:58:57 +0100
Subject: [PATCH] Fix build on gcc < 5 (std::is_trivially_copyable missing)
Ref: https://sourceware.org/ml/gdb-patches/2017-04/msg00660.html
Simply skip the poisoning on older compilers.
gdb/ChangeLog:
2017-04-25 Pedro Alves <palves@redhat.com>
* common/poison.h [!HAVE_IS_TRIVIALLY_COPYABLE] (IsRelocatable)
(BothAreRelocatable, memcopy, memmove): Don't define.
* common/traits.h (__has_feature, HAVE_IS_TRIVIALLY_COPYABLE): New
macros.
---
gdb/ChangeLog | 7 +++++++
gdb/common/poison.h | 4 ++++
gdb/common/traits.h | 13 +++++++++++++
3 files changed, 24 insertions(+)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 26e6370..d1c1942 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2017-04-25 Pedro Alves <palves@redhat.com>
+ * common/poison.h [!HAVE_IS_TRIVIALLY_COPYABLE] (IsRelocatable)
+ (BothAreRelocatable, memcopy, memmove): Don't define.
+ * common/traits.h (__has_feature, HAVE_IS_TRIVIALLY_COPYABLE): New
+ macros.
+
+2017-04-25 Pedro Alves <palves@redhat.com>
+
* common/common-defs.h: Include "common/poison.h".
* common/function-view.h: (Not, Or, Requires): Move to traits.h
and adjust.
diff --git a/gdb/common/poison.h b/gdb/common/poison.h
index a875568..37dd35e 100644
--- a/gdb/common/poison.h
+++ b/gdb/common/poison.h
@@ -55,6 +55,8 @@ template <typename T,
typename = gdb::Requires<gdb::Not<IsMemsettable<T>>>>
void *memset (T *s, int c, size_t n) = delete;
+#if HAVE_IS_TRIVIALLY_COPYABLE
+
/* Similarly, poison memcpy and memmove of non trivially-copyable
types, which is undefined. */
@@ -80,4 +82,6 @@ template <typename D, typename S,
typename = gdb::Requires<gdb::Not<BothAreRelocatable<D, S>>>>
void *memmove (D *dest, const S *src, size_t n) = delete;
+#endif /* HAVE_IS_TRIVIALLY_COPYABLE */
+
#endif /* COMMON_POISON_H */
diff --git a/gdb/common/traits.h b/gdb/common/traits.h
index 4f7161b..8c41b03 100644
--- a/gdb/common/traits.h
+++ b/gdb/common/traits.h
@@ -20,6 +20,19 @@
#include <type_traits>
+/* GCC does not understand __has_feature. */
+#if !defined(__has_feature)
+# define __has_feature(x) 0
+#endif
+
+/* HAVE_IS_TRIVIALLY_COPYABLE is defined as 1 iff
+ std::is_trivially_copyable is available. GCC only implemented it
+ in GCC 5. */
+#if (__has_feature(is_trivially_copyable) \
+ || (defined __GNUC__ && __GNUC__ >= 5))
+# define HAVE_IS_TRIVIALLY_COPYABLE 1
+#endif
+
namespace gdb {
/* Pre C++14-safe (CWG 1558) version of C++17's std::void_t. See
--
2.5.5
next prev parent reply other threads:[~2017-04-25 10:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-13 2:27 [PATCH 0/4] " Pedro Alves
2017-04-13 2:28 ` [PATCH 3/5] Don't memset non-POD types: struct bp_location Pedro Alves
2017-04-13 2:28 ` [PATCH 4/5] Don't memset non-POD types: struct btrace_insn Pedro Alves
2017-04-13 7:57 ` Metzger, Markus T
2017-04-25 1:11 ` Pedro Alves
2017-04-13 2:28 ` [PATCH 1/5] Poison non-POD memset & non-trivially-copyable memcpy/memmove Pedro Alves
2017-04-20 3:27 ` Simon Marchi
2017-04-25 1:14 ` Pedro Alves
2017-04-25 1:19 ` Pedro Alves
2017-04-25 8:24 ` Yao Qi
2017-04-25 9:24 ` Pedro Alves
2017-04-25 10:02 ` Pedro Alves [this message]
2017-04-24 1:12 ` Simon Marchi
2017-04-24 1:53 ` Simon Marchi
2017-04-27 13:58 ` Pedro Alves
2017-04-30 1:51 ` Simon Marchi
2017-05-17 11:35 ` Pedro Alves
2017-05-17 13:11 ` Simon Marchi
2017-05-17 13:20 ` Pedro Alves
2017-04-27 13:57 ` Pedro Alves
2017-04-13 2:28 ` [PATCH 2/5] Don't memcpy non-trivially-copyable types: Make enum_flags triv. copyable Pedro Alves
2017-04-20 3:34 ` Simon Marchi
2017-04-25 1:10 ` Pedro Alves
2017-04-13 2:35 ` [PATCH 5/5] Don't memset non-POD types: struct breakpoint Pedro Alves
2017-04-20 4:00 ` Simon Marchi
2017-04-25 1:11 ` Pedro Alves
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=83f0f951-ce42-1b71-e970-816a92c8478f@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=qiyaoltc@gmail.com \
--cc=simon.marchi@polymtl.ca \
/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