Problem compiling demonstration module using 2.4.18
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Distribution: Used many over the years, main ones now "CentOS", Slackware and Arch
Posts: 31
Rep:
Problem compiling demonstration module using 2.4.18
For various reasons too boring to go into in detail I have been reading up on writing linux kernel modules, and I figured a good place to start was the "lkmpg" (linux kernel module programming guide" on the linux documentation project.
Now I know just about enough 'c' to be a danger to myself and others (where have I heard that before !!!) but I reckoned that even I could follow the examples in a linux documentaion project guide and get somewhere, yeah ?
Wrong. I'm a miserable failure. I can't even get past creating the module of "hello, world !!" I followed the details in the guide to the letter, created the example hello.c, created the Makefile, and then ran make.
it came back with a complaint that there was a "parse error before 'size_t'" in lines 73 and 75 of /usr/include/linux/kernel.h before whingeing about an implicit definition of print_k and a final [Error 1]
I've spent a day now poking round other modules, google and FAQS till I've got 'C' code burned into my retinas.
My best guess is that I need some other header files in front of the #include <linux/kernel.h> in order to provide the definition of "size_t". However I have no idea which ones they might be.
I have looked round the linux source tree for some inspiration, but just became more and more confused as I dug deeper !
I'm running a Slackware 8.0 distribution (downloaded as ISOS) buit I have upgraded the linux kernel source to 2.4.18 and modutils to 2.4.16 because that was supposed to have fixed problems with the new firewall code and also is said to support the Belkin Direct Connect USB networking cable.
My gcc version is 2.95.3
If I need to supply more details to pin this down, please tell me what I need to specify.
Distribution: Used many over the years, main ones now "CentOS", Slackware and Arch
Posts: 31
Original Poster
Rep:
Well, I found an answer to this, although i do not (yet) fully understand what is going on. It makes me feel a bit stupid owning up to this, but I see from a google search that there are others with the same problem, who have not yet received an answer.
First thing to say is that if you take the standard example code and example makefile as shown in Ori Pomerantz's lkmpg document, and try that against a linux box running a 2.2.19 kernel and the 2.2.19 source tree on the slackware 8.0 distrib, IT WORKS. It whinges a bit with warnings out of gcc 2.95.3 but it does work. Do the same against a 2.4.5 kernel and source and it ALSO works, this time without whingeing. So IMHO it HAD to be something in the gcc flags for the makefile.
I went back to basics on a 2.4.18 system, rebuilt a kernel for the sheer hell of it and captured the output at the "make modules" stage. "make modules > my_logfile 2>&1" did the trick
I then took a HARD look at how the makefile made the dummy.o module in /usr/src/linux/drivers/net. This dummy module was, I reckoned, a good candidate for scrutiny as it is not much more than a skeleton driver. From the make modules logfile, I saw the command line to gcc was huge compared to the one used in the lkmpg demo.
I cut and pasted every gcc flag into the lkmpg demo makefile and once I had done so, the hello, world module compiled !!!!
The makefile I used now looks like this
#Makefile for Ori Pomerantz lkmpg, 2.4.18 kernel version
#Author: John Voisey. Use at Own Risk !!!
cc=gcc
MODCFLAGS := -D__KERNEL__ \
-I/usr/src/linux-2.4.18/include -Wall \
-Wstrict-prototypes -Wno-trigraphs -O2 \
-fomit-frame-pointer -fno-strict-aliasing \
-fno-common -pipe -mpreferred-stack-boundary=2 \
-march=k6 -DMODULE -DMODVERSIONS \
-include /usr/src/linux-2.4.18/include/linux/modversions.h -DKBUILD_BASENAME=hello
hello.o: hello.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c hello.c
echo insmod hello.o to turn it on
echo rmmod hello to turn it off
I hope this helps anyone in the same predicament as me !!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.