mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Rob Landley <rob@landley.net>,
	Aboriginal Linux <aboriginal@lists.landley.net>,
	musl <musl@lists.openwall.com>
Subject: Re: Re: musl and kernel headers [was Re: system-images 1.4.2: od is broken; bzip2 is missing]
Date: Fri, 9 Oct 2015 15:46:41 -0400	[thread overview]
Message-ID: <20151009194641.GI8645@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAK1hOcNjVG2zM4hxzwar3M=HB7d6Yq1RjzmwZiDhCjRj8fwOcg@mail.gmail.com>

On Fri, Oct 09, 2015 at 09:11:08PM +0200, Denys Vlasenko wrote:
> On Thu, Oct 8, 2015 at 6:58 PM, Rich Felker <dalias@aerifal.cx> wrote:
> >> > Including kernel headers is just really problematic. These days they
> >> > try to make it work on glibc with a complex dance between glibc's
> >> > headers and the kernel headers. You're likely to have the best luck by
> >> > including the libc headers first.
> >>
> >> brctl.c  was including <linux/if_bridge.h> after <netinet/in.h>
> >
> > The problem is linux/libc-compat.h, which should fix this, only works
> > on glibc, by design. See:
> >
> > #ifndef _LIBC_COMPAT_H
> > #define _LIBC_COMPAT_H
> >
> > /* We have included glibc headers... */
> > #if defined(__GLIBC__)
> >
> > /* Coordinate with glibc netinet/in.h header. */
> > #if defined(_NETINET_IN_H)
> >
> > If you patch it like this:
> >
> > -#if defined(__GLIBC__)
> > +#if 1
> >
> > then it should mostly work but it's still all a big hack. I think
> > that's what distros are doing. The problem is that the same header is
> > trying to do two different things:
> >
> > 1. Provide extra linux-kernel-API stuff that's not in the
> >    libc/userspace headers.
> >
> > 2. Provide definitions of the standard types and constants for uClibc
> >    and klibc, which don't have complete libc headers and rely on the
> >    kernel headers for definitions.
> >
> > These two uses really should be separated out into separate headers so
> > that the latter only get included explicitly by uClibc and klibc and
> > otherwise remain completely unused. But that would require coordinated
> > changes/upgrades which are unlikely to happen. :(
> 
> Looking at kernel's libc-compat.h, it looks like you can get away
> with using __UAPI_DEF_foo's like this?
> 
> 
> #if  defined(__UAPI_DEF_SOCKADDR_IN) && __UAPI_DEF_SOCKADDR_IN == 1
> /* kernel already defined the struct, do nothing */
> #else
> struct sockaddr_in {
>         ...
> };

This would address the case where the kernel header is included first,
but it's not a case I or most of the musl community wants to support,
because there's no guarantee that the kernel's definitions of these
structures will actually be compatible with use elsewhere in the libc
headers, etc.

The other direction, suppressing kernel headers' definition of the
structs, is what we want to work, but they've restricted their logic
for that to only work when __GLIBC__ is defined. :(

> #undef __UAPI_DEF_SOCKADDR_IN
> /* tell kernel to not define the struct */
> #define __UAPI_DEF_SOCKADDR_IN 0
> #endif

We could do something like this but then we would need to keep up with
the list of all the __UAPI defines we need to suppress unwanted kernel
definitions.

What if we could get the kernel to change the #if defined(__GLIBC__)
to #if defined(__GLIBC__) || defined(__UAPI_DONTNEED_DEFS) or similar,
so that there would only be one macro we need to define, and the
kernel would then use the same logic it uses with glibc to suppress
all of these.

Rich


  reply	other threads:[~2015-10-09 19:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAK1hOcNm-rwGdr1_THZoHA-TTxOjpzUU=Lnraqt6mj+JmBdvFw@mail.gmail.com>
     [not found] ` <5612925A.4070402@landley.net>
2015-10-06  1:44   ` Rich Felker
2015-10-06  2:24     ` Rob Landley
2015-10-06 11:01       ` Szabolcs Nagy
2015-10-06 14:30       ` Rich Felker
2015-10-06 16:05         ` Denys Vlasenko
2015-10-06 16:09     ` Denys Vlasenko
2015-10-08 16:58       ` Rich Felker
2015-10-09 19:11         ` Denys Vlasenko
2015-10-09 19:46           ` Rich Felker [this message]
2015-10-10  4:56             ` Rob Landley
2015-10-13 12:10             ` Denys Vlasenko
2015-10-13 14:16               ` Ruben Winistörfer
2015-10-13 14:53               ` Szabolcs Nagy
2015-10-13 15:05                 ` Rich Felker
2015-10-13 18:02                   ` Denys Vlasenko
2015-10-13 18:56                     ` Rich Felker
2015-10-13 15:10               ` Rich Felker
2015-10-13 21:55                 ` Isaac Dunham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151009194641.GI8645@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=aboriginal@lists.landley.net \
    --cc=musl@lists.openwall.com \
    --cc=rob@landley.net \
    --cc=vda.linux@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).