编译可加载内核模块(Debian/Ubuntu)

Compiling a loadable kernel module(Debian/Ubuntu)

此问题是 this 问题的后续问题。我正在尝试将 ELF 加载器编译为单独的 LKM,并将其用作独立的应用程序(替换基本内核中的原始模块听起来风险太大)。 到目前为止,我已将 source file 复制到一个单独的目录树中,并尝试使用以下 Makefile:

对其进行编译
obj-m += binfmt_elf_mod.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

模块已生成,但出现以下警告:

make -C /lib/modules/3.13.0-32-generic/build M=/path/to/source/Resources modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-32-generic'
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "start_thread" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "arch_randomize_brk" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "find_extend_vma" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "security_bprm_secureexec" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "vdso_enabled" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "arch_align_stack" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "arch_setup_additional_pages" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "randomize_va_space" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "set_personality_64bit" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "elf_core_write_extra_data" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "get_dump_page" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "elf_core_write_extra_phdrs" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "task_cputime" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "elf_core_extra_data_size" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "copy_siginfo_to_user" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "thread_group_cputime" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "elf_core_extra_phdrs" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "arch_vma_name" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
WARNING: "get_gate_vma" [/path/to/source/Resources/binfmt_elf_mod.ko] undefined!
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-32-generic'

目前我正在使用 /lib/modules/3.13.0-32-generic 中的默认构建脚本而不是下载的源代码进行构建。如何解决这些依赖关系?

实际上,你不能。 Linux 内核中的 ELF 加载器链接了一些内核模块不可用的符号。

但更糟糕的是,如果您将 ELF 加载程序构建为模块,您将无法启动系统!您正在构建的模块和加载它的可执行文件都是 ELF 可执行文件;如果内核中已经存在 ELF 支持,则无法使用它们。