This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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: libelf gelf_newehdr and gelf_newphdr return types


On 12/02/2016 01:42 AM, Mark Wielaard wrote:
> Hi,
> 
> Someone was porting elfutils libelf to Windows64 and noticed that the
> return types of gelf_newehdr and gelf_newphdr (unsigned long int) is not
> appropriate on that platform. It uses the LLP64 data model where int and
> long are both 32bits, while pointers are 64bits. Instead of the more
> common LP64 model where both long and pointer are 64bits. This obviously
> breaks that interface.
> 
> I couldn't find the history behind this return type. Both elfutils and
> solaris libelf share the same return type, but some other libelf
> implementations, like the freebsd one, return a void *. Which does make
> more sense IMHO. Does someone remember the background?
> 
> I have been pondering just changing the return type to void *, which
> should be abi compatible on any platform that elfutils currently
> supports. But it might cause some compiler warnings about needed or
> unneeded casts when existing code relies on the the return type being an
> integral type. So an alternative would be to make the functions return
> an uintptr_t, which should work in all data models.

I'd favor uintptr_t to keep better compatibility with current elfutils.

That's not perfect either, since glibc uses "unsigned int" on 32-bit
platforms, so that could still cause warnings for things that strictly
expect long, like printf "%lx".  But directly printing a newehdr return
value (without saving it somewhere) is a weird thing to do, so I think
we can dismiss that case, at least.  Off the top of my head, I can't
think of anything else that's so strict about long vs. int.

Another option is to make the change conditional on __LP64__, so
existing platforms are totally unaffected.  I'd still lean toward
uintptr_t for the new case, so existing libelf code can port easily.

> Any opinions if this is something to clarify/fix across
> implementations/platforms supporting an libelf implementation?
> 
> Thanks,
> 
> Mark
> _______________________________________________
> elfutils-devel mailing list -- elfutils-devel@lists.fedorahosted.org
> To unsubscribe send an email to elfutils-devel-leave@lists.fedorahosted.org
> 

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