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

时间:2015-03-12 00:52:48

标签: c linux ubuntu linux-kernel kernel-module

这个问题是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 中的默认构建脚本而不是下载的源构建。如何解决这些依赖关系呢?

1 个答案:

答案 0 :(得分:2)

实际上,你不能。 Linux内核中的ELF加载程序链接了许多内核模块无法使用的符号。

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