kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: gmate.amit@gmail.com (amit mehta)
To: kernelnewbies@lists.kernelnewbies.org
Subject: kernel module spanning multiple files
Date: Wed, 15 Jun 2011 15:29:52 +0530	[thread overview]
Message-ID: <BANLkTikABcC70AOPHh9RsRfs1+fbMPM-1w@mail.gmail.com> (raw)

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

             reply	other threads:[~2011-06-15  9:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-15  9:59 amit mehta [this message]
2011-06-15 10:09 ` kernel module spanning multiple files amit mehta
2011-06-15 17:29 ` Prashant Shah
2011-06-15 17:54   ` Dave Hylands
2011-06-16  3:27     ` amit mehta

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=BANLkTikABcC70AOPHh9RsRfs1+fbMPM-1w@mail.gmail.com \
    --to=gmate.amit@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.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 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).