无法构建自定义模块 CentOS 7



我正在尝试在 CentOS 7 中构建一个内核模块。当我运行make时,我得到以下内容

$ make
make -C /usr/src/kernels/`uname -r` SUBDIRS= modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-514.21.1.el7.x86_64'
Makefile:641: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
make[2]: *** No rule to make target `arch/x86/syscalls/syscall_32.tbl', needed by `arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h'.  Stop.
make[1]: *** [archheaders] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.10.0-514.21.1.el7.x86_64'
make: *** [default] Error 2

根据我的在线阅读,看起来我没有内核源代码。

我按照这些说明进行操作,但仍然收到相同的错误。

我也发现了这些说明,但是一开始就介绍了问题。

以下是页面开头的声明:

假设您已经拥有完整的内核源代码树 安装。如果您遵循了我需要内核源代码的第2 节,则 将在目录中找到~/rpmbuild/BUILD/kernel-2.6.18/linux-2.6.18.uname -m/

这是我运行时得到的tree ~/rpmbuild

/home/user/rpmbuild
|-- BUILD
|-- BUILDROOT
|-- RPMS
|-- SOURCES
|   |-- centos.cer
|   |-- centos-kpatch.x509
|   |-- centos-ldup.x509
|   |-- check-kabi
|   |-- cpupower.config
|   |-- cpupower.service
|   |-- debrand-rh-i686-cpu.patch
|   |-- debrand-rh_taint.patch
|   |-- debrand-single-cpu.patch
|   |-- extra_certificates
|   |-- kernel-3.10.0-ppc64.config
|   |-- kernel-3.10.0-ppc64-debug.config
|   |-- kernel-3.10.0-ppc64le.config
|   |-- kernel-3.10.0-ppc64le-debug.config
|   |-- kernel-3.10.0-s390x.config
|   |-- kernel-3.10.0-s390x-debug.config
|   |-- kernel-3.10.0-s390x-kdump.config
|   |-- kernel-3.10.0-x86_64.config
|   |-- kernel-3.10.0-x86_64-debug.config
|   |-- kernel-abi-whitelists-514.tar.bz2
|   |-- linux-3.10.0-514.21.1.el7.tar.xz
|   |-- linux-3.10.0-514.26.2.el7.tar.xz
|   |-- linux-kernel-test.patch
|   |-- Makefile.common
|   |-- Module.kabi_dup_ppc64
|   |-- Module.kabi_dup_ppc64le
|   |-- Module.kabi_dup_s390x
|   |-- Module.kabi_dup_x86_64
|   |-- Module.kabi_ppc64
|   |-- Module.kabi_ppc64le
|   |-- Module.kabi_s390x
|   |-- Module.kabi_x86_64
|   |-- secureboot.cer
|   |-- sign-modules
|   `-- x509.genkey
|-- SPECS
|   `-- kernel.spec
`-- SRPMS

我的BUILD目录为空。我需要做什么才能在 CentOS7 中编译内核模块?

这是内核模块的代码

#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>
static int __init ofd_init(void) {
printk(KERN_INFO, "OFD registered");
return 0;
}
static int __exit ofd_exit(void) {
printk(KERN_INFO, "OFD unregistered");
return 0;
}
module_init(ofd_init);
module_exit(ofd_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Test");

这是它的制作文件

# makefile - makefile for test
# If KERNELRELEASE is defined, we've been invoked from the
# kernek build system and need to use its language
ifneq ($(KERNELRELEASE),)
obj-m := ofd.o
# Otherwise we've been invoked from the command line.
# Invoke the kernel build system
else
KERNEL_SOURCE := /usr/src/kernels/`uname -r`
PWD := $(shel pwd)
default:
$(MAKE) -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) clean
endif

也许您错过了源树提取过程。

从 https://wiki.centos.org/HowTos/I_need_the_Kernel_Source:

作为普通用户(而不是 root(,通过执行以下命令安装源码包:

[user@host]$ rpm -i http://vault.centos.org/7.4.1708/updates/Source/SPackages/kernel-3.10.0-693.21.1.el7.src.rpm 2>&1 | grep -v exist

这会将内核源代码树解压缩到~/rpmbuild/BUILD

最新更新