LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 06-22-2011, 03:10 PM   #1
yuhuahe
LQ Newbie
 
Registered: Mar 2004
Posts: 16

Rep: Reputation: 0
insmod failed with invalid module format -1


Hi,

With hello kernel module, i use two types of Makefile, one is using kernel build system:

-----------------------------------------------
obj-m += hello.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

-----------------------------------------------

module loads successfully;

another is using (CC) and then creating the module by "make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules", this module gives the error message when it is inserted,

------------------------------------------------
$dmesg:

overflow in relocation type 10 val ffffffff88640070
`mudule_name' likely not compiled with -mcmodel=kernel
-------------------------------------------------

For this Makefile, i need to add
#include <linux/autoconf.h> in hello.c source code for it to build.

Is there anything that needs to be added in Makefile or source code?

One thing that i notice is the second module doesn't have srcversion when using modinfo, the first one has. vermagic is correct on both modules.

The system is 1.6.18-194.el5 x86_64. The second module works fine when it is in i386 machine ( srcversion is not in the module either, but module works).

Thanks!
 
Old 06-27-2011, 04:41 PM   #2
yuhuahe
LQ Newbie
 
Registered: Mar 2004
Posts: 16

Original Poster
Rep: Reputation: 0
deleted

Last edited by yuhuahe; 06-28-2011 at 03:53 PM.
 
Old 06-27-2011, 04:42 PM   #3
yuhuahe
LQ Newbie
 
Registered: Mar 2004
Posts: 16

Original Poster
Rep: Reputation: 0
deleted

Last edited by yuhuahe; 06-28-2011 at 03:52 PM.
 
Old 06-28-2011, 03:45 PM   #4
yuhuahe
LQ Newbie
 
Registered: Mar 2004
Posts: 16

Original Poster
Rep: Reputation: 0
#Makefile, mix of (CC) and kernel module build system

CFLAGS+=-D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(hello)"
CFLAGS+=-D__KERNEL__ -DMODULE -I$(KERNEL_BUILD_DIR)/include

KERNEL_BUILD_DIR=/lib/modules/2.6.18-194.el5/build
TARGETNAME=hello
BUILD_ALT_DIR=linux

# The main target (note that both library and driver are .ko files
#
all: $(BUILD_ALT_DIR)/$(TARGETNAME).ko
$(BUILD_ALT_DIR)/_$(TARGETNAME).o: hello.o
@echo Linking objects to loadable module
@mkdir -p $(BUILD_ALT_DIR)
@echo $(CURDIR)/$@
@$(LD) -Map=$@.map -r -o $@ $^
@echo " LD_D [$@]"

$(BUILD_ALT_DIR)/$(TARGETNAME).ko: $(BUILD_ALT_DIR)/_$(TARGETNAME).o
@rm -f $(BUILD_ALT_DIR)/$(TARGETNAME).o
@echo create Makefile
@$(SHELL) -c 'echo "obj-m := $(TARGETNAME).o" > $(BUILD_ALT_DIR)/Makefile'
@$(SHELL) -c 'echo "$(TARGETNAME)-objs := _$(TARGETNAME).o" >> $(BUILD_ALT_DIR)/Makefile'
@$(SHELL) -c 'echo ".PHONY: `pwd`/$(BUILD_ALT_DIR)/_$(TARGETNAME).o" >> $(BUILD_ALT_DIR)/Makefile'
@$(SHELL) -c 'cd $(BUILD_ALT_DIR); $(MAKE) -C $(KERNEL_BUILD_DIR) M=`pwd`'
@echo " KO_D [$@]"


$(BUILD_ALT_DIR)/%.o: %.c
@echo Compiling C source to object file:
@mkdir -p $(BUILD_ALT_DIR)
# @echo $(CURDIR)/$@
@$(CC) -c -Wall $(CFLAGS) $(CFLAGS) $< -o $@
@echo " CC_D [$@]"

clean:
rm -f $(BUILD_ALT_DIR)/*.o $(BUILD_ALT_DIR)/*.d $(BUILD_ALT_DIR)/core $(BUILD_ALT_DIR)/*.map

Last edited by yuhuahe; 06-28-2011 at 04:37 PM.
 
Old 06-28-2011, 03:52 PM   #5
yuhuahe
LQ Newbie
 
Registered: Mar 2004
Posts: 16

Original Poster
Rep: Reputation: 0
//hello.c

#include <linux/autoconf.h> // this is needed

#include <linux/init.h>
#include <linux/module.h>

static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");

return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

Last edited by yuhuahe; 06-28-2011 at 04:18 PM.
 
  


Reply

Tags
kernel module



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error: -1 Invalid module format when using insmod with module cross-compiled for arm AndrewShanks Linux - Embedded & Single-board computer 4 10-15-2007 03:50 AM
insmod: error inserting 'module.o': -1 Invalid module format ksrinivas Linux - Newbie 5 10-11-2006 07:29 AM
insmod: error inserting 'new.ko': -1 Invalid module format hemk76 Programming 2 01-26-2005 10:52 AM
insmod invalid module format csfalcon Linux - Hardware 6 01-24-2005 11:03 AM
insmod: error inserting 'new.ko': -1 Invalid module format hemk76 Programming 2 01-24-2005 10:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration