2008-03-23 06:32:05

by Robert P. J. Day

[permalink] [raw]
Subject: why so many unexported headers checking __KERNEL__?


as an unintended side effect of checking for proper exporting to
user space and unifdef'ing, i noticed that there are literally
hundreds of kernel header files that check the value of __KERNEL__ in
some way, but are never exported to user space. what's the point of
that? thanks.

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================


2008-03-26 12:08:54

by David Woodhouse

[permalink] [raw]
Subject: Re: why so many unexported headers checking __KERNEL__?

On Sun, 2008-03-23 at 02:31 -0400, Robert P. J. Day wrote:
>
> as an unintended side effect of checking for proper exporting to
> user space and unifdef'ing, i noticed that there are literally
> hundreds of kernel header files that check the value of __KERNEL__ in
> some way, but are never exported to user space. what's the point of
> that? thanks.

There's no point -- we just haven't got round to removing it yet.

We should probably make headers_check or some other automated check
catch these two cases:

If a header is exported by header-y or not exported at all, it shouldn't
contain any #ifdef __KERNEL__.

And if it's exported and doesn't contain any #ifdef __KERNEL__, it
should be header-y not unifdef-y (and that's the case we should be
moving towards, by cleaning up headers to have separate files for the
user-visible parts).

--
dwmw2

2008-03-26 12:53:48

by Robert P. J. Day

[permalink] [raw]
Subject: Re: why so many unexported headers checking __KERNEL__?

On Wed, 26 Mar 2008, David Woodhouse wrote:

> On Sun, 2008-03-23 at 02:31 -0400, Robert P. J. Day wrote:
> >
> > as an unintended side effect of checking for proper exporting to
> > user space and unifdef'ing, i noticed that there are literally
> > hundreds of kernel header files that check the value of __KERNEL__
> > in some way, but are never exported to user space. what's the
> > point of that? thanks.
>
> There's no point -- we just haven't got round to removing it yet.
>
> We should probably make headers_check or some other automated check
> catch these two cases:
>
> If a header is exported by header-y or not exported at all, it shouldn't
> contain any #ifdef __KERNEL__.
>
> And if it's exported and doesn't contain any #ifdef __KERNEL__, it
> should be header-y not unifdef-y (and that's the case we should be
> moving towards, by cleaning up headers to have separate files for
> the user-visible parts).

not surprisingly, the only reason i noticed the above was because i
hacked together a short script that went looking for all of the above
and i was surprised at the number of files it identified. (i've
already submitted a few patches to clean up the obviously erroneous
cases, like being miscategorized or being in both categories at once
so, after the next merge window, those should all be gone.)

rday

p.s. the other case that could be identified is when a header file has
its *entire* contents encased in a __KERNEL__ test, (either ifdef or
ifndef). AFAICT, unless that kind of test is partitioning *some* of a
header file content from the remainder, there's little value in a
__KERNEL__test if the end result is to either:

a) leave the file exactly as is, or
b) reduce it to empty

--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================

2008-03-26 13:10:40

by David Woodhouse

[permalink] [raw]
Subject: Re: why so many unexported headers checking __KERNEL__?

On Wed, 2008-03-26 at 08:53 -0400, Robert P. J. Day wrote:
> not surprisingly, the only reason i noticed the above was because i
> hacked together a short script that went looking for all of the above
> and i was surprised at the number of files it identified.

It's not _that_ surprising. Remember, before headers_install people just
used to copy _all_ the headers across, and so the only way to hide stuff
was to wrap entire files in #ifdef __KERNEL__.

> p.s. the other case that could be identified is when a header file has
> its *entire* contents encased in a __KERNEL__ test, (either ifdef or
> ifndef). AFAICT, unless that kind of test is partitioning *some* of a
> header file content from the remainder, there's little value in a
> __KERNEL__test if the end result is to either:
>
> a) leave the file exactly as is, or
> b) reduce it to empty

Right.

If it's entirely #ifndef __KERNEL__ then it's a userspace header. It
probably doesn't live in the kernel source tree at all.

If it's entirely #ifdef __KERNEL__ then it shouldn't be exported at all
(although when we do that we sometimes have to deal with userspace
programs which include it even though it's empty).

--
dwmw2

2008-03-26 13:16:45

by Robert P. J. Day

[permalink] [raw]
Subject: Re: why so many unexported headers checking __KERNEL__?

On Wed, 26 Mar 2008, David Woodhouse wrote:

> On Wed, 2008-03-26 at 08:53 -0400, Robert P. J. Day wrote:
> > not surprisingly, the only reason i noticed the above was because
> > i hacked together a short script that went looking for all of the
> > above and i was surprised at the number of files it identified.
>
> It's not _that_ surprising. Remember, before headers_install people
> just used to copy _all_ the headers across, and so the only way to
> hide stuff was to wrap entire files in #ifdef __KERNEL__.

ah, i had no idea. that explains it.

> > p.s. the other case that could be identified is when a header file
> > has its *entire* contents encased in a __KERNEL__ test, (either
> > ifdef or ifndef). AFAICT, unless that kind of test is
> > partitioning *some* of a header file content from the remainder,
> > there's little value in a __KERNEL__test if the end result is to
> > either:
> >
> > a) leave the file exactly as is, or
> > b) reduce it to empty
>
> Right.
>
> If it's entirely #ifndef __KERNEL__ then it's a userspace header. It
> probably doesn't live in the kernel source tree at all.
>
> If it's entirely #ifdef __KERNEL__ then it shouldn't be exported at
> all (although when we do that we sometimes have to deal with
> userspace programs which include it even though it's empty).

well, since i already have the output from my script, i might toss
together some per-directory patches to start removing some of that.
this sounds more like a one-shot thing than adding permanent checking
to the build process.

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================

2008-03-26 13:19:56

by David Woodhouse

[permalink] [raw]
Subject: Re: why so many unexported headers checking __KERNEL__?

On Wed, 2008-03-26 at 09:16 -0400, Robert P. J. Day wrote:
> well, since i already have the output from my script, i might toss
> together some per-directory patches to start removing some of that.
> this sounds more like a one-shot thing than adding permanent checking
> to the build process.

Makes sense.

Remember, one of our goals is to move towards having files which are
just _copied_ (header-y) instead of having these ifdefs. If, in your
travels, you see a way you can split headers up more sensibly to achieve
that, it would be good.

--
dwmw2

2008-03-26 13:23:54

by Robert P. J. Day

[permalink] [raw]
Subject: Re: why so many unexported headers checking __KERNEL__?

On Wed, 26 Mar 2008, David Woodhouse wrote:

> On Wed, 2008-03-26 at 09:16 -0400, Robert P. J. Day wrote:
> > well, since i already have the output from my script, i might toss
> > together some per-directory patches to start removing some of
> > that. this sounds more like a one-shot thing than adding permanent
> > checking to the build process.
>
> Makes sense.
>
> Remember, one of our goals is to move towards having files which are
> just _copied_ (header-y) instead of having these ifdefs. If, in your
> travels, you see a way you can split headers up more sensibly to
> achieve that, it would be good.

that might be harder to encode into a script. :-)

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================

2008-03-26 13:37:26

by Robert P. J. Day

[permalink] [raw]
Subject: Re: why so many unexported headers checking __KERNEL__?


On Wed, 26 Mar 2008, David Woodhouse wrote:

> On Wed, 2008-03-26 at 09:16 -0400, Robert P. J. Day wrote:
> > well, since i already have the output from my script, i might toss
> > together some per-directory patches to start removing some of that.
> > this sounds more like a one-shot thing than adding permanent checking
> > to the build process.
>
> Makes sense.
>
> Remember, one of our goals is to move towards having files which are
> just _copied_ (header-y) instead of having these ifdefs. If, in your
> travels, you see a way you can split headers up more sensibly to
> achieve that, it would be good.

just in case anyone was curious, i've attached my Kbuild checking
script. i'm guessing it's pretty self-explanatory -- you can get an
idea of the condition of the header files at the moment.

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================


Attachments:
check_kbuild.sh (1.39 kB)