* kernel module spanning multiple files
@ 2011-06-15 9:59 amit mehta
2011-06-15 10:09 ` amit mehta
2011-06-15 17:29 ` Prashant Shah
0 siblings, 2 replies; 5+ messages in thread
From: amit mehta @ 2011-06-15 9:59 UTC (permalink / raw)
To: kernelnewbies
Hi,
After looking at some Makefiles under Linux Driver sources
which uses multiple files to create the target, i tried to write
a simple hello world kernel module spanning multiple files for learning purpose.
But I'm observing a strange behavior. After inserting the module,
I don't see the prints getting logged into the syslog(/var/log/message)
or in the dmesg. Maybe its just a C programming mistake, or is due to
an incorrect Makefile but as of now I'm clueless.
Here are the code snippet from the four files(hello_multi.c, helper.c,
myhdr.h, Makefile)
[root at localhost #] cat hello_multi.c
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include "myhdr.h"
static int __init hello_init(void)
{
printk(KERN_WARNING "Hello world\n");
foo(); //defined in anther file
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_WARNING "goodbye world\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL v2");
[root at localhost #] cat helper.c
#include <linux/kernel.h>
#include "myhdr.h"
void foo(void)
{
printk(KERN_WARNING "inside foo\n");
}
[root at localhost #] cat myhdr.h
#ifndef __MY_HDR_H
#define __MY_HDR_H
void foo(void);
#endif
[root at localhost #] cat Makefile
obj-m += hello_multi.o
hello_multi-objs := helper.o
KERNELDIR=/lib/modules/$(shell uname -r)/build
PWD=$(shell pwd)
modules:
make -C $(KERNELDIR) M=$(PWD) modules
modules_install:
make -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *.ko *~ core .depend .tmp_versions .*.cmd *.mod.c
.PHONY: modules modules_install clean
Invoking 'make modules' completes with success and i am able to
insert this module.
[root at localhost #] make modules
make -C /lib/modules/2.6.31-23-generic/build
M=/home/superman/programming/ldd/hello_multi modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.31-23-generic'
CC [M] /home/superman/programming/ldd/hello_multi/helper.o
LD [M] /home/superman/programming/ldd/hello_multi/hello_multi.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/superman/programming/ldd/hello_multi/hello_multi.mod.o
LD [M] /home/superman/programming/ldd/hello_multi/hello_multi.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-23-generic'
[root at localhost #] dmesg -c
[root at localhost #] insmod hello_multi.ko
[root at localhost #] dmesg|tail <-- -- No messages here
[root at localhost #] cat /proc/modules |grep -i hello
hello_multi 727 0 - Live 0xffffffffa020b000 (PN
[root@localhost #] nm hello_multi.ko
0000000000000000 r ____versions
0000000000000000 r __mod_srcversion26
0000000000000040 r __mod_vermagic5
0000000000000023 r __module_depends
0000000000000000 D __this_module
0000000000000000 T foo
U printk
Regards,
amit
^ permalink raw reply [flat|nested] 5+ messages in thread
* kernel module spanning multiple files
2011-06-15 9:59 kernel module spanning multiple files amit mehta
@ 2011-06-15 10:09 ` amit mehta
2011-06-15 17:29 ` Prashant Shah
1 sibling, 0 replies; 5+ messages in thread
From: amit mehta @ 2011-06-15 10:09 UTC (permalink / raw)
To: kernelnewbies
Whereas for a simple single file hello world kernel module, i see that
the symbols in the object (hello_world.ko) for the init and exit routines.
<snip>
[root at localhost #] nm hello_world.ko
0000000000000000 r ____versions
000000000000000c r __mod_license17
0000000000000020 r __mod_srcversion30
0000000000000060 r __mod_vermagic5
0000000000000000 r __mod_version18
0000000000000043 r __module_depends
0000000000000000 D __this_module
0000000000000000 T cleanup_module
0000000000000000 t hello_exit < --- --------
0000000000000000 t hello_init < -- ---------
0000000000000000 T init_module
U printk
<snip>
Regards,
amit
On Wed, Jun 15, 2011 at 3:29 PM, amit mehta <gmate.amit@gmail.com> wrote:
> Hi,
>
> After looking at some Makefiles under Linux Driver sources
> which uses multiple files to create the target, i tried to write
> a simple hello world kernel module spanning multiple files for learning purpose.
> But I'm observing a strange behavior. After inserting the module,
> I don't see the prints getting logged into the syslog(/var/log/message)
> or in the dmesg. Maybe its just a C programming mistake, or is due to
> an incorrect Makefile but as of now I'm clueless.
>
> Here are the code snippet from the four files(hello_multi.c, helper.c,
> myhdr.h, Makefile)
>
> [root at localhost #] cat hello_multi.c
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/init.h>
> #include "myhdr.h"
> static int __init hello_init(void)
> {
> ? ? ? ?printk(KERN_WARNING "Hello world\n");
> ? ? ? ?foo(); //defined in anther file
> ? ? ? ?return 0;
> }
>
> static void __exit hello_exit(void)
> {
> ? ? ? ?printk(KERN_WARNING "goodbye world\n");
> }
>
> module_init(hello_init);
> module_exit(hello_exit);
>
> MODULE_LICENSE("GPL v2");
>
> [root at localhost #] cat helper.c
> #include <linux/kernel.h>
> #include "myhdr.h"
> void foo(void)
> {
> ? ? ? ?printk(KERN_WARNING "inside foo\n");
> }
>
> [root at localhost #] cat myhdr.h
> #ifndef __MY_HDR_H
> #define __MY_HDR_H
> void foo(void);
> #endif
>
> [root at localhost #] cat Makefile
> obj-m += hello_multi.o
> hello_multi-objs := helper.o
> KERNELDIR=/lib/modules/$(shell uname -r)/build
> PWD=$(shell pwd)
>
> modules:
> ? ? ? ?make -C $(KERNELDIR) M=$(PWD) modules
>
> modules_install:
> ? ? ? ?make -C $(KERNELDIR) M=$(PWD) modules_install
>
> clean:
> ? ? ? ?rm -rf *.o *.ko *~ core .depend .tmp_versions .*.cmd *.mod.c
> .PHONY: modules modules_install clean
>
> Invoking 'make modules' completes with success and i am able to
> insert this module.
>
> [root at localhost #] ?make modules
> make -C /lib/modules/2.6.31-23-generic/build
> M=/home/superman/programming/ldd/hello_multi modules
> make[1]: Entering directory `/usr/src/linux-headers-2.6.31-23-generic'
> ?CC [M] ?/home/superman/programming/ldd/hello_multi/helper.o
> ?LD [M] ?/home/superman/programming/ldd/hello_multi/hello_multi.o
> ?Building modules, stage 2.
> ?MODPOST 1 modules
> ?CC ? ? ?/home/superman/programming/ldd/hello_multi/hello_multi.mod.o
> ?LD [M] ?/home/superman/programming/ldd/hello_multi/hello_multi.ko
> make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-23-generic'
> [root at localhost #] dmesg -c
> [root at localhost #] insmod hello_multi.ko
> [root at localhost #] dmesg|tail ? ?<-- -- No messages here
>
> [root at localhost #] cat /proc/modules |grep -i hello
> hello_multi 727 0 - Live 0xffffffffa020b000 (PN
>
> [root at localhost #] nm hello_multi.ko
> 0000000000000000 r ____versions
> 0000000000000000 r __mod_srcversion26
> 0000000000000040 r __mod_vermagic5
> 0000000000000023 r __module_depends
> 0000000000000000 D __this_module
> 0000000000000000 T foo
> ? ? ? ? ? ? ? ? U printk
>
> Regards,
> amit
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* kernel module spanning multiple files
2011-06-15 9:59 kernel module spanning multiple files amit mehta
2011-06-15 10:09 ` amit mehta
@ 2011-06-15 17:29 ` Prashant Shah
2011-06-15 17:54 ` Dave Hylands
1 sibling, 1 reply; 5+ messages in thread
From: Prashant Shah @ 2011-06-15 17:29 UTC (permalink / raw)
To: kernelnewbies
Hi amit,
On Wed, Jun 15, 2011 at 3:29 PM, amit mehta <gmate.amit@gmail.com> wrote:
> Hi,
>
> static int __init hello_init(void)
> {
> ? ? ? ?printk(KERN_WARNING "Hello world\n");
> ? ? ? ?foo(); //defined in anther file
I removed the foo(); call
> [root at localhost #] cat Makefile
> obj-m += hello_multi.o
> hello_multi-objs := helper.o
I removed the "hello_multi-objs := helper.o" line
complied the module, changed all printk's to KERN_INFO and it shows up in dmesg
I think the problem is with the "hello_multi-objs := helper.o" line.
There is something wrong with it.
^ permalink raw reply [flat|nested] 5+ messages in thread
* kernel module spanning multiple files
2011-06-15 17:29 ` Prashant Shah
@ 2011-06-15 17:54 ` Dave Hylands
2011-06-16 3:27 ` amit mehta
0 siblings, 1 reply; 5+ messages in thread
From: Dave Hylands @ 2011-06-15 17:54 UTC (permalink / raw)
To: kernelnewbies
Hi Prashat,
On Wed, Jun 15, 2011 at 10:29 AM, Prashant Shah <pshah.mumbai@gmail.com> wrote:
> Hi amit,
>
> On Wed, Jun 15, 2011 at 3:29 PM, amit mehta <gmate.amit@gmail.com> wrote:
>> Hi,
>>
>> static int __init hello_init(void)
>> {
>> ? ? ? ?printk(KERN_WARNING "Hello world\n");
>> ? ? ? ?foo(); //defined in anther file
>
> I removed the foo(); call
>
>> [root at localhost #] cat Makefile
>> obj-m += hello_multi.o
>> hello_multi-objs := helper.o
>
> I removed the "hello_multi-objs := helper.o" line
The hello_multi-objs is supposed to contain all of the objects.
So you need:
hello_multi-objs := object1.o object2.o
Since the kernel build system will create hello_multi.o as a result of
building the multi object, you can't use a source file named
hello-multi.c.
You could do
hello_multi-objs := hello.o helper.o
and rename your hello_multi.c to be hello.c
--
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* kernel module spanning multiple files
2011-06-15 17:54 ` Dave Hylands
@ 2011-06-16 3:27 ` amit mehta
0 siblings, 0 replies; 5+ messages in thread
From: amit mehta @ 2011-06-16 3:27 UTC (permalink / raw)
To: kernelnewbies
Dave, Sunny thank you.
it worked :)
On Wed, Jun 15, 2011 at 11:24 PM, Dave Hylands <dhylands@gmail.com> wrote:
> Hi Prashat,
>
> On Wed, Jun 15, 2011 at 10:29 AM, Prashant Shah <pshah.mumbai@gmail.com> wrote:
>> Hi amit,
>>
>> On Wed, Jun 15, 2011 at 3:29 PM, amit mehta <gmate.amit@gmail.com> wrote:
>>> Hi,
>>>
>>> static int __init hello_init(void)
>>> {
>>> ? ? ? ?printk(KERN_WARNING "Hello world\n");
>>> ? ? ? ?foo(); //defined in anther file
>>
>> I removed the foo(); call
>>
>>> [root at localhost #] cat Makefile
>>> obj-m += hello_multi.o
>>> hello_multi-objs := helper.o
>>
>> I removed the "hello_multi-objs := helper.o" line
>
> The hello_multi-objs is supposed to contain all of the objects.
>
> So you need:
>
> hello_multi-objs := object1.o object2.o
>
> Since the kernel build system will create hello_multi.o as a result of
> building the multi object, you can't use a source file named
> hello-multi.c.
>
> You could do
>
> hello_multi-objs := hello.o helper.o
>
> and rename your hello_multi.c to be hello.c
>
> --
> Dave Hylands
> Shuswap, BC, Canada
> http://www.davehylands.com
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-06-16 3:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-15 9:59 kernel module spanning multiple files amit mehta
2011-06-15 10:09 ` amit mehta
2011-06-15 17:29 ` Prashant Shah
2011-06-15 17:54 ` Dave Hylands
2011-06-16 3:27 ` amit mehta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).