title: Invalid module format
body: <pre><code>$insmod helloworld module generates the error message "Invalid module format".
  
  $dmesg outputs:
  
  overflow in relocation type 10 val ffffffff88640070
  'hello' likely not compiled with -mcmodel=kernel
  </code></pre>
  
  <p>The Makefile is a mix of tradition format (using (CC)) and module build system format <code>"make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules"</code>. </p>
  
  <p>The system is 1.6.18-194.el5 x86_64. The same Makefile works fine when it is used in i386 machine. </p>
  
  <p>Any idea of what to look into? Thanks.</p>
  
  <hr>
  
  <pre><code>#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" &gt; $(BUILD_ALT_DIR)/Makefile'
  @$(SHELL) -c 'echo "$(TARGETNAME)-objs := _$(TARGETNAME).o" &gt;&gt; $(BUILD_ALT_DIR)/Makefile'
  @$(SHELL) -c 'echo ".PHONY: `pwd`/$(BUILD_ALT_DIR)/_$(TARGETNAME).o" &gt;&gt; $(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) $&lt; -o $@
  @echo " CC_D [$@]"
  
  clean:
      rm -f $(BUILD_ALT_DIR)/*.o $(BUILD_ALT_DIR)/*.d  $(BUILD_ALT_DIR)/core  $(BUILD_ALT_DIR)/*.map
  </code></pre>
  
  <h2>hello.c</h2>
  
  <pre><code>#include &lt;linux/autoconf.h&gt; // this is needed
  
  #include &lt;linux/init.h&gt;
  #include &lt;linux/module.h&gt; 
  
  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);
  </code></pre>