This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] Change PCH "checksum"


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]