lkml.org 
[lkml]   [2004]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRFC: Testing for kernel features in external modules
The last couple of kbuild patches has put attention to testing for
features in the kernel so an external modules can stay compatible
with a broad range of kernels.
Since vendors backport patches then testing for the kernel version is not
an option, so other means are reqired.

Two approaches are in widespread use:
a) grep kernel headers
b) Try to compile a small .c file (nvidia is a good example)

The a) approach is not robust for changes in .h files, mainly when contant
is moved from one file to another. This will happen when the linuxabi
project is kicked off.

The b) approach required glibc headers to be in full sync with the kernel,
this cannot be guaranteed. And will fail when building for another kernel
version than the running one.


How about the following approach where the kbuild system is used to compile
a few sample programs?
If compile succeeeds -> feature is present.
If compile fails -> feature not implemented.

The files needs to be in a separate directory.
Use: dir/feature.sh /lib/modules/`uname -r`/build ../feature.h

The script usually used to build the module can call feature.sh, and afterwards
the module can include the feature.h file.

Comments welcome...

Sam


--- /dev/null 2003-09-23 19:59:22.000000000 +0200
+++ features.sh 2004-06-24 22:23:10.475441120 +0200
@@ -0,0 +1,19 @@
+# Check for presence of certain kernel features
+# $1 = kernel dir
+# $2 = output file
+
+#
+dir=`dirname $0`
+cd $dir
+
+
+make -C $1 M=`pwd`
+
+if [ -f remap4.o ]; then
+ echo "#define REMAP4 1" > $2
+elif [ -f remap5.o ]; then
+ echo "#define REMAP5 1" > $2
+fi
+
+make -C $1 M=`pwd` clean
+
--- /dev/null 2003-09-23 19:59:22.000000000 +0200
+++ Makefile 2004-06-24 21:55:45.071580528 +0200
@@ -0,0 +1,5 @@
+MAKEFLAGS += -k
+
+obj-y := remap4.o remap5.o
+
+
--- /dev/null 2003-09-23 19:59:22.000000000 +0200
+++ remap4.c 2004-06-24 21:44:28.022507632 +0200
@@ -0,0 +1,7 @@
+#include <linux/mm.h>
+
+int do_test_remap_page_range(void)
+{
+ pgprot_t pgprot;
+ remap_page_range(0L, 0L, 0L, pgprot);
+}
--- /dev/null 2003-09-23 19:59:22.000000000 +0200
+++ remap5.c 2004-06-24 21:44:10.033242416 +0200
@@ -0,0 +1,7 @@
+#include <linux/mm.h>
+
+int do_test_remap_page_range(void)
+{
+ pgprot_t pgprot;
+ remap_page_range(NULL, 0L, 0L, 0L, pgprot);
+}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 14:04    [W:0.315 / U:0.056 seconds]
©2003-2011 Jasper Spaans. Advertise on this site