Linux:modpost 不构建任何东西

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4715259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 02:30:28  来源:igfitidea点击:

Linux: modpost does not build anything

linuxgcckernel-module

提问by waffleman

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 总是说有零个模块:

MODPOST 0 modules

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

为了解决这个问题,我写了一个测试模块(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:

这是模块的 Makefile:

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?

我查找了有关 modpost 的任何相关文档,但发现很少。任何人都知道 modpost 如何决定构建什么?是否有我可能缺少的环境?

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:

这是 V=1 的 make 运行:

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

采纳答案by waffleman

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.

错误神秘地消失了。如果有人知道可能导致这种情况的原因。如果有下次,我想知道。

回答by gravitron

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

在出现故障的机器上,您的 .config 是否禁用了模块支持?

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

尝试执行“make menuconfig”并确保启用模块支持。

回答by user562374

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'

回答by dsf

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

我整天盯着我的电脑解决这个精确的问题......最终像 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.

我至少可以从我的经验中提供这个微不足道的细节:我得到了与 OP 相同的输出(对于 make V=1)并将打印语句放在 ${kernel_directory}/scripts/makefile.build 中表明 obj-m 奇怪地不是在包含我的 makefile 后进行设置,即使它已明确键入如上。

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?

我对“obj-m += hello.o”及其周围的行进行了一些鬼混。最终它神奇地起作用了......尽管它最终看起来和以前完全一样。也许我从在线教程中复制了这些行并且它包含某种无效/不正确的字符?

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.

对于遇到这种情况的任何人,请确认 obj-m 实际上已设置为 hello.o
如果它神秘地不是,请删除该行,删除整个 Makefile,然后重新键入它。

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

我知道这没有多大帮助;我希望我能重现发生的事情!

回答by saai63

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.

我猜你是从 PDF 或一些 HTML 文档中复制了 Makefile 的内容。使用的连字符有些奇怪。只需尝试替换 makefile 中的连字符;它会像魅力一样工作。

回答by Ilya Matveychikov

Try to remove modulesstring from the Makefile:

尝试modules从 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

回答by PunkFloyd

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.

我刚刚遇到了同样的问题,对我来说这是由于通过 GREP_OPTIONS 环境变量更改默认 grep 选项引起的。我没有深入研究细节,但模块构建过程中的某些内容不喜欢我的备用 grep 输出(包括文件名和行号)。删除 GREP_OPTIONS 环境变量可以解决问题。

回答by Suraj

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.

发生这种情况是因为当您从 PDF 或任何其他教程网站复制 make 文件内容并按原样使用时。在进行复制粘贴时,内容在 Linux 环境中会显得有些奇怪。IE; 会有一些特殊的字符问题。如果您在 Linux 环境中重新键入内容并进行 make,这应该可以工作。

回答by Fliperdo

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.

在另一个线程中,我发现当我复制粘贴 makefile 内容时,make 后面的 -C 使用了错误的“-”符号,我不得不重新输入它。碰巧上面的 obj-m += ... 行就是这种情况。您需要重新键入该字符以使其有效。希望任何遵循 hello world 模块教程的人都能找到它。

回答by cnnrznn

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.txtfor a hint as to why this might work

在名为Kbuild的单独文件中。请参阅Linux/documentation/kbuild/modules.txt以获取有关为什么这可能起作用的提示