c - helloworld 内核模块中的 insmod 错误:模块格式无效
问题描述
我正在交叉编译一个 helloworld 内核模块
我的文件是:
你好-1.c
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
KBuild
obj-m := hello-1-helper.o
hello-1-helper-y := hsllo-1.o
生成文件
export KERNDIR=/home/myname/NXP/SDK2_0/QorIQ-SDK-V2.0-20160527-yocto/build_t1042d4rdb/tmp/work/t1042d4rdb-fsl-linux/linux-qoriq/4.1-r0/git
export PATH:=/opt/fsl-qoriq/2.0/sysroots/x86_64-fslsdk-linux/usr/bin/powerpc-fsl-linux:${PATH}
export ARCH=powerpc
export ARCH_CFLAGS+= -fPIC
default:
$(MAKE) -C $(KERNDIR) CROSS_COMPILE=powerpc-fsl-linux- M=`pwd` V=1 modules
clean:
$(MAKE) -C $(KERNDIR) M=`pwd` clean
这是我的终端输出,在 insmod 命令中显示错误:
module_32: hello-1-helper: unknown ADD relocation: 18
insmod: can't insert 'hello-1-helper.ko': invalid module format
但是当我在makefile下面的行评论时,一切都很好。
export ARCH_CFLAGS+= -fPIC
对于像这样的简单代码,我可以删除这个标志。但在另一个我应该使用 -fPIC 标志的代码中,我有同样的错误
我该如何解决?
解决方案
推荐阅读
- c# - 在不使用 SRC 的情况下从 Web 浏览器控件获取验证码图像
- node.js - Gmail NodeMailer 无效状态码 401
- android - 某些自定义字体在 TextView 上被截断
- java - 为什么在java中最后一个索引的子字符串不等于“”?
- css - :not 选择器,为正文中的所有内容设置样式,除了
- python - 通过对值求和来遍历字典键
- xamarin - 我需要创建一个垂直列表视图。在 Xamarin.Forms 上
- lua - lua为什么有时在lua中乘法和除法的精度不一样?例如下面
- java - 如何在 CompletableFuture 中抛出检查异常?
- javascript - 如何在单击 javascript/jquery 中的文本时滚动到底部?