【问题标题】:unable to build a custom module CentOS 7无法构建自定义模块 CentOS 7
【发布时间】:2017-07-10 18:42:15
【问题描述】:

我正在尝试在 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

根据我的在线阅读,我似乎没有内核源代码。

我关注了these instructions,但仍然遇到同样的错误。

我也找到了these instructions,但是一开始就介绍了这个问题。

这是页面开头的声明:

假设您已经拥有完整的内核源代码树 安装。如果您遵循I need the Kernel Source第 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 - 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

【问题讨论】:

    标签: linux linux-kernel centos linux-device-driver


    【解决方案1】:

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

    来自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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 2013-12-27
      • 2022-01-04
      • 1970-01-01
      相关资源
      最近更新 更多