According include/linux/module.h: /* For every exported symbol, place a struct in the __ksymtab section */ #define __EXPORT_SYMBOL(sym, sec) \ extern typeof(sym) sym; \ __CRC_SYMBOL(sym, sec) \ static const char __kstrtab_##sym[] \ __attribute__((section("__ksymtab_strings"), aligned(1))) \ = MODULE_SYMBOL_PREFIX #sym; \ static const struct kernel_symbol __ksymtab_##sym \ __used \ __attribute__((section("__ksymtab" sec), unused)) \ = { (unsigned long)&sym, __kstrtab_##sym } #define EXPORT_SYMBOL(sym) \ __EXPORT_SYMBOL(sym, "") first noticed the "extern".....so that the symbol can be accessed outside the current file, and this also means that any other file wanting to use the symbol must use "extern" to access it as well. next u noticed the CRC_SYMBOL above, it is defined in the same file: #ifndef __GENKSYMS__ #ifdef CONFIG_MODVERSIONS /* Mark the CRC weak since genksyms apparently decides not to * generate a checksums for some symbols */ #define __CRC_SYMBOL(sym, sec) \ extern void *__crc_##sym __attribute__((weak)); \ static const unsigned long __kcrctab_##sym \ __used \ __attribute__((section("__kcrctab" sec), unused)) \ = (unsigned long) &__crc_##sym; #else #define __CRC_SYMBOL(sym, sec) #endif where the crc is stored together with the name: struct modversion_info { unsigned long crc; char name[MODULE_NAME_LEN]; }; As far as I know, this is first created during modposting: scripts/mod/modpost.c: #define CRC_PFX MODULE_SYMBOL_PREFIX "__crc_" #define KSYMTAB_PFX MODULE_SYMBOL_PREFIX "__ksymtab_" static void handle_modversions(struct module *mod, struct elf_info *info, Elf_Sym *sym, const char *symname) { unsigned int crc; enum export export = export_from_sec(info, sym->st_shndx); switch (sym->st_shndx) { case SHN_COMMON: warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); break; case SHN_ABS: /* CRC'd symbol */ if (memcmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { crc = (unsigned int) sym->st_value; sym_update_crc(symname + strlen(CRC_PFX), mod, crc, export); } break; case SHN_UNDEF: /* undefined symbol */ if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && ELF_ST_BIND(sym->st_info) != STB_WEAK) break; where main()---->read_symbol()--->handle_modversions() etc. who is the user of the CRC? I guessed it is during the mod loading stage......but let others contribute from here.....i did not check further than here. On Wed, Feb 25, 2009 at 8:36 PM, Durga Prasad <writexdp@xxxxxxxxx> wrote: > Using elfread, I could see that symbol "struct_module" is saved in the > __versions section of moduleX.ko > Typo above. the tool used in readelf. > - Durga > ________________________________ > From: Durga Prasad <writexdp@xxxxxxxxx> > To: kernelnewbies@xxxxxxxxxxxx > Sent: Wednesday, February 25, 2009 6:01:37 PM > Subject: How does EXPORT_SYMBOL work? > > Hi, > I am trying to understand how module versioning works in Linux kernel. > If I have a moduleX.ko file with me, how do I determine if it would load > successfully (using insmod or modprobe)? This is purely from versioning > perspective. I assume that no other errors related to memory allocation, > etc. > From the code, I could see the load_module () compares the CRC of the module > against the CRC of "struct_module" symbol in the kernel. > When are these CRCs created. Using elfread, I could see that symbol > "struct_module" is saved in the __versions section of moduleX.ko > I could not understand the EXPORT_SYMBOL code clearly. It seem to me that it > creates a CRC (somehow) and saves to the kernel symbol table (kallsyms?) > Please clarify to clear my doubt. > Thanks > Durga > > -- Regards, Peter Teoh -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ