简体   繁体   中英

Why would a Linux kernel module symbol not be exported globally properly?

We have written a number of kernel modules and many with exported symbols that all work fine except for 2 symbols (which is baffling). We have exported them as all the others but the 2 symbols are not globally exported once they are inserted into the kernel.

In our C code we have (in wdt.ko):

EXPORT_SYMBOL(WDT_Enable);
EXPORT_SYMBOL(WDT_Disable);

If we run nm on the generated kernel object, they appear correctly:

nm wdt.ko | grep WDT
00000000 T WDT_Enable
00000000 T WDT_Disable

This should mean that those symbols are globally exported. Once we insmod the kernel object:

# insmod wdt.ko
# insmod apphandler.ko
apphandler: Unknown symbol WDT_Enable
apphandler: Unknown symbol WDT_Disable

If we look at the kallsyms:

# cat /proc/kallsyms | grep WDT
c12504dc t WDT_Enable  [wdt]
c12502d8 t WDT_Disable [wdt]

Once they are inside the kernel, they are not global.

We have confirmed that correct file is being inserted into the kernel and that the functions are visible in the same module, but we cannot explain why the symbols suddenly become local and not global like nm suggests.

Does anyone know where our error might be?

Ok - shortly after posting the question we noticed that our include paths were missing the module include:

#include <linux/module.h>

The code seemed to compile file without the #include being included and the compiler did not generate errors or complaints but the net effect was that the symbols where not available to subsequent modules.

Since including the header file the symbols indicated above are available to modules and the kernel is able to resolve and execute the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM