Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


The following call is needed to generate the checksum of the exported function^25 :

wolfgang@meitner>gcc -E test.h -D__GENKSYMS__ -D__KERNEL__ | genksyms > test.ver

The contents oftest.verare then as follows:

wolfgang@meitner>cat test.ver
__crc_accelerate_task = 0x3341f339 ;

If the definition ofaccelerate_taskchanges because, for example, an integer is used as the first param-
eter, the checksum also changes: in this case,genksymcalculates0xbb29f607.

If several symbols are defined in a file,genksymsgenerates several checksums. The resulting file has the
following sample contents for thevfatmodule:

wolfgang@meitner>cat .tmp_vfat.ver
__crc_vfat_create = 0x50fed954 ;
__crc_vfat_unlink = 0xe8acaa66 ;
__crc_vfat_mkdir = 0x66923cde ;
__crc_vfat_rmdir = 0xd3bf328b ;
__crc_vfat_rename = 0xc2cd0db3 ;
__crc_vfat_lookup = 0x61b29e32 ;

This is a script for the linkerldwhose significance in the compilation process is explained below.

Linking Into Modulesand the Kernel


The kernel must incorporate the information supplied bygenksymin the binary code of a module in order
to use it later; how this is done is discussed in the following.

Exported Functions


Recall that__EXPORT_SYMBOLcalls the__CRC_SYMBOLmacro internally, as discussed in Section 7.3.3. This
is defined as follows when version control is enabled:

<module.h>
#define __CRC_SYMBOL(sym, sec) \
extern void *__crc_##sym __attribute__((weak)); \
static const unsigned long __kcrctab_##sym \
__attribute_used__ \
__attribute__((section("__kcrctab" sec), unused)) \
= (unsigned long) &__crc_##sym;

WhenEXPORT_SYMBOL(get_shorty)is called,__CRC_SYMBOLexpands as follows:

extern void *__crc_get_richard __attribute__((weak));
static const unsigned long __kcrctab_get_shorty
__attribute_used__
__attribute__((section("__kcrctab" ""), unused)) =
(unsigned long) &__crc_get_shorty;

(^25) For simplicity’s sake, the parameters for matching the include paths to the kernel sources are not shown; also, in a genuine module
compilation,-DMODULE, for example, would also be specified. Refer to the output ofmake modulesfor details.

Free download pdf