Message ID | 20230124201624.875658-1-mark@klomp.org |
---|---|
State | Superseded |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 218043858428 for <patchwork@sourceware.org>; Tue, 24 Jan 2023 20:16:51 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from csb.redhat.com (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 418F93858D1E for <gdb-patches@sourceware.org>; Tue, 24 Jan 2023 20:16:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 418F93858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: by csb.redhat.com (Postfix, from userid 10916) id BD7D8CF467; Tue, 24 Jan 2023 21:16:34 +0100 (CET) From: Mark Wielaard <mark@klomp.org> To: gdb-patches@sourceware.org Cc: Simon Marchi <simark@simark.ca>, Sam James <sam@gentoo.org>, Tom Tromey <tom@tromey.com>, Mark Wielaard <mark@klomp.org> Subject: [PATCHv3] gdb: Replace memcpy with std::copy to avoid some g++ warnings on sparc Date: Tue, 24 Jan 2023 21:16:24 +0100 Message-Id: <20230124201624.875658-1-mark@klomp.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3037.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEXHASH_WORD, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
[PATCHv3] gdb: Replace memcpy with std::copy to avoid some g++ warnings on sparc
|
|
Commit Message
Mark Wielaard
Jan. 24, 2023, 8:16 p.m. UTC
For some reason g++ 12.2.1 on sparc produces a spurious warnings for stringop-overread and restrict in fbsd-tdep.c for some memcpy calls. Use std::copy to avoid those. In function ‘void* memcpy(void*, const void*, size_t)’, inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:666:10: /usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified bound 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=] In function ‘void* memcpy(void*, const void*, size_t)’, inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:673:10: /usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 18446744073709551612 bytes at offsets 0 and 0 overlaps 9223372036854775801 bytes at offset -9223372036854775805 [-Werror=restrict] gdb/ChangeLog: * fbsd-tdep.c (fbsd_make_note_desc): Use std::copy instead of memcpy. --- V3: Drop diagnostic suppressions just use std::copy V2: Fix typos and add example errors to commit messages gdb/fbsd-tdep.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On 1/24/23 15:16, Mark Wielaard wrote: > For some reason g++ 12.2.1 on sparc produces a spurious warnings for > stringop-overread and restrict in fbsd-tdep.c for some memcpy calls. > Use std::copy to avoid those. > > In function ‘void* memcpy(void*, const void*, size_t)’, > inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:666:10: > /usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified bound 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=] > > In function ‘void* memcpy(void*, const void*, size_t)’, > inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:673:10: > /usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 18446744073709551612 bytes at offsets 0 and 0 overlaps 9223372036854775801 bytes at offset -9223372036854775805 [-Werror=restrict] > > gdb/ChangeLog: > > * fbsd-tdep.c (fbsd_make_note_desc): Use std::copy instead > of memcpy. > --- > > V3: Drop diagnostic suppressions just use std::copy > V2: Fix typos and add example errors to commit messages > > gdb/fbsd-tdep.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c > index 203390d9880..ebc15543149 100644 > --- a/gdb/fbsd-tdep.c > +++ b/gdb/fbsd-tdep.c > @@ -662,8 +662,9 @@ fbsd_make_note_desc (enum target_object object, uint32_t structsize) > return buf; > > gdb::byte_vector desc (sizeof (structsize) + buf->size ()); > - memcpy (desc.data (), &structsize, sizeof (structsize)); > - memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ()); > + std::copy (&structsize, &structsize + sizeof (structsize), desc.data ()); > + std::copy (buf->data (), desc.data () + sizeof (structsize), > + desc.data () + sizeof (structsize)); I think the second argument to the second std::copy call should have `buf->data ()`, not `desc.data (). Otherwise, LGTM. However, it would be nice to have the approval from John Baldwin. Simon
Hi Simon, On Tue, Jan 24, 2023 at 04:29:20PM -0500, Simon Marchi wrote: > > diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c > > index 203390d9880..ebc15543149 100644 > > --- a/gdb/fbsd-tdep.c > > +++ b/gdb/fbsd-tdep.c > > @@ -662,8 +662,9 @@ fbsd_make_note_desc (enum target_object object, uint32_t structsize) > > return buf; > > > > gdb::byte_vector desc (sizeof (structsize) + buf->size ()); > > - memcpy (desc.data (), &structsize, sizeof (structsize)); > > - memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ()); > > + std::copy (&structsize, &structsize + sizeof (structsize), desc.data ()); > > + std::copy (buf->data (), desc.data () + sizeof (structsize), > > + desc.data () + sizeof (structsize)); > > I think the second argument to the second std::copy call should have > `buf->data ()`, not `desc.data (). Otherwise, LGTM. However, it would > be nice to have the approval from John Baldwin. Bah, what a stupid typo. You are right of course. Sorry. v4 coming up. Thanks, Mark
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index 203390d9880..ebc15543149 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -662,8 +662,9 @@ fbsd_make_note_desc (enum target_object object, uint32_t structsize) return buf; gdb::byte_vector desc (sizeof (structsize) + buf->size ()); - memcpy (desc.data (), &structsize, sizeof (structsize)); - memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ()); + std::copy (&structsize, &structsize + sizeof (structsize), desc.data ()); + std::copy (buf->data (), desc.data () + sizeof (structsize), + desc.data () + sizeof (structsize)); return desc; }