From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1674595762; bh=fy2tKlpDGwvEz/8ELuGsQmpcLPrF+VWJ43WQOaC7Yww=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=sWg2T/78+VrSITzuLA/K2zFE+Oy5qjCzvWghHhSfwZPbznd9Lc6f1II+FpSLaK6Le 0nEnuUT/WnOJJGwGK6gf6RFVcZXrSmPu0ebhf4p8DWqOmShESj/HoXERn0ENAxLU0R VMm3c7wtQR9QYw1mtJ5EsFKTNWemOYL06Zbi+jrA= 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> From: Simon Marchi In-Reply-To: <20230124201624.875658-1-mark@klomp.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,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 List-Id: 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