public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: elfutils-devel@sourceware.org
Subject: Re: [PATCH] libelf: Use offsetof to get field of unaligned
Date: Thu, 16 Dec 2021 18:12:28 +0100	[thread overview]
Message-ID: <d50dd8f1c66f507742583bc04c479ebedccb6a1e.camel@klomp.org> (raw)
In-Reply-To: <87wnk5o5kn.fsf@oldenburg.str.redhat.com>

Hi Florian,

On Wed, 2021-12-15 at 23:40 +0100, Florian Weimer via Elfutils-devel
wrote:
> * Mark Wielaard:
> 
> > 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.
> 
> 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

      reply	other threads:[~2021-12-16 17:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15 22:05 Mark Wielaard
2021-12-15 22:40 ` Florian Weimer
2021-12-16 17:12   ` Mark Wielaard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d50dd8f1c66f507742583bc04c479ebedccb6a1e.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=fweimer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).