Re: About exporting symbols from an external module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 






On Tue, Jan 14, 2014 at 12:38 PM, Le Tan <tamlokveer@xxxxxxxxx> wrote:
Thanks very much! I will try that later. What you mentioned is another amazing sight. But I am confused that why it can't work if I export a function from my module and call it in the kvm? Do I have to modify the makefile of kvm? How? I have referenced to the doc of KBuild. It said that :
    Sometimes, an external module uses exported symbols from
    another external module. kbuild needs to have full knowledge of
    all symbols to avoid spliitting out warnings about undefined
    symbols. Three solutions exist for this situation.
 
    NOTE: The method with a top-level kbuild file is recommended
    but may be impractical in certain situations.
 
    Use a top-level kbuild file
        If you have two modules, foo.ko and bar.ko, where
        foo.ko needs symbols from bar.ko, you can use a
        common top-level kbuild file so both modules are
        compiled in the same build. Consider the following
        directory layout:
 
        ./foo/ <= contains foo.ko
        ./bar/ <= contains bar.ko
 
        The top-level kbuild file would then look like:
 
        #./Kbuild (or ./Makefile):
            obj-y := foo/ bar/
 
        And executing
 
            $ make -C $KDIR M=$PWD
 
        will then do the expected and compile both modules with
        full knowledge of symbols from either module.
 
    Use an extra Module.symvers file
        When an external module is built, a Module.symvers file
        is generated containing all exported symbols which are
        not defined in the kernel. To get access to symbols
        from bar.ko, copy the Module.symvers file from the
        compilation of bar.ko to the directory where foo.ko is
        built. During the module build, kbuild will read the
        Module.symvers file in the directory of the external
        module, and when the build is finished, a new
        Module.symvers file is created containing the sum of
        all symbols defined and not part of the kernel.
 
    Use "make" variable KBUILD_EXTRA_SYMBOLS
        If it is impractical to copy Module.symvers from
        another module, you can assign a space separated list
        of files to KBUILD_EXTRA_SYMBOLS in your build file.
        These files will be loaded by modpost during the
        initialization of its symbol tables.

But I have tried those methods. They don't work. Why?
Thanks for your help very much!
 
Please show your kvm module makefile, 
 
 


2014/1/14 Henrique Rodrigues <henriquesilvar@xxxxxxxxx>
Hi Le,

You can do that by exporting a function pointer from the kvm code that is only called if it is not null. Then, when you load your module, you set that exported function pointer (I'm assuming that you want to call your module's function from the kvm code... ). Here is a post on how to do that:


Best,
--
Henrique Rodrigues


On Mon, Jan 13, 2014 at 2:47 AM, Le Tan <tamlokveer@xxxxxxxxx> wrote:
Hello! I am writing a device driver module. I define some functions in the module, for example print_record(). I am doing something in the kvm, so I want to call print_record() in the file of kvm module, for example, I may call print_record() in file /arch/x86/kvm/x86.c to put something into my device driver module.
Now comes the question.
1. Where should I put the codes of my device driver module? It's the first time I write the device driver.
2. After compiling my module, I encounter an error when I compile the kvm module.
     ERROR: "print_record" [arch/x86/kvm/kvm.ko] undefined!
    I use EXPORT_SYMBOL(print_record) in my module file. I use "extern" to declare print_record() and then call print_record()  in file x86.c. 
    To solve this problem, I have tried to copy the Module.symvers from my module folder to /arch/x86/kvm/. But it doesn't work. I have also tried to add KBUILD_EXTRA_SYMBOLS to the Makefile of kvm. It doesn't work either.
    I cat /proc/kallsyms and find that the type of symbol "print_record" is "t" ( local text). What should I do? How to call functions defined in my own module from kvm? Maybe there is something wrong in Makefiles?

Any suggestion is appreciated!
Thanks!

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies




_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux