1 /* Postprocess module symbol versions
3 * Copyright 2003 Kai Germaschewski
4 * Copyright 2002-2004 Rusty Russell, IBM Corporation
5 * Copyright 2006-2008 Sam Ravnborg
6 * Based in part on module-init-tools/depmod.c,file2alias
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * Usage: modpost vmlinux module1.o module2.o ...
16 #include "../../include/linux/license.h"
18 /* Are we using CONFIG_MODVERSIONS? */
20 /* Warn about undefined symbols? (do so if we have vmlinux) */
22 /* Is CONFIG_MODULE_SRCVERSION_ALL set? */
23 static int all_versions = 0;
24 /* If we are modposting external module set to 1 */
25 static int external_module = 0;
26 /* Warn about section mismatch in vmlinux if set to 1 */
27 static int vmlinux_section_warnings = 1;
28 /* Only warn about unresolved symbols */
29 static int warn_unresolved = 0;
30 /* How a symbol is exported */
31 static int sec_mismatch_count = 0;
32 static int sec_mismatch_verbose = 1;
35 export_plain, export_unused, export_gpl,
36 export_unused_gpl, export_gpl_future, export_unknown
39 #define PRINTF __attribute__ ((format (printf, 1, 2)))
41 PRINTF void fatal(const char *fmt, ...)
45 fprintf(stderr, "FATAL: ");
47 va_start(arglist, fmt);
48 vfprintf(stderr, fmt, arglist);
54 PRINTF void warn(const char *fmt, ...)
58 fprintf(stderr, "WARNING: ");
60 va_start(arglist, fmt);
61 vfprintf(stderr, fmt, arglist);
65 PRINTF void merror(const char *fmt, ...)
69 fprintf(stderr, "ERROR: ");
71 va_start(arglist, fmt);
72 vfprintf(stderr, fmt, arglist);
76 static int is_vmlinux(const char *modname)
80 myname = strrchr(modname, '/');
86 return (strcmp(myname, "vmlinux") == 0) ||
87 (strcmp(myname, "vmlinux.o") == 0);
90 void *do_nofail(void *ptr, const char *expr)
93 fatal("modpost: Memory allocation failure: %s.\n", expr);
98 /* A list of all modules we processed */
99 static struct module *modules;
101 static struct module *find_module(char *modname)
105 for (mod = modules; mod; mod = mod->next)
106 if (strcmp(mod->name, modname) == 0)
111 static struct module *new_module(char *modname)
116 mod = NOFAIL(malloc(sizeof(*mod)));
117 memset(mod, 0, sizeof(*mod));
118 p = NOFAIL(strdup(modname));
120 /* strip trailing .o */
123 if (strcmp(s, ".o") == 0)
128 mod->gpl_compatible = -1;
135 /* A hash of all exported symbols,
136 * struct symbol is also used for lists of unresolved symbols */
138 #define SYMBOL_HASH_SIZE 1024
142 struct module *module;
146 unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */
147 unsigned int kernel:1; /* 1 if symbol is from kernel
148 * (only for external modules) **/
149 unsigned int preloaded:1; /* 1 if symbol from Module.symvers */
150 enum export export; /* Type of export */
154 static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
156 /* This is based on the hash agorithm from gdbm, via tdb */
157 static inline unsigned int tdb_hash(const char *name)
159 unsigned value; /* Used to compute the hash value. */
160 unsigned i; /* Used to cycle through random values. */
162 /* Set the initial value from the key size. */
163 for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++)
164 value = (value + (((unsigned char *)name)[i] << (i*5 % 24)));
166 return (1103515243 * value + 12345);
170 * Allocate a new symbols for use in the hash of exported symbols or
171 * the list of unresolved symbols per module
173 static struct symbol *alloc_symbol(const char *name, unsigned int weak,
176 struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
178 memset(s, 0, sizeof(*s));
179 strcpy(s->name, name);
185 /* For the hash of exported symbols */
186 static struct symbol *new_symbol(const char *name, struct module *module,
192 hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
193 new = symbolhash[hash] = alloc_symbol(name, 0, symbolhash[hash]);
194 new->module = module;
195 new->export = export;
199 static struct symbol *find_symbol(const char *name)
203 /* For our purposes, .foo matches foo. PPC64 needs this. */
207 for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) {
208 if (strcmp(s->name, name) == 0)
218 { .str = "EXPORT_SYMBOL", .export = export_plain },
219 { .str = "EXPORT_UNUSED_SYMBOL", .export = export_unused },
220 { .str = "EXPORT_SYMBOL_GPL", .export = export_gpl },
221 { .str = "EXPORT_UNUSED_SYMBOL_GPL", .export = export_unused_gpl },
222 { .str = "EXPORT_SYMBOL_GPL_FUTURE", .export = export_gpl_future },
223 { .str = "(unknown)", .export = export_unknown },
227 static const char *export_str(enum export ex)
229 return export_list[ex].str;
232 static enum export export_no(const char *s)
237 return export_unknown;
238 for (i = 0; export_list[i].export != export_unknown; i++) {
239 if (strcmp(export_list[i].str, s) == 0)
240 return export_list[i].export;
242 return export_unknown;
245 static enum export export_from_sec(struct elf_info *elf, Elf_Section sec)
247 if (sec == elf->export_sec)
249 else if (sec == elf->export_unused_sec)
250 return export_unused;
251 else if (sec == elf->export_gpl_sec)
253 else if (sec == elf->export_unused_gpl_sec)
254 return export_unused_gpl;
255 else if (sec == elf->export_gpl_future_sec)
256 return export_gpl_future;
258 return export_unknown;
262 * Add an exported symbol - it may have already been added without a
263 * CRC, in this case just update the CRC
265 static struct symbol *sym_add_exported(const char *name, struct module *mod,
268 struct symbol *s = find_symbol(name);
271 s = new_symbol(name, mod, export);
274 warn("%s: '%s' exported twice. Previous export "
275 "was in %s%s\n", mod->name, name,
277 is_vmlinux(s->module->name) ?"":".ko");
279 /* In case Modules.symvers was out of date */
284 s->vmlinux = is_vmlinux(mod->name);
290 static void sym_update_crc(const char *name, struct module *mod,
291 unsigned int crc, enum export export)
293 struct symbol *s = find_symbol(name);
296 s = new_symbol(name, mod, export);
301 void *grab_file(const char *filename, unsigned long *size)
307 fd = open(filename, O_RDONLY);
308 if (fd < 0 || fstat(fd, &st) != 0)
312 map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
315 if (map == MAP_FAILED)
321 * Return a copy of the next line in a mmap'ed file.
322 * spaces in the beginning of the line is trimmed away.
323 * Return a pointer to a static buffer.
325 char *get_next_line(unsigned long *pos, void *file, unsigned long size)
327 static char line[4096];
330 signed char *p = (signed char *)file + *pos;
333 for (; *pos < size ; (*pos)++) {
334 if (skip && isspace(*p)) {
339 if (*p != '\n' && (*pos < size)) {
343 break; /* Too long, stop */
354 void release_file(void *file, unsigned long size)
359 static int parse_elf(struct elf_info *info, const char *filename)
366 hdr = grab_file(filename, &info->size);
372 if (info->size < sizeof(*hdr)) {
373 /* file too small, assume this is an empty .o file */
376 /* Is this a valid ELF file? */
377 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
378 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
379 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
380 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
381 /* Not an ELF file - silently ignore it */
384 /* Fix endianness in ELF header */
385 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
386 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
387 hdr->e_shnum = TO_NATIVE(hdr->e_shnum);
388 hdr->e_machine = TO_NATIVE(hdr->e_machine);
389 hdr->e_type = TO_NATIVE(hdr->e_type);
390 sechdrs = (void *)hdr + hdr->e_shoff;
391 info->sechdrs = sechdrs;
393 /* Check if file offset is correct */
394 if (hdr->e_shoff > info->size) {
395 fatal("section header offset=%lu in file '%s' is bigger than "
396 "filesize=%lu\n", (unsigned long)hdr->e_shoff,
397 filename, info->size);
401 /* Fix endianness in section headers */
402 for (i = 0; i < hdr->e_shnum; i++) {
403 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type);
404 sechdrs[i].sh_offset = TO_NATIVE(sechdrs[i].sh_offset);
405 sechdrs[i].sh_size = TO_NATIVE(sechdrs[i].sh_size);
406 sechdrs[i].sh_link = TO_NATIVE(sechdrs[i].sh_link);
407 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name);
408 sechdrs[i].sh_info = TO_NATIVE(sechdrs[i].sh_info);
409 sechdrs[i].sh_addr = TO_NATIVE(sechdrs[i].sh_addr);
411 /* Find symbol table. */
412 for (i = 1; i < hdr->e_shnum; i++) {
413 const char *secstrings
414 = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
417 if (sechdrs[i].sh_offset > info->size) {
418 fatal("%s is truncated. sechdrs[i].sh_offset=%lu > "
419 "sizeof(*hrd)=%zu\n", filename,
420 (unsigned long)sechdrs[i].sh_offset,
424 secname = secstrings + sechdrs[i].sh_name;
425 if (strcmp(secname, ".modinfo") == 0) {
426 info->modinfo = (void *)hdr + sechdrs[i].sh_offset;
427 info->modinfo_len = sechdrs[i].sh_size;
428 } else if (strcmp(secname, "__ksymtab") == 0)
429 info->export_sec = i;
430 else if (strcmp(secname, "__ksymtab_unused") == 0)
431 info->export_unused_sec = i;
432 else if (strcmp(secname, "__ksymtab_gpl") == 0)
433 info->export_gpl_sec = i;
434 else if (strcmp(secname, "__ksymtab_unused_gpl") == 0)
435 info->export_unused_gpl_sec = i;
436 else if (strcmp(secname, "__ksymtab_gpl_future") == 0)
437 info->export_gpl_future_sec = i;
439 if (sechdrs[i].sh_type != SHT_SYMTAB)
442 info->symtab_start = (void *)hdr + sechdrs[i].sh_offset;
443 info->symtab_stop = (void *)hdr + sechdrs[i].sh_offset
444 + sechdrs[i].sh_size;
445 info->strtab = (void *)hdr +
446 sechdrs[sechdrs[i].sh_link].sh_offset;
448 if (!info->symtab_start)
449 fatal("%s has no symtab?\n", filename);
451 /* Fix endianness in symbols */
452 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
453 sym->st_shndx = TO_NATIVE(sym->st_shndx);
454 sym->st_name = TO_NATIVE(sym->st_name);
455 sym->st_value = TO_NATIVE(sym->st_value);
456 sym->st_size = TO_NATIVE(sym->st_size);
461 static void parse_elf_finish(struct elf_info *info)
463 release_file(info->hdr, info->size);
466 #define CRC_PFX MODULE_SYMBOL_PREFIX "__crc_"
467 #define KSYMTAB_PFX MODULE_SYMBOL_PREFIX "__ksymtab_"
469 static void handle_modversions(struct module *mod, struct elf_info *info,
470 Elf_Sym *sym, const char *symname)
473 enum export export = export_from_sec(info, sym->st_shndx);
475 switch (sym->st_shndx) {
477 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name);
481 if (memcmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) {
482 crc = (unsigned int) sym->st_value;
483 sym_update_crc(symname + strlen(CRC_PFX), mod, crc,
488 /* undefined symbol */
489 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
490 ELF_ST_BIND(sym->st_info) != STB_WEAK)
492 /* ignore global offset table */
493 if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
495 /* ignore __this_module, it will be resolved shortly */
496 if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0)
498 /* cope with newer glibc (2.3.4 or higher) STT_ definition in elf.h */
499 #if defined(STT_REGISTER) || defined(STT_SPARC_REGISTER)
500 /* add compatibility with older glibc */
501 #ifndef STT_SPARC_REGISTER
502 #define STT_SPARC_REGISTER STT_REGISTER
504 if (info->hdr->e_machine == EM_SPARC ||
505 info->hdr->e_machine == EM_SPARCV9) {
506 /* Ignore register directives. */
507 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
509 if (symname[0] == '.') {
510 char *munged = strdup(symname);
512 munged[1] = toupper(munged[1]);
518 if (memcmp(symname, MODULE_SYMBOL_PREFIX,
519 strlen(MODULE_SYMBOL_PREFIX)) == 0) {
521 alloc_symbol(symname +
522 strlen(MODULE_SYMBOL_PREFIX),
523 ELF_ST_BIND(sym->st_info) == STB_WEAK,
528 /* All exported symbols */
529 if (memcmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) {
530 sym_add_exported(symname + strlen(KSYMTAB_PFX), mod,
533 if (strcmp(symname, MODULE_SYMBOL_PREFIX "init_module") == 0)
535 if (strcmp(symname, MODULE_SYMBOL_PREFIX "cleanup_module") == 0)
536 mod->has_cleanup = 1;
542 * Parse tag=value strings from .modinfo section
544 static char *next_string(char *string, unsigned long *secsize)
546 /* Skip non-zero chars */
549 if ((*secsize)-- <= 1)
553 /* Skip any zero padding. */
556 if ((*secsize)-- <= 1)
562 static char *get_next_modinfo(void *modinfo, unsigned long modinfo_len,
563 const char *tag, char *info)
566 unsigned int taglen = strlen(tag);
567 unsigned long size = modinfo_len;
570 size -= info - (char *)modinfo;
571 modinfo = next_string(info, &size);
574 for (p = modinfo; p; p = next_string(p, &size)) {
575 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
576 return p + taglen + 1;
581 static char *get_modinfo(void *modinfo, unsigned long modinfo_len,
585 return get_next_modinfo(modinfo, modinfo_len, tag, NULL);
589 * Test if string s ends in string sub
592 static int strrcmp(const char *s, const char *sub)
600 sublen = strlen(sub);
602 if ((slen == 0) || (sublen == 0))
608 return memcmp(s + slen - sublen, sub, sublen);
611 static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
614 return elf->strtab + sym->st_name;
619 static const char *sec_name(struct elf_info *elf, int shndx)
621 Elf_Shdr *sechdrs = elf->sechdrs;
622 return (void *)elf->hdr +
623 elf->sechdrs[elf->hdr->e_shstrndx].sh_offset +
624 sechdrs[shndx].sh_name;
627 static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr)
629 return (void *)elf->hdr +
630 elf->sechdrs[elf->hdr->e_shstrndx].sh_offset +
634 /* if sym is empty or point to a string
635 * like ".[0-9]+" then return 1.
636 * This is the optional prefix added by ld to some sections
638 static int number_prefix(const char *sym)
646 if (c < '0' || c > '9')
652 /* The pattern is an array of simple patterns.
653 * "foo" will match an exact string equal to "foo"
654 * "*foo" will match a string that ends with "foo"
655 * "foo*" will match a string that begins with "foo"
656 * "foo$" will match a string equal to "foo" or "foo.1"
657 * where the '1' can be any number including several digits.
658 * The $ syntax is for sections where ld append a dot number
659 * to make section name unique.
661 int match(const char *sym, const char * const pat[])
666 const char *endp = p + strlen(p) - 1;
670 if (strrcmp(sym, p + 1) == 0)
674 else if (*endp == '*') {
675 if (strncmp(sym, p, strlen(p) - 1) == 0)
679 else if (*endp == '$') {
680 if (strncmp(sym, p, strlen(p) - 1) == 0) {
681 if (number_prefix(sym + strlen(p) - 1))
687 if (strcmp(p, sym) == 0)
695 /* sections that we do not want to do full section mismatch check on */
696 static const char *section_white_list[] =
697 { ".debug*", ".stab*", ".note*", ".got*", ".toc*", NULL };
699 #define ALL_INIT_DATA_SECTIONS \
700 ".init.data$", ".devinit.data$", ".cpuinit.data$", ".meminit.data$"
701 #define ALL_EXIT_DATA_SECTIONS \
702 ".exit.data$", ".devexit.data$", ".cpuexit.data$", ".memexit.data$"
704 #define ALL_INIT_TEXT_SECTIONS \
705 ".init.text$", ".devinit.text$", ".cpuinit.text$", ".meminit.text$"
706 #define ALL_EXIT_TEXT_SECTIONS \
707 ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$"
709 #define ALL_INIT_SECTIONS ALL_INIT_DATA_SECTIONS, ALL_INIT_TEXT_SECTIONS
710 #define ALL_EXIT_SECTIONS ALL_EXIT_DATA_SECTIONS, ALL_EXIT_TEXT_SECTIONS
712 #define DATA_SECTIONS ".data$", ".data.rel$"
713 #define TEXT_SECTIONS ".text$"
715 #define INIT_SECTIONS ".init.data$", ".init.text$"
716 #define DEV_INIT_SECTIONS ".devinit.data$", ".devinit.text$"
717 #define CPU_INIT_SECTIONS ".cpuinit.data$", ".cpuinit.text$"
718 #define MEM_INIT_SECTIONS ".meminit.data$", ".meminit.text$"
720 #define EXIT_SECTIONS ".exit.data$", ".exit.text$"
721 #define DEV_EXIT_SECTIONS ".devexit.data$", ".devexit.text$"
722 #define CPU_EXIT_SECTIONS ".cpuexit.data$", ".cpuexit.text$"
723 #define MEM_EXIT_SECTIONS ".memexit.data$", ".memexit.text$"
725 /* init data sections */
726 static const char *init_data_sections[] = { ALL_INIT_DATA_SECTIONS, NULL };
728 /* all init sections */
729 static const char *init_sections[] = { ALL_INIT_SECTIONS, NULL };
731 /* All init and exit sections (code + data) */
732 static const char *init_exit_sections[] =
733 {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL };
736 static const char *data_sections[] = { DATA_SECTIONS, NULL };
738 /* sections that may refer to an init/exit section with no warning */
739 static const char *initref_sections[] =
748 /* symbols in .data that may refer to init/exit sections */
749 static const char *symbol_white_list[] =
752 "*_template", /* scsi uses *_template a lot */
753 "*_timer", /* arm uses ops structures named _timer a lot */
754 "*_sht", /* scsi also used *_sht to some extent */
762 static const char *head_sections[] = { ".head.text*", NULL };
763 static const char *linker_symbols[] =
764 { "__init_begin", "_sinittext", "_einittext", NULL };
779 struct sectioncheck {
780 const char *fromsec[20];
781 const char *tosec[20];
782 enum mismatch mismatch;
785 const struct sectioncheck sectioncheck[] = {
786 /* Do not reference init/exit code/data from
787 * normal code and data
790 .fromsec = { TEXT_SECTIONS, NULL },
791 .tosec = { ALL_INIT_SECTIONS, NULL },
792 .mismatch = TEXT_TO_INIT,
795 .fromsec = { DATA_SECTIONS, NULL },
796 .tosec = { ALL_INIT_SECTIONS, NULL },
797 .mismatch = DATA_TO_INIT,
800 .fromsec = { TEXT_SECTIONS, NULL },
801 .tosec = { ALL_EXIT_SECTIONS, NULL },
802 .mismatch = TEXT_TO_EXIT,
805 .fromsec = { DATA_SECTIONS, NULL },
806 .tosec = { ALL_EXIT_SECTIONS, NULL },
807 .mismatch = DATA_TO_EXIT,
809 /* Do not reference init code/data from devinit/cpuinit/meminit code/data */
811 .fromsec = { DEV_INIT_SECTIONS, CPU_INIT_SECTIONS, MEM_INIT_SECTIONS, NULL },
812 .tosec = { INIT_SECTIONS, NULL },
813 .mismatch = XXXINIT_TO_INIT,
815 /* Do not reference exit code/data from devexit/cpuexit/memexit code/data */
817 .fromsec = { DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS, NULL },
818 .tosec = { EXIT_SECTIONS, NULL },
819 .mismatch = XXXEXIT_TO_EXIT,
821 /* Do not use exit code/data from init code */
823 .fromsec = { ALL_INIT_SECTIONS, NULL },
824 .tosec = { ALL_EXIT_SECTIONS, NULL },
825 .mismatch = INIT_TO_EXIT,
827 /* Do not use init code/data from exit code */
829 .fromsec = { ALL_EXIT_SECTIONS, NULL },
830 .tosec = { ALL_INIT_SECTIONS, NULL },
831 .mismatch = EXIT_TO_INIT,
833 /* Do not export init/exit functions or data */
835 .fromsec = { "__ksymtab*", NULL },
836 .tosec = { ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL },
837 .mismatch = EXPORT_TO_INIT_EXIT
841 static int section_mismatch(const char *fromsec, const char *tosec)
844 int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck);
845 const struct sectioncheck *check = §ioncheck[0];
847 for (i = 0; i < elems; i++) {
848 if (match(fromsec, check->fromsec) &&
849 match(tosec, check->tosec))
850 return check->mismatch;
857 * Whitelist to allow certain references to pass with no warning.
860 * Do not warn if funtion/data are marked with __init_refok/__initdata_refok.
861 * The pattern is identified by:
862 * fromsec = .text.init.refok* | .data.init.refok*
865 * If a module parameter is declared __initdata and permissions=0
866 * then this is legal despite the warning generated.
867 * We cannot see value of permissions here, so just ignore
869 * The pattern is identified by:
875 * Many drivers utilise a *driver container with references to
876 * add, remove, probe functions etc.
877 * These functions may often be marked __init and we do not want to
879 * the pattern is identified by:
880 * tosec = init or exit section
881 * fromsec = data section
882 * atsym = *driver, *_template, *_sht, *_ops, *_probe,
883 * *probe_one, *_console, *_timer
886 * Whitelist all refereces from .text.head to .init.data
887 * Whitelist all refereces from .text.head to .init.text
890 * Some symbols belong to init section but still it is ok to reference
891 * these from non-init sections as these symbols don't have any memory
892 * allocated for them and symbol address and value are same. So even
893 * if init section is freed, its ok to reference those symbols.
894 * For ex. symbols marking the init section boundaries.
895 * This pattern is identified by
896 * refsymname = __init_begin, _sinittext, _einittext
899 static int secref_whitelist(const char *fromsec, const char *fromsym,
900 const char *tosec, const char *tosym)
902 /* Check for pattern 0 */
903 if (match(fromsec, initref_sections))
906 /* Check for pattern 1 */
907 if (match(tosec, init_data_sections) &&
908 match(fromsec, data_sections) &&
909 (strncmp(fromsym, "__param", strlen("__param")) == 0))
912 /* Check for pattern 2 */
913 if (match(tosec, init_exit_sections) &&
914 match(fromsec, data_sections) &&
915 match(fromsym, symbol_white_list))
918 /* Check for pattern 3 */
919 if (match(fromsec, head_sections) &&
920 match(tosec, init_sections))
923 /* Check for pattern 4 */
924 if (match(tosym, linker_symbols))
931 * Find symbol based on relocation record info.
932 * In some cases the symbol supplied is a valid symbol so
933 * return refsym. If st_name != 0 we assume this is a valid symbol.
934 * In other cases the symbol needs to be looked up in the symbol table
935 * based on section and address.
937 static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
941 Elf_Sym *near = NULL;
942 Elf64_Sword distance = 20;
945 if (relsym->st_name != 0)
947 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
948 if (sym->st_shndx != relsym->st_shndx)
950 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
952 if (sym->st_value == addr)
954 /* Find a symbol nearby - addr are maybe negative */
955 d = sym->st_value - addr;
957 d = addr - sym->st_value;
963 /* We need a close match */
970 static inline int is_arm_mapping_symbol(const char *str)
972 return str[0] == '$' && strchr("atd", str[1])
973 && (str[2] == '\0' || str[2] == '.');
977 * If there's no name there, ignore it; likewise, ignore it if it's
978 * one of the magic symbols emitted used by current ARM tools.
980 * Otherwise if find_symbols_between() returns those symbols, they'll
981 * fail the whitelist tests and cause lots of false alarms ... fixable
982 * only by merging __exit and __init sections into __text, bloating
983 * the kernel (which is especially evil on embedded platforms).
985 static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
987 const char *name = elf->strtab + sym->st_name;
989 if (!name || !strlen(name))
991 return !is_arm_mapping_symbol(name);
995 * Find symbols before or equal addr and after addr - in the section sec.
996 * If we find two symbols with equal offset prefer one with a valid name.
997 * The ELF format may have a better way to detect what type of symbol
998 * it is, but this works for now.
1000 static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1004 Elf_Sym *near = NULL;
1005 Elf_Addr distance = ~0;
1007 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1010 if (sym->st_shndx >= SHN_LORESERVE)
1012 symsec = sec_name(elf, sym->st_shndx);
1013 if (strcmp(symsec, sec) != 0)
1015 if (!is_valid_name(elf, sym))
1017 if (sym->st_value <= addr) {
1018 if ((addr - sym->st_value) < distance) {
1019 distance = addr - sym->st_value;
1021 } else if ((addr - sym->st_value) == distance) {
1030 * Convert a section name to the function/data attribute
1031 * .init.text => __init
1032 * .cpuinit.data => __cpudata
1033 * .memexitconst => __memconst
1036 static char *sec2annotation(const char *s)
1038 if (match(s, init_exit_sections)) {
1039 char *p = malloc(20);
1046 while (*s && *s != '.')
1051 if (strstr(s, "rodata") != NULL)
1052 strcat(p, "const ");
1053 else if (strstr(s, "data") != NULL)
1057 return r; /* we leak her but we do not care */
1063 static int is_function(Elf_Sym *sym)
1066 return ELF_ST_TYPE(sym->st_info) == STT_FUNC;
1072 * Print a warning about a section mismatch.
1073 * Try to find symbols near it so user can find it.
1074 * Check whitelist before warning - it may be a false positive.
1076 static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
1077 const char *fromsec,
1078 unsigned long long fromaddr,
1079 const char *fromsym,
1081 const char *tosec, const char *tosym,
1084 const char *from, *from_p;
1085 const char *to, *to_p;
1086 from = from_is_func ? "function" : "variable";
1087 from_p = from_is_func ? "()" : "";
1088 to = to_is_func ? "function" : "variable";
1089 to_p = to_is_func ? "()" : "";
1091 fprintf(stderr, "WARNING: %s(%s+0x%llx): Section mismatch in"
1092 " reference from the %s %s%s to the %s %s:%s%s\n",
1093 modname, fromsec, fromaddr, from, fromsym, from_p,
1094 to, tosec, tosym, to_p);
1096 sec_mismatch_count++;
1097 if (!sec_mismatch_verbose)
1103 "The function %s %s() references\n"
1105 "This is often because %s lacks a %s\n"
1106 "annotation or the annotation of %s is wrong.\n",
1107 sec2annotation(fromsec), fromsym,
1108 to, sec2annotation(tosec), tosym, to_p,
1109 fromsym, sec2annotation(tosec), tosym);
1111 case DATA_TO_INIT: {
1112 const char **s = symbol_white_list;
1114 "The variable %s references\n"
1116 "If the reference is valid then annotate the\n"
1117 "variable with __init* (see linux/init.h) "
1118 "or name the variable:\n",
1119 fromsym, to, sec2annotation(tosec), tosym, to_p);
1121 fprintf(stderr, "%s, ", *s++);
1122 fprintf(stderr, "\n");
1127 "The function %s() references a %s in an exit section.\n"
1128 "Often the %s %s%s has valid usage outside the exit section\n"
1129 "and the fix is to remove the %sannotation of %s.\n",
1130 fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym);
1132 case DATA_TO_EXIT: {
1133 const char **s = symbol_white_list;
1135 "The variable %s references\n"
1137 "If the reference is valid then annotate the\n"
1138 "variable with __exit* (see linux/init.h) or "
1139 "name the variable:\n",
1140 fromsym, to, sec2annotation(tosec), tosym, to_p);
1142 fprintf(stderr, "%s, ", *s++);
1143 fprintf(stderr, "\n");
1146 case XXXINIT_TO_INIT:
1147 case XXXEXIT_TO_EXIT:
1149 "The %s %s%s%s references\n"
1151 "If %s is only used by %s then\n"
1152 "annotate %s with a matching annotation.\n",
1153 from, sec2annotation(fromsec), fromsym, from_p,
1154 to, sec2annotation(tosec), tosym, to_p,
1155 fromsym, tosym, fromsym);
1159 "The %s %s%s%s references\n"
1161 "This is often seen when error handling "
1162 "in the init function\n"
1163 "uses functionality in the exit path.\n"
1164 "The fix is often to remove the %sannotation of\n"
1165 "%s%s so it may be used outside an exit section.\n",
1166 from, sec2annotation(fromsec), fromsym, from_p,
1167 to, sec2annotation(tosec), tosym, to_p,
1168 sec2annotation(tosec), tosym, to_p);
1172 "The %s %s%s%s references\n"
1174 "This is often seen when error handling "
1175 "in the exit function\n"
1176 "uses functionality in the init path.\n"
1177 "The fix is often to remove the %sannotation of\n"
1178 "%s%s so it may be used outside an init section.\n",
1179 from, sec2annotation(fromsec), fromsym, from_p,
1180 to, sec2annotation(tosec), tosym, to_p,
1181 sec2annotation(tosec), tosym, to_p);
1183 case EXPORT_TO_INIT_EXIT:
1185 "The symbol %s is exported and annotated %s\n"
1186 "Fix this by removing the %sannotation of %s "
1187 "or drop the export.\n",
1188 tosym, sec2annotation(tosec), sec2annotation(tosec), tosym);
1190 /* To get warnings on missing members */
1193 fprintf(stderr, "\n");
1196 static void check_section_mismatch(const char *modname, struct elf_info *elf,
1197 Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
1200 enum mismatch mismatch;
1202 tosec = sec_name(elf, sym->st_shndx);
1203 mismatch = section_mismatch(fromsec, tosec);
1204 if (mismatch != NO_MISMATCH) {
1208 const char *fromsym;
1210 from = find_elf_symbol2(elf, r->r_offset, fromsec);
1211 fromsym = sym_name(elf, from);
1212 to = find_elf_symbol(elf, r->r_addend, sym);
1213 tosym = sym_name(elf, to);
1215 /* check whitelist - we may ignore it */
1216 if (secref_whitelist(fromsec, fromsym, tosec, tosym)) {
1217 report_sec_mismatch(modname, mismatch,
1218 fromsec, r->r_offset, fromsym,
1219 is_function(from), tosec, tosym,
1225 static unsigned int *reloc_location(struct elf_info *elf,
1226 Elf_Shdr *sechdr, Elf_Rela *r)
1228 Elf_Shdr *sechdrs = elf->sechdrs;
1229 int section = sechdr->sh_info;
1231 return (void *)elf->hdr + sechdrs[section].sh_offset +
1232 (r->r_offset - sechdrs[section].sh_addr);
1235 static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1237 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1238 unsigned int *location = reloc_location(elf, sechdr, r);
1242 r->r_addend = TO_NATIVE(*location);
1245 r->r_addend = TO_NATIVE(*location) + 4;
1246 /* For CONFIG_RELOCATABLE=y */
1247 if (elf->hdr->e_type == ET_EXEC)
1248 r->r_addend += r->r_offset;
1254 static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1256 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1260 /* From ARM ABI: (S + A) | T */
1261 r->r_addend = (int)(long)
1262 (elf->symtab_start + ELF_R_SYM(r->r_info));
1265 /* From ARM ABI: ((S + A) | T) - P */
1266 r->r_addend = (int)(long)(elf->hdr +
1268 (r->r_offset - sechdr->sh_addr));
1276 static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1278 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1279 unsigned int *location = reloc_location(elf, sechdr, r);
1282 if (r_typ == R_MIPS_HI16)
1283 return 1; /* skip this */
1284 inst = TO_NATIVE(*location);
1287 r->r_addend = inst & 0xffff;
1290 r->r_addend = (inst & 0x03ffffff) << 2;
1299 static void section_rela(const char *modname, struct elf_info *elf,
1306 const char *fromsec;
1308 Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset;
1309 Elf_Rela *stop = (void *)start + sechdr->sh_size;
1311 fromsec = sech_name(elf, sechdr);
1312 fromsec += strlen(".rela");
1313 /* if from section (name) is know good then skip it */
1314 if (match(fromsec, section_white_list))
1316 for (rela = start; rela < stop; rela++) {
1317 r.r_offset = TO_NATIVE(rela->r_offset);
1318 #if KERNEL_ELFCLASS == ELFCLASS64
1319 if (elf->hdr->e_machine == EM_MIPS) {
1321 r_sym = ELF64_MIPS_R_SYM(rela->r_info);
1322 r_sym = TO_NATIVE(r_sym);
1323 r_typ = ELF64_MIPS_R_TYPE(rela->r_info);
1324 r.r_info = ELF64_R_INFO(r_sym, r_typ);
1326 r.r_info = TO_NATIVE(rela->r_info);
1327 r_sym = ELF_R_SYM(r.r_info);
1330 r.r_info = TO_NATIVE(rela->r_info);
1331 r_sym = ELF_R_SYM(r.r_info);
1333 r.r_addend = TO_NATIVE(rela->r_addend);
1334 sym = elf->symtab_start + r_sym;
1335 /* Skip special sections */
1336 if (sym->st_shndx >= SHN_LORESERVE)
1338 check_section_mismatch(modname, elf, &r, sym, fromsec);
1342 static void section_rel(const char *modname, struct elf_info *elf,
1349 const char *fromsec;
1351 Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset;
1352 Elf_Rel *stop = (void *)start + sechdr->sh_size;
1354 fromsec = sech_name(elf, sechdr);
1355 fromsec += strlen(".rel");
1356 /* if from section (name) is know good then skip it */
1357 if (match(fromsec, section_white_list))
1360 for (rel = start; rel < stop; rel++) {
1361 r.r_offset = TO_NATIVE(rel->r_offset);
1362 #if KERNEL_ELFCLASS == ELFCLASS64
1363 if (elf->hdr->e_machine == EM_MIPS) {
1365 r_sym = ELF64_MIPS_R_SYM(rel->r_info);
1366 r_sym = TO_NATIVE(r_sym);
1367 r_typ = ELF64_MIPS_R_TYPE(rel->r_info);
1368 r.r_info = ELF64_R_INFO(r_sym, r_typ);
1370 r.r_info = TO_NATIVE(rel->r_info);
1371 r_sym = ELF_R_SYM(r.r_info);
1374 r.r_info = TO_NATIVE(rel->r_info);
1375 r_sym = ELF_R_SYM(r.r_info);
1378 switch (elf->hdr->e_machine) {
1380 if (addend_386_rel(elf, sechdr, &r))
1384 if (addend_arm_rel(elf, sechdr, &r))
1388 if (addend_mips_rel(elf, sechdr, &r))
1392 sym = elf->symtab_start + r_sym;
1393 /* Skip special sections */
1394 if (sym->st_shndx >= SHN_LORESERVE)
1396 check_section_mismatch(modname, elf, &r, sym, fromsec);
1401 * A module includes a number of sections that are discarded
1402 * either when loaded or when used as built-in.
1403 * For loaded modules all functions marked __init and all data
1404 * marked __initdata will be discarded when the module has been intialized.
1405 * Likewise for modules used built-in the sections marked __exit
1406 * are discarded because __exit marked function are supposed to be called
1407 * only when a moduel is unloaded which never happes for built-in modules.
1408 * The check_sec_ref() function traverses all relocation records
1409 * to find all references to a section that reference a section that will
1410 * be discarded and warns about it.
1412 static void check_sec_ref(struct module *mod, const char *modname,
1413 struct elf_info *elf)
1416 Elf_Shdr *sechdrs = elf->sechdrs;
1418 /* Walk through all sections */
1419 for (i = 0; i < elf->hdr->e_shnum; i++) {
1420 /* We want to process only relocation sections and not .init */
1421 if (sechdrs[i].sh_type == SHT_RELA)
1422 section_rela(modname, elf, &elf->sechdrs[i]);
1423 else if (sechdrs[i].sh_type == SHT_REL)
1424 section_rel(modname, elf, &elf->sechdrs[i]);
1428 static void read_symbols(char *modname)
1430 const char *symname;
1434 struct elf_info info = { };
1437 if (!parse_elf(&info, modname))
1440 mod = new_module(modname);
1442 /* When there's no vmlinux, don't print warnings about
1443 * unresolved symbols (since there'll be too many ;) */
1444 if (is_vmlinux(modname)) {
1449 license = get_modinfo(info.modinfo, info.modinfo_len, "license");
1451 if (license_is_gpl_compatible(license))
1452 mod->gpl_compatible = 1;
1454 mod->gpl_compatible = 0;
1457 license = get_next_modinfo(info.modinfo, info.modinfo_len,
1458 "license", license);
1461 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
1462 symname = info.strtab + sym->st_name;
1464 handle_modversions(mod, &info, sym, symname);
1465 handle_moddevtable(mod, &info, sym, symname);
1467 if (!is_vmlinux(modname) ||
1468 (is_vmlinux(modname) && vmlinux_section_warnings))
1469 check_sec_ref(mod, modname, &info);
1471 version = get_modinfo(info.modinfo, info.modinfo_len, "version");
1473 maybe_frob_rcs_version(modname, version, info.modinfo,
1474 version - (char *)info.hdr);
1475 if (version || (all_versions && !is_vmlinux(modname)))
1476 get_src_version(modname, mod->srcversion,
1477 sizeof(mod->srcversion)-1);
1479 parse_elf_finish(&info);
1481 /* Our trick to get versioning for struct_module - it's
1482 * never passed as an argument to an exported function, so
1483 * the automatic versioning doesn't pick it up, but it's really
1484 * important anyhow */
1486 mod->unres = alloc_symbol("struct_module", 0, mod->unres);
1491 /* We first write the generated file into memory using the
1492 * following helper, then compare to the file on disk and
1493 * only update the later if anything changed */
1495 void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
1496 const char *fmt, ...)
1503 len = vsnprintf(tmp, SZ, fmt, ap);
1504 buf_write(buf, tmp, len);
1508 void buf_write(struct buffer *buf, const char *s, int len)
1510 if (buf->size - buf->pos < len) {
1511 buf->size += len + SZ;
1512 buf->p = realloc(buf->p, buf->size);
1514 strncpy(buf->p + buf->pos, s, len);
1518 static void check_for_gpl_usage(enum export exp, const char *m, const char *s)
1520 const char *e = is_vmlinux(m) ?"":".ko";
1524 fatal("modpost: GPL-incompatible module %s%s "
1525 "uses GPL-only symbol '%s'\n", m, e, s);
1527 case export_unused_gpl:
1528 fatal("modpost: GPL-incompatible module %s%s "
1529 "uses GPL-only symbol marked UNUSED '%s'\n", m, e, s);
1531 case export_gpl_future:
1532 warn("modpost: GPL-incompatible module %s%s "
1533 "uses future GPL-only symbol '%s'\n", m, e, s);
1537 case export_unknown:
1543 static void check_for_unused(enum export exp, const char *m, const char *s)
1545 const char *e = is_vmlinux(m) ?"":".ko";
1549 case export_unused_gpl:
1550 warn("modpost: module %s%s "
1551 "uses symbol '%s' marked UNUSED\n", m, e, s);
1559 static void check_exports(struct module *mod)
1561 struct symbol *s, *exp;
1563 for (s = mod->unres; s; s = s->next) {
1564 const char *basename;
1565 exp = find_symbol(s->name);
1566 if (!exp || exp->module == mod)
1568 basename = strrchr(mod->name, '/');
1572 basename = mod->name;
1573 if (!mod->gpl_compatible)
1574 check_for_gpl_usage(exp->export, basename, exp->name);
1575 check_for_unused(exp->export, basename, exp->name);
1580 * Header for the generated file
1582 static void add_header(struct buffer *b, struct module *mod)
1584 buf_printf(b, "#include <linux/module.h>\n");
1585 buf_printf(b, "#include <linux/vermagic.h>\n");
1586 buf_printf(b, "#include <linux/compiler.h>\n");
1587 buf_printf(b, "\n");
1588 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
1589 buf_printf(b, "\n");
1590 buf_printf(b, "struct module __this_module\n");
1591 buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
1592 buf_printf(b, " .name = KBUILD_MODNAME,\n");
1594 buf_printf(b, " .init = init_module,\n");
1595 if (mod->has_cleanup)
1596 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"
1597 " .exit = cleanup_module,\n"
1599 buf_printf(b, " .arch = MODULE_ARCH_INIT,\n");
1600 buf_printf(b, "};\n");
1604 * Record CRCs for unresolved symbols
1606 static int add_versions(struct buffer *b, struct module *mod)
1608 struct symbol *s, *exp;
1611 for (s = mod->unres; s; s = s->next) {
1612 exp = find_symbol(s->name);
1613 if (!exp || exp->module == mod) {
1614 if (have_vmlinux && !s->weak) {
1615 if (warn_unresolved) {
1616 warn("\"%s\" [%s.ko] undefined!\n",
1617 s->name, mod->name);
1619 merror("\"%s\" [%s.ko] undefined!\n",
1620 s->name, mod->name);
1626 s->module = exp->module;
1627 s->crc_valid = exp->crc_valid;
1634 buf_printf(b, "\n");
1635 buf_printf(b, "static const struct modversion_info ____versions[]\n");
1636 buf_printf(b, "__used\n");
1637 buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n");
1639 for (s = mod->unres; s; s = s->next) {
1642 if (!s->crc_valid) {
1643 warn("\"%s\" [%s.ko] has no CRC!\n",
1644 s->name, mod->name);
1647 buf_printf(b, "\t{ %#8x, \"%s\" },\n", s->crc, s->name);
1650 buf_printf(b, "};\n");
1655 static void add_depends(struct buffer *b, struct module *mod,
1656 struct module *modules)
1662 for (m = modules; m; m = m->next)
1663 m->seen = is_vmlinux(m->name);
1665 buf_printf(b, "\n");
1666 buf_printf(b, "static const char __module_depends[]\n");
1667 buf_printf(b, "__used\n");
1668 buf_printf(b, "__attribute__((section(\".modinfo\"))) =\n");
1669 buf_printf(b, "\"depends=");
1670 for (s = mod->unres; s; s = s->next) {
1675 if (s->module->seen)
1678 s->module->seen = 1;
1679 p = strrchr(s->module->name, '/');
1683 p = s->module->name;
1684 buf_printf(b, "%s%s", first ? "" : ",", p);
1687 buf_printf(b, "\";\n");
1690 static void add_srcversion(struct buffer *b, struct module *mod)
1692 if (mod->srcversion[0]) {
1693 buf_printf(b, "\n");
1694 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
1699 static void write_if_changed(struct buffer *b, const char *fname)
1705 file = fopen(fname, "r");
1709 if (fstat(fileno(file), &st) < 0)
1712 if (st.st_size != b->pos)
1715 tmp = NOFAIL(malloc(b->pos));
1716 if (fread(tmp, 1, b->pos, file) != b->pos)
1719 if (memcmp(tmp, b->p, b->pos) != 0)
1731 file = fopen(fname, "w");
1736 if (fwrite(b->p, 1, b->pos, file) != b->pos) {
1743 /* parse Module.symvers file. line format:
1744 * 0x12345678<tab>symbol<tab>module[[<tab>export]<tab>something]
1746 static void read_dump(const char *fname, unsigned int kernel)
1748 unsigned long size, pos = 0;
1749 void *file = grab_file(fname, &size);
1753 /* No symbol versions, silently ignore */
1756 while ((line = get_next_line(&pos, file, size))) {
1757 char *symname, *modname, *d, *export, *end;
1762 if (!(symname = strchr(line, '\t')))
1765 if (!(modname = strchr(symname, '\t')))
1768 if ((export = strchr(modname, '\t')) != NULL)
1770 if (export && ((end = strchr(export, '\t')) != NULL))
1772 crc = strtoul(line, &d, 16);
1773 if (*symname == '\0' || *modname == '\0' || *d != '\0')
1775 mod = find_module(modname);
1777 if (is_vmlinux(modname))
1779 mod = new_module(NOFAIL(strdup(modname)));
1782 s = sym_add_exported(symname, mod, export_no(export));
1785 sym_update_crc(symname, mod, crc, export_no(export));
1789 fatal("parse error in symbol dump file\n");
1792 /* For normal builds always dump all symbols.
1793 * For external modules only dump symbols
1794 * that are not read from kernel Module.symvers.
1796 static int dump_sym(struct symbol *sym)
1798 if (!external_module)
1800 if (sym->vmlinux || sym->kernel)
1805 static void write_dump(const char *fname)
1807 struct buffer buf = { };
1808 struct symbol *symbol;
1811 for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
1812 symbol = symbolhash[n];
1814 if (dump_sym(symbol))
1815 buf_printf(&buf, "0x%08x\t%s\t%s\t%s\n",
1816 symbol->crc, symbol->name,
1817 symbol->module->name,
1818 export_str(symbol->export));
1819 symbol = symbol->next;
1822 write_if_changed(&buf, fname);
1825 int main(int argc, char **argv)
1828 struct buffer buf = { };
1829 char *kernel_read = NULL, *module_read = NULL;
1830 char *dump_write = NULL;
1834 while ((opt = getopt(argc, argv, "i:I:msSo:aw")) != -1) {
1837 kernel_read = optarg;
1840 module_read = optarg;
1841 external_module = 1;
1847 dump_write = optarg;
1853 vmlinux_section_warnings = 0;
1856 sec_mismatch_verbose = 0;
1859 warn_unresolved = 1;
1867 read_dump(kernel_read, 1);
1869 read_dump(module_read, 0);
1871 while (optind < argc)
1872 read_symbols(argv[optind++]);
1874 for (mod = modules; mod; mod = mod->next) {
1882 for (mod = modules; mod; mod = mod->next) {
1883 char fname[strlen(mod->name) + 10];
1890 add_header(&buf, mod);
1891 err |= add_versions(&buf, mod);
1892 add_depends(&buf, mod, modules);
1893 add_moddevtable(&buf, mod);
1894 add_srcversion(&buf, mod);
1896 sprintf(fname, "%s.mod.c", mod->name);
1897 write_if_changed(&buf, fname);
1901 write_dump(dump_write);
1902 if (sec_mismatch_count && !sec_mismatch_verbose)
1903 fprintf(stderr, "modpost: Found %d section mismatch(es).\n"
1904 "To see additional details select \"Enable full "
1905 "Section mismatch analysis\"\n"
1906 "in the Kernel Hacking menu "
1907 "(CONFIG_SECTION_MISMATCH).\n", sec_mismatch_count);