Re: suse 2.6.5 insmod: error inserting 'kprobe.o': -1 Invalid module format

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I can roughly guess the problem from the output message: you are compiling your module using user-space library. What you really should use is kernel header files. (1) if you use your own compiled kernel, the header files are at "/usr/src/$(shell uname -r)/include/". In the Makefile, it specifies that the kernel path is "/lib/modules/$(shell uname -r)/build" - this path will be used by kernel build system to figure out the real kernel path which is "/usr/src/$(shell uname -r)/include/". (2) If you don't have your own compiled kernel, you should install the kernel header package that is matched with your current running kernel. If you use Debian,
this can be easily solved by command "apt-cache search kernel header", or something like that.

I strongly suggest that you should have your own kernel running. It not only solve the compilation problem, but you can also find docs under the "Documentation" directory and hack into the kernel source.

Final thing, this is the right output you should have for compiling your module:
make -C /lib/modules/2.6.10/build M=/home/fei/ldd-3ed-examples/misc-modules modules
make[1]: Entering directory `/usr/src/linux-2.6.10'
  CC [M]  /home/fei/ldd-3ed-examples/misc-modules/kobject.o
  Building modules, stage 2.
  MODPOST
  CC      /home/fei/ldd-3ed-examples/misc-modules/kobject.mod.o
  LD [M]  /home/fei/ldd-3ed-examples/misc-modules/kobject.ko
make[1]: Leaving directory `/usr/src/linux-2.6.10'


Fei


On 4/24/05, anew bie <anewbie79@xxxxxxxxx> wrote:
Thanks a lot Xiangfei for your pointers.
(Ignore my previous mail, i was not giving "myprobe"
argument to make)
I am facing a different problem now, please give your
suggestion

make -f Makefile myprobe
cc     myprobe.c   -o myprobe
In file included from /usr/include/linux/sched.h:12,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/jiffies.h:16: error: parse error
before "jiffies_64"
/usr/include/linux/jiffies.h:20: error: parse error
before "get_jiffies_64"
In file included from /usr/include/linux/sched.h:21,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/asm/mmu.h:13: error: field `sem' has
incomplete type
In file included from /usr/include/linux/signal.h:4,
                 from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/list.h:604:2: warning: #warning
"don't include kernel headers in userspace"
In file included from /usr/include/asm/siginfo.h:4,
                 from /usr/include/linux/signal.h:7,
                 from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/asm-generic/siginfo.h:58: error: size of
array `_pad' is too large
In file included from /usr/include/linux/sched.h:27,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
oracle@indl104ga:/local/oracle/try>
oracle@indl104ga:/local/oracle/try>
oracle@indl104ga:/local/oracle/try> make -f
Makefile.kprobe2 myprobe
cc     myprobe.c   -o myprobe
In file included from /usr/include/linux/sched.h:12,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/jiffies.h:16: error: parse error
before "jiffies_64"
/usr/include/linux/jiffies.h:20: error: parse error
before "get_jiffies_64"
In file included from /usr/include/linux/sched.h:21,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/asm/mmu.h:13: error: field `sem' has
incomplete type
In file included from /usr/include/linux/signal.h:4,
                 from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/list.h:604:2: warning: #warning
"don't include kernel headers in userspace"
In file included from /usr/include/asm/siginfo.h:4,
                 from /usr/include/linux/signal.h:7,
                 from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/asm-generic/siginfo.h:58: error: size of
array `_pad' is too large
In file included from /usr/include/linux/sched.h:27,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/fs_struct.h:9: error: parse error
before "rwlock_t"
/usr/include/linux/fs_struct.h:13: error: parse error
before '}' token
In file included from /usr/include/linux/sched.h:29,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/completion.h:15: error: parse error
before "wait_queue_head_t"
/usr/include/linux/completion.h: In function
`init_completion':
/usr/include/linux/completion.h:26: error:
dereferencing pointer to incomplete type
/usr/include/linux/completion.h:27: error:
dereferencing pointer to incomplete type
In file included from /usr/include/linux/sched.h:30,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/pid.h: At top level:
/usr/include/linux/pid.h:18: error: field `task_list'
has incomplete type
/usr/include/linux/pid.h:19: error: field `hash_chain'
has incomplete type
/usr/include/linux/pid.h:24: error: field `pid_chain'
has incomplete type
In file included from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/sched.h:93: error: parse error
before "process_counts"
In file included from /usr/include/linux/sched.h:102,
                 from /usr/include/linux/module.h:9,
                 from myprobe.c:2:
/usr/include/linux/timer.h:10: error: field `entry'
has incomplete type
myprobe.c:11: error: variable or field
`__attribute_used__' declared void
myprobe.c:11: error: parse error before "myprobe_exit"
myprobe.c:16: error: parse error before
"__attribute_used__"
myprobe.c:16: error: conflicting declarations of
`__attribute_used__'
myprobe.c:11: error: `__attribute_used__' previously
declared here
myprobe.c:16: warning: initialization makes integer
from pointer without a cast
myprobe.c:16: warning: data definition has no type or
storage class
myprobe.c:17: error: parse error before
"__attribute_used__"
myprobe.c:17: error: redefinition of
`__attribute_used__'
myprobe.c:16: error: `__attribute_used__' previously
defined here
myprobe.c :17: error: `myprobe_exit' undeclared here
(not in a function)
myprobe.c:17: warning: data definition has no type or
storage class
--- Xiangfei Jia <xjianz@xxxxxxxxx> wrote:

> There is nothing wrong with your coding. The problem
> is you have to use the
> kernel build system to compile your module since
> 2.6. Read the chapter 2 on
> section "Compiling and Loading" for detail from
>
http://www.oreilly.com/catalog/linuxdrive3/book/index.csp
> .
>
> Here is a simple Makefile to compile your module:
> # To build modules outside of the kernel tree, we
> run "make"
> # in the kernel source tree; the Makefile these then
> includes this
> # Makefile once again.
> # This conditional selects whether we are being
> included from the
> # kernel Makefile or not.
> ifeq ($(KERNELRELEASE),)
>
> # Assume the source tree is where the running kernel
> was built
> # You should set KERNELDIR in the environment if
> it's elsewhere
> KERNELDIR ?= /lib/modules/$(shell uname -r)/build
> # The current directory is passed to sub-makes as
> argument
> PWD := $(shell pwd)
>
> modules:
> $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
>
> modules_install:
> $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
>
> clean:
> rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c
> .tmp_versions
>
> .PHONY: modules modules_install clean
>
> else
> # called from kernel build system: just declare what
> our modules are
> obj-m := kprobe.o
>
> endif
>
>
>
> On 4/24/05, anew bie < anewbie79@xxxxxxxxx> wrote:
> >
> > I have written a tiny kernel module (see below)
> > It compiles fine and generates kprobe.o without
> any
> > warning. But when i do insmod, it gives error:
> > # insmod kprobe.o
> > insmod: error inserting 'kprobe.o': -1 Invalid
> module
> > format
> >
> > Any idea why this is happening ?
> > I am using gcc-3.3.3
> >
> > gcc -nostdinc -fno-strict-aliasing
> > -fomit-frame-pointer -Wall -O2
> > -I/local/oracle/linux-2.6.5-7.162/include -I
> > /usr/lib/gcc-lib/i586-suse-linux/3.3.3/include
> > -DMODULE -DLINUX -D__KERNEL__ -o kprobe.o -c
> kprobe.c
> >
> > kprobe.c:
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > #include <linux/init.h>
> >
> > static int __init kprobe_init (void)
> > {
> > printk("module kprobe loading");
> > return 0;
> > }
> >
> > static void __exit kprobe_exit (void)
> > {
> > printk("module kprobe exiting");
> > }
> >
> > module_init(kprobe_init);
> > module_exit(kprobe_exit);
> > MODULE_LICENSE ("GPL");
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> > --
> > Kernelnewbies: Help each other learn about the
> Linux kernel.
> > Archive: http://mail.nl.linux.org/kernelnewbies/
> > FAQ: http://kernelnewbies.org/faq/
> >
> >
>
> On 4/24/05, anew bie <anewbie79@xxxxxxxxx > wrote:
> >
> > I have written a tiny kernel module (see below)
> > It compiles fine and generates kprobe.o without
> any
> > warning. But when i do insmod, it gives error:
> > # insmod kprobe.o
> > insmod: error inserting 'kprobe.o': -1 Invalid
> module
> > format
> >
> > Any idea why this is happening ?
> > I am using gcc-3.3.3
> >
> > gcc -nostdinc -fno-strict-aliasing
> > -fomit-frame-pointer -Wall -O2
> > -I/local/oracle/linux-2.6.5-7.162/include -I
> > /usr/lib/gcc-lib/i586-suse-linux/3.3.3/include
> > -DMODULE -DLINUX -D__KERNEL__ -o kprobe.o -c
> kprobe.c
> >
> > kprobe.c:
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > #include <linux/init.h>
> >
> > static int __init kprobe_init (void)
> > {
> > printk("module kprobe loading");
> > return 0;
> > }
> >
> > static void __exit kprobe_exit (void)
> > {
> > printk("module kprobe exiting");
> > }
> >
> > module_init(kprobe_init);
> > module_exit(kprobe_exit);
> > MODULE_LICENSE ("GPL");
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> > --
> > Kernelnewbies: Help each other learn about the
> Linux kernel.
> > Archive: http://mail.nl.linux.org/kernelnewbies/
> > FAQ: http://kernelnewbies.org/faq/
> >
> >
>

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux