Linux: modpost does not build anything
Asked Answered
B

13

10

I am having problems getting any kernel modules to build on my machine. Whenever I build a module, modpost always says there are zero modules:

MODPOST 0 modules

To troubleshoot the problem, I wrote a test module (hello.c):

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/init.h>         /* Needed for the macros */

static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}

static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}

module_init(hello_start);
module_exit(hello_end);

Here is the Makefile for the module:

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
        make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) modules
clean:
        make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) clean

When I build it on my machine, I get the following output:

make -C /lib/modules/2.6.32-27-generic/build M=/home/waffleman/tmp/mod-test modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-27-generic'
  CC [M]  /home/waffleman/tmp/mod-test/hello.o
  Building modules, stage 2.
  MODPOST 0 modules
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-27-generic'

When I make the module on another machine, it is successful:

make -C /lib/modules/2.6.24-27-generic/build M=/home/somedude/tmp/mod-test modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-27-generic'
  CC [M]  /home/somedude/tmp/mod-test/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/somedude/tmp/mod-test/hello.mod.o
  LD [M]  /home/somedude/tmp/mod-test/hello.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-27-generic'

I looked for any relevant documentation about modpost, but found little. Anyone know how modpost decides what to build? Is there an environment that I am possibly missing?

BTW here is what I am running:

uname -a
Linux waffleman-desktop 2.6.32-27-generic #49-Ubuntu SMP Wed Dec 1 23:52:12 UTC 2010 i686 GNU/Linux

Edit

Here is make ran with V=1:

make -C /lib/modules/2.6.32-27-generic/build M=/home/waffleman/tmp/mod-test modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-27-generic'
test -e include/linux/autoconf.h -a -e include/config/auto.conf || (        \
    echo;                               \
    echo "  ERROR: Kernel configuration is invalid.";       \
    echo "         include/linux/autoconf.h or include/config/auto.conf are missing.";  \
    echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";  \
    echo;                               \
    /bin/false)
mkdir -p /home/waffleman/tmp/mod-test/.tmp_versions ; rm -f /home/waffleman/tmp/mod-test/.tmp_versions/*
make -f scripts/Makefile.build obj=/home/waffleman/tmp/mod-test
  gcc -Wp,-MD,/home/waffleman/tmp/mod-test/.hello.o.d  -nostdinc -isystem /usr/lib/gcc/i486-linux-gnu/4.4.3/include  -Iinclude  -I/usr/src/linux-headers-2.6.32-27-generic/arch/x86/include -include include/linux/autoconf.h -Iubuntu/include  -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -O2 -m32 -msoft-float -mregparm=3 -freg-struct-return -mpreferred-stack-boundary=2 -march=i586 -mtune=generic -maccumulate-outgoing-args -Wa,-mtune=generic32 -ffreestanding -fstack-protector -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Wframe-larger-than=1024 -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack  -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(hello)"  -D"KBUILD_MODNAME=KBUILD_STR(hello)"  -c -o /home/waffleman/tmp/mod-test/.tmp_hello.o /home/waffleman/tmp/mod-test/hello.c
  set -e ; perl /usr/src/linux-headers-2.6.32-27-generic/scripts/recordmcount.pl "i386" "32" "objdump" "objcopy" "gcc" "ld" "nm" "" "" "1" "/home/waffleman/tmp/mod-test/hello.o";
(cat /dev/null;   echo kernel//home/waffleman/tmp/mod-test/hello.ko;) > /home/waffleman/tmp/mod-test/modules.order
make -f /usr/src/linux-headers-2.6.32-27-generic/scripts/Makefile.modpost
  scripts/mod/modpost -m -a -i /usr/src/linux-headers-2.6.32-27-generic/Module.symvers -I /home/waffleman/tmp/mod-test/Module.symvers  -o /home/waffleman/tmp/mod-test/Module.symvers -S -w  -s
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-27-generic'
waffleman@waffleman-desktop:~/tmp/mod-test$ cat /home/waffleman/tmp/mod-test/modules.order
kernel//home/waffleman/tmp/mod-test/hello.ko
Brower answered 17/1, 2011 at 16:10 Comment(2)
Try compiling with make V=1 there might be a compile error.Antonietta
This gave a little more output. Both include/linux/autoconf.h and include/config/auto.conf exist.Brower
B
0

The error mysteriously went away. If anyone has an idea what could cause this. I'd like to know in case there is a next time.

Brower answered 17/3, 2011 at 14:20 Comment(2)
Most likely your distro did an automatic update, because it's been a week at my machine now, and no miraculous cures have manifested themselves yet. :/Floyfloyd
I had the same problem with u. I copy the Makefile from tldp.org/LDP/lkmpg/2.6/html/lkmpg.html . It didn't work at the first time. Then I used a Makefile I was written before. Weirdly, then I use it again It works! I have no idea why It works.Skell
B
7

I spent all day glued to my computer fighting this precise problem..which ended up mysteriously disappearing like for OP.

I can at least offer this meager detail from my experience: I was getting the same output as OP (for make V=1) and putting print statements in ${kernel_directory}/scripts/makefile.build showed that obj-m was strangely NOT being set after including my makefile, even though it was clearly typed as above.

I did a bunch of fooling around with the line "obj-m += hello.o" and the ones around it. Eventually it magically worked..although it looked exactly the same as before in the end. Maybe I had copied those lines from a tutorial online and it contained some sort of invalid/incorrect character?

For anyone experiencing this, verify that obj-m is in fact getting set to hello.o
If it mysteriously isn't, delete the line, hell the whole Makefile, and retype it.

I know that's not much help; I wish I could reproduce what happened!

Belfry answered 8/10, 2011 at 21:1 Comment(2)
same problem faced ... its due to copy of Makefile ,if anybody faces this problem edit you Makefile dont copy and paste itKingsley
Thanks, rewriting this line instead of pasting it worked for me too.Berard
P
2

In another thread I found that when I copy pasted the makefile contents, the -C after make was using the wrong "-" symbol and I had to re type it. It just so happens that this is the case for the obj-m += ... line above. You need to retype that character to make it valid. This should hopefully be found by anyone following the hello world module tutorial.

Purpure answered 19/9, 2015 at 21:31 Comment(2)
I think this is the real solution o the problem. Wrong "-" character!Acevedo
Yeah, this is a nasty kind of problem... once wasted hours figuring out that a co-worker was somehow getting pretty directional unicode quotes when copying a shell incantantion out of slack...Fade
A
1

I guess you copied the contents of the Makefile from a PDF or some HTML document. The hyphens used are somewhat weird. Just try replacing the hyphens in the makefile; it will work like a charm.

Alethaalethea answered 22/9, 2012 at 10:5 Comment(2)
Welcome to Stack Overflow. That's an interesting thesis, but I'm not sure it is justified here. At least, when I copy the makefile shown in the question to a Mac (Mac OS X 10.7.5; Firefox 15.0.1), and then analyze the data, all the characters are regular ASCII. That isn't to say that it doesn't happen; 'intelligent quotes' can certainly cause grief. I just don't see a basis for making that assumption with this question. (Additionally, if the hyphens weren't hyphens, the compiler would complain about not finding files with names that start with the non-hyphens; that isn't the trouble AFAICS).Diandrous
I just shared what happened with me. I copied the contents of the Makefile from a PDF document to my Makefile opened through vim in Ubuntu-11.10. There the copied hyphens were invalid characters.Alethaalethea
S
1

I just ran into this same problem and for me it was caused by changing the default grep options via the GREP_OPTIONS environment variable. I didn't dig into the details, but something in the module build process didn't like my alternate grep output (include file name and line number). Removing the GREP_OPTIONS environment variable fixed things right up.

Stoller answered 7/5, 2014 at 18:59 Comment(0)
C
1

This happens because when you copy the make file contents from the PDF or any other tutorial websites and use it as it is. While you do a copy-paste, the contents will appear a bit weird in Linux environment. ie; Some special character issues will be there. If you retype the contents in Linux environment and do a make, this should work.

Chryso answered 19/7, 2014 at 13:1 Comment(0)
K
0

On the machine that fails does your .config have module support disabled?

Try doing "make menuconfig" and make sure module support is enabled.

Katanga answered 17/1, 2011 at 16:50 Comment(0)
R
0

I can only guess your kernel build environment is botched, because it passes both the theoretical check (the look of the developer) as well as the practical test:

make -C /lib/modules/2.6.36-rc8-32-desktop/build M=/dev/shm modules
make[1]: Entering directory `/usr/src/linux-2.6.36-rc8-32-obj/x86_64/desktop'
make -C ../../../linux-2.6.36-rc8-32 O=/usr/src/linux-2.6.36-rc8-32-obj/x86_64/desktop/. modules
  CC [M]  /dev/shm/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /dev/shm/hello.mod.o
  LD [M]  /dev/shm/hello.ko
make[1]: Leaving directory `/usr/src/linux-2.6.36-rc8-32-obj/x86_64/desktop'
Rem answered 17/1, 2011 at 22:14 Comment(0)
B
0

The error mysteriously went away. If anyone has an idea what could cause this. I'd like to know in case there is a next time.

Brower answered 17/3, 2011 at 14:20 Comment(2)
Most likely your distro did an automatic update, because it's been a week at my machine now, and no miraculous cures have manifested themselves yet. :/Floyfloyd
I had the same problem with u. I copy the Makefile from tldp.org/LDP/lkmpg/2.6/html/lkmpg.html . It didn't work at the first time. Then I used a Makefile I was written before. Weirdly, then I use it again It works! I have no idea why It works.Skell
D
0

Try to remove modules string from the Makefile:

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
        make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) # <--
clean:
        make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) clean
Drawing answered 16/9, 2013 at 14:48 Comment(0)
W
0

I was able to solve this problem by putting the

obj-m += <module name>.o

In a separate file named Kbuild. See Linux/documentation/kbuild/modules.txt for a hint as to why this might work

White answered 29/12, 2015 at 2:3 Comment(0)
P
0

I had the same problem. Finally, I rebuilt the kernel, rewrote the makefile. It worked finally.

I guess the main reason is because I had M=$(PWD) modules in the following line right after make ARCH=arm...

Patisserie answered 24/4, 2016 at 17:34 Comment(0)
B
-1

I solved this problem by correcting Makefile, i.e.:

obj-m := modulename.o
Benediction answered 15/5, 2018 at 12:46 Comment(0)
M
-1

I think it's not about special characters. I couldn't solve even when I manually typed! Then I tried again using kate text editor because previously I used nano and this time it worked like charm by even simple copy and paste. Because of that, I think the issue is the text editor

Malave answered 11/4, 2021 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.