- 论坛徽章:
- 1
|
总算找到了
Documentation/kbuild/modules.txt
- 442 === 7. Module versioning & Module.symvers
- 443
- 444 Module versioning is enabled by the CONFIG_MODVERSIONS tag.
- 445
- 446 Module versioning is used as a simple ABI consistency check. The Module
- 447 versioning creates a CRC value of the full prototype for an exported symbol and
- 448 when a module is loaded/used then the CRC values contained in the kernel are
- 449 compared with similar values in the module. If they are not equal, then the
- 450 kernel refuses to load the module.
- 451
- 452 Module.symvers contains a list of all exported symbols from a kernel build.
- 453
- 454 --- 7.1 Symbols from the kernel (vmlinux + modules)
- 455
- 456 During a kernel build, a file named Module.symvers will be generated.
- 457 Module.symvers contains all exported symbols from the kernel and
- 458 compiled modules. For each symbols, the corresponding CRC value
- 459 is stored too.
- 460
- 461 The syntax of the Module.symvers file is:
- 462 <CRC> <Symbol> <module>
- 463 Sample:
- 464 0x2d036834 scsi_remove_host drivers/scsi/scsi_mod
- 465
- 466 For a kernel build without CONFIG_MODVERSIONS enabled, the crc
- 467 would read: 0x00000000
- 468
- 469 Module.symvers serves two purposes:
- 470 1) It lists all exported symbols both from vmlinux and all modules
- 471 2) It lists the CRC if CONFIG_MODVERSIONS is enabled
- 472
- 473 --- 7.2 Symbols and external modules
- 474
- 475 When building an external module, the build system needs access to
- 476 the symbols from the kernel to check if all external symbols are
- 477 defined. This is done in the MODPOST step and to obtain all
- 478 symbols, modpost reads Module.symvers from the kernel.
- 479 If a Module.symvers file is present in the directory where
- 480 the external module is being built, this file will be read too.
- 481 During the MODPOST step, a new Module.symvers file will be written
- 482 containing all exported symbols that were not defined in the kernel.
- 483
- 484 --- 7.3 Symbols from another external module
- 485
- 486 Sometimes, an external module uses exported symbols from another
- 487 external module. Kbuild needs to have full knowledge on all symbols
- 488 to avoid spitting out warnings about undefined symbols.
- 489 Three solutions exist to let kbuild know all symbols of more than
- 490 one external module.
- 491 The method with a top-level kbuild file is recommended but may be
- 492 impractical in certain situations.
- 493
- 494 Use a top-level Kbuild file
- 495 If you have two modules: 'foo' and 'bar', and 'foo' needs
- 496 symbols from 'bar', then one can use a common top-level kbuild
- 497 file so both modules are compiled in same build.
- 498
- 499 Consider following directory layout:
- 500 ./foo/ <= contains the foo module
- 501 ./bar/ <= contains the bar module
- 502 The top-level Kbuild file would then look like:
- 503
- 504 #./Kbuild: (this file may also be named Makefile)
- 505 obj-y := foo/ bar/
- 506
- 507 Executing:
- 508 make -C $KDIR M=`pwd`
- 509
- 510 will then do the expected and compile both modules with full
- 511 knowledge on symbols from both modules.
- 512
- 513 Use an extra Module.symvers file
- 514 When an external module is built, a Module.symvers file is
- 515 generated containing all exported symbols which are not
- 516 defined in the kernel.
- 517 To get access to symbols from module 'bar', one can copy the
- 518 Module.symvers file from the compilation of the 'bar' module
- 519 to the directory where the 'foo' module is built.
- 520 During the module build, kbuild will read the Module.symvers
- 521 file in the directory of the external module and when the
- 522 build is finished, a new Module.symvers file is created
- 523 containing the sum of all symbols defined and not part of the
- 524 kernel.
- 525
- 526 Use make variable KBUILD_EXTRA_SYMBOLS in the Makefile
- 527 If it is impractical to copy Module.symvers from another
- 528 module, you can assign a space separated list of files to
- 529 KBUILD_EXTRA_SYMBOLS in your Makfile. These files will be
- 530 loaded by modpost during the initialisation of its symbol
- 531 tables.
- 532
复制代码 |
|