This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Fix aliasing violation tst-rec-dlopen
- From: Rich Felker <dalias at libc dot org>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: Zack Weinberg <zackw at panix dot com>, Pedro Alves <palves at redhat dot com>, Florian Weimer <fweimer at redhat dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Wed, 16 Dec 2015 02:05:47 -0500
- Subject: Re: [PATCH] Fix aliasing violation tst-rec-dlopen
- Authentication-results: sourceware.org; auth=none
- References: <566FE225 dot 8020208 at redhat dot com> <56702B7D dot 4040109 at redhat dot com> <20151215150434 dot GU11489 at vapier dot lan> <56702E3E dot 4050405 at redhat dot com> <CAKCAbMjJw1-JDMA_KX08+Q3A4hvYWbGXsqk2jGkUVOYz=uzLYQ at mail dot gmail dot com> <56704297 dot 3040409 at redhat dot com>
On Tue, Dec 15, 2015 at 11:40:55AM -0500, Carlos O'Donell wrote:
> On 12/15/2015 10:30 AM, Zack Weinberg wrote:
> > POSIX assumes an architecture where object and function pointers
> > are interconvertible, and ...
> >
> >> The 2013 Technical Corrigendum to POSIX.1-2008 (a.k.a.
> >> POSIX.1-2013) improved matters by requiring that conforming
> >> implementations support casting 'void *' to a function pointer.
> >
> > ... that was the correct thing for them to do, and the right way to write
> > this program is just to use a cast.
>
> I wrote the code in question, and I did what was historically considered
> best practice, old habits die hard.
>
> If new compilers complain then we should absolutely switch to and encourage
> correct casting of function pointers to their appropriate types. It's the
> only thing that makes sense.
If you want to avoid both you can use a temp object of type void* and
memcpy to the actual object with function pointer type. I don't
particularly recommend that though. The value conversion is perfectly
fine and it was only a mistake in POSIX (which has since been fixed)
that caused the aliasing-violation monstrosity to be introduced.
Rich