内核编译期间的奇怪错误

Strange error during kernel compilation

我编辑了 2.6.32.65 linux 内核的某些部分并编译了它。内核编译得很好并正常生成 bzImage。然而 make 然后继续如下:

Kernel: arch/x86/boot/bzImage is ready.  (#170)
   Building modules, stage 2.
   MODPOST 2414 modules.
ERROR: "external_page_start" [fs/cachefiles/cachefiles.ko] undefined!
ERROR: "variable_hash_start" [fs/cachefiles/cachefiles.ko] undefined!

不过这有两个问题。 首先,这些变量在头文件include/linux/stthash.h中定义如下:

extern unsigned long fixed_hash_start;
extern unsigned long variable_hash_start;
extern unsigned long external_page_start;
extern unsigned long command_space_start;

mm/page_alloc.c中定义如下:

unsigned long fixed_hash_start;
unsigned long variable_hash_start;
unsigned long external_page_start;
unsigned long command_space_start;

然后根据需要为它们分配变量。他们确实通过了编译并创建了 bzImage 所以我不知道那有什么问题。

第二个问题是 fs/cachefiles 中的任何文件都没有使用 variable_hash_start,[=19= 中只有 external_page_start 被访问(读取,而不是写入) ].

我不知道是什么导致了这个错误,我猜测 cachefiles.ko 中的变量没有正确链接,但我不知道如何解决这个问题。有帮助吗?

首先,构建内核时遇到错误modules,它们是独立于主内核映像生成的,因此模块中的错误将停止编译,但仍然会给你 bzImage.

另外,随意浏览内核2.6.32.65发现变量external_page_start和command_space_start在mm/page_alloc.c

中不存在

https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/mm/page_alloc.c?id=refs/tags/v2.6.32.65

但是你没有告诉我们你修改了什么,那些变量是你加的吗?

在任何情况下,包括您定义这些变量的正确头文件将停止未定义变量错误。

Linux 内核的动态模块在默认情况下无法访问内核中的全局变量和函数(头文件中的函数除外)。您需要专门为模块导出它。

EXPORT_SYMBOL宏是最常用的一个。您也可以通过使用 EXPORT_SYMBOL_GPL.

导出变量和函数来限制仅 GPL 模块访问您的变量和函数

详情: http://tuxthink.blogspot.in/2011/07/exporting-symbols-from-module.html