If two kernel module contain EXPORT_SYMBOL(a), a is defined as: int a, what will happen if two module was inserted? which "a" will be used?
It is used to qualify a declaration to a non-static symbol from another translation unit. EXPORT_SYMBOL() is specific to the Linux kernel. It is used in the translation unit of the definition to make the symbol available to loadable modules.
A user can link a module into the running kernel by executing the insmod external program. This program performs the following operations: Reads from the command line the name of the module to be linked. Locates the file containing the module's object code in the system directory tree.
Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. A module can be configured as built-in or loadable.
To load a kernel module, use the /sbin/modprobe command followed by the kernel module name. By default, modprobe attempts to load the module from the /lib/modules/<kernel-version>/kernel/drivers/ subdirectories.
You can't insert duplicate symbols into the kernel. Example:
xor
module loaded in my kernelnwatkins@kyoto:~$ lsmod | grep xor
xor 4685 1 async_xor
xor_blocks
symbol in the xor
modulenwatkins@kyoto:~$ nm /lib/modules/2.6.32-24-generic/kernel/crypto/xor.ko | grep xor_blocks
0000000000000000 r __kcrctab_xor_blocks
0000000000000000 r __kstrtab_xor_blocks
0000000000000000 r __ksymtab_xor_blocks
0000000000000bb0 T xor_blocks
xor_blocks
symbol in a module I creatednwatkins@kyoto:~$ nm mod-t1.ko | grep xor
0000000000000000 r __kcrctab_xor_blocks
0000000000000000 r __kstrtab_xor_blocks
0000000000000000 r __ksymtab_xor_blocks
0000000000000000 T xor_blocks
insmod
nwatkins@kyoto:~$ sudo insmod mod-t1.ko
insmod: error inserting 'mod-t1.ko': -1 Invalid module format
dmesg
[422002.174033] mod_t1: exports duplicate symbol xor_blocks (owned by xor)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With