From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id RxLDEMZN0GOkliAAWB0awg (envelope-from ) for ; Tue, 24 Jan 2023 16:29:42 -0500 Received: by simark.ca (Postfix, from userid 112) id 357AC1E128; Tue, 24 Jan 2023 16:29:42 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=fncReNKu; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_HI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BDC381E110 for ; Tue, 24 Jan 2023 16:29:41 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5669D3858C53 for ; Tue, 24 Jan 2023 21:29:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5669D3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674595781; bh=Dbw8ACRKXh5Pv7/uR94C56X4eVfeUW+qmyC5P3fBd4w=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fncReNKuB9z6jBGx+1o5mOQgRnk/+ekvlREej87ie/rNXdIhOPcmNCsI9rnkH6d0h uDuLEuYkEehcOqShODp9Wm2ABWp0DliDhveGBwjjK38Lg0y9xtNPOM9DW7WAJLy9iD oHcB4bsW/6JpCEl0HxM9S+lra70g0NHL7h10DsRI= Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id B31213858D1E for ; Tue, 24 Jan 2023 21:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B31213858D1E Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8C8DD1E110; Tue, 24 Jan 2023 16:29:21 -0500 (EST) Message-ID: <2f5e28eb-a5f2-0995-506f-b6632333c7b2@simark.ca> Date: Tue, 24 Jan 2023 16:29:20 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCHv3] gdb: Replace memcpy with std::copy to avoid some g++ warnings on sparc Content-Language: en-US To: Mark Wielaard , gdb-patches@sourceware.org, John Baldwin Cc: Sam James , Tom Tromey References: <20230124201624.875658-1-mark@klomp.org> In-Reply-To: <20230124201624.875658-1-mark@klomp.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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 > > > 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 > > > 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