关于内核中export_symbols()用后warning修改。

no symbol version for XXXX  


    用EXPORT_SYMBOL引出函数后,第二个模块加载时候报错:
osd: no symbol version for func_test
osd: Unknown symbol func_test
    确认了下,GPL声明了,/proc/kallsyms里也能查到func_test。查了半天终于明白了
    6.1 Symbols From the Kernel (vmlinux + modules)

        During a kernel build, a file named Module.symvers will be generated. Module.symvers contains all exported symbols from the kernel and compiled modules. For each symbol, the corresponding CRC value is also stored.
        The syntax of the Module.symvers file is:
                <CRC>       <Symbol>           <module>
                0x2d036834  scsi_remove_host   drivers/scsi/scsi_mod
        For a kernel build without CONFIG_MODVERSIONS enabled, the CRC would read 0x00000000.
        Module.symvers serves two purposes:
        1) It lists all exported symbols from vmlinux and all modules.
        2) It lists the CRC if CONFIG_MODVERSIONS is enabled.

    6.2 Symbols and External Modules
        When building an external module, the build system needs access to the symbols from the kernel to check if all external symbols  are defined. This is done in the MODPOST step. modpost obtains the symbols by reading Module.symvers from the kernel source tree. If a Module.symvers file is present in the directory where the external module is being built, this file will be read too. During the MODPOST step, a new Module.symvers file will be written containing all exported symbols that were not defined in the kernel.

    6.3 Symbols From Another External Module
        Sometimes, an external module uses exported symbols from another external module. kbuild needs to have full knowledge of all symbols to avoid spitting 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.

   即
有两个我们自己的模块,其中Module B使用了Module A中export的函数,因此在Module B的Makefile中必须加上这样的选项
KBUILD_EXTRA_SYMBOLS += /path/to/Module A/Module.symvers
export KBUILD_EXTRA_SYMBOLS

这样在编译Module B时,才不会出现Warning,提示说func1这个符号找不到,而编译得到的ko加载时也会出错。






转自http://falloutmx.blog.163.com/blog/static/39236020201110152245513/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值