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 ...
23 #include "../../include/linux/license.h"
25 /* Are we using CONFIG_MODVERSIONS? */
26 static int modversions = 0;
27 /* Warn about undefined symbols? (do so if we have vmlinux) */
28 static int have_vmlinux = 0;
29 /* Is CONFIG_MODULE_SRCVERSION_ALL set? */
30 static int all_versions = 0;
31 /* If we are modposting external module set to 1 */
32 static int external_module = 0;
33 /* Only warn about unresolved symbols */
34 static int warn_unresolved = 0;
35 /* How a symbol is exported */
36 static int sec_mismatch_count = 0;
37 static int sec_mismatch_fatal = 0;
38 /* ignore missing files */
39 static int ignore_missing_files;
40 /* If set to 1, only warn (instead of error) about missing ns imports */
41 static int allow_missing_ns_imports;
44 export_plain, export_unused, export_gpl,
45 export_unused_gpl, export_gpl_future, export_unknown
48 /* In kernel, this size is defined in linux/module.h;
49 * here we use Elf_Addr instead of long for covering cross-compile
52 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
54 void __attribute__((format(printf, 2, 3)))
55 modpost_log(enum loglevel loglevel, const char *fmt, ...)
61 fprintf(stderr, "WARNING: ");
64 fprintf(stderr, "ERROR: ");
67 fprintf(stderr, "FATAL: ");
69 default: /* invalid loglevel, ignore */
73 fprintf(stderr, "modpost: ");
75 va_start(arglist, fmt);
76 vfprintf(stderr, fmt, arglist);
79 if (loglevel == LOG_FATAL)
83 static inline bool strends(const char *str, const char *postfix)
85 if (strlen(str) < strlen(postfix))
88 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
91 static int is_vmlinux(const char *modname)
95 myname = strrchr(modname, '/');
101 return (strcmp(myname, "vmlinux") == 0) ||
102 (strcmp(myname, "vmlinux.o") == 0);
105 void *do_nofail(void *ptr, const char *expr)
108 fatal("Memory allocation failure: %s.\n", expr);
113 char *read_text_file(const char *filename)
120 fd = open(filename, O_RDONLY);
126 if (fstat(fd, &st) < 0) {
131 buf = NOFAIL(malloc(st.st_size + 1));
138 bytes_read = read(fd, buf, nbytes);
139 if (bytes_read < 0) {
144 nbytes -= bytes_read;
146 buf[st.st_size] = '\0';
153 char *get_line(char **stringp)
155 /* do not return the unwanted extra line at EOF */
156 if (*stringp && **stringp == '\0')
159 return strsep(stringp, "\n");
162 /* A list of all modules we processed */
163 static struct module *modules;
165 static struct module *find_module(const char *modname)
169 for (mod = modules; mod; mod = mod->next)
170 if (strcmp(mod->name, modname) == 0)
175 static struct module *new_module(const char *modname)
180 mod = NOFAIL(malloc(sizeof(*mod)));
181 memset(mod, 0, sizeof(*mod));
182 p = NOFAIL(strdup(modname));
184 /* strip trailing .o */
185 if (strends(p, ".o"))
186 p[strlen(p) - 2] = '\0';
190 mod->is_vmlinux = is_vmlinux(modname);
191 mod->gpl_compatible = -1;
198 /* A hash of all exported symbols,
199 * struct symbol is also used for lists of unresolved symbols */
201 #define SYMBOL_HASH_SIZE 1024
205 struct module *module;
210 unsigned int is_static:1; /* 1 if symbol is not global */
211 enum export export; /* Type of export */
215 static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
217 /* This is based on the hash agorithm from gdbm, via tdb */
218 static inline unsigned int tdb_hash(const char *name)
220 unsigned value; /* Used to compute the hash value. */
221 unsigned i; /* Used to cycle through random values. */
223 /* Set the initial value from the key size. */
224 for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++)
225 value = (value + (((unsigned char *)name)[i] << (i*5 % 24)));
227 return (1103515243 * value + 12345);
231 * Allocate a new symbols for use in the hash of exported symbols or
232 * the list of unresolved symbols per module
234 static struct symbol *alloc_symbol(const char *name, unsigned int weak,
237 struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
239 memset(s, 0, sizeof(*s));
240 strcpy(s->name, name);
247 /* For the hash of exported symbols */
248 static struct symbol *new_symbol(const char *name, struct module *module,
253 hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
254 symbolhash[hash] = alloc_symbol(name, 0, symbolhash[hash]);
256 return symbolhash[hash];
259 static struct symbol *find_symbol(const char *name)
263 /* For our purposes, .foo matches foo. PPC64 needs this. */
267 for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) {
268 if (strcmp(s->name, name) == 0)
274 static bool contains_namespace(struct namespace_list *list,
275 const char *namespace)
277 for (; list; list = list->next)
278 if (!strcmp(list->namespace, namespace))
284 static void add_namespace(struct namespace_list **list, const char *namespace)
286 struct namespace_list *ns_entry;
288 if (!contains_namespace(*list, namespace)) {
289 ns_entry = NOFAIL(malloc(sizeof(struct namespace_list) +
290 strlen(namespace) + 1));
291 strcpy(ns_entry->namespace, namespace);
292 ns_entry->next = *list;
297 static bool module_imports_namespace(struct module *module,
298 const char *namespace)
300 return contains_namespace(module->imported_namespaces, namespace);
303 static const struct {
307 { .str = "EXPORT_SYMBOL", .export = export_plain },
308 { .str = "EXPORT_UNUSED_SYMBOL", .export = export_unused },
309 { .str = "EXPORT_SYMBOL_GPL", .export = export_gpl },
310 { .str = "EXPORT_UNUSED_SYMBOL_GPL", .export = export_unused_gpl },
311 { .str = "EXPORT_SYMBOL_GPL_FUTURE", .export = export_gpl_future },
312 { .str = "(unknown)", .export = export_unknown },
316 static const char *export_str(enum export ex)
318 return export_list[ex].str;
321 static enum export export_no(const char *s)
326 return export_unknown;
327 for (i = 0; export_list[i].export != export_unknown; i++) {
328 if (strcmp(export_list[i].str, s) == 0)
329 return export_list[i].export;
331 return export_unknown;
334 static void *sym_get_data_by_offset(const struct elf_info *info,
335 unsigned int secindex, unsigned long offset)
337 Elf_Shdr *sechdr = &info->sechdrs[secindex];
339 if (info->hdr->e_type != ET_REL)
340 offset -= sechdr->sh_addr;
342 return (void *)info->hdr + sechdr->sh_offset + offset;
345 static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
347 return sym_get_data_by_offset(info, get_secindex(info, sym),
351 static const char *sech_name(const struct elf_info *info, Elf_Shdr *sechdr)
353 return sym_get_data_by_offset(info, info->secindex_strings,
357 static const char *sec_name(const struct elf_info *info, int secindex)
359 return sech_name(info, &info->sechdrs[secindex]);
362 #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
364 static enum export export_from_secname(struct elf_info *elf, unsigned int sec)
366 const char *secname = sec_name(elf, sec);
368 if (strstarts(secname, "___ksymtab+"))
370 else if (strstarts(secname, "___ksymtab_unused+"))
371 return export_unused;
372 else if (strstarts(secname, "___ksymtab_gpl+"))
374 else if (strstarts(secname, "___ksymtab_unused_gpl+"))
375 return export_unused_gpl;
376 else if (strstarts(secname, "___ksymtab_gpl_future+"))
377 return export_gpl_future;
379 return export_unknown;
382 static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
384 if (sec == elf->export_sec)
386 else if (sec == elf->export_unused_sec)
387 return export_unused;
388 else if (sec == elf->export_gpl_sec)
390 else if (sec == elf->export_unused_gpl_sec)
391 return export_unused_gpl;
392 else if (sec == elf->export_gpl_future_sec)
393 return export_gpl_future;
395 return export_unknown;
398 static const char *namespace_from_kstrtabns(const struct elf_info *info,
401 const char *value = sym_get_data(info, sym);
402 return value[0] ? value : NULL;
405 static void sym_update_namespace(const char *symname, const char *namespace)
407 struct symbol *s = find_symbol(symname);
410 * That symbol should have been created earlier and thus this is
411 * actually an assertion.
414 merror("Could not update namespace(%s) for symbol %s\n",
421 namespace && namespace[0] ? NOFAIL(strdup(namespace)) : NULL;
425 * Add an exported symbol - it may have already been added without a
426 * CRC, in this case just update the CRC
428 static struct symbol *sym_add_exported(const char *name, struct module *mod,
431 struct symbol *s = find_symbol(name);
434 s = new_symbol(name, mod, export);
435 } else if (!external_module || s->module->is_vmlinux ||
437 warn("%s: '%s' exported twice. Previous export was in %s%s\n",
438 mod->name, name, s->module->name,
439 s->module->is_vmlinux ? "" : ".ko");
448 static void sym_set_crc(const char *name, unsigned int crc)
450 struct symbol *s = find_symbol(name);
453 * Ignore stand-alone __crc_*, which might be auto-generated symbols
454 * such as __*_veneer in ARM ELF.
463 static void *grab_file(const char *filename, unsigned long *size)
466 void *map = MAP_FAILED;
469 fd = open(filename, O_RDONLY);
476 map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
480 if (map == MAP_FAILED)
485 static void release_file(void *file, unsigned long size)
490 static int parse_elf(struct elf_info *info, const char *filename)
496 const char *secstrings;
497 unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U;
499 hdr = grab_file(filename, &info->size);
501 if (ignore_missing_files) {
502 fprintf(stderr, "%s: %s (ignored)\n", filename,
510 if (info->size < sizeof(*hdr)) {
511 /* file too small, assume this is an empty .o file */
514 /* Is this a valid ELF file? */
515 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
516 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
517 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
518 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
519 /* Not an ELF file - silently ignore it */
522 /* Fix endianness in ELF header */
523 hdr->e_type = TO_NATIVE(hdr->e_type);
524 hdr->e_machine = TO_NATIVE(hdr->e_machine);
525 hdr->e_version = TO_NATIVE(hdr->e_version);
526 hdr->e_entry = TO_NATIVE(hdr->e_entry);
527 hdr->e_phoff = TO_NATIVE(hdr->e_phoff);
528 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
529 hdr->e_flags = TO_NATIVE(hdr->e_flags);
530 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize);
531 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize);
532 hdr->e_phnum = TO_NATIVE(hdr->e_phnum);
533 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize);
534 hdr->e_shnum = TO_NATIVE(hdr->e_shnum);
535 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
536 sechdrs = (void *)hdr + hdr->e_shoff;
537 info->sechdrs = sechdrs;
539 /* Check if file offset is correct */
540 if (hdr->e_shoff > info->size) {
541 fatal("section header offset=%lu in file '%s' is bigger than "
542 "filesize=%lu\n", (unsigned long)hdr->e_shoff,
543 filename, info->size);
547 if (hdr->e_shnum == SHN_UNDEF) {
549 * There are more than 64k sections,
550 * read count from .sh_size.
552 info->num_sections = TO_NATIVE(sechdrs[0].sh_size);
555 info->num_sections = hdr->e_shnum;
557 if (hdr->e_shstrndx == SHN_XINDEX) {
558 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link);
561 info->secindex_strings = hdr->e_shstrndx;
564 /* Fix endianness in section headers */
565 for (i = 0; i < info->num_sections; i++) {
566 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name);
567 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type);
568 sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags);
569 sechdrs[i].sh_addr = TO_NATIVE(sechdrs[i].sh_addr);
570 sechdrs[i].sh_offset = TO_NATIVE(sechdrs[i].sh_offset);
571 sechdrs[i].sh_size = TO_NATIVE(sechdrs[i].sh_size);
572 sechdrs[i].sh_link = TO_NATIVE(sechdrs[i].sh_link);
573 sechdrs[i].sh_info = TO_NATIVE(sechdrs[i].sh_info);
574 sechdrs[i].sh_addralign = TO_NATIVE(sechdrs[i].sh_addralign);
575 sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize);
577 /* Find symbol table. */
578 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset;
579 for (i = 1; i < info->num_sections; i++) {
581 int nobits = sechdrs[i].sh_type == SHT_NOBITS;
583 if (!nobits && sechdrs[i].sh_offset > info->size) {
584 fatal("%s is truncated. sechdrs[i].sh_offset=%lu > "
585 "sizeof(*hrd)=%zu\n", filename,
586 (unsigned long)sechdrs[i].sh_offset,
590 secname = secstrings + sechdrs[i].sh_name;
591 if (strcmp(secname, ".modinfo") == 0) {
593 fatal("%s has NOBITS .modinfo\n", filename);
594 info->modinfo = (void *)hdr + sechdrs[i].sh_offset;
595 info->modinfo_len = sechdrs[i].sh_size;
596 } else if (strcmp(secname, "__ksymtab") == 0)
597 info->export_sec = i;
598 else if (strcmp(secname, "__ksymtab_unused") == 0)
599 info->export_unused_sec = i;
600 else if (strcmp(secname, "__ksymtab_gpl") == 0)
601 info->export_gpl_sec = i;
602 else if (strcmp(secname, "__ksymtab_unused_gpl") == 0)
603 info->export_unused_gpl_sec = i;
604 else if (strcmp(secname, "__ksymtab_gpl_future") == 0)
605 info->export_gpl_future_sec = i;
607 if (sechdrs[i].sh_type == SHT_SYMTAB) {
608 unsigned int sh_link_idx;
610 info->symtab_start = (void *)hdr +
611 sechdrs[i].sh_offset;
612 info->symtab_stop = (void *)hdr +
613 sechdrs[i].sh_offset + sechdrs[i].sh_size;
614 sh_link_idx = sechdrs[i].sh_link;
615 info->strtab = (void *)hdr +
616 sechdrs[sh_link_idx].sh_offset;
619 /* 32bit section no. table? ("more than 64k sections") */
620 if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) {
621 symtab_shndx_idx = i;
622 info->symtab_shndx_start = (void *)hdr +
623 sechdrs[i].sh_offset;
624 info->symtab_shndx_stop = (void *)hdr +
625 sechdrs[i].sh_offset + sechdrs[i].sh_size;
628 if (!info->symtab_start)
629 fatal("%s has no symtab?\n", filename);
631 /* Fix endianness in symbols */
632 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
633 sym->st_shndx = TO_NATIVE(sym->st_shndx);
634 sym->st_name = TO_NATIVE(sym->st_name);
635 sym->st_value = TO_NATIVE(sym->st_value);
636 sym->st_size = TO_NATIVE(sym->st_size);
639 if (symtab_shndx_idx != ~0U) {
641 if (symtab_idx != sechdrs[symtab_shndx_idx].sh_link)
642 fatal("%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n",
643 filename, sechdrs[symtab_shndx_idx].sh_link,
646 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop;
654 static void parse_elf_finish(struct elf_info *info)
656 release_file(info->hdr, info->size);
659 static int ignore_undef_symbol(struct elf_info *info, const char *symname)
661 /* ignore __this_module, it will be resolved shortly */
662 if (strcmp(symname, "__this_module") == 0)
664 /* ignore global offset table */
665 if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
667 if (info->hdr->e_machine == EM_PPC)
668 /* Special register function linked on all modules during final link of .ko */
669 if (strstarts(symname, "_restgpr_") ||
670 strstarts(symname, "_savegpr_") ||
671 strstarts(symname, "_rest32gpr_") ||
672 strstarts(symname, "_save32gpr_") ||
673 strstarts(symname, "_restvr_") ||
674 strstarts(symname, "_savevr_"))
676 if (info->hdr->e_machine == EM_PPC64)
677 /* Special register function linked on all modules during final link of .ko */
678 if (strstarts(symname, "_restgpr0_") ||
679 strstarts(symname, "_savegpr0_") ||
680 strstarts(symname, "_restvr_") ||
681 strstarts(symname, "_savevr_") ||
682 strcmp(symname, ".TOC.") == 0)
684 /* Do not ignore this symbol */
688 static void handle_modversion(const struct module *mod,
689 const struct elf_info *info,
690 const Elf_Sym *sym, const char *symname)
694 if (sym->st_shndx == SHN_UNDEF) {
695 warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n",
696 symname, mod->name, mod->is_vmlinux ? "" : ".ko");
700 if (sym->st_shndx == SHN_ABS) {
705 /* symbol points to the CRC in the ELF object */
706 crcp = sym_get_data(info, sym);
707 crc = TO_NATIVE(*crcp);
709 sym_set_crc(symname, crc);
712 static void handle_symbol(struct module *mod, struct elf_info *info,
713 const Elf_Sym *sym, const char *symname)
718 if (strstarts(symname, "__ksymtab"))
719 export = export_from_secname(info, get_secindex(info, sym));
721 export = export_from_sec(info, get_secindex(info, sym));
723 switch (sym->st_shndx) {
725 if (strstarts(symname, "__gnu_lto_")) {
726 /* Should warn here, but modpost runs before the linker */
728 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name);
731 /* undefined symbol */
732 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
733 ELF_ST_BIND(sym->st_info) != STB_WEAK)
735 if (ignore_undef_symbol(info, symname))
737 if (info->hdr->e_machine == EM_SPARC ||
738 info->hdr->e_machine == EM_SPARCV9) {
739 /* Ignore register directives. */
740 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
742 if (symname[0] == '.') {
743 char *munged = NOFAIL(strdup(symname));
745 munged[1] = toupper(munged[1]);
750 mod->unres = alloc_symbol(symname,
751 ELF_ST_BIND(sym->st_info) == STB_WEAK,
755 /* All exported symbols */
756 if (strstarts(symname, "__ksymtab_")) {
757 name = symname + strlen("__ksymtab_");
758 sym_add_exported(name, mod, export);
760 if (strcmp(symname, "init_module") == 0)
762 if (strcmp(symname, "cleanup_module") == 0)
763 mod->has_cleanup = 1;
769 * Parse tag=value strings from .modinfo section
771 static char *next_string(char *string, unsigned long *secsize)
773 /* Skip non-zero chars */
776 if ((*secsize)-- <= 1)
780 /* Skip any zero padding. */
783 if ((*secsize)-- <= 1)
789 static char *get_next_modinfo(struct elf_info *info, const char *tag,
793 unsigned int taglen = strlen(tag);
794 char *modinfo = info->modinfo;
795 unsigned long size = info->modinfo_len;
798 size -= prev - modinfo;
799 modinfo = next_string(prev, &size);
802 for (p = modinfo; p; p = next_string(p, &size)) {
803 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
804 return p + taglen + 1;
809 static char *get_modinfo(struct elf_info *info, const char *tag)
812 return get_next_modinfo(info, tag, NULL);
816 * Test if string s ends in string sub
819 static int strrcmp(const char *s, const char *sub)
827 sublen = strlen(sub);
829 if ((slen == 0) || (sublen == 0))
835 return memcmp(s + slen - sublen, sub, sublen);
838 static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
841 return elf->strtab + sym->st_name;
846 /* The pattern is an array of simple patterns.
847 * "foo" will match an exact string equal to "foo"
848 * "*foo" will match a string that ends with "foo"
849 * "foo*" will match a string that begins with "foo"
850 * "*foo*" will match a string that contains "foo"
852 static int match(const char *sym, const char * const pat[])
857 const char *endp = p + strlen(p) - 1;
860 if (*p == '*' && *endp == '*') {
861 char *bare = NOFAIL(strndup(p + 1, strlen(p) - 2));
862 char *here = strstr(sym, bare);
869 else if (*p == '*') {
870 if (strrcmp(sym, p + 1) == 0)
874 else if (*endp == '*') {
875 if (strncmp(sym, p, strlen(p) - 1) == 0)
880 if (strcmp(p, sym) == 0)
888 /* sections that we do not want to do full section mismatch check on */
889 static const char *const section_white_list[] =
893 ".cranges", /* sh64 */
894 ".zdebug*", /* Compressed debug sections. */
895 ".GCC.command.line", /* record-gcc-switches */
896 ".mdebug*", /* alpha, score, mips etc. */
897 ".pdr", /* alpha, score, mips etc. */
902 ".xt.prop", /* xtensa */
903 ".xt.lit", /* xtensa */
904 ".arcextmap*", /* arc */
905 ".gnu.linkonce.arcext*", /* arc : modules */
906 ".cmem*", /* EZchip */
907 ".fmt_slot*", /* EZchip */
914 * This is used to find sections missing the SHF_ALLOC flag.
915 * The cause of this is often a section specified in assembler
916 * without "ax" / "aw".
918 static void check_section(const char *modname, struct elf_info *elf,
921 const char *sec = sech_name(elf, sechdr);
923 if (sechdr->sh_type == SHT_PROGBITS &&
924 !(sechdr->sh_flags & SHF_ALLOC) &&
925 !match(sec, section_white_list)) {
926 warn("%s (%s): unexpected non-allocatable section.\n"
927 "Did you forget to use \"ax\"/\"aw\" in a .S file?\n"
928 "Note that for example <linux/init.h> contains\n"
929 "section definitions for use in .S files.\n\n",
936 #define ALL_INIT_DATA_SECTIONS \
937 ".init.setup", ".init.rodata", ".meminit.rodata", \
938 ".init.data", ".meminit.data"
939 #define ALL_EXIT_DATA_SECTIONS \
940 ".exit.data", ".memexit.data"
942 #define ALL_INIT_TEXT_SECTIONS \
943 ".init.text", ".meminit.text"
944 #define ALL_EXIT_TEXT_SECTIONS \
945 ".exit.text", ".memexit.text"
947 #define ALL_PCI_INIT_SECTIONS \
948 ".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \
949 ".pci_fixup_enable", ".pci_fixup_resume", \
950 ".pci_fixup_resume_early", ".pci_fixup_suspend"
952 #define ALL_XXXINIT_SECTIONS MEM_INIT_SECTIONS
953 #define ALL_XXXEXIT_SECTIONS MEM_EXIT_SECTIONS
955 #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
956 #define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS
958 #define DATA_SECTIONS ".data", ".data.rel"
959 #define TEXT_SECTIONS ".text", ".text.unlikely", ".sched.text", \
960 ".kprobes.text", ".cpuidle.text"
961 #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
962 ".fixup", ".entry.text", ".exception.text", ".text.*", \
965 #define INIT_SECTIONS ".init.*"
966 #define MEM_INIT_SECTIONS ".meminit.*"
968 #define EXIT_SECTIONS ".exit.*"
969 #define MEM_EXIT_SECTIONS ".memexit.*"
971 #define ALL_TEXT_SECTIONS ALL_INIT_TEXT_SECTIONS, ALL_EXIT_TEXT_SECTIONS, \
972 TEXT_SECTIONS, OTHER_TEXT_SECTIONS
974 /* init data sections */
975 static const char *const init_data_sections[] =
976 { ALL_INIT_DATA_SECTIONS, NULL };
978 /* all init sections */
979 static const char *const init_sections[] = { ALL_INIT_SECTIONS, NULL };
981 /* All init and exit sections (code + data) */
982 static const char *const init_exit_sections[] =
983 {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL };
985 /* all text sections */
986 static const char *const text_sections[] = { ALL_TEXT_SECTIONS, NULL };
989 static const char *const data_sections[] = { DATA_SECTIONS, NULL };
992 /* symbols in .data that may refer to init/exit sections */
993 #define DEFAULT_SYMBOL_WHITE_LIST \
995 "*_template", /* scsi uses *_template a lot */ \
996 "*_timer", /* arm uses ops structures named _timer a lot */ \
997 "*_sht", /* scsi also used *_sht to some extent */ \
1003 static const char *const head_sections[] = { ".head.text*", NULL };
1004 static const char *const linker_symbols[] =
1005 { "__init_begin", "_sinittext", "_einittext", NULL };
1006 static const char *const optim_symbols[] = { "*.constprop.*", NULL };
1013 XXXINIT_TO_SOME_INIT,
1014 XXXEXIT_TO_SOME_EXIT,
1015 ANY_INIT_TO_ANY_EXIT,
1016 ANY_EXIT_TO_ANY_INIT,
1017 EXPORT_TO_INIT_EXIT,
1018 EXTABLE_TO_NON_TEXT,
1022 * Describe how to match sections on different criterias:
1024 * @fromsec: Array of sections to be matched.
1026 * @bad_tosec: Relocations applied to a section in @fromsec to a section in
1027 * this array is forbidden (black-list). Can be empty.
1029 * @good_tosec: Relocations applied to a section in @fromsec must be
1030 * targetting sections in this array (white-list). Can be empty.
1032 * @mismatch: Type of mismatch.
1034 * @symbol_white_list: Do not match a relocation to a symbol in this list
1035 * even if it is targetting a section in @bad_to_sec.
1037 * @handler: Specific handler to call when a match is found. If NULL,
1038 * default_mismatch_handler() will be called.
1041 struct sectioncheck {
1042 const char *fromsec[20];
1043 const char *bad_tosec[20];
1044 const char *good_tosec[20];
1045 enum mismatch mismatch;
1046 const char *symbol_white_list[20];
1047 void (*handler)(const char *modname, struct elf_info *elf,
1048 const struct sectioncheck* const mismatch,
1049 Elf_Rela *r, Elf_Sym *sym, const char *fromsec);
1053 static void extable_mismatch_handler(const char *modname, struct elf_info *elf,
1054 const struct sectioncheck* const mismatch,
1055 Elf_Rela *r, Elf_Sym *sym,
1056 const char *fromsec);
1058 static const struct sectioncheck sectioncheck[] = {
1059 /* Do not reference init/exit code/data from
1060 * normal code and data
1063 .fromsec = { TEXT_SECTIONS, NULL },
1064 .bad_tosec = { ALL_INIT_SECTIONS, NULL },
1065 .mismatch = TEXT_TO_ANY_INIT,
1066 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1069 .fromsec = { DATA_SECTIONS, NULL },
1070 .bad_tosec = { ALL_XXXINIT_SECTIONS, NULL },
1071 .mismatch = DATA_TO_ANY_INIT,
1072 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1075 .fromsec = { DATA_SECTIONS, NULL },
1076 .bad_tosec = { INIT_SECTIONS, NULL },
1077 .mismatch = DATA_TO_ANY_INIT,
1078 .symbol_white_list = {
1079 "*_template", "*_timer", "*_sht", "*_ops",
1080 "*_probe", "*_probe_one", "*_console", NULL
1084 .fromsec = { TEXT_SECTIONS, NULL },
1085 .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
1086 .mismatch = TEXT_TO_ANY_EXIT,
1087 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1090 .fromsec = { DATA_SECTIONS, NULL },
1091 .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
1092 .mismatch = DATA_TO_ANY_EXIT,
1093 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1095 /* Do not reference init code/data from meminit code/data */
1097 .fromsec = { ALL_XXXINIT_SECTIONS, NULL },
1098 .bad_tosec = { INIT_SECTIONS, NULL },
1099 .mismatch = XXXINIT_TO_SOME_INIT,
1100 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1102 /* Do not reference exit code/data from memexit code/data */
1104 .fromsec = { ALL_XXXEXIT_SECTIONS, NULL },
1105 .bad_tosec = { EXIT_SECTIONS, NULL },
1106 .mismatch = XXXEXIT_TO_SOME_EXIT,
1107 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1109 /* Do not use exit code/data from init code */
1111 .fromsec = { ALL_INIT_SECTIONS, NULL },
1112 .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
1113 .mismatch = ANY_INIT_TO_ANY_EXIT,
1114 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1116 /* Do not use init code/data from exit code */
1118 .fromsec = { ALL_EXIT_SECTIONS, NULL },
1119 .bad_tosec = { ALL_INIT_SECTIONS, NULL },
1120 .mismatch = ANY_EXIT_TO_ANY_INIT,
1121 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1124 .fromsec = { ALL_PCI_INIT_SECTIONS, NULL },
1125 .bad_tosec = { INIT_SECTIONS, NULL },
1126 .mismatch = ANY_INIT_TO_ANY_EXIT,
1127 .symbol_white_list = { NULL },
1129 /* Do not export init/exit functions or data */
1131 .fromsec = { "__ksymtab*", NULL },
1132 .bad_tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
1133 .mismatch = EXPORT_TO_INIT_EXIT,
1134 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1137 .fromsec = { "__ex_table", NULL },
1138 /* If you're adding any new black-listed sections in here, consider
1139 * adding a special 'printer' for them in scripts/check_extable.
1141 .bad_tosec = { ".altinstr_replacement", NULL },
1142 .good_tosec = {ALL_TEXT_SECTIONS , NULL},
1143 .mismatch = EXTABLE_TO_NON_TEXT,
1144 .handler = extable_mismatch_handler,
1148 static const struct sectioncheck *section_mismatch(
1149 const char *fromsec, const char *tosec)
1152 int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck);
1153 const struct sectioncheck *check = §ioncheck[0];
1156 * The target section could be the SHT_NUL section when we're
1157 * handling relocations to un-resolved symbols, trying to match it
1158 * doesn't make much sense and causes build failures on parisc
1164 for (i = 0; i < elems; i++) {
1165 if (match(fromsec, check->fromsec)) {
1166 if (check->bad_tosec[0] && match(tosec, check->bad_tosec))
1168 if (check->good_tosec[0] && !match(tosec, check->good_tosec))
1177 * Whitelist to allow certain references to pass with no warning.
1180 * If a module parameter is declared __initdata and permissions=0
1181 * then this is legal despite the warning generated.
1182 * We cannot see value of permissions here, so just ignore
1184 * The pattern is identified by:
1185 * tosec = .init.data
1190 * module_param_call() ops can refer to __init set function if permissions=0
1191 * The pattern is identified by:
1192 * tosec = .init.text
1194 * atsym = __param_ops_*
1197 * Many drivers utilise a *driver container with references to
1198 * add, remove, probe functions etc.
1199 * the pattern is identified by:
1200 * tosec = init or exit section
1201 * fromsec = data section
1202 * atsym = *driver, *_template, *_sht, *_ops, *_probe,
1203 * *probe_one, *_console, *_timer
1206 * Whitelist all references from .head.text to any init section
1209 * Some symbols belong to init section but still it is ok to reference
1210 * these from non-init sections as these symbols don't have any memory
1211 * allocated for them and symbol address and value are same. So even
1212 * if init section is freed, its ok to reference those symbols.
1213 * For ex. symbols marking the init section boundaries.
1214 * This pattern is identified by
1215 * refsymname = __init_begin, _sinittext, _einittext
1218 * GCC may optimize static inlines when fed constant arg(s) resulting
1219 * in functions like cpumask_empty() -- generating an associated symbol
1220 * cpumask_empty.constprop.3 that appears in the audit. If the const that
1221 * is passed in comes from __init, like say nmi_ipi_mask, we get a
1222 * meaningless section warning. May need to add isra symbols too...
1223 * This pattern is identified by
1224 * tosec = init section
1225 * fromsec = text section
1226 * refsymname = *.constprop.*
1229 * Hide section mismatch warnings for ELF local symbols. The goal
1230 * is to eliminate false positive modpost warnings caused by
1231 * compiler-generated ELF local symbol names such as ".LANCHOR1".
1232 * Autogenerated symbol names bypass modpost's "Pattern 2"
1233 * whitelisting, which relies on pattern-matching against symbol
1234 * names to work. (One situation where gcc can autogenerate ELF
1235 * local symbols is when "-fsection-anchors" is used.)
1237 static int secref_whitelist(const struct sectioncheck *mismatch,
1238 const char *fromsec, const char *fromsym,
1239 const char *tosec, const char *tosym)
1241 /* Check for pattern 1 */
1242 if (match(tosec, init_data_sections) &&
1243 match(fromsec, data_sections) &&
1244 strstarts(fromsym, "__param"))
1247 /* Check for pattern 1a */
1248 if (strcmp(tosec, ".init.text") == 0 &&
1249 match(fromsec, data_sections) &&
1250 strstarts(fromsym, "__param_ops_"))
1253 /* Check for pattern 2 */
1254 if (match(tosec, init_exit_sections) &&
1255 match(fromsec, data_sections) &&
1256 match(fromsym, mismatch->symbol_white_list))
1259 /* Check for pattern 3 */
1260 if (match(fromsec, head_sections) &&
1261 match(tosec, init_sections))
1264 /* Check for pattern 4 */
1265 if (match(tosym, linker_symbols))
1268 /* Check for pattern 5 */
1269 if (match(fromsec, text_sections) &&
1270 match(tosec, init_sections) &&
1271 match(fromsym, optim_symbols))
1274 /* Check for pattern 6 */
1275 if (strstarts(fromsym, ".L"))
1281 static inline int is_arm_mapping_symbol(const char *str)
1283 return str[0] == '$' && strchr("axtd", str[1])
1284 && (str[2] == '\0' || str[2] == '.');
1288 * If there's no name there, ignore it; likewise, ignore it if it's
1289 * one of the magic symbols emitted used by current ARM tools.
1291 * Otherwise if find_symbols_between() returns those symbols, they'll
1292 * fail the whitelist tests and cause lots of false alarms ... fixable
1293 * only by merging __exit and __init sections into __text, bloating
1294 * the kernel (which is especially evil on embedded platforms).
1296 static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
1298 const char *name = elf->strtab + sym->st_name;
1300 if (!name || !strlen(name))
1302 return !is_arm_mapping_symbol(name);
1306 * Find symbol based on relocation record info.
1307 * In some cases the symbol supplied is a valid symbol so
1308 * return refsym. If st_name != 0 we assume this is a valid symbol.
1309 * In other cases the symbol needs to be looked up in the symbol table
1310 * based on section and address.
1312 static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1316 Elf_Sym *near = NULL;
1317 Elf64_Sword distance = 20;
1319 unsigned int relsym_secindex;
1321 if (relsym->st_name != 0)
1324 relsym_secindex = get_secindex(elf, relsym);
1325 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1326 if (get_secindex(elf, sym) != relsym_secindex)
1328 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
1330 if (!is_valid_name(elf, sym))
1332 if (sym->st_value == addr)
1334 /* Find a symbol nearby - addr are maybe negative */
1335 d = sym->st_value - addr;
1337 d = addr - sym->st_value;
1343 /* We need a close match */
1351 * Find symbols before or equal addr and after addr - in the section sec.
1352 * If we find two symbols with equal offset prefer one with a valid name.
1353 * The ELF format may have a better way to detect what type of symbol
1354 * it is, but this works for now.
1356 static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1360 Elf_Sym *near = NULL;
1361 Elf_Addr distance = ~0;
1363 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1366 if (is_shndx_special(sym->st_shndx))
1368 symsec = sec_name(elf, get_secindex(elf, sym));
1369 if (strcmp(symsec, sec) != 0)
1371 if (!is_valid_name(elf, sym))
1373 if (sym->st_value <= addr) {
1374 if ((addr - sym->st_value) < distance) {
1375 distance = addr - sym->st_value;
1377 } else if ((addr - sym->st_value) == distance) {
1386 * Convert a section name to the function/data attribute
1387 * .init.text => __init
1388 * .memexitconst => __memconst
1391 * The memory of returned value has been allocated on a heap. The user of this
1392 * method should free it after usage.
1394 static char *sec2annotation(const char *s)
1396 if (match(s, init_exit_sections)) {
1397 char *p = NOFAIL(malloc(20));
1404 while (*s && *s != '.')
1409 if (strstr(s, "rodata") != NULL)
1410 strcat(p, "const ");
1411 else if (strstr(s, "data") != NULL)
1417 return NOFAIL(strdup(""));
1421 static int is_function(Elf_Sym *sym)
1424 return ELF_ST_TYPE(sym->st_info) == STT_FUNC;
1429 static void print_section_list(const char * const list[20])
1431 const char *const *s = list;
1434 fprintf(stderr, "%s", *s);
1437 fprintf(stderr, ", ");
1439 fprintf(stderr, "\n");
1442 static inline void get_pretty_name(int is_func, const char** name, const char** name_p)
1445 case 0: *name = "variable"; *name_p = ""; break;
1446 case 1: *name = "function"; *name_p = "()"; break;
1447 default: *name = "(unknown reference)"; *name_p = ""; break;
1452 * Print a warning about a section mismatch.
1453 * Try to find symbols near it so user can find it.
1454 * Check whitelist before warning - it may be a false positive.
1456 static void report_sec_mismatch(const char *modname,
1457 const struct sectioncheck *mismatch,
1458 const char *fromsec,
1459 unsigned long long fromaddr,
1460 const char *fromsym,
1462 const char *tosec, const char *tosym,
1465 const char *from, *from_p;
1466 const char *to, *to_p;
1470 sec_mismatch_count++;
1472 get_pretty_name(from_is_func, &from, &from_p);
1473 get_pretty_name(to_is_func, &to, &to_p);
1475 warn("%s(%s+0x%llx): Section mismatch in reference from the %s %s%s "
1476 "to the %s %s:%s%s\n",
1477 modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec,
1480 switch (mismatch->mismatch) {
1481 case TEXT_TO_ANY_INIT:
1482 prl_from = sec2annotation(fromsec);
1483 prl_to = sec2annotation(tosec);
1485 "The function %s%s() references\n"
1487 "This is often because %s lacks a %s\n"
1488 "annotation or the annotation of %s is wrong.\n",
1490 to, prl_to, tosym, to_p,
1491 fromsym, prl_to, tosym);
1495 case DATA_TO_ANY_INIT: {
1496 prl_to = sec2annotation(tosec);
1498 "The variable %s references\n"
1500 "If the reference is valid then annotate the\n"
1501 "variable with __init* or __refdata (see linux/init.h) "
1502 "or name the variable:\n",
1503 fromsym, to, prl_to, tosym, to_p);
1504 print_section_list(mismatch->symbol_white_list);
1508 case TEXT_TO_ANY_EXIT:
1509 prl_to = sec2annotation(tosec);
1511 "The function %s() references a %s in an exit section.\n"
1512 "Often the %s %s%s has valid usage outside the exit section\n"
1513 "and the fix is to remove the %sannotation of %s.\n",
1514 fromsym, to, to, tosym, to_p, prl_to, tosym);
1517 case DATA_TO_ANY_EXIT: {
1518 prl_to = sec2annotation(tosec);
1520 "The variable %s references\n"
1522 "If the reference is valid then annotate the\n"
1523 "variable with __exit* (see linux/init.h) or "
1524 "name the variable:\n",
1525 fromsym, to, prl_to, tosym, to_p);
1526 print_section_list(mismatch->symbol_white_list);
1530 case XXXINIT_TO_SOME_INIT:
1531 case XXXEXIT_TO_SOME_EXIT:
1532 prl_from = sec2annotation(fromsec);
1533 prl_to = sec2annotation(tosec);
1535 "The %s %s%s%s references\n"
1537 "If %s is only used by %s then\n"
1538 "annotate %s with a matching annotation.\n",
1539 from, prl_from, fromsym, from_p,
1540 to, prl_to, tosym, to_p,
1541 tosym, fromsym, tosym);
1545 case ANY_INIT_TO_ANY_EXIT:
1546 prl_from = sec2annotation(fromsec);
1547 prl_to = sec2annotation(tosec);
1549 "The %s %s%s%s references\n"
1551 "This is often seen when error handling "
1552 "in the init function\n"
1553 "uses functionality in the exit path.\n"
1554 "The fix is often to remove the %sannotation of\n"
1555 "%s%s so it may be used outside an exit section.\n",
1556 from, prl_from, fromsym, from_p,
1557 to, prl_to, tosym, to_p,
1558 prl_to, tosym, to_p);
1562 case ANY_EXIT_TO_ANY_INIT:
1563 prl_from = sec2annotation(fromsec);
1564 prl_to = sec2annotation(tosec);
1566 "The %s %s%s%s references\n"
1568 "This is often seen when error handling "
1569 "in the exit function\n"
1570 "uses functionality in the init path.\n"
1571 "The fix is often to remove the %sannotation of\n"
1572 "%s%s so it may be used outside an init section.\n",
1573 from, prl_from, fromsym, from_p,
1574 to, prl_to, tosym, to_p,
1575 prl_to, tosym, to_p);
1579 case EXPORT_TO_INIT_EXIT:
1580 prl_to = sec2annotation(tosec);
1582 "The symbol %s is exported and annotated %s\n"
1583 "Fix this by removing the %sannotation of %s "
1584 "or drop the export.\n",
1585 tosym, prl_to, prl_to, tosym);
1588 case EXTABLE_TO_NON_TEXT:
1589 fatal("There's a special handler for this mismatch type, "
1590 "we should never get here.");
1593 fprintf(stderr, "\n");
1596 static void default_mismatch_handler(const char *modname, struct elf_info *elf,
1597 const struct sectioncheck* const mismatch,
1598 Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
1604 const char *fromsym;
1606 from = find_elf_symbol2(elf, r->r_offset, fromsec);
1607 fromsym = sym_name(elf, from);
1609 if (strstarts(fromsym, "reference___initcall"))
1612 tosec = sec_name(elf, get_secindex(elf, sym));
1613 to = find_elf_symbol(elf, r->r_addend, sym);
1614 tosym = sym_name(elf, to);
1616 /* check whitelist - we may ignore it */
1617 if (secref_whitelist(mismatch,
1618 fromsec, fromsym, tosec, tosym)) {
1619 report_sec_mismatch(modname, mismatch,
1620 fromsec, r->r_offset, fromsym,
1621 is_function(from), tosec, tosym,
1626 static int is_executable_section(struct elf_info* elf, unsigned int section_index)
1628 if (section_index > elf->num_sections)
1629 fatal("section_index is outside elf->num_sections!\n");
1631 return ((elf->sechdrs[section_index].sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR);
1635 * We rely on a gross hack in section_rel[a]() calling find_extable_entry_size()
1636 * to know the sizeof(struct exception_table_entry) for the target architecture.
1638 static unsigned int extable_entry_size = 0;
1639 static void find_extable_entry_size(const char* const sec, const Elf_Rela* r)
1642 * If we're currently checking the second relocation within __ex_table,
1643 * that relocation offset tells us the offsetof(struct
1644 * exception_table_entry, fixup) which is equal to sizeof(struct
1645 * exception_table_entry) divided by two. We use that to our advantage
1646 * since there's no portable way to get that size as every architecture
1647 * seems to go with different sized types. Not pretty but better than
1648 * hard-coding the size for every architecture..
1650 if (!extable_entry_size)
1651 extable_entry_size = r->r_offset * 2;
1654 static inline bool is_extable_fault_address(Elf_Rela *r)
1657 * extable_entry_size is only discovered after we've handled the
1658 * _second_ relocation in __ex_table, so only abort when we're not
1659 * handling the first reloc and extable_entry_size is zero.
1661 if (r->r_offset && extable_entry_size == 0)
1662 fatal("extable_entry size hasn't been discovered!\n");
1664 return ((r->r_offset == 0) ||
1665 (r->r_offset % extable_entry_size == 0));
1668 #define is_second_extable_reloc(Start, Cur, Sec) \
1669 (((Cur) == (Start) + 1) && (strcmp("__ex_table", (Sec)) == 0))
1671 static void report_extable_warnings(const char* modname, struct elf_info* elf,
1672 const struct sectioncheck* const mismatch,
1673 Elf_Rela* r, Elf_Sym* sym,
1674 const char* fromsec, const char* tosec)
1676 Elf_Sym* fromsym = find_elf_symbol2(elf, r->r_offset, fromsec);
1677 const char* fromsym_name = sym_name(elf, fromsym);
1678 Elf_Sym* tosym = find_elf_symbol(elf, r->r_addend, sym);
1679 const char* tosym_name = sym_name(elf, tosym);
1680 const char* from_pretty_name;
1681 const char* from_pretty_name_p;
1682 const char* to_pretty_name;
1683 const char* to_pretty_name_p;
1685 get_pretty_name(is_function(fromsym),
1686 &from_pretty_name, &from_pretty_name_p);
1687 get_pretty_name(is_function(tosym),
1688 &to_pretty_name, &to_pretty_name_p);
1690 warn("%s(%s+0x%lx): Section mismatch in reference"
1691 " from the %s %s%s to the %s %s:%s%s\n",
1692 modname, fromsec, (long)r->r_offset, from_pretty_name,
1693 fromsym_name, from_pretty_name_p,
1694 to_pretty_name, tosec, tosym_name, to_pretty_name_p);
1696 if (!match(tosec, mismatch->bad_tosec) &&
1697 is_executable_section(elf, get_secindex(elf, sym)))
1699 "The relocation at %s+0x%lx references\n"
1700 "section \"%s\" which is not in the list of\n"
1701 "authorized sections. If you're adding a new section\n"
1702 "and/or if this reference is valid, add \"%s\" to the\n"
1703 "list of authorized sections to jump to on fault.\n"
1704 "This can be achieved by adding \"%s\" to \n"
1705 "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n",
1706 fromsec, (long)r->r_offset, tosec, tosec, tosec);
1709 static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
1710 const struct sectioncheck* const mismatch,
1711 Elf_Rela* r, Elf_Sym* sym,
1712 const char *fromsec)
1714 const char* tosec = sec_name(elf, get_secindex(elf, sym));
1716 sec_mismatch_count++;
1718 report_extable_warnings(modname, elf, mismatch, r, sym, fromsec, tosec);
1720 if (match(tosec, mismatch->bad_tosec))
1721 fatal("The relocation at %s+0x%lx references\n"
1722 "section \"%s\" which is black-listed.\n"
1723 "Something is seriously wrong and should be fixed.\n"
1724 "You might get more information about where this is\n"
1725 "coming from by using scripts/check_extable.sh %s\n",
1726 fromsec, (long)r->r_offset, tosec, modname);
1727 else if (!is_executable_section(elf, get_secindex(elf, sym))) {
1728 if (is_extable_fault_address(r))
1729 fatal("The relocation at %s+0x%lx references\n"
1730 "section \"%s\" which is not executable, IOW\n"
1731 "it is not possible for the kernel to fault\n"
1732 "at that address. Something is seriously wrong\n"
1733 "and should be fixed.\n",
1734 fromsec, (long)r->r_offset, tosec);
1736 fatal("The relocation at %s+0x%lx references\n"
1737 "section \"%s\" which is not executable, IOW\n"
1738 "the kernel will fault if it ever tries to\n"
1739 "jump to it. Something is seriously wrong\n"
1740 "and should be fixed.\n",
1741 fromsec, (long)r->r_offset, tosec);
1745 static void check_section_mismatch(const char *modname, struct elf_info *elf,
1746 Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
1748 const char *tosec = sec_name(elf, get_secindex(elf, sym));
1749 const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec);
1752 if (mismatch->handler)
1753 mismatch->handler(modname, elf, mismatch,
1756 default_mismatch_handler(modname, elf, mismatch,
1761 static unsigned int *reloc_location(struct elf_info *elf,
1762 Elf_Shdr *sechdr, Elf_Rela *r)
1764 return sym_get_data_by_offset(elf, sechdr->sh_info, r->r_offset);
1767 static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1769 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1770 unsigned int *location = reloc_location(elf, sechdr, r);
1774 r->r_addend = TO_NATIVE(*location);
1777 r->r_addend = TO_NATIVE(*location) + 4;
1778 /* For CONFIG_RELOCATABLE=y */
1779 if (elf->hdr->e_type == ET_EXEC)
1780 r->r_addend += r->r_offset;
1787 #define R_ARM_CALL 28
1789 #ifndef R_ARM_JUMP24
1790 #define R_ARM_JUMP24 29
1793 #ifndef R_ARM_THM_CALL
1794 #define R_ARM_THM_CALL 10
1796 #ifndef R_ARM_THM_JUMP24
1797 #define R_ARM_THM_JUMP24 30
1799 #ifndef R_ARM_THM_JUMP19
1800 #define R_ARM_THM_JUMP19 51
1803 static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1805 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1809 /* From ARM ABI: (S + A) | T */
1810 r->r_addend = (int)(long)
1811 (elf->symtab_start + ELF_R_SYM(r->r_info));
1816 case R_ARM_THM_CALL:
1817 case R_ARM_THM_JUMP24:
1818 case R_ARM_THM_JUMP19:
1819 /* From ARM ABI: ((S + A) | T) - P */
1820 r->r_addend = (int)(long)(elf->hdr +
1822 (r->r_offset - sechdr->sh_addr));
1830 static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1832 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1833 unsigned int *location = reloc_location(elf, sechdr, r);
1836 if (r_typ == R_MIPS_HI16)
1837 return 1; /* skip this */
1838 inst = TO_NATIVE(*location);
1841 r->r_addend = inst & 0xffff;
1844 r->r_addend = (inst & 0x03ffffff) << 2;
1853 static void section_rela(const char *modname, struct elf_info *elf,
1860 const char *fromsec;
1862 Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset;
1863 Elf_Rela *stop = (void *)start + sechdr->sh_size;
1865 fromsec = sech_name(elf, sechdr);
1866 fromsec += strlen(".rela");
1867 /* if from section (name) is know good then skip it */
1868 if (match(fromsec, section_white_list))
1871 for (rela = start; rela < stop; rela++) {
1872 r.r_offset = TO_NATIVE(rela->r_offset);
1873 #if KERNEL_ELFCLASS == ELFCLASS64
1874 if (elf->hdr->e_machine == EM_MIPS) {
1876 r_sym = ELF64_MIPS_R_SYM(rela->r_info);
1877 r_sym = TO_NATIVE(r_sym);
1878 r_typ = ELF64_MIPS_R_TYPE(rela->r_info);
1879 r.r_info = ELF64_R_INFO(r_sym, r_typ);
1881 r.r_info = TO_NATIVE(rela->r_info);
1882 r_sym = ELF_R_SYM(r.r_info);
1885 r.r_info = TO_NATIVE(rela->r_info);
1886 r_sym = ELF_R_SYM(r.r_info);
1888 r.r_addend = TO_NATIVE(rela->r_addend);
1889 sym = elf->symtab_start + r_sym;
1890 /* Skip special sections */
1891 if (is_shndx_special(sym->st_shndx))
1893 if (is_second_extable_reloc(start, rela, fromsec))
1894 find_extable_entry_size(fromsec, &r);
1895 check_section_mismatch(modname, elf, &r, sym, fromsec);
1899 static void section_rel(const char *modname, struct elf_info *elf,
1906 const char *fromsec;
1908 Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset;
1909 Elf_Rel *stop = (void *)start + sechdr->sh_size;
1911 fromsec = sech_name(elf, sechdr);
1912 fromsec += strlen(".rel");
1913 /* if from section (name) is know good then skip it */
1914 if (match(fromsec, section_white_list))
1917 for (rel = start; rel < stop; rel++) {
1918 r.r_offset = TO_NATIVE(rel->r_offset);
1919 #if KERNEL_ELFCLASS == ELFCLASS64
1920 if (elf->hdr->e_machine == EM_MIPS) {
1922 r_sym = ELF64_MIPS_R_SYM(rel->r_info);
1923 r_sym = TO_NATIVE(r_sym);
1924 r_typ = ELF64_MIPS_R_TYPE(rel->r_info);
1925 r.r_info = ELF64_R_INFO(r_sym, r_typ);
1927 r.r_info = TO_NATIVE(rel->r_info);
1928 r_sym = ELF_R_SYM(r.r_info);
1931 r.r_info = TO_NATIVE(rel->r_info);
1932 r_sym = ELF_R_SYM(r.r_info);
1935 switch (elf->hdr->e_machine) {
1937 if (addend_386_rel(elf, sechdr, &r))
1941 if (addend_arm_rel(elf, sechdr, &r))
1945 if (addend_mips_rel(elf, sechdr, &r))
1949 sym = elf->symtab_start + r_sym;
1950 /* Skip special sections */
1951 if (is_shndx_special(sym->st_shndx))
1953 if (is_second_extable_reloc(start, rel, fromsec))
1954 find_extable_entry_size(fromsec, &r);
1955 check_section_mismatch(modname, elf, &r, sym, fromsec);
1960 * A module includes a number of sections that are discarded
1961 * either when loaded or when used as built-in.
1962 * For loaded modules all functions marked __init and all data
1963 * marked __initdata will be discarded when the module has been initialized.
1964 * Likewise for modules used built-in the sections marked __exit
1965 * are discarded because __exit marked function are supposed to be called
1966 * only when a module is unloaded which never happens for built-in modules.
1967 * The check_sec_ref() function traverses all relocation records
1968 * to find all references to a section that reference a section that will
1969 * be discarded and warns about it.
1971 static void check_sec_ref(struct module *mod, const char *modname,
1972 struct elf_info *elf)
1975 Elf_Shdr *sechdrs = elf->sechdrs;
1977 /* Walk through all sections */
1978 for (i = 0; i < elf->num_sections; i++) {
1979 check_section(modname, elf, &elf->sechdrs[i]);
1980 /* We want to process only relocation sections and not .init */
1981 if (sechdrs[i].sh_type == SHT_RELA)
1982 section_rela(modname, elf, &elf->sechdrs[i]);
1983 else if (sechdrs[i].sh_type == SHT_REL)
1984 section_rel(modname, elf, &elf->sechdrs[i]);
1988 static char *remove_dot(char *s)
1990 size_t n = strcspn(s, ".");
1993 size_t m = strspn(s + n + 1, "0123456789");
1994 if (m && (s[n + m] == '.' || s[n + m] == 0))
2000 static void read_symbols(const char *modname)
2002 const char *symname;
2007 struct elf_info info = { };
2010 if (!parse_elf(&info, modname))
2013 mod = new_module(modname);
2015 if (mod->is_vmlinux)
2018 if (!mod->is_vmlinux) {
2019 license = get_modinfo(&info, "license");
2021 warn("missing MODULE_LICENSE() in %s\n", modname);
2023 if (license_is_gpl_compatible(license))
2024 mod->gpl_compatible = 1;
2026 mod->gpl_compatible = 0;
2029 license = get_next_modinfo(&info, "license", license);
2032 namespace = get_modinfo(&info, "import_ns");
2034 add_namespace(&mod->imported_namespaces, namespace);
2035 namespace = get_next_modinfo(&info, "import_ns",
2040 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2041 symname = remove_dot(info.strtab + sym->st_name);
2043 handle_symbol(mod, &info, sym, symname);
2044 handle_moddevtable(mod, &info, sym, symname);
2047 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2048 symname = remove_dot(info.strtab + sym->st_name);
2050 /* Apply symbol namespaces from __kstrtabns_<symbol> entries. */
2051 if (strstarts(symname, "__kstrtabns_"))
2052 sym_update_namespace(symname + strlen("__kstrtabns_"),
2053 namespace_from_kstrtabns(&info,
2056 if (strstarts(symname, "__crc_"))
2057 handle_modversion(mod, &info, sym,
2058 symname + strlen("__crc_"));
2061 // check for static EXPORT_SYMBOL_* functions && global vars
2062 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2063 unsigned char bind = ELF_ST_BIND(sym->st_info);
2065 if (bind == STB_GLOBAL || bind == STB_WEAK) {
2067 find_symbol(remove_dot(info.strtab +
2075 check_sec_ref(mod, modname, &info);
2077 if (!mod->is_vmlinux) {
2078 version = get_modinfo(&info, "version");
2079 if (version || all_versions)
2080 get_src_version(modname, mod->srcversion,
2081 sizeof(mod->srcversion) - 1);
2084 parse_elf_finish(&info);
2086 /* Our trick to get versioning for module struct etc. - it's
2087 * never passed as an argument to an exported function, so
2088 * the automatic versioning doesn't pick it up, but it's really
2089 * important anyhow */
2091 mod->unres = alloc_symbol("module_layout", 0, mod->unres);
2094 static void read_symbols_from_files(const char *filename)
2097 char fname[PATH_MAX];
2099 if (strcmp(filename, "-") != 0) {
2100 in = fopen(filename, "r");
2102 fatal("Can't open filenames file %s: %m", filename);
2105 while (fgets(fname, PATH_MAX, in) != NULL) {
2106 if (strends(fname, "\n"))
2107 fname[strlen(fname)-1] = '\0';
2108 read_symbols(fname);
2117 /* We first write the generated file into memory using the
2118 * following helper, then compare to the file on disk and
2119 * only update the later if anything changed */
2121 void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
2122 const char *fmt, ...)
2129 len = vsnprintf(tmp, SZ, fmt, ap);
2130 buf_write(buf, tmp, len);
2134 void buf_write(struct buffer *buf, const char *s, int len)
2136 if (buf->size - buf->pos < len) {
2137 buf->size += len + SZ;
2138 buf->p = NOFAIL(realloc(buf->p, buf->size));
2140 strncpy(buf->p + buf->pos, s, len);
2144 static void check_for_gpl_usage(enum export exp, const char *m, const char *s)
2148 fatal("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
2151 case export_unused_gpl:
2152 fatal("GPL-incompatible module %s.ko uses GPL-only symbol marked UNUSED '%s'\n",
2155 case export_gpl_future:
2156 warn("GPL-incompatible module %s.ko uses future GPL-only symbol '%s'\n",
2161 case export_unknown:
2167 static void check_for_unused(enum export exp, const char *m, const char *s)
2171 case export_unused_gpl:
2172 warn("module %s.ko uses symbol '%s' marked UNUSED\n",
2181 static int check_exports(struct module *mod)
2183 struct symbol *s, *exp;
2186 for (s = mod->unres; s; s = s->next) {
2187 const char *basename;
2188 exp = find_symbol(s->name);
2189 if (!exp || exp->module == mod) {
2190 if (have_vmlinux && !s->weak) {
2191 modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
2192 "\"%s\" [%s.ko] undefined!\n",
2193 s->name, mod->name);
2194 if (!warn_unresolved)
2199 basename = strrchr(mod->name, '/');
2203 basename = mod->name;
2205 if (exp->namespace &&
2206 !module_imports_namespace(mod, exp->namespace)) {
2207 modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
2208 "module %s uses symbol %s from namespace %s, but does not import it.\n",
2209 basename, exp->name, exp->namespace);
2210 if (!allow_missing_ns_imports)
2212 add_namespace(&mod->missing_namespaces, exp->namespace);
2215 if (!mod->gpl_compatible)
2216 check_for_gpl_usage(exp->export, basename, exp->name);
2217 check_for_unused(exp->export, basename, exp->name);
2223 static int check_modname_len(struct module *mod)
2225 const char *mod_name;
2227 mod_name = strrchr(mod->name, '/');
2228 if (mod_name == NULL)
2229 mod_name = mod->name;
2232 if (strlen(mod_name) >= MODULE_NAME_LEN) {
2233 merror("module name is too long [%s.ko]\n", mod->name);
2241 * Header for the generated file
2243 static void add_header(struct buffer *b, struct module *mod)
2245 buf_printf(b, "#include <linux/module.h>\n");
2247 * Include build-salt.h after module.h in order to
2248 * inherit the definitions.
2250 buf_printf(b, "#include <linux/build-salt.h>\n");
2251 buf_printf(b, "#include <linux/vermagic.h>\n");
2252 buf_printf(b, "#include <linux/compiler.h>\n");
2253 buf_printf(b, "\n");
2254 buf_printf(b, "BUILD_SALT;\n");
2255 buf_printf(b, "\n");
2256 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
2257 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
2258 buf_printf(b, "\n");
2259 buf_printf(b, "__visible struct module __this_module\n");
2260 buf_printf(b, "__section(.gnu.linkonce.this_module) = {\n");
2261 buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
2263 buf_printf(b, "\t.init = init_module,\n");
2264 if (mod->has_cleanup)
2265 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"
2266 "\t.exit = cleanup_module,\n"
2268 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n");
2269 buf_printf(b, "};\n");
2272 static void add_intree_flag(struct buffer *b, int is_intree)
2275 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
2278 /* Cannot check for assembler */
2279 static void add_retpoline(struct buffer *b)
2281 buf_printf(b, "\n#ifdef CONFIG_RETPOLINE\n");
2282 buf_printf(b, "MODULE_INFO(retpoline, \"Y\");\n");
2283 buf_printf(b, "#endif\n");
2286 static void add_staging_flag(struct buffer *b, const char *name)
2288 if (strstarts(name, "drivers/staging"))
2289 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
2293 * Record CRCs for unresolved symbols
2295 static int add_versions(struct buffer *b, struct module *mod)
2297 struct symbol *s, *exp;
2300 for (s = mod->unres; s; s = s->next) {
2301 exp = find_symbol(s->name);
2302 if (!exp || exp->module == mod)
2304 s->module = exp->module;
2305 s->crc_valid = exp->crc_valid;
2312 buf_printf(b, "\n");
2313 buf_printf(b, "static const struct modversion_info ____versions[]\n");
2314 buf_printf(b, "__used __section(__versions) = {\n");
2316 for (s = mod->unres; s; s = s->next) {
2319 if (!s->crc_valid) {
2320 warn("\"%s\" [%s.ko] has no CRC!\n",
2321 s->name, mod->name);
2324 if (strlen(s->name) >= MODULE_NAME_LEN) {
2325 merror("too long symbol \"%s\" [%s.ko]\n",
2326 s->name, mod->name);
2330 buf_printf(b, "\t{ %#8x, \"%s\" },\n",
2334 buf_printf(b, "};\n");
2339 static void add_depends(struct buffer *b, struct module *mod)
2344 /* Clear ->seen flag of modules that own symbols needed by this. */
2345 for (s = mod->unres; s; s = s->next)
2347 s->module->seen = s->module->is_vmlinux;
2349 buf_printf(b, "\n");
2350 buf_printf(b, "MODULE_INFO(depends, \"");
2351 for (s = mod->unres; s; s = s->next) {
2356 if (s->module->seen)
2359 s->module->seen = 1;
2360 p = strrchr(s->module->name, '/');
2364 p = s->module->name;
2365 buf_printf(b, "%s%s", first ? "" : ",", p);
2368 buf_printf(b, "\");\n");
2371 static void add_srcversion(struct buffer *b, struct module *mod)
2373 if (mod->srcversion[0]) {
2374 buf_printf(b, "\n");
2375 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
2380 static void write_buf(struct buffer *b, const char *fname)
2384 file = fopen(fname, "w");
2389 if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2393 if (fclose(file) != 0) {
2399 static void write_if_changed(struct buffer *b, const char *fname)
2405 file = fopen(fname, "r");
2409 if (fstat(fileno(file), &st) < 0)
2412 if (st.st_size != b->pos)
2415 tmp = NOFAIL(malloc(b->pos));
2416 if (fread(tmp, 1, b->pos, file) != b->pos)
2419 if (memcmp(tmp, b->p, b->pos) != 0)
2431 write_buf(b, fname);
2434 /* parse Module.symvers file. line format:
2435 * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
2437 static void read_dump(const char *fname)
2439 char *buf, *pos, *line;
2441 buf = read_text_file(fname);
2443 /* No symbol versions, silently ignore */
2448 while ((line = get_line(&pos))) {
2449 char *symname, *namespace, *modname, *d, *export;
2454 if (!(symname = strchr(line, '\t')))
2457 if (!(modname = strchr(symname, '\t')))
2460 if (!(export = strchr(modname, '\t')))
2463 if (!(namespace = strchr(export, '\t')))
2465 *namespace++ = '\0';
2467 crc = strtoul(line, &d, 16);
2468 if (*symname == '\0' || *modname == '\0' || *d != '\0')
2470 mod = find_module(modname);
2472 mod = new_module(modname);
2473 if (mod->is_vmlinux)
2477 s = sym_add_exported(symname, mod, export_no(export));
2479 sym_set_crc(symname, crc);
2480 sym_update_namespace(symname, namespace);
2486 fatal("parse error in symbol dump file\n");
2489 /* For normal builds always dump all symbols.
2490 * For external modules only dump symbols
2491 * that are not read from kernel Module.symvers.
2493 static int dump_sym(struct symbol *sym)
2495 if (!external_module)
2497 if (sym->module->from_dump)
2502 static void write_dump(const char *fname)
2504 struct buffer buf = { };
2505 struct symbol *symbol;
2506 const char *namespace;
2509 for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
2510 symbol = symbolhash[n];
2512 if (dump_sym(symbol)) {
2513 namespace = symbol->namespace;
2514 buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n",
2515 symbol->crc, symbol->name,
2516 symbol->module->name,
2517 export_str(symbol->export),
2518 namespace ? namespace : "");
2520 symbol = symbol->next;
2523 write_buf(&buf, fname);
2527 static void write_namespace_deps_files(const char *fname)
2530 struct namespace_list *ns;
2531 struct buffer ns_deps_buf = {};
2533 for (mod = modules; mod; mod = mod->next) {
2535 if (mod->from_dump || !mod->missing_namespaces)
2538 buf_printf(&ns_deps_buf, "%s.ko:", mod->name);
2540 for (ns = mod->missing_namespaces; ns; ns = ns->next)
2541 buf_printf(&ns_deps_buf, " %s", ns->namespace);
2543 buf_printf(&ns_deps_buf, "\n");
2546 write_if_changed(&ns_deps_buf, fname);
2547 free(ns_deps_buf.p);
2551 struct dump_list *next;
2555 int main(int argc, char **argv)
2558 struct buffer buf = { };
2559 char *missing_namespace_deps = NULL;
2560 char *dump_write = NULL, *files_source = NULL;
2564 struct dump_list *dump_read_start = NULL;
2565 struct dump_list **dump_read_iter = &dump_read_start;
2567 while ((opt = getopt(argc, argv, "ei:mnT:o:awENd:")) != -1) {
2570 external_module = 1;
2574 NOFAIL(calloc(1, sizeof(**dump_read_iter)));
2575 (*dump_read_iter)->file = optarg;
2576 dump_read_iter = &(*dump_read_iter)->next;
2582 ignore_missing_files = 1;
2585 dump_write = optarg;
2591 files_source = optarg;
2594 warn_unresolved = 1;
2597 sec_mismatch_fatal = 1;
2600 allow_missing_ns_imports = 1;
2603 missing_namespace_deps = optarg;
2610 while (dump_read_start) {
2611 struct dump_list *tmp;
2613 read_dump(dump_read_start->file);
2614 tmp = dump_read_start->next;
2615 free(dump_read_start);
2616 dump_read_start = tmp;
2619 while (optind < argc)
2620 read_symbols(argv[optind++]);
2623 read_symbols_from_files(files_source);
2626 * When there's no vmlinux, don't print warnings about
2627 * unresolved symbols (since there'll be too many ;)
2630 warn("Symbol info of vmlinux is missing. Unresolved symbol check will be entirely skipped.\n");
2634 for (mod = modules; mod; mod = mod->next) {
2635 char fname[PATH_MAX];
2637 if (mod->is_vmlinux || mod->from_dump)
2642 err |= check_modname_len(mod);
2643 err |= check_exports(mod);
2645 add_header(&buf, mod);
2646 add_intree_flag(&buf, !external_module);
2647 add_retpoline(&buf);
2648 add_staging_flag(&buf, mod->name);
2649 err |= add_versions(&buf, mod);
2650 add_depends(&buf, mod);
2651 add_moddevtable(&buf, mod);
2652 add_srcversion(&buf, mod);
2654 sprintf(fname, "%s.mod.c", mod->name);
2655 write_if_changed(&buf, fname);
2658 if (missing_namespace_deps)
2659 write_namespace_deps_files(missing_namespace_deps);
2662 write_dump(dump_write);
2663 if (sec_mismatch_count && sec_mismatch_fatal)
2664 fatal("Section mismatches detected.\n"
2665 "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2666 for (n = 0; n < SYMBOL_HASH_SIZE; n++) {
2669 for (s = symbolhash[n]; s; s = s->next) {
2671 warn("\"%s\" [%s] is a static %s\n",
2672 s->name, s->module->name,
2673 export_str(s->export));