This is the mail archive of the
mailing list for the elfutils project.
Re: libelf gelf_newehdr and gelf_newphdr return types
- From: Mark Wielaard <mark at klomp dot org>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Tue, 06 Dec 2016 15:31:52 +0100
- Subject: Re: libelf gelf_newehdr and gelf_newphdr return types
On Sat, 2016-12-03 at 23:02 +0100, Kurt Roeckx wrote:
> On Sat, Dec 03, 2016 at 02:05:41PM -0700, Ali Bahrami wrote:
> > I also googled for these APIs, and found very little of note,
> > other than manpages.
> You can search the source in Debian here:
> The only things really are:
> - dwz casts it to a char *.
> - prelink has it's own implementation that uses unsigned long
> All the rest seems to either compare it to NULL, or not even do
> anything with the return value.
That is a nice code search interface. I wish I had something like that
for Fedora. I haven't done a "make world" but I also didn't find
anything that relied on these functions returning an unsigned long. At
most code compares the result to 0 or NULL.
I did find the following in dwz. As Kurt did in Debian. But the cast
isn't really to (char *) that is only in comments. What the code really
/* Some gelf_newehdr implementations don't return the resulting
ElfNN_Ehdr, so we have to do it the hard way instead of:
e_ident = (char *) gelf_newehdr (elf, gelf_getclass (dso->elf)); */
switch (gelf_getclass (dso->elf))
e_ident = (char *) elf32_newehdr (elf);
e_ident = (char *) elf64_newehdr (elf);
e_ident = NULL;
Which is slightly horrible. But neither the Solaris documentation, nor
the elfutils libelf documentation seem to actually make any promise
about the return value. It is only implied that, like all gelf
functions, zero will be returned on failure.
I wanted to update the elfutils gelf documentation for these functions
to state that the returned pointer is to the appropriate header for the
ELF class. Which I believe is the only sane thing to do. I don't know of
any libelf implementation where the comment from dwz is true.