From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id tiJeKA+0mWDAKwAAWB0awg (envelope-from ) for ; Mon, 10 May 2021 18:30:39 -0400 Received: by simark.ca (Postfix, from userid 112) id 9720C1F11C; Mon, 10 May 2021 18:30:39 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 EAB321E813 for ; Mon, 10 May 2021 18:30:38 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16D183857C73; Mon, 10 May 2021 22:30:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16D183857C73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620685838; bh=Ux8hOD1PJ0GbyhiEYtUK8CRjU446IC60KZ1pbQ4OyP8=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lapnLHe+ExXA0mPi3l1oJeKGsEOcy3K1NZ4r3mhNXpwSqjtOPz0kchrMHzhxu+sg5 Z0cmJxlRxQf+6VBFiRaDOw/KiUgoawkryJ2WVqoRJ4SaDTrvyCiZ6iztE8ye/cvIrR +Nw4dyTPQz0XwPQBltaOzmLXUUNcKvHU1oAlreFg= Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id DBDD23857C73 for ; Mon, 10 May 2021 22:30:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DBDD23857C73 Received: from vapier (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0714A335D97; Mon, 10 May 2021 22:30:33 +0000 (UTC) Date: Mon, 10 May 2021 18:30:33 -0400 To: Luis Machado Subject: Re: [PATCH] [sim] Fix build failure in d10v sim Message-ID: Mail-Followup-To: Luis Machado , gdb-patches@sourceware.org References: <20210510191423.3627307-1-luis.machado@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210510191423.3627307-1-luis.machado@linaro.org> 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: Mike Frysinger via Gdb-patches Reply-To: Mike Frysinger Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 10 May 2021 16:14, Luis Machado via Gdb-patches wrote: > While building all targets on Ubuntu 20.04/aarch64, I ran into the following > build error: > > In file included from /usr/include/string.h:495, > from ../../bfd/bfd.h:48, > from ../../../../repos/binutils-gdb/sim/d10v/interp.c:4: > In function 'memset', > inlined from 'sim_create_inferior' at ../../../../repos/binutils-gdb/sim/d10v/interp.c:1146:3: > /usr/include/aarch64-linux-gnu/bits/string_fortified.h:71:10: error: ‘__builtin_memset’ offset [33, 616] from the object at ‘State’ is out of the bounds of referenced subobject ‘regs’ with type ‘reg_t[16]’ {aka ‘short unsigned int[16]’} at offset 0 [-Werror=array-bounds] > 71 | return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest)); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > cc1: all warnings being treated as errors > make[3]: *** [Makefile:558: interp.o] Error 1 > > I looked at a different sim (cr16), and it zeroes out the entire State, not > just the registers. it's clearing more than just the regs. it's clearing all the members in the state struct from regs up to mem. so regs, cregs, sp, a, slot, etc... if you want to change it, the comment in the header probably needs adjusting. > It is unclear why we have the casts to uintptr. because pointer math on diff types isn't allowed, and the 3rd arg to memset needs to be a scalar integer. so casting to uintptr_t is the correct way to calculate this value. > The following patch fixes this for me. > > - memset (&State.regs, 0, (uintptr_t)&State.mem - (uintptr_t)&State.regs); > + memset (&State, 0, sizeof (State)); i think changing the first arg to &State is sufficient and keeping the mem-regs calculation. and maybe add a static assert that &State == &State.regs ? this code needs to be rewritten fundamentally at some point :/. -mike