This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: AR archive iteration broken?
- From: Richard Guenther <rguenther at suse dot de>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Mon, 02 Nov 2009 10:57:38 +0100
- Subject: Re: AR archive iteration broken?
On Sun, 1 Nov 2009, Roland McGrath wrote:
> Are you aware of a different libelf implementation (e.g. Solaris) where
> your test program works as you expect?
It works with libelf from Michael Riepe and I got the idiom from
some Solaris libelf tutorial (can't find it right now).
> The normal idiom for archive iteration is to use the return value from
> elf_next, rather than ignoring it. It returns ELF_C_NULL when there is no
> later element. You don't need to test that return value directly unless
> you want to. The normal idiom is to pass that return value in to
> elf_begin, and ELF_C_NULL to elf_begin just returns NULL. e.g.:
>
> Elf_Cmd cmd = ELF_C_READ;
> while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
> {
> Elf_Arhdr *arhdr = elf_getarhdr (subelf);
> ... work on subelf ...
> /* Get next archive element. */
> cmd = elf_next (subelf);
> if (elf_end (subelf) != 0)
> ... diagnose error ...;
> }
Ok, I'll see if that works across the different libelfs I have access to.
Documentation seems to be a scarce resource here...
Thanks,
Richard.