From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 85144 invoked by alias); 25 Apr 2017 10:02:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 85106 invoked by uid 89); 25 Apr 2017 10:02:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=HCc:D*ca X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 10:02:50 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5BE865D17; Tue, 25 Apr 2017 10:02:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A5BE865D17 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A5BE865D17 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5546F7FE80; Tue, 25 Apr 2017 10:02:50 +0000 (UTC) Subject: Re: [PATCH 1/5] Poison non-POD memset & non-trivially-copyable memcpy/memmove To: Yao Qi References: <1492050475-9238-1-git-send-email-palves@redhat.com> <1492050475-9238-2-git-send-email-palves@redhat.com> <44b612a2b2dadc142c054a1967dc2600@polymtl.ca> <86d1c0sxnf.fsf@gmail.com> Cc: Simon Marchi , gdb-patches@sourceware.org From: Pedro Alves Message-ID: <83f0f951-ce42-1b71-e970-816a92c8478f@redhat.com> Date: Tue, 25 Apr 2017 10:02:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2017-04/txt/msg00662.txt.bz2 On 04/25/2017 10:24 AM, Pedro Alves wrote: > On 04/25/2017 09:24 AM, Yao Qi wrote: >> Pedro Alves writes: >> >> Hi Pedro, >> >>> +/* True if "T *" is relocatable. I.e., copyable with memcpy/memmove. >>> + I.e., T is either trivially copyable, or void. */ >>> +template >>> +struct IsRelocatable >>> + : gdb::Or, >>> + std::is_trivially_copyable> >>> +{}; >> >> 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> >> ^ >> > > 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 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 * 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 + * 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 + * 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 >>> 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 >>> 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 +/* 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