From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 3F95D3858D28 for ; Thu, 16 Dec 2021 17:12:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F95D3858D28 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: from tarox.wildebeest.org (83-87-18-245.cable.dynamic.v4.ziggo.nl [83.87.18.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 23949302FBA5; Thu, 16 Dec 2021 18:12:29 +0100 (CET) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id D0483425A473; Thu, 16 Dec 2021 18:12:28 +0100 (CET) Message-ID: Subject: Re: [PATCH] libelf: Use offsetof to get field of unaligned From: Mark Wielaard To: Florian Weimer Cc: elfutils-devel@sourceware.org Date: Thu, 16 Dec 2021 18:12:28 +0100 In-Reply-To: <87wnk5o5kn.fsf@oldenburg.str.redhat.com> References: <20211215220544.625735-1-mark@klomp.org> <87wnk5o5kn.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Evolution 3.28.5 (3.28.5-10.el7) Mime-Version: 1.0 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Dec 2021 17:12:31 -0000 Hi Florian, On Wed, 2021-12-15 at 23:40 +0100, Florian Weimer via Elfutils-devel wrote: > * Mark Wielaard: >=20 > > This seems a wrong warning since we aren't accessing the field member > > of the struct, but are taking the address of it. But we can do the > > same by adding the field offsetof to the base address. Which doesn't > > trigger a runtime error. >=20 > I think the warning is correct. I believe it is motivated by the GCC > optimizers using this to infer alignment of the original pointer. It > won't make a difference for this expression, but it can cause crashes > elsewhere with strict-alignment targets. I think that does make sense. I tweaked to commit message a bit before pushing the commit to say: We aren't actually accessing the field member of the struct, but are taking the address of it. Which the compiler can take as a hint that the address is correctly aligned. But we can do the same by adding the field offsetof to the base address. Which doesn't trigger a runtime error. Thanks, Mark