public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Mark Wielaard <mark@klomp.org>
Cc: gcc@gcc.gnu.org
Subject: Re: [RFC] Change PCH "checksum"
Date: Tue, 26 Feb 2019 08:33:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1902260923260.23386@zhemvz.fhfr.qr> (raw)
In-Reply-To: <4b144c8b12b3413b1ec450d9ba468b71dd5b4547.camel@klomp.org>

On Mon, 25 Feb 2019, Mark Wielaard wrote:

> On Fri, 2019-02-22 at 12:29 +0100, Richard Biener wrote:
> > +struct build_id_note {
> > +    /* The NHdr.  */
> > +    uint32_t namesz;
> > +    uint32_t descsz;
> > +    uint32_t type;
> > +
> > +    char name[4]; /* Note name for build-id is "GNU\0" */
> > +    unsigned char build_id[16];
> > +};
> 
> Note that build-ids can be of different sizes depending on the style
> used to generate them, you get the correct size by looking at the
> descsz.

Yeah, as said it's currently a hack...

> > +static int
> > +get_build_id_1 (struct dl_phdr_info *info, size_t, void *data)
> > +{
> > +  for (unsigned i = 0; i < info->dlpi_phnum; ++i)
> > +    {
> > +      if (info->dlpi_phdr[i].p_type != PT_NOTE)
> > +	continue;
> > +      build_id_note *note
> > +	= (build_id_note *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
> > +      ptrdiff_t size = info->dlpi_phdr[i].p_filesz;
> > +      while (size >= (ptrdiff_t)sizeof (build_id_note))
> > +	{
> > +	  if (note->type == NT_GNU_BUILD_ID
> > +	      && note->namesz == 4
> > +	      && note->descsz >= 16)
> > +	    {
> > +	      memcpy (data, note->build_id, 16);
> > +	      return 1;
> > +	    }
> > +	  size_t offset = (sizeof (uint32_t) * 3
> > +			   + ALIGN(note->namesz, 4)
> > +			   + ALIGN(note->descsz, 4));
> > +	  note = (build_id_note *)((char *)note + offset);
> > +	  size -= offset;
> 
> Since the introduction of GNU Property notes this is (sadly) no longer
> the correct way to iterate through ELF notes. The padding of names and
> desc  might now depend on the alignment of the PT_NOTE segment.
> https://sourceware.org/ml/binutils/2018-09/msg00359.html

Ick, that's of course worse ;)  So it's not entirely clear what
the correct thing to do is - from how I read the mail at the above
link only iff sh_align of the note section is exactly 8 the above
ALIGN would use 8 byte alignment and else 4 is correct (independent
on sh_align).  Or can I assume sh_align of the note section is
"correct" for all existing binaries?  Note also the eventual difference
between note sections and note program headers which have another,
possibly different(?) alignment?  It's of course "easy" to replace
4 above by info->dlpi_phdr[i].p_align (but the align field differs
in width between elfclass 32 and 64 ... :/).

So - is merely changing the re-alignment from 4 to 
info->dlpi_phdr[i].p_align "correct"?

Richard.

> Cheers,
> 
> Mark
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

  reply	other threads:[~2019-02-26  8:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 11:29 Richard Biener
2019-02-22 15:47 ` Jeff Law
2019-02-22 16:03   ` Jakub Jelinek
2019-02-22 17:12     ` Richard Biener
2019-02-25  8:42 ` Mark Wielaard
2019-02-26  8:33   ` Richard Biener [this message]
2019-02-26 11:40     ` Mark Wielaard
2019-02-26 14:36       ` Richard Biener
2019-02-26 14:49         ` Richard Biener
2019-02-26 16:18           ` Michael Matz
2019-02-26 17:02             ` Richard Biener
2019-02-27 16:56             ` Nathan Sidwell
2019-02-26 17:03         ` Mark Wielaard
2019-02-26 17:13           ` Richard Biener
2019-02-26 17:35             ` Mark Wielaard
2019-02-27 13:12     ` Florian Weimer

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=alpine.LSU.2.20.1902260923260.23386@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc@gcc.gnu.org \
    --cc=mark@klomp.org \
    /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).