libprocstat(3): retrieve process command line args and environment

Konstantin Belousov kostikbel at gmail.com
Sun Mar 31 13:41:00 UTC 2013


On Fri, Mar 29, 2013 at 02:31:57PM +0200, Mikolaj Golub wrote:
> On Fri, Mar 29, 2013 at 11:22:45AM +0200, Konstantin Belousov wrote:
> > On Thu, Mar 28, 2013 at 11:18:21PM +0200, Mikolaj Golub wrote:
> > > On Thu, Mar 28, 2013 at 12:51:34PM +0200, Konstantin Belousov wrote:
> > > 
> > > > In the generic Elf 64bit draft specification I have, the notes sections
> > > > are specified to consists of entries, each of which is an array of 8-byte
> > > > words. I think we are right using the 8-byte alignment.
> > > 
> > > I have impression many implementations use 4-byte alignment. E.g. in
> > > NetBSD:
> > > 
> > > sys/kern/core_elf32.c:
> > > 
> > > #define ELFROUNDSIZE    4       /* XXX Should it be sizeof(Elf_Word)? */
> > > #define elfround(x)     roundup((x), ELFROUNDSIZE)
> > Note that this is core_elf32. I am concerned with the 64-bit cores.
> 
> core_elf64.c:
> 
> #define	ELFSIZE	64
> 
> #include "core_elf32.c"
Also, the 4-bytes alignment is described in the comments in the glibc
csu/abi-note.S.

> 
> > > 
> > > Also, we have inconsistency with imgactl_elf.c/parse_notes(), which
> > > uses 4-byte alignment:
> > > 
> > > 		note = (const Elf_Note *)((const char *)(note + 1) +
> > > 		    roundup2(note->n_namesz, sizeof(Elf32_Addr)) +
> > > 		    roundup2(note->n_descsz, sizeof(Elf32_Addr)));
> > > 
> > > I suppose there were no issues before, because accidentally the sizes
> > > of all notes we had were 8 bytes aligned.
> > Indeed, both ABI and NOINIT notes have size which is multiple of 8.
> > 
> > > 
> > > Now, when I add new notes it will break things. I don't have strong
> > > opinion, it will be ok for me to leave 8-byte alignment and fix
> > > issues, just want to have strong support here :-)
> > Well, while the issue is discussed and decided, you could just make
> > your new notes size be multiple of 8 too.
> 
> I thought about this too. Then I need to be more caerful when
> extracting stats from notes, because the length returned by
> procstat_core_get() can be more than a real payload.
> 
> Ok, I will try this way.
> 
> I could add length to the note header, which is currently contains
> only structsize, so it would became something like:
> 
> struct {
>   int structsize;
>   int lenght;
> }
> 
> But not sure it is worth doing, especially if the forced 8-bit
> alignment is a temporary mesure.
No, it is definitely not worth it.

I inspected imgact_elf.c:parse_note(), imgact_elf.c:putnote() and
rtld.c:digest_notes(). Only  putnote() uses 8-byte alignment.
Every other OS and our !coredump code assumes 4-byte alignment.

Does changing the putnote() to align on the 4-byte boundary cause
real change in the core file notes layout ?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20130331/3d5b0ca3/attachment.sig>


More information about the freebsd-hackers mailing list