Search code examples
linuxlinux-kernelkernel-module

How to get default kernel module name from *.ko files?


Usually, the filename of a kernel module is the same as the module name. For example, after doing insmod fuse.ko, I can see fuse inserted in /proc/modules.

However, renaming the kernel module (mv fuse.ko foo.ko) doesn't affect the inserted module name. Doing insmod foo.ko still inserts fuse in /proc/modules.

Is there any system call or glibc function that can extract the module name from a kernel module file? In the previous example, I want to extract the name fuse from foo.ko.


Solution

  • Name of the module is contained in THIS_MODULE module object (of type struct module). This object is stored in the kernel module file as a section .gnu.linkonce.this_module.

    So, you may examine content of that section and find module's name there:

    objdump -s -j .gnu.linkonce.this_module foo.ko
    

    or

    readelf -x .gnu.linkonce.this_module foo.ko
    

    Module name is located at offset 12 (on 32-bit machine) or at offset 24 (on 64-bit machine).


    modinfo doesn't print module's name. Probably, this is because offset of the name in the struct module structure is not standardized.