Reg: Kernel library - Linux

This is a discussion on Reg: Kernel library - Linux ; Hi, Actually I have some common code which I want to use as a library for my kernel modules. Can anybody tell me how to make kernel library (static or dynamic) and how to use that library for compiling my ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Reg: Kernel library

  1. Reg: Kernel library

    Hi,
    Actually I have some common code which I want to use as a library
    for my kernel modules. Can anybody tell me how to make kernel library
    (static or dynamic) and how to use that library for compiling my
    kernel modules.


    regards
    bsahai


  2. Re: Reg: Kernel library

    bsahai wrote:
    > Hi,
    > Actually I have some common code which I want to use as a library
    > for my kernel modules. Can anybody tell me how to make kernel library
    > (static or dynamic) and how to use that library for compiling my
    > kernel modules.


    There are two ways to do that:
    1. if your library is generic enough to be used by a huge amount of
    modules, you'd compile it into the core kernel and export the symbols
    for use by the modules.
    2. if your library is only relevant to a few modules, put it into a
    module itself and export the symbols. depmod and modprobe will take care
    of the dependencies for you.
    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html


  3. Re: Reg: Kernel library

    bsahai schrieb:
    > Hi,
    > Actually I have some common code which I want to use as a library
    > for my kernel modules. Can anybody tell me how to make kernel library
    > (static or dynamic) and how to use that library for compiling my
    > kernel modules.
    >

    "Static library": Nothing prevents you from bundling .o files into a .a
    archive (static library) with "ar" and use that one during your module
    compilation steps instead of a bunch of .o files.

    "dynamic library": You have to understand there is no "standard" dynamic
    loader like "ld" in Linux kernel code. Instead, the kernel for various
    reasons has it's own dynamic loader, which consists of driver modules,
    dependency files and "modprobe" as the dynamic loader.

    So the only things you have to do for establishing your "dynamic kernel code
    library" is to create a kernel module "bsahai_lib" with all your common
    code, mark all useful symbols in that module as exported using the
    EXPORT_SYMBOL(symbol_name); or EXPORT_SYMBOL_GPL(symbol_name); macro.

    Then write your other modules (e.g. "bsahai_useful_module"), which are using
    at least one of the exported symbols of "bsahai_lib".

    Install all the modules into /lib/modules/$(uname -r)/ or any subdirectory
    of it, run "depmod -a" and now, whenever you run

    # modprobe bsahai_useful_module

    the "bsahai_lib" module is loaded before "bsahai_useful_module"
    automagically.


    Kind regards

    Jan

+ Reply to Thread