Find the answer to your Linux question:
Results 1 to 6 of 6
Hi all, I am writing some modules in linux 2.6 and have some wonders. The following text is from the book Linux Device Driver 3rd edition: Regardless of the origin ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2004
    Posts
    47

    question regarding linux -2.6 modules


    Hi all,

    I am writing some modules in linux 2.6 and have some wonders. The following text is from the book Linux Device Driver 3rd edition:

    Regardless of the origin of your kernel, building modules for 2.6.x requires that you
    have a configured and built kernel tree on your system. This requirement is a change
    from previous versions of the kernel, where a current set of header files was sufficient.
    2.6 modules are linked against object files found in the kernel source tree; the
    result is a more robust module loader, but also the requirement that those object filesbe available.
    I don't really understand what "2.6 modules are linked against object files found in the kernel source tree" the author said means. How do modules link against kernel object files? I suppose kernel modules just dereference exported kernel symbols they used after they are loaded into kernel. Do I misunderstand somewhere? Moreover, I observed that the 2.6 module binary (*.ko) is quite bigger in size comparing with 2.4 old one, which give some feeling about additional linking (???). Could some body explain to me about above text in the book and why 2.6 module size is so large? Or give me some documents. I had a search but didn't find.

    Thanks very much

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    The answer is in that paragraph right there:
    Rather than just referencing header files, each module is linked against a set of object files in the kernel source tree, resulting in a larger module.

  3. #3
    Just Joined!
    Join Date
    Nov 2004
    Posts
    47
    ok, the text may implies why a kernel binary is larger in size. But how is the linking? Include kernel code in module code?

  4. #4
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    Well, kernel modules, afaik, are statically linked against the 2.6 source tree's object files, so that means that the code has to be built in the modules (or else you'd have to require everybody who uses a kernel module to have a source tree installed in the exact same place)

  5. #5
    Just Joined!
    Join Date
    Nov 2004
    Posts
    47
    Well, kernel modules, afaik, are statically linked against the 2.6 source tree's object files, so that means that the code has to be built in the modules
    It 's clearer now.

    So it means all kernel modules (including which are in kernel source tree but are configured as loadable modules rather than built-in) are statically linked to all kernel functions they use. It means modules no longer link to kernel when they are loaded into kernel (as linking means dereference kernel functions in kernel symbol table).

    or else you'd have to require everybody who uses a kernel module to have a source tree installed in the exact same place
    I don't understand. Did you mean this way "or else you'd have to require everybody who uses your kernel module to run a kernel which provides all symbols your module calls" (I suppose this is the way old 2.4 worked)

    There are more things I need to find out before I can understand this. Because now the module is independent of kernel code, all it needs is already included in itself, can it break some policy the running kernel selected (suppose the runing kernel configuration is different from the kernel configuration against which we built our module, this is also an expected situation because if we can be always sure that the two kernels are same then we don't need the mentioned method). Or there is no way for such a situation? I am thinking How is your idea?

  6. #6
    Just Joined!
    Join Date
    Nov 2004
    Posts
    47
    I am building modules for my embedded board. So size of modules is really considered. I 've had some tests and found my answer.

    At the time I posted my question here, I built my module with CONFIG_DEBUG_INFO enabled in kernel configuration (without notice about it). The resulting module size was 127102 bytes, which is quite large comparing with one compiled with linux-2.4 (3372 bytes). And at that same time, I read the book mentioned above. The text in the book as well as the fact about module size made me think that kernel functions are statically linked with module. But the idea of modules are statically link with kernel functions is so strange, I think, as in my above message.

    When I disable CONFIG_DEBUG_INFO in kernel configuration and rebuild my module, I get module executable of size 7410 bytes (linux-2.6 may produce modules with larger size than linux-2.4 but I can't discuss about this here, because I have modified my module code when moving it to 2.6). Now module size is returned to normal value as I expected.

    Then I used nm program to examine my module binaries in both case (one built with COFIG_DEBUG_INFO and one built without CONFIG_DEBUG_INFO) and found that all called kernel symbols are marked as U (undefined reference, which means the symbols are not defined anywhere in the binary itself) for both case. So kernel symbols aren't linked into modules, are they?

    Code:
             U __arch_copy_to_user
    00000000 T cleanup_module
             U free_irq
    00000000 T init_module
             U jiffies
    00000008 b keyData
    00000000 t keypad_cleanup
    00000004 D keypad_fop
    00000000 D keypad_fop_array
    00000000 t keypad_init
    000004b8 T keypad_isr
    00000000 t keypad_open
    00000454 t keypad_read
    0000038c t keypad_release
    00000000 b keypad_usage
    00000004 b me_current.0
    00000000 r __mod_license315
    00000030 r __module_depends
    0000000c r __mod_vermagic5
             U printk
             U register_chrdev
             U request_irq
             U s3c2410_gpio_cfgpin
    00000000 D __this_module
             U unregister_chrdev
    00000000 r ____versions
    Moreover, I try to compile my module with an uncompiled kernel (only make config done and some symbolic links like ~asm and ~arch in /include directory are made) and the module build process is also fine. It means, module build process just do reference to kernel configuration, it doesn't link any thing from kernel into the being built modules or refer to any kernel objects.

    Someone confirm my idea?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •