This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Calling functions through a pointer of incorrect type
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 22 Mar 2016 21:33:11 +0000
- Subject: Re: Calling functions through a pointer of incorrect type
- Authentication-results: sourceware.org; auth=none
- References: <56F10E3B dot 60300 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1603221912110 dot 30564 at digraph dot polyomino dot org dot uk> <56F1AA47 dot 6040509 at redhat dot com>
On Tue, 22 Mar 2016, Florian Weimer wrote:
> On 03/22/2016 08:14 PM, Joseph Myers wrote:
> > On Tue, 22 Mar 2016, Florian Weimer wrote:
> >
> >> Just a sanity check: It is no longer acceptable glibc coding style to
> >> call functions through mismatching pointer types. Correct?
> >
> > I think more specific examples would help so we can see if there are
> > cleaner approaches that generate the same code. (For example, it's
> > deliberate that in some places functions with incompatible C types but
> > compatible ABIs are aliased to each other.)
>
> I saw this in getaddrinfo:
>
> if (fct == NULL)
> /* We are cheating here. The gethostbyname2_r
> function does not have the same interface as
> gethostbyname3_r but the extra arguments the
> latter takes are added at the end. So the
> gethostbyname2_r code will just ignore them. */
> fct = __nss_lookup_function (nip, "gethostbyname2_r");
Well, glibc is written with knowledge of ABI properties - that is, objects
can assume that other objects follow the ABI and so interact in ways that
are not valid whole-program C but are valid given that each object is an
ABI-conforming compilation of its own sources on their own. So while
cleaning up cases like this would seem desirable unless particularly
performance-critical, and I wouldn't like to see new code like this
without strong justification, they aren't inherently bugs if all supported
ABIs have the required property.
--
Joseph S. Myers
joseph@codesourcery.com