From: Arnd Bergmann <arnd@arndb.de>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: David Woodhouse <dwmw2@infradead.org>,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [patch 1/8] extend make headers_check to detect more problems
Date: Mon, 18 Sep 2006 10:05:36 +0200 [thread overview]
Message-ID: <200609181005.36817.arnd@arndb.de> (raw)
In-Reply-To: <20060918062152.GA7088@uranus.ravnborg.org>
On Monday 18 September 2006 08:21, Sam Ravnborg wrote:
> > --- linux-cg.orig/scripts/hdrcheck.sh 2006-09-18 02:04:44.000000000 +0200
> > +++ linux-cg/scripts/hdrcheck.sh 2006-09-18 02:04:45.000000000 +0200
> > @@ -1,8 +1,28 @@
> > #!/bin/sh
> >
> > +# check if all included files exist
> > for FILE in `grep '^[ \t]*#[ \t]*include[ \t]*<' $2 | cut -f2 -d\< | cut -f1 -d\> | egrep ^linux\|^asm` ; do
> > if [ ! -r $1/$FILE ]; then
> > echo $2 requires $FILE, which does not exist in exported headers
> > exit 1
> > fi
> > done
> > +
> > +# try to compile in order to see CC warnings, show only the first few
> > +CHECK_CFLAGS=`grep @headercheck: $2 | sed -e 's/^.*@headercheck:\([^@]*\)@.*$/\1/'`
>
> The purpose of @headercheck: should be documented sonewhere.
> A simple way to do so would be to paste the content of the changelog that
> describe it in the top of this file.
ok. I've ended up writing more than that now, since the headers_install
target also wasn't documented well.
> > +CFLAGS="-Wall -std=gnu99 -xc -O2 -I$1 ${CHECK_CFLAGS}"
> > +tmpfile=`mktemp`
> Can't we do this with a hdrchk$$$ filename to avoid using
> random entropy for each compile?
For now, I've hacked something up in the script below. I suppose
that can be improved with Dave's proposal by doing it from the
Makefile.
> > +${CC:-gcc} ${CFLAGS} -c $2 -o $tmpfile 2>&1 | sed -e "s:$1:include:g" >&2
> > +
> > +# check if object file is empty
> > +if [ "`nm $tmpfile`" ] ; then
> Replace nm with {NM:-nm} to obtain correct NM when cross compiling.
>
> > + echo include${2#$1}: warning: non-empty output >&2
> Paste output of nm so one can see what is defined?
>
ok
Arnd <><
---
In addition to the problem of including non-existant header
files, a number of other things can go wrong with header
files exported to user space. This adds checks for some
common problems:
- The header fails to include the files it needs, which
results in build errors when a program tries to include
it. Check this by doing a dummy compile.
- There is a declarations of a static variable or non-inline
function in the header, which results in object code
in every file including it. Check for symbols in the object
with 'nm'.
- Part of the header is subject to conditional compilation
based on CONFIG_*. Add a regex search for this.
I found many problems with this, which I then fixed for
powerpc, s390 and i386, in subsequent patches.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
Index: linux-cg/scripts/hdrcheck.sh
===================================================================
--- linux-cg.orig/scripts/hdrcheck.sh 2006-09-18 08:44:08.000000000 +0200
+++ linux-cg/scripts/hdrcheck.sh 2006-09-18 09:59:13.000000000 +0200
@@ -1,8 +1,28 @@
#!/bin/sh
+# check if all included files exist
for FILE in `grep '^[ \t]*#[ \t]*include[ \t]*<' $2 | cut -f2 -d\< | cut -f1 -d\> | egrep ^linux\|^asm` ; do
if [ ! -r $1/$FILE ]; then
echo $2 requires $FILE, which does not exist in exported headers
exit 1
fi
done
+
+# try to compile in order to see CC warnings, show only the first few
+CHECK_CFLAGS=`grep @headercheck: $2 | sed -e 's/^.*@headercheck:\([^@]*\)@.*$/\1/'`
+CFLAGS="-Wall -std=gnu99 -xc -O2 -I$1 ${CHECK_CFLAGS}"
+mkdir -p ${3%/*}
+${CC:-gcc} ${CFLAGS} -c $2 -o $3 2>&1 | sed -e "s:$1:include:g" >&2
+
+# check if object file is empty
+if [ "`${NM:-nm} $3`" ] ; then
+ echo include${2#$1}: warning: non-empty output >&2
+ ${NM:-nm} $3 >&2
+fi
+
+# check if we use a CONFIG_ symbol, which is not allowed in installed headers
+grep '^[ \t]*#[ \t]*if.*\<CONFIG_[[:alnum:]_]*\>' -n $2 |
+while read i ; do
+ echo include${2#$1}:${i%%:*}: warning: invalid use of `echo $i |
+ sed -e 's/.*\(\<CONFIG_[[:alnum:]_]*\>\).*/\1/g'` >&2
+done
Index: linux-cg/Documentation/headers.txt
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-cg/Documentation/headers.txt 2006-09-18 09:45:17.000000000 +0200
@@ -0,0 +1,96 @@
+ Exporting data structures to user space
+
+
+=== Background
+
+Traditionally, headers in include/asm and include/linux symlinked to
+/usr/include [1]. This has always been a bad idea and stopped working
+well a few years ago. The next step was that distributions shipped
+their own copy of sometimes heavily modified headers to have
+something usable. Mariusz Mazur was maintaining pre-packaged
+linux-libc-headers [2] that were picked up by some distros but
+in the end that turned out too much work to keep up with.
+
+In 2.6.18, the current mechanism was merged, which uses Makefile
+in the include directory to install a minimal set of user space
+headers that can be used in /usr/include.
+
+
+=== Installing headers
+
+The 'make headers_install' command is used to install headers
+into the location specified with the 'INSTALL_HDR_PATH' environment
+variable. The default location for this is ${OBJDIR}/usr/include.
+
+Which headers get installed is specified in the 'Kbuild' file in
+the source directory containing each headers. The variables used
+in Kbuild to designate these files are:
+
+headers-y Files that are installed verbatim from the source
+ directory, as well subdirectories that also contain
+ installable header files.
+objhdr-y Files that are installed from the object directory,
+ having been generated during the kernel build.
+unifdef-y Files that have both parts for installations and
+ parts that are private to the kernel. These files
+ are run through the 'unifdef'(1) program that will
+ strip all parts inside of '#ifdef __KERNEL__'.
+
+Apart from unifdef, all files are also run through a sed script
+that strips the usage of '#include <linux/compiler.h' [5].
+
+
+=== What should be in installed headers
+
+The contents of /usr/include/linux define the binary interface
+to the kernel. It should ideally only contain data structures
+and definitions of constants used on the kernel ABI. In particular,
+it is not a general helper library. While some applications
+are attempting to e.g. spinlocks or linked lists from the kernel
+in user space, such uses are usually subtly broken and should
+not be encouraged.
+
+The set of installed headers is supposed to be usable without
+dependencies on other files, so none of them can #include headers
+that are not also installed nor use types or macros defined
+elsewhere. Typically, this requires enclosing parts of the header
+inside of #ifdef __KERNEL__, or (preferred) splitting the header
+file into a file that can be included in user space and another
+one that contains the kernel-only parts and is not installed.
+
+
+=== Checking header files
+
+The 'make headers_check' target is used to perform a sanity
+check on the contents of the installed headers[6]. It checks for
+a number of common problems:
+
+- The header file includes another header that is not also
+ present in the set of installed headers.
+
+- The header fails to include the files it needs, which
+ results in build errors when a program tries to include
+ it. Check this by doing a dummy compile.
+
+- There is a declarations of a static variable or non-inline
+ function in the header, which results in object code
+ in every file including it. Check for symbols in the object
+ with 'nm'.
+
+- Part of the header is subject to conditional compilation
+ based on CONFIG_*. Add a regex search for this.
+
+Since the headers are different on each architectures, and
+at least the compile step of headers_check requires a compiler
+for the target architectures, only one architecture can be
+checked at a time.
+
+
+=== References
+
+[1] http://linuxmafia.com/faq/Kernel/usr-src-olinux-symlink.html
+[2] http://ep09.pld-linux.org/~mmazur/linux-libc-headers/
+[3] http://lkml.org/lkml/2006/3/14/144
+[4] http://kerneltrap.org/node/6536
+[5] file:../scripts/Makefile.headersinst
+[6] file:../scripts/hdrcheck.sh
next prev parent reply other threads:[~2006-09-18 8:05 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-12 16:44 All arch maintainers: 'make headers_check' fails on most architectures David Woodhouse
2006-09-14 22:34 ` [PATCH] [1/5] Fix 'make headers_check' on biarch architectures for 2.6.18 David Woodhouse
2006-09-14 22:35 ` [PATCH] [2/5] Fix 'make headers_check' on s390 " David Woodhouse
2006-09-15 8:25 ` Martin Schwidefsky
2006-09-14 22:36 ` [PATCH] [3/5] Fix 'make headers_check' on ia64 " David Woodhouse
2006-09-14 22:36 ` [PATCH] [4/5] Fix 'make headers_check' on x86_64 " David Woodhouse
2006-09-14 22:37 ` [PATCH] [5/5] Fix 'make headers_check' on i386 " David Woodhouse
2006-09-17 7:39 ` All arch maintainers: 'make headers_check' fails on most architectures David Woodhouse
2006-09-17 11:51 ` Paul Mundt
2006-09-17 12:10 ` David Woodhouse
2006-09-17 12:20 ` lethal
2006-09-17 12:51 ` Paul Mundt
2006-09-17 11:56 ` Paul Mundt
2006-09-17 11:58 ` David Woodhouse
2006-09-17 12:27 ` Paul Mundt
2006-09-19 7:04 ` Hirokazu Takata
2006-09-19 8:25 ` Ian Molton
2006-09-19 15:31 ` Jeff Dike
2006-09-19 15:39 ` David Woodhouse
2006-09-19 22:03 ` Jeff Dike
2006-09-20 6:18 ` Arnd Bergmann
2006-09-20 15:02 ` Jeff Dike
2006-09-17 9:52 ` Geert Uytterhoeven
2006-09-17 10:36 ` David Woodhouse
2006-09-18 1:27 ` [patch 0/8] " Arnd Bergmann
2006-09-18 1:27 ` [patch 1/8] extend make headers_check to detect more problems Arnd Bergmann
2006-09-18 6:21 ` Sam Ravnborg
2006-09-18 6:45 ` David Woodhouse
2006-09-21 15:13 ` David Woodhouse
2006-09-18 8:05 ` Arnd Bergmann [this message]
2006-09-18 8:10 ` David Woodhouse
2006-09-23 11:04 ` David Woodhouse
2006-09-23 13:18 ` Arnd Bergmann
2006-09-18 1:27 ` [patch 2/8] fix byteorder headers for make headers_check Arnd Bergmann
2006-09-18 1:27 ` [patch 3/8] hide kernel-only parts of some installed headers Arnd Bergmann
2006-09-18 1:27 ` [patch 4/8] fix exported flock64 constants Arnd Bergmann
2006-09-18 1:27 ` [patch 5/8] add missing #includes in user space parts of headers Arnd Bergmann
2006-09-18 1:27 ` [patch 6/8] annotate header files for make headers_check Arnd Bergmann
2006-09-18 1:27 ` [patch 8/8] annotate netfilter header " Arnd Bergmann
2006-09-18 1:37 ` [patch 7/8] annotate if_* " Arnd Bergmann
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=200609181005.36817.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=dwmw2@infradead.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sam@ravnborg.org \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.