A problem with printk?
I am trying to do some programming exercice with the kernel of Linux and I want to start by a small and simple "Hello world" module. But I have something wrong :-(
I use the kernel 2.2.0-pre5 with module versioning enabled. Here you have a trace what I did:
bash-2.01# lsMakefile hello.c
bash-2.01# cat Makefile
SHELL = /bin/sh
CC =/usr/local/bin/sparc64-linux-gcc
hello.o: hello.c
$(CC) -D__KERNEL__ -DMODULE -O -Wall -I/usr/include -c $<
bash-2.01# cat hello.c
#include <linux/autoconf.h>
#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS) #define MODVERSIONS
#endif
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/module.h>
int init_module(void) {
printk("Hello, Hello, world\n");
return 0;
}
void cleanup_module(void) {
printk("Goodbye cruel world\n");
}
/* It is a copy from "Linux device drivers" */
bash-2.01# make/usr/local/bin/sparc64-linux-gcc -D__KERNEL__ -DMODULE -O -Wall -I/usr/include -c hello.c
In file included from /usr/include/asm/system.h:12,
from /usr/include/asm/atomic.h:19,
from /usr/include/linux/module.h:23,
from hello.c:12:/usr/include/asm/page.h:31: warning: `clear_page' redefined /usr/include/linux/modules/sparc64_ksyms.ver:120: warning: this is the location of the previous definition
bash-2.01# /etc/rc.d/init.d/syslog stop
Shutting down system loggers: syslogd klogd
/* I do not want to mess with them right now. I should be able to
get the messages with /proc/kmsg, shouldn't I? */
bash-2.01# /sbin/insmod hello.o
bash-2.01# cat /proc/kmsg
/* I had to return with C-C */
bash-2.01# cat /proc/modules
hello 280 0 (unused)
bash-2.01# /sbin/rmmod hello
bash-2.01# cat /proc/kmsg
/* like before C-C to exit */
bash-2.01# cat /proc/modules
bash-2.01#
A last thing
bash-2.01# ls -l /sbin/*mod*
(...)
lrwxrwxrwx 1 root root 8 Jan 13 18:46 /sbin/insmod -> insmod64 -rwxr-xr-x 2 root root 33232 May 8 1998 /sbin/insmod.old /* It is not so old but it did the same thing that insmod64. By the way, which is the difference between insmod64 and the insmod (now insmod.old) that was installed with UP 1.1.9 (kernel 2.1.106) */ -rwxr-xr-x 1 root root 243892 May 8 1998 /sbin/insmod.static -rwxr-xr-x 1 root root 37168 May 8 1998 /sbin/insmod64 -rwxr-xr-x 1 root root 245324 May 8 1998 /sbin/insmod64.static
(...)
-rwxr-xr-x 2 root root 33232 May 8 1998 /sbin/rmmod
bash-2.01#
/* :-( I have to change those flags */
If someone can give me a hint about what is wrong I will apreciate very much. I really don't think printk is buggy but I hadn't no other subject.
Regards,
Marc
Date: Thu, 14 Jan 1999 13:37:29 +0900
From: "Durantez, Marc" <[email protected]>
If someone can give me a hint about what is wrong I will apreciate very much. I really don't think printk is buggy but I hadn't no other subject.
Pay attention to the cflags given to the compiler when the sparc64 kernel build compiles the modules... some are different on every platform, but most are the same.
For sparc64 with module symbols you'd do something like:
export KSRC_PATH=/path/to/kernel/src
#if defined(ULTRAPENGUIN_1_1_9) || (SPARC64_GCC_IS_EGCS)
sparc64-linux-gcc -D__KERNEL__ -I$(KSRC_PATH)/linux/include -Wall \
-Wstrict-prototypes -O2 -fomit-frame-pointer -m64 \
-pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow \
-ffixed-g4 -fcall-used-g5 -fcall-used-g7 \
-Wno-sign-compare -DMODULES -DMODVERSIONS \
-include $(KSRC_PATH)/linux/include/linux/modversions.h \
-c -o mymodule.o mymodule.c
#else
sparc64-linux-gcc -D__KERNEL__ -I$(KSRC_PATH)/linux/include -Wall \
-Wstrict-prototypes -O2 -fomit-frame-pointer \
-pipe -mno-fpu -mtune=ultrasparc -mcmodel=medlow \
-ffixed-g4 -fcall-used-g5 -fcall-used-g7 \
-Wno-sign-compare -DMODULES -DMODVERSIONS \
-include $(KSRC_PATH)/linux/include/linux/modversions.h \
-c -o mymodule.o mymodule.c#endif
Later,
David S. Miller
[email protected]