tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: ELF sections vs. segments



On Fri, Jan 20, 2017 at 05:22:20 +0300, Valery Ushakov wrote:

> On Thu, Jan 19, 2017 at 19:02:15 +0300, Valery Ushakov wrote:
> 
> > The question I have can probably be classified as a platonic
> > essentialism problem, but it has some practical conseqeunces too.
> > 
> > I've noticed that netbsd native elf signature check looks for a netbsd
> > note _section_.
> > 
> >   sys/kern/exec_elf.c
> >   - netbsd_elf_signature
> > 
> > 
> > OTOH, linunx compat looks for a linux note _segment_.
> > 
> >   sys/compat/linux/common/linux_exec_elf32.c
> >   - ELFNAME2(linux,signature)
> > 
> > 
> > Normally, it doesn't matter, as there's a note segment for each note
> > section.  However I'm playing with a forth system that cross-compiles
> > and writes out its own ELF image and that standalone image only has
> > segments, but no sections.
> > 
> > I'm inclined to think that a standalone ELF binary should be able to
> > get away with this kind of arrangement.  Sections are for linkers,
> > segments are for loaders.  The binary is intended to be loaded, so it
> > provides info about its segments and that should be enough.
> > 
> > Comments?  Shall we fix the check to look for note segments?
> 
> Studying the history of exec_elf.c I can see:
> 
> revision 1.15
> date: 2010-03-20 01:08:13 +0300;  author: christos;  state: Exp;  lines: +74 -50;
> [...]
> - Re-do note parsing code to read the section headers instead of the program
>   headers because the new binutils merge all the note sections in one program
>   header. This fixes all the pax note parsing which has been broken for all
>   binaries built with the new binutils.
> 
> I guess that's still a concern since x86 and e.g. sh3 do have single
> note segments for two note sections (hmm, OTOH on my -6 macppc there
> are two segments).

Elf spec says:

| The note information in sections and program header elements holds
| any number of entries,

Which seems to imply that note sections also can contain multiple
notes.  The spec also gives an example of a note segment with two
notes, so I guess we really should properly parse such multi-note
segments.

-uwe


Home | Main Index | Thread Index | Old Index