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 bool modversions;
27 /* Is CONFIG_MODULE_SRCVERSION_ALL set? */
28 static bool all_versions;
29 /* If we are modposting external module set to 1 */
30 static bool external_module;
31 /* Only warn about unresolved symbols */
32 static bool warn_unresolved;
34 static int sec_mismatch_count;
35 static bool sec_mismatch_warn_only = true;
36 /* ignore missing files */
37 static bool ignore_missing_files;
38 /* If set to 1, only warn (instead of error) about missing ns imports */
39 static bool allow_missing_ns_imports;
41 static bool error_occurred;
44 * Cut off the warnings when there are too many. This typically occurs when
45 * vmlinux is missing. ('make modules' without building vmlinux.)
47 #define MAX_UNRESOLVED_REPORTS 10
48 static unsigned int nr_unresolved;
50 /* In kernel, this size is defined in linux/module.h;
51 * here we use Elf_Addr instead of long for covering cross-compile
54 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
56 void __attribute__((format(printf, 2, 3)))
57 modpost_log(enum loglevel loglevel, const char *fmt, ...)
63 fprintf(stderr, "WARNING: ");
66 fprintf(stderr, "ERROR: ");
69 fprintf(stderr, "FATAL: ");
71 default: /* invalid loglevel, ignore */
75 fprintf(stderr, "modpost: ");
77 va_start(arglist, fmt);
78 vfprintf(stderr, fmt, arglist);
81 if (loglevel == LOG_FATAL)
83 if (loglevel == LOG_ERROR)
84 error_occurred = true;
87 static inline bool strends(const char *str, const char *postfix)
89 if (strlen(str) < strlen(postfix))
92 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
95 void *do_nofail(void *ptr, const char *expr)
98 fatal("Memory allocation failure: %s.\n", expr);
103 char *read_text_file(const char *filename)
110 fd = open(filename, O_RDONLY);
116 if (fstat(fd, &st) < 0) {
121 buf = NOFAIL(malloc(st.st_size + 1));
128 bytes_read = read(fd, buf, nbytes);
129 if (bytes_read < 0) {
134 nbytes -= bytes_read;
136 buf[st.st_size] = '\0';
143 char *get_line(char **stringp)
145 char *orig = *stringp, *next;
147 /* do not return the unwanted extra line at EOF */
148 if (!orig || *orig == '\0')
151 /* don't use strsep here, it is not available everywhere */
152 next = strchr(orig, '\n');
161 /* A list of all modules we processed */
164 static struct module *find_module(const char *modname)
168 list_for_each_entry(mod, &modules, list) {
169 if (strcmp(mod->name, modname) == 0)
175 static struct module *new_module(const char *modname)
179 mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1));
180 memset(mod, 0, sizeof(*mod));
182 INIT_LIST_HEAD(&mod->exported_symbols);
183 INIT_LIST_HEAD(&mod->unresolved_symbols);
184 INIT_LIST_HEAD(&mod->missing_namespaces);
185 INIT_LIST_HEAD(&mod->imported_namespaces);
187 strcpy(mod->name, modname);
188 mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0);
191 * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE()
192 * is missing, do not check the use for EXPORT_SYMBOL_GPL() becasue
193 * modpost will exit wiht error anyway.
195 mod->is_gpl_compatible = true;
197 list_add_tail(&mod->list, &modules);
202 /* A hash of all exported symbols,
203 * struct symbol is also used for lists of unresolved symbols */
205 #define SYMBOL_HASH_SIZE 1024
209 struct list_head list; /* link to module::exported_symbols or module::unresolved_symbols */
210 struct module *module;
215 bool is_static; /* true if symbol is not global */
216 bool is_gpl_only; /* exported by EXPORT_SYMBOL_GPL */
220 static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
222 /* This is based on the hash algorithm from gdbm, via tdb */
223 static inline unsigned int tdb_hash(const char *name)
225 unsigned value; /* Used to compute the hash value. */
226 unsigned i; /* Used to cycle through random values. */
228 /* Set the initial value from the key size. */
229 for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++)
230 value = (value + (((unsigned char *)name)[i] << (i*5 % 24)));
232 return (1103515243 * value + 12345);
236 * Allocate a new symbols for use in the hash of exported symbols or
237 * the list of unresolved symbols per module
239 static struct symbol *alloc_symbol(const char *name)
241 struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
243 memset(s, 0, sizeof(*s));
244 strcpy(s->name, name);
249 /* For the hash of exported symbols */
250 static void hash_add_symbol(struct symbol *sym)
254 hash = tdb_hash(sym->name) % SYMBOL_HASH_SIZE;
255 sym->next = symbolhash[hash];
256 symbolhash[hash] = sym;
259 static void sym_add_unresolved(const char *name, struct module *mod, bool weak)
263 sym = alloc_symbol(name);
266 list_add_tail(&sym->list, &mod->unresolved_symbols);
269 static struct symbol *sym_find_with_module(const char *name, struct module *mod)
273 /* For our purposes, .foo matches foo. PPC64 needs this. */
277 for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) {
278 if (strcmp(s->name, name) == 0 && (!mod || s->module == mod))
284 static struct symbol *find_symbol(const char *name)
286 return sym_find_with_module(name, NULL);
289 struct namespace_list {
290 struct list_head list;
294 static bool contains_namespace(struct list_head *head, const char *namespace)
296 struct namespace_list *list;
298 list_for_each_entry(list, head, list) {
299 if (!strcmp(list->namespace, namespace))
306 static void add_namespace(struct list_head *head, const char *namespace)
308 struct namespace_list *ns_entry;
310 if (!contains_namespace(head, namespace)) {
311 ns_entry = NOFAIL(malloc(sizeof(*ns_entry) +
312 strlen(namespace) + 1));
313 strcpy(ns_entry->namespace, namespace);
314 list_add_tail(&ns_entry->list, head);
318 static void *sym_get_data_by_offset(const struct elf_info *info,
319 unsigned int secindex, unsigned long offset)
321 Elf_Shdr *sechdr = &info->sechdrs[secindex];
323 if (info->hdr->e_type != ET_REL)
324 offset -= sechdr->sh_addr;
326 return (void *)info->hdr + sechdr->sh_offset + offset;
329 static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
331 return sym_get_data_by_offset(info, get_secindex(info, sym),
335 static const char *sech_name(const struct elf_info *info, Elf_Shdr *sechdr)
337 return sym_get_data_by_offset(info, info->secindex_strings,
341 static const char *sec_name(const struct elf_info *info, int secindex)
343 return sech_name(info, &info->sechdrs[secindex]);
346 #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
348 static void sym_update_namespace(const char *symname, const char *namespace)
350 struct symbol *s = find_symbol(symname);
353 * That symbol should have been created earlier and thus this is
354 * actually an assertion.
357 error("Could not update namespace(%s) for symbol %s\n",
363 s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL;
366 static struct symbol *sym_add_exported(const char *name, struct module *mod,
369 struct symbol *s = find_symbol(name);
371 if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) {
372 error("%s: '%s' exported twice. Previous export was in %s%s\n",
373 mod->name, name, s->module->name,
374 s->module->is_vmlinux ? "" : ".ko");
377 s = alloc_symbol(name);
379 s->is_gpl_only = gpl_only;
380 list_add_tail(&s->list, &mod->exported_symbols);
386 static void sym_set_crc(struct symbol *sym, unsigned int crc)
389 sym->crc_valid = true;
392 static void *grab_file(const char *filename, size_t *size)
395 void *map = MAP_FAILED;
398 fd = open(filename, O_RDONLY);
405 map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
409 if (map == MAP_FAILED)
414 static void release_file(void *file, size_t size)
419 static int parse_elf(struct elf_info *info, const char *filename)
425 const char *secstrings;
426 unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U;
428 hdr = grab_file(filename, &info->size);
430 if (ignore_missing_files) {
431 fprintf(stderr, "%s: %s (ignored)\n", filename,
439 if (info->size < sizeof(*hdr)) {
440 /* file too small, assume this is an empty .o file */
443 /* Is this a valid ELF file? */
444 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
445 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
446 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
447 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
448 /* Not an ELF file - silently ignore it */
451 /* Fix endianness in ELF header */
452 hdr->e_type = TO_NATIVE(hdr->e_type);
453 hdr->e_machine = TO_NATIVE(hdr->e_machine);
454 hdr->e_version = TO_NATIVE(hdr->e_version);
455 hdr->e_entry = TO_NATIVE(hdr->e_entry);
456 hdr->e_phoff = TO_NATIVE(hdr->e_phoff);
457 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
458 hdr->e_flags = TO_NATIVE(hdr->e_flags);
459 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize);
460 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize);
461 hdr->e_phnum = TO_NATIVE(hdr->e_phnum);
462 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize);
463 hdr->e_shnum = TO_NATIVE(hdr->e_shnum);
464 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
465 sechdrs = (void *)hdr + hdr->e_shoff;
466 info->sechdrs = sechdrs;
468 /* Check if file offset is correct */
469 if (hdr->e_shoff > info->size) {
470 fatal("section header offset=%lu in file '%s' is bigger than filesize=%zu\n",
471 (unsigned long)hdr->e_shoff, filename, info->size);
475 if (hdr->e_shnum == SHN_UNDEF) {
477 * There are more than 64k sections,
478 * read count from .sh_size.
480 info->num_sections = TO_NATIVE(sechdrs[0].sh_size);
483 info->num_sections = hdr->e_shnum;
485 if (hdr->e_shstrndx == SHN_XINDEX) {
486 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link);
489 info->secindex_strings = hdr->e_shstrndx;
492 /* Fix endianness in section headers */
493 for (i = 0; i < info->num_sections; i++) {
494 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name);
495 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type);
496 sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags);
497 sechdrs[i].sh_addr = TO_NATIVE(sechdrs[i].sh_addr);
498 sechdrs[i].sh_offset = TO_NATIVE(sechdrs[i].sh_offset);
499 sechdrs[i].sh_size = TO_NATIVE(sechdrs[i].sh_size);
500 sechdrs[i].sh_link = TO_NATIVE(sechdrs[i].sh_link);
501 sechdrs[i].sh_info = TO_NATIVE(sechdrs[i].sh_info);
502 sechdrs[i].sh_addralign = TO_NATIVE(sechdrs[i].sh_addralign);
503 sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize);
505 /* Find symbol table. */
506 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset;
507 for (i = 1; i < info->num_sections; i++) {
509 int nobits = sechdrs[i].sh_type == SHT_NOBITS;
511 if (!nobits && sechdrs[i].sh_offset > info->size) {
512 fatal("%s is truncated. sechdrs[i].sh_offset=%lu > "
513 "sizeof(*hrd)=%zu\n", filename,
514 (unsigned long)sechdrs[i].sh_offset,
518 secname = secstrings + sechdrs[i].sh_name;
519 if (strcmp(secname, ".modinfo") == 0) {
521 fatal("%s has NOBITS .modinfo\n", filename);
522 info->modinfo = (void *)hdr + sechdrs[i].sh_offset;
523 info->modinfo_len = sechdrs[i].sh_size;
526 if (sechdrs[i].sh_type == SHT_SYMTAB) {
527 unsigned int sh_link_idx;
529 info->symtab_start = (void *)hdr +
530 sechdrs[i].sh_offset;
531 info->symtab_stop = (void *)hdr +
532 sechdrs[i].sh_offset + sechdrs[i].sh_size;
533 sh_link_idx = sechdrs[i].sh_link;
534 info->strtab = (void *)hdr +
535 sechdrs[sh_link_idx].sh_offset;
538 /* 32bit section no. table? ("more than 64k sections") */
539 if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) {
540 symtab_shndx_idx = i;
541 info->symtab_shndx_start = (void *)hdr +
542 sechdrs[i].sh_offset;
543 info->symtab_shndx_stop = (void *)hdr +
544 sechdrs[i].sh_offset + sechdrs[i].sh_size;
547 if (!info->symtab_start)
548 fatal("%s has no symtab?\n", filename);
550 /* Fix endianness in symbols */
551 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
552 sym->st_shndx = TO_NATIVE(sym->st_shndx);
553 sym->st_name = TO_NATIVE(sym->st_name);
554 sym->st_value = TO_NATIVE(sym->st_value);
555 sym->st_size = TO_NATIVE(sym->st_size);
558 if (symtab_shndx_idx != ~0U) {
560 if (symtab_idx != sechdrs[symtab_shndx_idx].sh_link)
561 fatal("%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n",
562 filename, sechdrs[symtab_shndx_idx].sh_link,
565 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop;
573 static void parse_elf_finish(struct elf_info *info)
575 release_file(info->hdr, info->size);
578 static int ignore_undef_symbol(struct elf_info *info, const char *symname)
580 /* ignore __this_module, it will be resolved shortly */
581 if (strcmp(symname, "__this_module") == 0)
583 /* ignore global offset table */
584 if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
586 if (info->hdr->e_machine == EM_PPC)
587 /* Special register function linked on all modules during final link of .ko */
588 if (strstarts(symname, "_restgpr_") ||
589 strstarts(symname, "_savegpr_") ||
590 strstarts(symname, "_rest32gpr_") ||
591 strstarts(symname, "_save32gpr_") ||
592 strstarts(symname, "_restvr_") ||
593 strstarts(symname, "_savevr_"))
595 if (info->hdr->e_machine == EM_PPC64)
596 /* Special register function linked on all modules during final link of .ko */
597 if (strstarts(symname, "_restgpr0_") ||
598 strstarts(symname, "_savegpr0_") ||
599 strstarts(symname, "_restvr_") ||
600 strstarts(symname, "_savevr_") ||
601 strcmp(symname, ".TOC.") == 0)
604 if (info->hdr->e_machine == EM_S390)
605 /* Expoline thunks are linked on all kernel modules during final link of .ko */
606 if (strstarts(symname, "__s390_indirect_jump_r"))
608 /* Do not ignore this symbol */
612 static void handle_symbol(struct module *mod, struct elf_info *info,
613 const Elf_Sym *sym, const char *symname)
615 switch (sym->st_shndx) {
617 if (strstarts(symname, "__gnu_lto_")) {
618 /* Should warn here, but modpost runs before the linker */
620 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name);
623 /* undefined symbol */
624 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
625 ELF_ST_BIND(sym->st_info) != STB_WEAK)
627 if (ignore_undef_symbol(info, symname))
629 if (info->hdr->e_machine == EM_SPARC ||
630 info->hdr->e_machine == EM_SPARCV9) {
631 /* Ignore register directives. */
632 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
634 if (symname[0] == '.') {
635 char *munged = NOFAIL(strdup(symname));
637 munged[1] = toupper(munged[1]);
642 sym_add_unresolved(symname, mod,
643 ELF_ST_BIND(sym->st_info) == STB_WEAK);
646 /* All exported symbols */
647 if (strstarts(symname, "__ksymtab_")) {
648 const char *name, *secname;
650 name = symname + strlen("__ksymtab_");
651 secname = sec_name(info, get_secindex(info, sym));
653 if (strstarts(secname, "___ksymtab_gpl+"))
654 sym_add_exported(name, mod, true);
655 else if (strstarts(secname, "___ksymtab+"))
656 sym_add_exported(name, mod, false);
658 if (strcmp(symname, "init_module") == 0)
659 mod->has_init = true;
660 if (strcmp(symname, "cleanup_module") == 0)
661 mod->has_cleanup = true;
667 * Parse tag=value strings from .modinfo section
669 static char *next_string(char *string, unsigned long *secsize)
671 /* Skip non-zero chars */
674 if ((*secsize)-- <= 1)
678 /* Skip any zero padding. */
681 if ((*secsize)-- <= 1)
687 static char *get_next_modinfo(struct elf_info *info, const char *tag,
691 unsigned int taglen = strlen(tag);
692 char *modinfo = info->modinfo;
693 unsigned long size = info->modinfo_len;
696 size -= prev - modinfo;
697 modinfo = next_string(prev, &size);
700 for (p = modinfo; p; p = next_string(p, &size)) {
701 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
702 return p + taglen + 1;
707 static char *get_modinfo(struct elf_info *info, const char *tag)
710 return get_next_modinfo(info, tag, NULL);
714 * Test if string s ends in string sub
717 static int strrcmp(const char *s, const char *sub)
725 sublen = strlen(sub);
727 if ((slen == 0) || (sublen == 0))
733 return memcmp(s + slen - sublen, sub, sublen);
736 static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
739 return elf->strtab + sym->st_name;
744 /* The pattern is an array of simple patterns.
745 * "foo" will match an exact string equal to "foo"
746 * "*foo" will match a string that ends with "foo"
747 * "foo*" will match a string that begins with "foo"
748 * "*foo*" will match a string that contains "foo"
750 static int match(const char *sym, const char * const pat[])
757 endp = p + strlen(p) - 1;
760 if (*p == '*' && *endp == '*') {
761 char *bare = NOFAIL(strndup(p + 1, strlen(p) - 2));
762 char *here = strstr(sym, bare);
769 else if (*p == '*') {
770 if (strrcmp(sym, p + 1) == 0)
774 else if (*endp == '*') {
775 if (strncmp(sym, p, strlen(p) - 1) == 0)
780 if (strcmp(p, sym) == 0)
788 /* sections that we do not want to do full section mismatch check on */
789 static const char *const section_white_list[] =
793 ".cranges", /* sh64 */
794 ".zdebug*", /* Compressed debug sections. */
795 ".GCC.command.line", /* record-gcc-switches */
796 ".mdebug*", /* alpha, score, mips etc. */
797 ".pdr", /* alpha, score, mips etc. */
802 ".xt.prop", /* xtensa */
803 ".xt.lit", /* xtensa */
804 ".arcextmap*", /* arc */
805 ".gnu.linkonce.arcext*", /* arc : modules */
806 ".cmem*", /* EZchip */
807 ".fmt_slot*", /* EZchip */
814 * This is used to find sections missing the SHF_ALLOC flag.
815 * The cause of this is often a section specified in assembler
816 * without "ax" / "aw".
818 static void check_section(const char *modname, struct elf_info *elf,
821 const char *sec = sech_name(elf, sechdr);
823 if (sechdr->sh_type == SHT_PROGBITS &&
824 !(sechdr->sh_flags & SHF_ALLOC) &&
825 !match(sec, section_white_list)) {
826 warn("%s (%s): unexpected non-allocatable section.\n"
827 "Did you forget to use \"ax\"/\"aw\" in a .S file?\n"
828 "Note that for example <linux/init.h> contains\n"
829 "section definitions for use in .S files.\n\n",
836 #define ALL_INIT_DATA_SECTIONS \
837 ".init.setup", ".init.rodata", ".meminit.rodata", \
838 ".init.data", ".meminit.data"
839 #define ALL_EXIT_DATA_SECTIONS \
840 ".exit.data", ".memexit.data"
842 #define ALL_INIT_TEXT_SECTIONS \
843 ".init.text", ".meminit.text"
844 #define ALL_EXIT_TEXT_SECTIONS \
845 ".exit.text", ".memexit.text"
847 #define ALL_PCI_INIT_SECTIONS \
848 ".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \
849 ".pci_fixup_enable", ".pci_fixup_resume", \
850 ".pci_fixup_resume_early", ".pci_fixup_suspend"
852 #define ALL_XXXINIT_SECTIONS MEM_INIT_SECTIONS
853 #define ALL_XXXEXIT_SECTIONS MEM_EXIT_SECTIONS
855 #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
856 #define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS
858 #define DATA_SECTIONS ".data", ".data.rel"
859 #define TEXT_SECTIONS ".text", ".text.unlikely", ".sched.text", \
860 ".kprobes.text", ".cpuidle.text", ".noinstr.text"
861 #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
862 ".fixup", ".entry.text", ".exception.text", ".text.*", \
863 ".coldtext", ".softirqentry.text"
865 #define INIT_SECTIONS ".init.*"
866 #define MEM_INIT_SECTIONS ".meminit.*"
868 #define EXIT_SECTIONS ".exit.*"
869 #define MEM_EXIT_SECTIONS ".memexit.*"
871 #define ALL_TEXT_SECTIONS ALL_INIT_TEXT_SECTIONS, ALL_EXIT_TEXT_SECTIONS, \
872 TEXT_SECTIONS, OTHER_TEXT_SECTIONS
874 /* init data sections */
875 static const char *const init_data_sections[] =
876 { ALL_INIT_DATA_SECTIONS, NULL };
878 /* all init sections */
879 static const char *const init_sections[] = { ALL_INIT_SECTIONS, NULL };
881 /* All init and exit sections (code + data) */
882 static const char *const init_exit_sections[] =
883 {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL };
885 /* all text sections */
886 static const char *const text_sections[] = { ALL_TEXT_SECTIONS, NULL };
889 static const char *const data_sections[] = { DATA_SECTIONS, NULL };
892 /* symbols in .data that may refer to init/exit sections */
893 #define DEFAULT_SYMBOL_WHITE_LIST \
895 "*_template", /* scsi uses *_template a lot */ \
896 "*_timer", /* arm uses ops structures named _timer a lot */ \
897 "*_sht", /* scsi also used *_sht to some extent */ \
903 static const char *const head_sections[] = { ".head.text*", NULL };
904 static const char *const linker_symbols[] =
905 { "__init_begin", "_sinittext", "_einittext", NULL };
906 static const char *const optim_symbols[] = { "*.constprop.*", NULL };
913 XXXINIT_TO_SOME_INIT,
914 XXXEXIT_TO_SOME_EXIT,
915 ANY_INIT_TO_ANY_EXIT,
916 ANY_EXIT_TO_ANY_INIT,
922 * Describe how to match sections on different criteria:
924 * @fromsec: Array of sections to be matched.
926 * @bad_tosec: Relocations applied to a section in @fromsec to a section in
927 * this array is forbidden (black-list). Can be empty.
929 * @good_tosec: Relocations applied to a section in @fromsec must be
930 * targeting sections in this array (white-list). Can be empty.
932 * @mismatch: Type of mismatch.
934 * @symbol_white_list: Do not match a relocation to a symbol in this list
935 * even if it is targeting a section in @bad_to_sec.
937 * @handler: Specific handler to call when a match is found. If NULL,
938 * default_mismatch_handler() will be called.
941 struct sectioncheck {
942 const char *fromsec[20];
943 const char *bad_tosec[20];
944 const char *good_tosec[20];
945 enum mismatch mismatch;
946 const char *symbol_white_list[20];
947 void (*handler)(const char *modname, struct elf_info *elf,
948 const struct sectioncheck* const mismatch,
949 Elf_Rela *r, Elf_Sym *sym, const char *fromsec);
953 static void extable_mismatch_handler(const char *modname, struct elf_info *elf,
954 const struct sectioncheck* const mismatch,
955 Elf_Rela *r, Elf_Sym *sym,
956 const char *fromsec);
958 static const struct sectioncheck sectioncheck[] = {
959 /* Do not reference init/exit code/data from
960 * normal code and data
963 .fromsec = { TEXT_SECTIONS, NULL },
964 .bad_tosec = { ALL_INIT_SECTIONS, NULL },
965 .mismatch = TEXT_TO_ANY_INIT,
966 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
969 .fromsec = { DATA_SECTIONS, NULL },
970 .bad_tosec = { ALL_XXXINIT_SECTIONS, NULL },
971 .mismatch = DATA_TO_ANY_INIT,
972 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
975 .fromsec = { DATA_SECTIONS, NULL },
976 .bad_tosec = { INIT_SECTIONS, NULL },
977 .mismatch = DATA_TO_ANY_INIT,
978 .symbol_white_list = {
979 "*_template", "*_timer", "*_sht", "*_ops",
980 "*_probe", "*_probe_one", "*_console", NULL
984 .fromsec = { TEXT_SECTIONS, NULL },
985 .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
986 .mismatch = TEXT_TO_ANY_EXIT,
987 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
990 .fromsec = { DATA_SECTIONS, NULL },
991 .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
992 .mismatch = DATA_TO_ANY_EXIT,
993 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
995 /* Do not reference init code/data from meminit code/data */
997 .fromsec = { ALL_XXXINIT_SECTIONS, NULL },
998 .bad_tosec = { INIT_SECTIONS, NULL },
999 .mismatch = XXXINIT_TO_SOME_INIT,
1000 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1002 /* Do not reference exit code/data from memexit code/data */
1004 .fromsec = { ALL_XXXEXIT_SECTIONS, NULL },
1005 .bad_tosec = { EXIT_SECTIONS, NULL },
1006 .mismatch = XXXEXIT_TO_SOME_EXIT,
1007 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1009 /* Do not use exit code/data from init code */
1011 .fromsec = { ALL_INIT_SECTIONS, NULL },
1012 .bad_tosec = { ALL_EXIT_SECTIONS, NULL },
1013 .mismatch = ANY_INIT_TO_ANY_EXIT,
1014 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1016 /* Do not use init code/data from exit code */
1018 .fromsec = { ALL_EXIT_SECTIONS, NULL },
1019 .bad_tosec = { ALL_INIT_SECTIONS, NULL },
1020 .mismatch = ANY_EXIT_TO_ANY_INIT,
1021 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1024 .fromsec = { ALL_PCI_INIT_SECTIONS, NULL },
1025 .bad_tosec = { INIT_SECTIONS, NULL },
1026 .mismatch = ANY_INIT_TO_ANY_EXIT,
1027 .symbol_white_list = { NULL },
1029 /* Do not export init/exit functions or data */
1031 .fromsec = { "__ksymtab*", NULL },
1032 .bad_tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
1033 .mismatch = EXPORT_TO_INIT_EXIT,
1034 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1037 .fromsec = { "__ex_table", NULL },
1038 /* If you're adding any new black-listed sections in here, consider
1039 * adding a special 'printer' for them in scripts/check_extable.
1041 .bad_tosec = { ".altinstr_replacement", NULL },
1042 .good_tosec = {ALL_TEXT_SECTIONS , NULL},
1043 .mismatch = EXTABLE_TO_NON_TEXT,
1044 .handler = extable_mismatch_handler,
1048 static const struct sectioncheck *section_mismatch(
1049 const char *fromsec, const char *tosec)
1052 int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck);
1053 const struct sectioncheck *check = §ioncheck[0];
1056 * The target section could be the SHT_NUL section when we're
1057 * handling relocations to un-resolved symbols, trying to match it
1058 * doesn't make much sense and causes build failures on parisc
1064 for (i = 0; i < elems; i++) {
1065 if (match(fromsec, check->fromsec)) {
1066 if (check->bad_tosec[0] && match(tosec, check->bad_tosec))
1068 if (check->good_tosec[0] && !match(tosec, check->good_tosec))
1077 * Whitelist to allow certain references to pass with no warning.
1080 * If a module parameter is declared __initdata and permissions=0
1081 * then this is legal despite the warning generated.
1082 * We cannot see value of permissions here, so just ignore
1084 * The pattern is identified by:
1085 * tosec = .init.data
1090 * module_param_call() ops can refer to __init set function if permissions=0
1091 * The pattern is identified by:
1092 * tosec = .init.text
1094 * atsym = __param_ops_*
1097 * Many drivers utilise a *driver container with references to
1098 * add, remove, probe functions etc.
1099 * the pattern is identified by:
1100 * tosec = init or exit section
1101 * fromsec = data section
1102 * atsym = *driver, *_template, *_sht, *_ops, *_probe,
1103 * *probe_one, *_console, *_timer
1106 * Whitelist all references from .head.text to any init section
1109 * Some symbols belong to init section but still it is ok to reference
1110 * these from non-init sections as these symbols don't have any memory
1111 * allocated for them and symbol address and value are same. So even
1112 * if init section is freed, its ok to reference those symbols.
1113 * For ex. symbols marking the init section boundaries.
1114 * This pattern is identified by
1115 * refsymname = __init_begin, _sinittext, _einittext
1118 * GCC may optimize static inlines when fed constant arg(s) resulting
1119 * in functions like cpumask_empty() -- generating an associated symbol
1120 * cpumask_empty.constprop.3 that appears in the audit. If the const that
1121 * is passed in comes from __init, like say nmi_ipi_mask, we get a
1122 * meaningless section warning. May need to add isra symbols too...
1123 * This pattern is identified by
1124 * tosec = init section
1125 * fromsec = text section
1126 * refsymname = *.constprop.*
1129 * Hide section mismatch warnings for ELF local symbols. The goal
1130 * is to eliminate false positive modpost warnings caused by
1131 * compiler-generated ELF local symbol names such as ".LANCHOR1".
1132 * Autogenerated symbol names bypass modpost's "Pattern 2"
1133 * whitelisting, which relies on pattern-matching against symbol
1134 * names to work. (One situation where gcc can autogenerate ELF
1135 * local symbols is when "-fsection-anchors" is used.)
1137 static int secref_whitelist(const struct sectioncheck *mismatch,
1138 const char *fromsec, const char *fromsym,
1139 const char *tosec, const char *tosym)
1141 /* Check for pattern 1 */
1142 if (match(tosec, init_data_sections) &&
1143 match(fromsec, data_sections) &&
1144 strstarts(fromsym, "__param"))
1147 /* Check for pattern 1a */
1148 if (strcmp(tosec, ".init.text") == 0 &&
1149 match(fromsec, data_sections) &&
1150 strstarts(fromsym, "__param_ops_"))
1153 /* Check for pattern 2 */
1154 if (match(tosec, init_exit_sections) &&
1155 match(fromsec, data_sections) &&
1156 match(fromsym, mismatch->symbol_white_list))
1159 /* Check for pattern 3 */
1160 if (match(fromsec, head_sections) &&
1161 match(tosec, init_sections))
1164 /* Check for pattern 4 */
1165 if (match(tosym, linker_symbols))
1168 /* Check for pattern 5 */
1169 if (match(fromsec, text_sections) &&
1170 match(tosec, init_sections) &&
1171 match(fromsym, optim_symbols))
1174 /* Check for pattern 6 */
1175 if (strstarts(fromsym, ".L"))
1181 static inline int is_arm_mapping_symbol(const char *str)
1183 return str[0] == '$' && strchr("axtd", str[1])
1184 && (str[2] == '\0' || str[2] == '.');
1188 * If there's no name there, ignore it; likewise, ignore it if it's
1189 * one of the magic symbols emitted used by current ARM tools.
1191 * Otherwise if find_symbols_between() returns those symbols, they'll
1192 * fail the whitelist tests and cause lots of false alarms ... fixable
1193 * only by merging __exit and __init sections into __text, bloating
1194 * the kernel (which is especially evil on embedded platforms).
1196 static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
1198 const char *name = elf->strtab + sym->st_name;
1200 if (!name || !strlen(name))
1202 return !is_arm_mapping_symbol(name);
1206 * Find symbol based on relocation record info.
1207 * In some cases the symbol supplied is a valid symbol so
1208 * return refsym. If st_name != 0 we assume this is a valid symbol.
1209 * In other cases the symbol needs to be looked up in the symbol table
1210 * based on section and address.
1212 static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1216 Elf_Sym *near = NULL;
1217 Elf64_Sword distance = 20;
1219 unsigned int relsym_secindex;
1221 if (relsym->st_name != 0)
1224 relsym_secindex = get_secindex(elf, relsym);
1225 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1226 if (get_secindex(elf, sym) != relsym_secindex)
1228 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
1230 if (!is_valid_name(elf, sym))
1232 if (sym->st_value == addr)
1234 /* Find a symbol nearby - addr are maybe negative */
1235 d = sym->st_value - addr;
1237 d = addr - sym->st_value;
1243 /* We need a close match */
1251 * Find symbols before or equal addr and after addr - in the section sec.
1252 * If we find two symbols with equal offset prefer one with a valid name.
1253 * The ELF format may have a better way to detect what type of symbol
1254 * it is, but this works for now.
1256 static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1260 Elf_Sym *near = NULL;
1261 Elf_Addr distance = ~0;
1263 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1266 if (is_shndx_special(sym->st_shndx))
1268 symsec = sec_name(elf, get_secindex(elf, sym));
1269 if (strcmp(symsec, sec) != 0)
1271 if (!is_valid_name(elf, sym))
1273 if (sym->st_value <= addr) {
1274 if ((addr - sym->st_value) < distance) {
1275 distance = addr - sym->st_value;
1277 } else if ((addr - sym->st_value) == distance) {
1286 * Convert a section name to the function/data attribute
1287 * .init.text => __init
1288 * .memexitconst => __memconst
1291 * The memory of returned value has been allocated on a heap. The user of this
1292 * method should free it after usage.
1294 static char *sec2annotation(const char *s)
1296 if (match(s, init_exit_sections)) {
1297 char *p = NOFAIL(malloc(20));
1304 while (*s && *s != '.')
1309 if (strstr(s, "rodata") != NULL)
1310 strcat(p, "const ");
1311 else if (strstr(s, "data") != NULL)
1317 return NOFAIL(strdup(""));
1321 static int is_function(Elf_Sym *sym)
1324 return ELF_ST_TYPE(sym->st_info) == STT_FUNC;
1329 static void print_section_list(const char * const list[20])
1331 const char *const *s = list;
1334 fprintf(stderr, "%s", *s);
1337 fprintf(stderr, ", ");
1339 fprintf(stderr, "\n");
1342 static inline void get_pretty_name(int is_func, const char** name, const char** name_p)
1345 case 0: *name = "variable"; *name_p = ""; break;
1346 case 1: *name = "function"; *name_p = "()"; break;
1347 default: *name = "(unknown reference)"; *name_p = ""; break;
1352 * Print a warning about a section mismatch.
1353 * Try to find symbols near it so user can find it.
1354 * Check whitelist before warning - it may be a false positive.
1356 static void report_sec_mismatch(const char *modname,
1357 const struct sectioncheck *mismatch,
1358 const char *fromsec,
1359 unsigned long long fromaddr,
1360 const char *fromsym,
1362 const char *tosec, const char *tosym,
1365 const char *from, *from_p;
1366 const char *to, *to_p;
1370 sec_mismatch_count++;
1372 get_pretty_name(from_is_func, &from, &from_p);
1373 get_pretty_name(to_is_func, &to, &to_p);
1375 warn("%s(%s+0x%llx): Section mismatch in reference from the %s %s%s "
1376 "to the %s %s:%s%s\n",
1377 modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec,
1380 switch (mismatch->mismatch) {
1381 case TEXT_TO_ANY_INIT:
1382 prl_from = sec2annotation(fromsec);
1383 prl_to = sec2annotation(tosec);
1385 "The function %s%s() references\n"
1387 "This is often because %s lacks a %s\n"
1388 "annotation or the annotation of %s is wrong.\n",
1390 to, prl_to, tosym, to_p,
1391 fromsym, prl_to, tosym);
1395 case DATA_TO_ANY_INIT: {
1396 prl_to = sec2annotation(tosec);
1398 "The variable %s references\n"
1400 "If the reference is valid then annotate the\n"
1401 "variable with __init* or __refdata (see linux/init.h) "
1402 "or name the variable:\n",
1403 fromsym, to, prl_to, tosym, to_p);
1404 print_section_list(mismatch->symbol_white_list);
1408 case TEXT_TO_ANY_EXIT:
1409 prl_to = sec2annotation(tosec);
1411 "The function %s() references a %s in an exit section.\n"
1412 "Often the %s %s%s has valid usage outside the exit section\n"
1413 "and the fix is to remove the %sannotation of %s.\n",
1414 fromsym, to, to, tosym, to_p, prl_to, tosym);
1417 case DATA_TO_ANY_EXIT: {
1418 prl_to = sec2annotation(tosec);
1420 "The variable %s references\n"
1422 "If the reference is valid then annotate the\n"
1423 "variable with __exit* (see linux/init.h) or "
1424 "name the variable:\n",
1425 fromsym, to, prl_to, tosym, to_p);
1426 print_section_list(mismatch->symbol_white_list);
1430 case XXXINIT_TO_SOME_INIT:
1431 case XXXEXIT_TO_SOME_EXIT:
1432 prl_from = sec2annotation(fromsec);
1433 prl_to = sec2annotation(tosec);
1435 "The %s %s%s%s references\n"
1437 "If %s is only used by %s then\n"
1438 "annotate %s with a matching annotation.\n",
1439 from, prl_from, fromsym, from_p,
1440 to, prl_to, tosym, to_p,
1441 tosym, fromsym, tosym);
1445 case ANY_INIT_TO_ANY_EXIT:
1446 prl_from = sec2annotation(fromsec);
1447 prl_to = sec2annotation(tosec);
1449 "The %s %s%s%s references\n"
1451 "This is often seen when error handling "
1452 "in the init function\n"
1453 "uses functionality in the exit path.\n"
1454 "The fix is often to remove the %sannotation of\n"
1455 "%s%s so it may be used outside an exit section.\n",
1456 from, prl_from, fromsym, from_p,
1457 to, prl_to, tosym, to_p,
1458 prl_to, tosym, to_p);
1462 case ANY_EXIT_TO_ANY_INIT:
1463 prl_from = sec2annotation(fromsec);
1464 prl_to = sec2annotation(tosec);
1466 "The %s %s%s%s references\n"
1468 "This is often seen when error handling "
1469 "in the exit function\n"
1470 "uses functionality in the init path.\n"
1471 "The fix is often to remove the %sannotation of\n"
1472 "%s%s so it may be used outside an init section.\n",
1473 from, prl_from, fromsym, from_p,
1474 to, prl_to, tosym, to_p,
1475 prl_to, tosym, to_p);
1479 case EXPORT_TO_INIT_EXIT:
1480 prl_to = sec2annotation(tosec);
1482 "The symbol %s is exported and annotated %s\n"
1483 "Fix this by removing the %sannotation of %s "
1484 "or drop the export.\n",
1485 tosym, prl_to, prl_to, tosym);
1488 case EXTABLE_TO_NON_TEXT:
1489 fatal("There's a special handler for this mismatch type, "
1490 "we should never get here.");
1493 fprintf(stderr, "\n");
1496 static void default_mismatch_handler(const char *modname, struct elf_info *elf,
1497 const struct sectioncheck* const mismatch,
1498 Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
1504 const char *fromsym;
1506 from = find_elf_symbol2(elf, r->r_offset, fromsec);
1507 fromsym = sym_name(elf, from);
1509 if (strstarts(fromsym, "reference___initcall"))
1512 tosec = sec_name(elf, get_secindex(elf, sym));
1513 to = find_elf_symbol(elf, r->r_addend, sym);
1514 tosym = sym_name(elf, to);
1516 /* check whitelist - we may ignore it */
1517 if (secref_whitelist(mismatch,
1518 fromsec, fromsym, tosec, tosym)) {
1519 report_sec_mismatch(modname, mismatch,
1520 fromsec, r->r_offset, fromsym,
1521 is_function(from), tosec, tosym,
1526 static int is_executable_section(struct elf_info* elf, unsigned int section_index)
1528 if (section_index > elf->num_sections)
1529 fatal("section_index is outside elf->num_sections!\n");
1531 return ((elf->sechdrs[section_index].sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR);
1535 * We rely on a gross hack in section_rel[a]() calling find_extable_entry_size()
1536 * to know the sizeof(struct exception_table_entry) for the target architecture.
1538 static unsigned int extable_entry_size = 0;
1539 static void find_extable_entry_size(const char* const sec, const Elf_Rela* r)
1542 * If we're currently checking the second relocation within __ex_table,
1543 * that relocation offset tells us the offsetof(struct
1544 * exception_table_entry, fixup) which is equal to sizeof(struct
1545 * exception_table_entry) divided by two. We use that to our advantage
1546 * since there's no portable way to get that size as every architecture
1547 * seems to go with different sized types. Not pretty but better than
1548 * hard-coding the size for every architecture..
1550 if (!extable_entry_size)
1551 extable_entry_size = r->r_offset * 2;
1554 static inline bool is_extable_fault_address(Elf_Rela *r)
1557 * extable_entry_size is only discovered after we've handled the
1558 * _second_ relocation in __ex_table, so only abort when we're not
1559 * handling the first reloc and extable_entry_size is zero.
1561 if (r->r_offset && extable_entry_size == 0)
1562 fatal("extable_entry size hasn't been discovered!\n");
1564 return ((r->r_offset == 0) ||
1565 (r->r_offset % extable_entry_size == 0));
1568 #define is_second_extable_reloc(Start, Cur, Sec) \
1569 (((Cur) == (Start) + 1) && (strcmp("__ex_table", (Sec)) == 0))
1571 static void report_extable_warnings(const char* modname, struct elf_info* elf,
1572 const struct sectioncheck* const mismatch,
1573 Elf_Rela* r, Elf_Sym* sym,
1574 const char* fromsec, const char* tosec)
1576 Elf_Sym* fromsym = find_elf_symbol2(elf, r->r_offset, fromsec);
1577 const char* fromsym_name = sym_name(elf, fromsym);
1578 Elf_Sym* tosym = find_elf_symbol(elf, r->r_addend, sym);
1579 const char* tosym_name = sym_name(elf, tosym);
1580 const char* from_pretty_name;
1581 const char* from_pretty_name_p;
1582 const char* to_pretty_name;
1583 const char* to_pretty_name_p;
1585 get_pretty_name(is_function(fromsym),
1586 &from_pretty_name, &from_pretty_name_p);
1587 get_pretty_name(is_function(tosym),
1588 &to_pretty_name, &to_pretty_name_p);
1590 warn("%s(%s+0x%lx): Section mismatch in reference"
1591 " from the %s %s%s to the %s %s:%s%s\n",
1592 modname, fromsec, (long)r->r_offset, from_pretty_name,
1593 fromsym_name, from_pretty_name_p,
1594 to_pretty_name, tosec, tosym_name, to_pretty_name_p);
1596 if (!match(tosec, mismatch->bad_tosec) &&
1597 is_executable_section(elf, get_secindex(elf, sym)))
1599 "The relocation at %s+0x%lx references\n"
1600 "section \"%s\" which is not in the list of\n"
1601 "authorized sections. If you're adding a new section\n"
1602 "and/or if this reference is valid, add \"%s\" to the\n"
1603 "list of authorized sections to jump to on fault.\n"
1604 "This can be achieved by adding \"%s\" to \n"
1605 "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n",
1606 fromsec, (long)r->r_offset, tosec, tosec, tosec);
1609 static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
1610 const struct sectioncheck* const mismatch,
1611 Elf_Rela* r, Elf_Sym* sym,
1612 const char *fromsec)
1614 const char* tosec = sec_name(elf, get_secindex(elf, sym));
1616 sec_mismatch_count++;
1618 report_extable_warnings(modname, elf, mismatch, r, sym, fromsec, tosec);
1620 if (match(tosec, mismatch->bad_tosec))
1621 fatal("The relocation at %s+0x%lx references\n"
1622 "section \"%s\" which is black-listed.\n"
1623 "Something is seriously wrong and should be fixed.\n"
1624 "You might get more information about where this is\n"
1625 "coming from by using scripts/check_extable.sh %s\n",
1626 fromsec, (long)r->r_offset, tosec, modname);
1627 else if (!is_executable_section(elf, get_secindex(elf, sym))) {
1628 if (is_extable_fault_address(r))
1629 fatal("The relocation at %s+0x%lx references\n"
1630 "section \"%s\" which is not executable, IOW\n"
1631 "it is not possible for the kernel to fault\n"
1632 "at that address. Something is seriously wrong\n"
1633 "and should be fixed.\n",
1634 fromsec, (long)r->r_offset, tosec);
1636 fatal("The relocation at %s+0x%lx references\n"
1637 "section \"%s\" which is not executable, IOW\n"
1638 "the kernel will fault if it ever tries to\n"
1639 "jump to it. Something is seriously wrong\n"
1640 "and should be fixed.\n",
1641 fromsec, (long)r->r_offset, tosec);
1645 static void check_section_mismatch(const char *modname, struct elf_info *elf,
1646 Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
1648 const char *tosec = sec_name(elf, get_secindex(elf, sym));
1649 const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec);
1652 if (mismatch->handler)
1653 mismatch->handler(modname, elf, mismatch,
1656 default_mismatch_handler(modname, elf, mismatch,
1661 static unsigned int *reloc_location(struct elf_info *elf,
1662 Elf_Shdr *sechdr, Elf_Rela *r)
1664 return sym_get_data_by_offset(elf, sechdr->sh_info, r->r_offset);
1667 static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1669 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1670 unsigned int *location = reloc_location(elf, sechdr, r);
1674 r->r_addend = TO_NATIVE(*location);
1677 r->r_addend = TO_NATIVE(*location) + 4;
1678 /* For CONFIG_RELOCATABLE=y */
1679 if (elf->hdr->e_type == ET_EXEC)
1680 r->r_addend += r->r_offset;
1687 #define R_ARM_CALL 28
1689 #ifndef R_ARM_JUMP24
1690 #define R_ARM_JUMP24 29
1693 #ifndef R_ARM_THM_CALL
1694 #define R_ARM_THM_CALL 10
1696 #ifndef R_ARM_THM_JUMP24
1697 #define R_ARM_THM_JUMP24 30
1699 #ifndef R_ARM_THM_JUMP19
1700 #define R_ARM_THM_JUMP19 51
1703 static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1705 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1709 /* From ARM ABI: (S + A) | T */
1710 r->r_addend = (int)(long)
1711 (elf->symtab_start + ELF_R_SYM(r->r_info));
1716 case R_ARM_THM_CALL:
1717 case R_ARM_THM_JUMP24:
1718 case R_ARM_THM_JUMP19:
1719 /* From ARM ABI: ((S + A) | T) - P */
1720 r->r_addend = (int)(long)(elf->hdr +
1722 (r->r_offset - sechdr->sh_addr));
1730 static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1732 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1733 unsigned int *location = reloc_location(elf, sechdr, r);
1736 if (r_typ == R_MIPS_HI16)
1737 return 1; /* skip this */
1738 inst = TO_NATIVE(*location);
1741 r->r_addend = inst & 0xffff;
1744 r->r_addend = (inst & 0x03ffffff) << 2;
1754 #define EM_RISCV 243
1757 #ifndef R_RISCV_SUB32
1758 #define R_RISCV_SUB32 39
1761 static void section_rela(const char *modname, struct elf_info *elf,
1768 const char *fromsec;
1770 Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset;
1771 Elf_Rela *stop = (void *)start + sechdr->sh_size;
1773 fromsec = sech_name(elf, sechdr);
1774 fromsec += strlen(".rela");
1775 /* if from section (name) is know good then skip it */
1776 if (match(fromsec, section_white_list))
1779 for (rela = start; rela < stop; rela++) {
1780 r.r_offset = TO_NATIVE(rela->r_offset);
1781 #if KERNEL_ELFCLASS == ELFCLASS64
1782 if (elf->hdr->e_machine == EM_MIPS) {
1784 r_sym = ELF64_MIPS_R_SYM(rela->r_info);
1785 r_sym = TO_NATIVE(r_sym);
1786 r_typ = ELF64_MIPS_R_TYPE(rela->r_info);
1787 r.r_info = ELF64_R_INFO(r_sym, r_typ);
1789 r.r_info = TO_NATIVE(rela->r_info);
1790 r_sym = ELF_R_SYM(r.r_info);
1793 r.r_info = TO_NATIVE(rela->r_info);
1794 r_sym = ELF_R_SYM(r.r_info);
1796 r.r_addend = TO_NATIVE(rela->r_addend);
1797 switch (elf->hdr->e_machine) {
1799 if (!strcmp("__ex_table", fromsec) &&
1800 ELF_R_TYPE(r.r_info) == R_RISCV_SUB32)
1804 sym = elf->symtab_start + r_sym;
1805 /* Skip special sections */
1806 if (is_shndx_special(sym->st_shndx))
1808 if (is_second_extable_reloc(start, rela, fromsec))
1809 find_extable_entry_size(fromsec, &r);
1810 check_section_mismatch(modname, elf, &r, sym, fromsec);
1814 static void section_rel(const char *modname, struct elf_info *elf,
1821 const char *fromsec;
1823 Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset;
1824 Elf_Rel *stop = (void *)start + sechdr->sh_size;
1826 fromsec = sech_name(elf, sechdr);
1827 fromsec += strlen(".rel");
1828 /* if from section (name) is know good then skip it */
1829 if (match(fromsec, section_white_list))
1832 for (rel = start; rel < stop; rel++) {
1833 r.r_offset = TO_NATIVE(rel->r_offset);
1834 #if KERNEL_ELFCLASS == ELFCLASS64
1835 if (elf->hdr->e_machine == EM_MIPS) {
1837 r_sym = ELF64_MIPS_R_SYM(rel->r_info);
1838 r_sym = TO_NATIVE(r_sym);
1839 r_typ = ELF64_MIPS_R_TYPE(rel->r_info);
1840 r.r_info = ELF64_R_INFO(r_sym, r_typ);
1842 r.r_info = TO_NATIVE(rel->r_info);
1843 r_sym = ELF_R_SYM(r.r_info);
1846 r.r_info = TO_NATIVE(rel->r_info);
1847 r_sym = ELF_R_SYM(r.r_info);
1850 switch (elf->hdr->e_machine) {
1852 if (addend_386_rel(elf, sechdr, &r))
1856 if (addend_arm_rel(elf, sechdr, &r))
1860 if (addend_mips_rel(elf, sechdr, &r))
1864 sym = elf->symtab_start + r_sym;
1865 /* Skip special sections */
1866 if (is_shndx_special(sym->st_shndx))
1868 if (is_second_extable_reloc(start, rel, fromsec))
1869 find_extable_entry_size(fromsec, &r);
1870 check_section_mismatch(modname, elf, &r, sym, fromsec);
1875 * A module includes a number of sections that are discarded
1876 * either when loaded or when used as built-in.
1877 * For loaded modules all functions marked __init and all data
1878 * marked __initdata will be discarded when the module has been initialized.
1879 * Likewise for modules used built-in the sections marked __exit
1880 * are discarded because __exit marked function are supposed to be called
1881 * only when a module is unloaded which never happens for built-in modules.
1882 * The check_sec_ref() function traverses all relocation records
1883 * to find all references to a section that reference a section that will
1884 * be discarded and warns about it.
1886 static void check_sec_ref(struct module *mod, const char *modname,
1887 struct elf_info *elf)
1890 Elf_Shdr *sechdrs = elf->sechdrs;
1892 /* Walk through all sections */
1893 for (i = 0; i < elf->num_sections; i++) {
1894 check_section(modname, elf, &elf->sechdrs[i]);
1895 /* We want to process only relocation sections and not .init */
1896 if (sechdrs[i].sh_type == SHT_RELA)
1897 section_rela(modname, elf, &elf->sechdrs[i]);
1898 else if (sechdrs[i].sh_type == SHT_REL)
1899 section_rel(modname, elf, &elf->sechdrs[i]);
1903 static char *remove_dot(char *s)
1905 size_t n = strcspn(s, ".");
1908 size_t m = strspn(s + n + 1, "0123456789");
1909 if (m && (s[n + m + 1] == '.' || s[n + m + 1] == 0))
1912 /* strip trailing .prelink */
1913 if (strends(s, ".prelink"))
1914 s[strlen(s) - 8] = '\0';
1920 * The CRCs are recorded in .*.cmd files in the form of:
1921 * #SYMVER <name> <crc>
1923 static void extract_crcs_for_object(const char *object, struct module *mod)
1925 char cmd_file[PATH_MAX];
1930 base = strrchr(object, '/');
1933 dirlen = base - object;
1939 ret = snprintf(cmd_file, sizeof(cmd_file), "%.*s.%s.cmd",
1940 dirlen, object, base);
1941 if (ret >= sizeof(cmd_file)) {
1942 error("%s: too long path was truncated\n", cmd_file);
1946 buf = read_text_file(cmd_file);
1949 while ((p = strstr(p, "\n#SYMVER "))) {
1955 name = p + strlen("\n#SYMVER ");
1957 p = strchr(name, ' ');
1965 continue; /* skip this line */
1967 crc = strtol(p, &p, 0);
1969 continue; /* skip this line */
1971 name[namelen] = '\0';
1974 * sym_find_with_module() may return NULL here.
1975 * It typically occurs when CONFIG_TRIM_UNUSED_KSYMS=y.
1976 * Since commit e1327a127703, genksyms calculates CRCs of all
1977 * symbols, including trimmed ones. Ignore orphan CRCs.
1979 sym = sym_find_with_module(name, mod);
1981 sym_set_crc(sym, crc);
1988 * The symbol versions (CRC) are recorded in the .*.cmd files.
1989 * Parse them to retrieve CRCs for the current module.
1991 static void mod_set_crcs(struct module *mod)
1993 char objlist[PATH_MAX];
1994 char *buf, *p, *obj;
1997 if (mod->is_vmlinux) {
1998 strcpy(objlist, ".vmlinux.objs");
2000 /* objects for a module are listed in the *.mod file. */
2001 ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name);
2002 if (ret >= sizeof(objlist)) {
2003 error("%s: too long path was truncated\n", objlist);
2008 buf = read_text_file(objlist);
2011 while ((obj = strsep(&p, "\n")) && obj[0])
2012 extract_crcs_for_object(obj, mod);
2017 static void read_symbols(const char *modname)
2019 const char *symname;
2024 struct elf_info info = { };
2027 if (!parse_elf(&info, modname))
2033 /* strip trailing .o */
2034 tmp = NOFAIL(strdup(modname));
2035 tmp[strlen(tmp) - 2] = '\0';
2036 /* strip trailing .prelink */
2037 if (strends(tmp, ".prelink"))
2038 tmp[strlen(tmp) - 8] = '\0';
2039 mod = new_module(tmp);
2043 if (!mod->is_vmlinux) {
2044 license = get_modinfo(&info, "license");
2046 error("missing MODULE_LICENSE() in %s\n", modname);
2048 if (!license_is_gpl_compatible(license)) {
2049 mod->is_gpl_compatible = false;
2052 license = get_next_modinfo(&info, "license", license);
2055 namespace = get_modinfo(&info, "import_ns");
2057 add_namespace(&mod->imported_namespaces, namespace);
2058 namespace = get_next_modinfo(&info, "import_ns",
2063 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2064 symname = remove_dot(info.strtab + sym->st_name);
2066 handle_symbol(mod, &info, sym, symname);
2067 handle_moddevtable(mod, &info, sym, symname);
2070 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2071 symname = remove_dot(info.strtab + sym->st_name);
2073 /* Apply symbol namespaces from __kstrtabns_<symbol> entries. */
2074 if (strstarts(symname, "__kstrtabns_"))
2075 sym_update_namespace(symname + strlen("__kstrtabns_"),
2076 sym_get_data(&info, sym));
2079 // check for static EXPORT_SYMBOL_* functions && global vars
2080 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
2081 unsigned char bind = ELF_ST_BIND(sym->st_info);
2083 if (bind == STB_GLOBAL || bind == STB_WEAK) {
2085 find_symbol(remove_dot(info.strtab +
2089 s->is_static = false;
2093 check_sec_ref(mod, modname, &info);
2095 if (!mod->is_vmlinux) {
2096 version = get_modinfo(&info, "version");
2097 if (version || all_versions)
2098 get_src_version(mod->name, mod->srcversion,
2099 sizeof(mod->srcversion) - 1);
2102 parse_elf_finish(&info);
2106 * Our trick to get versioning for module struct etc. - it's
2107 * never passed as an argument to an exported function, so
2108 * the automatic versioning doesn't pick it up, but it's really
2111 sym_add_unresolved("module_layout", mod, false);
2117 static void read_symbols_from_files(const char *filename)
2120 char fname[PATH_MAX];
2122 if (strcmp(filename, "-") != 0) {
2123 in = fopen(filename, "r");
2125 fatal("Can't open filenames file %s: %m", filename);
2128 while (fgets(fname, PATH_MAX, in) != NULL) {
2129 if (strends(fname, "\n"))
2130 fname[strlen(fname)-1] = '\0';
2131 read_symbols(fname);
2140 /* We first write the generated file into memory using the
2141 * following helper, then compare to the file on disk and
2142 * only update the later if anything changed */
2144 void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
2145 const char *fmt, ...)
2152 len = vsnprintf(tmp, SZ, fmt, ap);
2153 buf_write(buf, tmp, len);
2157 void buf_write(struct buffer *buf, const char *s, int len)
2159 if (buf->size - buf->pos < len) {
2160 buf->size += len + SZ;
2161 buf->p = NOFAIL(realloc(buf->p, buf->size));
2163 strncpy(buf->p + buf->pos, s, len);
2167 static void check_exports(struct module *mod)
2169 struct symbol *s, *exp;
2171 list_for_each_entry(s, &mod->unresolved_symbols, list) {
2172 const char *basename;
2173 exp = find_symbol(s->name);
2175 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
2176 modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
2177 "\"%s\" [%s.ko] undefined!\n",
2178 s->name, mod->name);
2181 if (exp->module == mod) {
2182 error("\"%s\" [%s.ko] was exported without definition\n",
2183 s->name, mod->name);
2187 s->module = exp->module;
2188 s->crc_valid = exp->crc_valid;
2191 basename = strrchr(mod->name, '/');
2195 basename = mod->name;
2197 if (exp->namespace &&
2198 !contains_namespace(&mod->imported_namespaces, exp->namespace)) {
2199 modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
2200 "module %s uses symbol %s from namespace %s, but does not import it.\n",
2201 basename, exp->name, exp->namespace);
2202 add_namespace(&mod->missing_namespaces, exp->namespace);
2205 if (!mod->is_gpl_compatible && exp->is_gpl_only)
2206 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
2207 basename, exp->name);
2211 static void check_modname_len(struct module *mod)
2213 const char *mod_name;
2215 mod_name = strrchr(mod->name, '/');
2216 if (mod_name == NULL)
2217 mod_name = mod->name;
2220 if (strlen(mod_name) >= MODULE_NAME_LEN)
2221 error("module name is too long [%s.ko]\n", mod->name);
2225 * Header for the generated file
2227 static void add_header(struct buffer *b, struct module *mod)
2229 buf_printf(b, "#include <linux/module.h>\n");
2231 * Include build-salt.h after module.h in order to
2232 * inherit the definitions.
2234 buf_printf(b, "#define INCLUDE_VERMAGIC\n");
2235 buf_printf(b, "#include <linux/build-salt.h>\n");
2236 buf_printf(b, "#include <linux/elfnote-lto.h>\n");
2237 buf_printf(b, "#include <linux/export-internal.h>\n");
2238 buf_printf(b, "#include <linux/vermagic.h>\n");
2239 buf_printf(b, "#include <linux/compiler.h>\n");
2240 buf_printf(b, "\n");
2241 buf_printf(b, "BUILD_SALT;\n");
2242 buf_printf(b, "BUILD_LTO_INFO;\n");
2243 buf_printf(b, "\n");
2244 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
2245 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
2246 buf_printf(b, "\n");
2247 buf_printf(b, "__visible struct module __this_module\n");
2248 buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n");
2249 buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
2251 buf_printf(b, "\t.init = init_module,\n");
2252 if (mod->has_cleanup)
2253 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"
2254 "\t.exit = cleanup_module,\n"
2256 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n");
2257 buf_printf(b, "};\n");
2259 if (!external_module)
2260 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
2264 "#ifdef CONFIG_RETPOLINE\n"
2265 "MODULE_INFO(retpoline, \"Y\");\n"
2268 if (strstarts(mod->name, "drivers/staging"))
2269 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
2272 static void add_exported_symbols(struct buffer *buf, struct module *mod)
2279 /* record CRCs for exported symbols */
2280 buf_printf(buf, "\n");
2281 list_for_each_entry(sym, &mod->exported_symbols, list) {
2282 if (!sym->crc_valid) {
2283 warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n"
2284 "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n",
2285 sym->name, mod->name, mod->is_vmlinux ? "" : ".ko",
2290 buf_printf(buf, "SYMBOL_CRC(%s, 0x%08x, \"%s\");\n",
2291 sym->name, sym->crc, sym->is_gpl_only ? "_gpl" : "");
2296 * Record CRCs for unresolved symbols
2298 static void add_versions(struct buffer *b, struct module *mod)
2305 buf_printf(b, "\n");
2306 buf_printf(b, "static const struct modversion_info ____versions[]\n");
2307 buf_printf(b, "__used __section(\"__versions\") = {\n");
2309 list_for_each_entry(s, &mod->unresolved_symbols, list) {
2312 if (!s->crc_valid) {
2313 warn("\"%s\" [%s.ko] has no CRC!\n",
2314 s->name, mod->name);
2317 if (strlen(s->name) >= MODULE_NAME_LEN) {
2318 error("too long symbol \"%s\" [%s.ko]\n",
2319 s->name, mod->name);
2322 buf_printf(b, "\t{ %#8x, \"%s\" },\n",
2326 buf_printf(b, "};\n");
2329 static void add_depends(struct buffer *b, struct module *mod)
2334 /* Clear ->seen flag of modules that own symbols needed by this. */
2335 list_for_each_entry(s, &mod->unresolved_symbols, list) {
2337 s->module->seen = s->module->is_vmlinux;
2340 buf_printf(b, "\n");
2341 buf_printf(b, "MODULE_INFO(depends, \"");
2342 list_for_each_entry(s, &mod->unresolved_symbols, list) {
2347 if (s->module->seen)
2350 s->module->seen = true;
2351 p = strrchr(s->module->name, '/');
2355 p = s->module->name;
2356 buf_printf(b, "%s%s", first ? "" : ",", p);
2359 buf_printf(b, "\");\n");
2362 static void add_srcversion(struct buffer *b, struct module *mod)
2364 if (mod->srcversion[0]) {
2365 buf_printf(b, "\n");
2366 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
2371 static void write_buf(struct buffer *b, const char *fname)
2378 file = fopen(fname, "w");
2383 if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2387 if (fclose(file) != 0) {
2393 static void write_if_changed(struct buffer *b, const char *fname)
2399 file = fopen(fname, "r");
2403 if (fstat(fileno(file), &st) < 0)
2406 if (st.st_size != b->pos)
2409 tmp = NOFAIL(malloc(b->pos));
2410 if (fread(tmp, 1, b->pos, file) != b->pos)
2413 if (memcmp(tmp, b->p, b->pos) != 0)
2425 write_buf(b, fname);
2428 static void write_vmlinux_export_c_file(struct module *mod)
2430 struct buffer buf = { };
2433 "#include <linux/export-internal.h>\n");
2435 add_exported_symbols(&buf, mod);
2436 write_if_changed(&buf, ".vmlinux.export.c");
2440 /* do sanity checks, and generate *.mod.c file */
2441 static void write_mod_c_file(struct module *mod)
2443 struct buffer buf = { };
2444 char fname[PATH_MAX];
2447 check_modname_len(mod);
2450 add_header(&buf, mod);
2451 add_exported_symbols(&buf, mod);
2452 add_versions(&buf, mod);
2453 add_depends(&buf, mod);
2454 add_moddevtable(&buf, mod);
2455 add_srcversion(&buf, mod);
2457 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
2458 if (ret >= sizeof(fname)) {
2459 error("%s: too long path was truncated\n", fname);
2463 write_if_changed(&buf, fname);
2469 /* parse Module.symvers file. line format:
2470 * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
2472 static void read_dump(const char *fname)
2474 char *buf, *pos, *line;
2476 buf = read_text_file(fname);
2478 /* No symbol versions, silently ignore */
2483 while ((line = get_line(&pos))) {
2484 char *symname, *namespace, *modname, *d, *export;
2490 if (!(symname = strchr(line, '\t')))
2493 if (!(modname = strchr(symname, '\t')))
2496 if (!(export = strchr(modname, '\t')))
2499 if (!(namespace = strchr(export, '\t')))
2501 *namespace++ = '\0';
2503 crc = strtoul(line, &d, 16);
2504 if (*symname == '\0' || *modname == '\0' || *d != '\0')
2507 if (!strcmp(export, "EXPORT_SYMBOL_GPL")) {
2509 } else if (!strcmp(export, "EXPORT_SYMBOL")) {
2512 error("%s: unknown license %s. skip", symname, export);
2516 mod = find_module(modname);
2518 mod = new_module(modname);
2519 mod->from_dump = true;
2521 s = sym_add_exported(symname, mod, gpl_only);
2522 s->is_static = false;
2523 sym_set_crc(s, crc);
2524 sym_update_namespace(symname, namespace);
2530 fatal("parse error in symbol dump file\n");
2533 static void write_dump(const char *fname)
2535 struct buffer buf = { };
2539 list_for_each_entry(mod, &modules, list) {
2542 list_for_each_entry(sym, &mod->exported_symbols, list) {
2543 buf_printf(&buf, "0x%08x\t%s\t%s\tEXPORT_SYMBOL%s\t%s\n",
2544 sym->crc, sym->name, mod->name,
2545 sym->is_gpl_only ? "_GPL" : "",
2546 sym->namespace ?: "");
2549 write_buf(&buf, fname);
2553 static void write_namespace_deps_files(const char *fname)
2556 struct namespace_list *ns;
2557 struct buffer ns_deps_buf = {};
2559 list_for_each_entry(mod, &modules, list) {
2561 if (mod->from_dump || list_empty(&mod->missing_namespaces))
2564 buf_printf(&ns_deps_buf, "%s.ko:", mod->name);
2566 list_for_each_entry(ns, &mod->missing_namespaces, list)
2567 buf_printf(&ns_deps_buf, " %s", ns->namespace);
2569 buf_printf(&ns_deps_buf, "\n");
2572 write_if_changed(&ns_deps_buf, fname);
2573 free(ns_deps_buf.p);
2577 struct list_head list;
2581 int main(int argc, char **argv)
2584 char *missing_namespace_deps = NULL;
2585 char *dump_write = NULL, *files_source = NULL;
2588 LIST_HEAD(dump_lists);
2589 struct dump_list *dl, *dl2;
2591 while ((opt = getopt(argc, argv, "ei:mnT:o:awENd:")) != -1) {
2594 external_module = true;
2597 dl = NOFAIL(malloc(sizeof(*dl)));
2599 list_add_tail(&dl->list, &dump_lists);
2605 ignore_missing_files = true;
2608 dump_write = optarg;
2611 all_versions = true;
2614 files_source = optarg;
2617 warn_unresolved = true;
2620 sec_mismatch_warn_only = false;
2623 allow_missing_ns_imports = true;
2626 missing_namespace_deps = optarg;
2633 list_for_each_entry_safe(dl, dl2, &dump_lists, list) {
2634 read_dump(dl->file);
2635 list_del(&dl->list);
2639 while (optind < argc)
2640 read_symbols(argv[optind++]);
2643 read_symbols_from_files(files_source);
2645 list_for_each_entry(mod, &modules, list) {
2649 if (mod->is_vmlinux)
2650 write_vmlinux_export_c_file(mod);
2652 write_mod_c_file(mod);
2655 if (missing_namespace_deps)
2656 write_namespace_deps_files(missing_namespace_deps);
2659 write_dump(dump_write);
2660 if (sec_mismatch_count && !sec_mismatch_warn_only)
2661 error("Section mismatches detected.\n"
2662 "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2663 for (n = 0; n < SYMBOL_HASH_SIZE; n++) {
2666 for (s = symbolhash[n]; s; s = s->next) {
2668 error("\"%s\" [%s] is a static EXPORT_SYMBOL\n",
2669 s->name, s->module->name);
2673 if (nr_unresolved > MAX_UNRESOLVED_REPORTS)
2674 warn("suppressed %u unresolved symbol warnings because there were too many)\n",
2675 nr_unresolved - MAX_UNRESOLVED_REPORTS);
2677 return error_occurred ? 1 : 0;