Lines Matching +full:mod +full:- +full:12 +full:b
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
39 /* Trim EXPORT_SYMBOLs that are unused by in-tree modules */
59 * here we use Elf_Addr instead of long for covering cross-compile
62 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
100 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; in strends()
142 nbytes -= bytes_read; in read_text_file()
174 struct module *mod; in find_module() local
176 list_for_each_entry(mod, &modules, list) { in find_module()
177 if (strcmp(mod->name, modname) == 0) in find_module()
178 return mod; in find_module()
185 struct module *mod; in new_module() local
187 mod = NOFAIL(malloc(sizeof(*mod) + namelen + 1)); in new_module()
188 memset(mod, 0, sizeof(*mod)); in new_module()
190 INIT_LIST_HEAD(&mod->exported_symbols); in new_module()
191 INIT_LIST_HEAD(&mod->unresolved_symbols); in new_module()
192 INIT_LIST_HEAD(&mod->missing_namespaces); in new_module()
193 INIT_LIST_HEAD(&mod->imported_namespaces); in new_module()
195 memcpy(mod->name, name, namelen); in new_module()
196 mod->name[namelen] = '\0'; in new_module()
197 mod->is_vmlinux = (strcmp(mod->name, "vmlinux") == 0); in new_module()
200 * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE() in new_module()
204 mod->is_gpl_compatible = true; in new_module()
206 list_add_tail(&mod->list, &modules); in new_module()
208 return mod; in new_module()
254 strcpy(s->name, name); in alloc_symbol()
264 hash = tdb_hash(sym->name) % SYMBOL_HASH_SIZE; in hash_add_symbol()
265 sym->next = symbolhash[hash]; in hash_add_symbol()
269 static void sym_add_unresolved(const char *name, struct module *mod, bool weak) in sym_add_unresolved() argument
274 sym->weak = weak; in sym_add_unresolved()
276 list_add_tail(&sym->list, &mod->unresolved_symbols); in sym_add_unresolved()
279 static struct symbol *sym_find_with_module(const char *name, struct module *mod) in sym_find_with_module() argument
287 for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) { in sym_find_with_module()
288 if (strcmp(s->name, name) == 0 && (!mod || s->module == mod)) in sym_find_with_module()
316 if (!strcmp(list->namespace, namespace)) in contains_namespace()
330 strcpy(ns_entry->namespace, namespace); in add_namespace()
331 list_add_tail(&ns_entry->list, head); in add_namespace()
338 Elf_Shdr *sechdr = &info->sechdrs[secindex]; in sym_get_data_by_offset()
340 return (void *)info->hdr + sechdr->sh_offset + offset; in sym_get_data_by_offset()
346 sym->st_value); in sym_get_data()
351 return sym_get_data_by_offset(info, info->secindex_strings, in sech_name()
352 sechdr->sh_name); in sech_name()
358 * If sym->st_shndx is a special section index, there is no in sec_name()
360 * Return "" if the index is out of range of info->sechdrs[] array. in sec_name()
362 if (secindex >= info->num_sections) in sec_name()
365 return sech_name(info, &info->sechdrs[secindex]); in sec_name()
370 static struct symbol *sym_add_exported(const char *name, struct module *mod, in sym_add_exported() argument
375 if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) { in sym_add_exported()
377 mod->name, name, s->module->name, in sym_add_exported()
378 s->module->is_vmlinux ? "" : ".ko"); in sym_add_exported()
382 s->module = mod; in sym_add_exported()
383 s->is_gpl_only = gpl_only; in sym_add_exported()
384 s->namespace = NOFAIL(strdup(namespace)); in sym_add_exported()
385 list_add_tail(&s->list, &mod->exported_symbols); in sym_add_exported()
393 sym->crc = crc; in sym_set_crc()
394 sym->crc_valid = true; in sym_set_crc()
433 hdr = grab_file(filename, &info->size); in parse_elf()
443 info->hdr = hdr; in parse_elf()
444 if (info->size < sizeof(*hdr)) { in parse_elf()
449 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) || in parse_elf()
450 (hdr->e_ident[EI_MAG1] != ELFMAG1) || in parse_elf()
451 (hdr->e_ident[EI_MAG2] != ELFMAG2) || in parse_elf()
452 (hdr->e_ident[EI_MAG3] != ELFMAG3)) { in parse_elf()
453 /* Not an ELF file - silently ignore it */ in parse_elf()
457 hdr->e_type = TO_NATIVE(hdr->e_type); in parse_elf()
458 hdr->e_machine = TO_NATIVE(hdr->e_machine); in parse_elf()
459 hdr->e_version = TO_NATIVE(hdr->e_version); in parse_elf()
460 hdr->e_entry = TO_NATIVE(hdr->e_entry); in parse_elf()
461 hdr->e_phoff = TO_NATIVE(hdr->e_phoff); in parse_elf()
462 hdr->e_shoff = TO_NATIVE(hdr->e_shoff); in parse_elf()
463 hdr->e_flags = TO_NATIVE(hdr->e_flags); in parse_elf()
464 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize); in parse_elf()
465 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize); in parse_elf()
466 hdr->e_phnum = TO_NATIVE(hdr->e_phnum); in parse_elf()
467 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize); in parse_elf()
468 hdr->e_shnum = TO_NATIVE(hdr->e_shnum); in parse_elf()
469 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); in parse_elf()
470 sechdrs = (void *)hdr + hdr->e_shoff; in parse_elf()
471 info->sechdrs = sechdrs; in parse_elf()
474 if (hdr->e_type != ET_REL) in parse_elf()
478 if (hdr->e_shoff > info->size) { in parse_elf()
480 (unsigned long)hdr->e_shoff, filename, info->size); in parse_elf()
484 if (hdr->e_shnum == SHN_UNDEF) { in parse_elf()
489 info->num_sections = TO_NATIVE(sechdrs[0].sh_size); in parse_elf()
492 info->num_sections = hdr->e_shnum; in parse_elf()
494 if (hdr->e_shstrndx == SHN_XINDEX) { in parse_elf()
495 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link); in parse_elf()
498 info->secindex_strings = hdr->e_shstrndx; in parse_elf()
502 for (i = 0; i < info->num_sections; i++) { in parse_elf()
515 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset; in parse_elf()
516 for (i = 1; i < info->num_sections; i++) { in parse_elf()
520 if (!nobits && sechdrs[i].sh_offset > info->size) { in parse_elf()
530 info->modinfo = (void *)hdr + sechdrs[i].sh_offset; in parse_elf()
531 info->modinfo_len = sechdrs[i].sh_size; in parse_elf()
533 info->export_symbol_secndx = i; in parse_elf()
539 info->symtab_start = (void *)hdr + in parse_elf()
541 info->symtab_stop = (void *)hdr + in parse_elf()
544 info->strtab = (void *)hdr + in parse_elf()
551 info->symtab_shndx_start = (void *)hdr + in parse_elf()
553 info->symtab_shndx_stop = (void *)hdr + in parse_elf()
557 if (!info->symtab_start) in parse_elf()
561 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { in parse_elf()
562 sym->st_shndx = TO_NATIVE(sym->st_shndx); in parse_elf()
563 sym->st_name = TO_NATIVE(sym->st_name); in parse_elf()
564 sym->st_value = TO_NATIVE(sym->st_value); in parse_elf()
565 sym->st_size = TO_NATIVE(sym->st_size); in parse_elf()
575 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; in parse_elf()
585 release_file(info->hdr, info->size); in parse_elf_finish()
596 if (info->hdr->e_machine == EM_PPC) in ignore_undef_symbol()
605 if (info->hdr->e_machine == EM_PPC64) in ignore_undef_symbol()
614 if (info->hdr->e_machine == EM_S390) in ignore_undef_symbol()
622 static void handle_symbol(struct module *mod, struct elf_info *info, in handle_symbol() argument
625 switch (sym->st_shndx) { in handle_symbol()
630 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); in handle_symbol()
634 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in handle_symbol()
635 ELF_ST_BIND(sym->st_info) != STB_WEAK) in handle_symbol()
639 if (info->hdr->e_machine == EM_SPARC || in handle_symbol()
640 info->hdr->e_machine == EM_SPARCV9) { in handle_symbol()
642 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) in handle_symbol()
652 sym_add_unresolved(symname, mod, in handle_symbol()
653 ELF_ST_BIND(sym->st_info) == STB_WEAK); in handle_symbol()
657 mod->has_init = true; in handle_symbol()
659 mod->has_cleanup = true; in handle_symbol()
669 /* Skip non-zero chars */ in next_string()
672 if ((*secsize)-- <= 1) in next_string()
679 if ((*secsize)-- <= 1) in next_string()
690 char *modinfo = info->modinfo; in get_next_modinfo()
691 unsigned long size = info->modinfo_len; in get_next_modinfo()
694 size -= prev - modinfo; in get_next_modinfo()
714 return elf->strtab + sym->st_name; in sym_name()
750 ".GCC.command.line", /* record-gcc-switches */
765 ".llvm.call-graph-profile", /* call graph */
779 if (sechdr->sh_type == SHT_PROGBITS && in check_section()
780 !(sechdr->sh_flags & SHF_ALLOC) && in check_section()
782 warn("%s (%s): unexpected non-allocatable section.\n" in check_section()
845 * this array is forbidden (black-list). Can be empty.
848 * targeting sections in this array (white-list). Can be empty.
903 /* If you're adding any new black-listed sections in here, consider
919 * handling relocations to un-resolved symbols, trying to match it in section_mismatch()
929 if (match(fromsec, check->fromsec)) { in section_mismatch()
930 if (check->bad_tosec[0] && match(tosec, check->bad_tosec)) in section_mismatch()
932 if (check->good_tosec[0] && !match(tosec, check->good_tosec)) in section_mismatch()
964 * these from non-init sections as these symbols don't have any memory
973 * in functions like cpumask_empty() -- generating an associated symbol
1056 const char *name = elf->strtab + sym->st_name; in is_valid_name()
1071 bool is_arm = (elf->hdr->e_machine == EM_ARM); in find_nearest_sym()
1073 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { in find_nearest_sym()
1079 sym_addr = sym->st_value; in find_nearest_sym()
1085 if (is_arm && ELF_ST_TYPE(sym->st_info) == STT_FUNC) in find_nearest_sym()
1089 distance = addr - sym_addr; in find_nearest_sym()
1091 distance = sym_addr - addr; in find_nearest_sym()
1127 if (secndx >= elf->num_sections) in is_executable_section()
1130 return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0; in is_executable_section()
1149 /* check whitelist - we may ignore it */ in default_mismatch_handler()
1155 warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n", in default_mismatch_handler()
1156 modname, fromsym, (unsigned int)(faddr - from->st_value), fromsec, tosym, tosec); in default_mismatch_handler()
1158 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { in default_mismatch_handler()
1159 if (match(tosec, mismatch->bad_tosec)) in default_mismatch_handler()
1161 "section \"%s\" which is black-listed.\n" in default_mismatch_handler()
1173 "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n", in default_mismatch_handler()
1176 error("%s+0x%lx references non-executable section '%s'\n", in default_mismatch_handler()
1181 static void check_export_symbol(struct module *mod, struct elf_info *elf, in check_export_symbol() argument
1191 label = find_fromsym(elf, faddr, elf->export_symbol_secndx); in check_export_symbol()
1196 mod->name, label_name); in check_export_symbol()
1200 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in check_export_symbol()
1201 ELF_ST_BIND(sym->st_info) != STB_WEAK) { in check_export_symbol()
1202 error("%s: local symbol '%s' was exported\n", mod->name, in check_export_symbol()
1210 mod->name, name); in check_export_symbol()
1221 mod->name, data, name); in check_export_symbol()
1226 s = sym_add_exported(name, mod, is_gpl, data); in check_export_symbol()
1232 s->is_func = (ELF_ST_TYPE(sym->st_info) == STT_FUNC); in check_export_symbol()
1238 if (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64 && in check_export_symbol()
1239 elf->hdr->e_machine == EM_PARISC && in check_export_symbol()
1240 ELF_ST_TYPE(sym->st_info) == STT_LOPROC) in check_export_symbol()
1241 s->is_func = true; in check_export_symbol()
1245 mod->name, name); in check_export_symbol()
1248 mod->name, name); in check_export_symbol()
1251 static void check_section_mismatch(struct module *mod, struct elf_info *elf, in check_section_mismatch() argument
1259 if (module_enabled && elf->export_symbol_secndx == fsecndx) { in check_section_mismatch()
1260 check_export_symbol(mod, elf, faddr, tosec, sym); in check_section_mismatch()
1268 default_mismatch_handler(mod->name, elf, mismatch, sym, in check_section_mismatch()
1282 return (Elf_Addr)(-1); in addend_386_rel()
1321 uint8_t shift = 31 - index; in sign_extend32()
1335 return inst + sym->st_value; in addend_arm_rel()
1341 return offset + sym->st_value; in addend_arm_rel()
1347 return offset + sym->st_value + 8; in addend_arm_rel()
1352 offset = sign_extend32(((upper & 0x000f) << 12) | in addend_arm_rel()
1357 return offset + sym->st_value; in addend_arm_rel()
1375 ((upper & 0x03f) << 12) | in addend_arm_rel()
1378 return offset + sym->st_value + 4; in addend_arm_rel()
1401 ((upper & 0x03ff) << 12) | in addend_arm_rel()
1404 return offset + sym->st_value + 4; in addend_arm_rel()
1407 return (Elf_Addr)(-1); in addend_arm_rel()
1423 return (Elf_Addr)(-1); in addend_mips_rel()
1453 bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64); in get_rel_type_and_sym()
1455 if (elf->hdr->e_machine == EM_MIPS && is_64bit) { in get_rel_type_and_sym()
1458 *r_type = mips64_r_info->r_type; in get_rel_type_and_sym()
1459 *r_sym = TO_NATIVE(mips64_r_info->r_sym); in get_rel_type_and_sym()
1477 static void section_rela(struct module *mod, struct elf_info *elf, in section_rela() argument
1481 unsigned int fsecndx = sechdr->sh_info; in section_rela()
1483 Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset; in section_rela()
1484 Elf_Rela *stop = (void *)start + sechdr->sh_size; in section_rela()
1495 r_offset = TO_NATIVE(rela->r_offset); in section_rela()
1496 get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); in section_rela()
1498 tsym = elf->symtab_start + r_sym; in section_rela()
1499 taddr = tsym->st_value + TO_NATIVE(rela->r_addend); in section_rela()
1501 switch (elf->hdr->e_machine) { in section_rela()
1514 check_section_mismatch(mod, elf, tsym, in section_rela()
1519 static void section_rel(struct module *mod, struct elf_info *elf, in section_rel() argument
1523 unsigned int fsecndx = sechdr->sh_info; in section_rel()
1525 Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset; in section_rel()
1526 Elf_Rel *stop = (void *)start + sechdr->sh_size; in section_rel()
1538 r_offset = TO_NATIVE(rel->r_offset); in section_rel()
1539 get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); in section_rel()
1542 tsym = elf->symtab_start + r_sym; in section_rel()
1544 switch (elf->hdr->e_machine) { in section_rel()
1558 check_section_mismatch(mod, elf, tsym, in section_rel()
1565 * either when loaded or when used as built-in.
1568 * Likewise for modules used built-in the sections marked __exit
1570 * only when a module is unloaded which never happens for built-in modules.
1575 static void check_sec_ref(struct module *mod, struct elf_info *elf) in check_sec_ref() argument
1578 Elf_Shdr *sechdrs = elf->sechdrs; in check_sec_ref()
1581 for (i = 0; i < elf->num_sections; i++) { in check_sec_ref()
1582 check_section(mod->name, elf, &elf->sechdrs[i]); in check_sec_ref()
1585 section_rela(mod, elf, &elf->sechdrs[i]); in check_sec_ref()
1587 section_rel(mod, elf, &elf->sechdrs[i]); in check_sec_ref()
1607 static void extract_crcs_for_object(const char *object, struct module *mod) in extract_crcs_for_object() argument
1617 dirlen = base - object; in extract_crcs_for_object()
1645 namelen = p - name; in extract_crcs_for_object()
1663 sym = sym_find_with_module(name, mod); in extract_crcs_for_object()
1675 static void mod_set_crcs(struct module *mod) in mod_set_crcs() argument
1681 if (mod->is_vmlinux) { in mod_set_crcs()
1684 /* objects for a module are listed in the *.mod file. */ in mod_set_crcs()
1685 ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name); in mod_set_crcs()
1696 extract_crcs_for_object(obj, mod); in mod_set_crcs()
1707 struct module *mod; in read_symbols() local
1720 mod = new_module(modname, strlen(modname) - strlen(".o")); in read_symbols()
1722 if (!mod->is_vmlinux) { in read_symbols()
1728 mod->is_gpl_compatible = false; in read_symbols()
1736 add_namespace(&mod->imported_namespaces, namespace); in read_symbols()
1745 symname = remove_dot(info.strtab + sym->st_name); in read_symbols()
1747 handle_symbol(mod, &info, sym, symname); in read_symbols()
1748 handle_moddevtable(mod, &info, sym, symname); in read_symbols()
1751 check_sec_ref(mod, &info); in read_symbols()
1753 if (!mod->is_vmlinux) { in read_symbols()
1756 get_src_version(mod->name, mod->srcversion, in read_symbols()
1757 sizeof(mod->srcversion) - 1); in read_symbols()
1764 * Our trick to get versioning for module struct etc. - it's in read_symbols()
1769 sym_add_unresolved("module_layout", mod, false); in read_symbols()
1771 mod_set_crcs(mod); in read_symbols()
1786 fname[strlen(fname)-1] = '\0'; in read_symbols_from_files()
1814 if (buf->size - buf->pos < len) { in buf_write()
1815 buf->size += len + SZ; in buf_write()
1816 buf->p = NOFAIL(realloc(buf->p, buf->size)); in buf_write()
1818 strncpy(buf->p + buf->pos, s, len); in buf_write()
1819 buf->pos += len; in buf_write()
1822 static void check_exports(struct module *mod) in check_exports() argument
1826 list_for_each_entry(s, &mod->unresolved_symbols, list) { in check_exports()
1828 exp = find_symbol(s->name); in check_exports()
1830 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS) in check_exports()
1833 s->name, mod->name); in check_exports()
1836 if (exp->module == mod) { in check_exports()
1838 s->name, mod->name); in check_exports()
1842 exp->used = true; in check_exports()
1843 s->module = exp->module; in check_exports()
1844 s->crc_valid = exp->crc_valid; in check_exports()
1845 s->crc = exp->crc; in check_exports()
1847 basename = strrchr(mod->name, '/'); in check_exports()
1851 basename = mod->name; in check_exports()
1853 if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) { in check_exports()
1856 basename, exp->name, exp->namespace); in check_exports()
1857 add_namespace(&mod->missing_namespaces, exp->namespace); in check_exports()
1860 if (!mod->is_gpl_compatible && exp->is_gpl_only) in check_exports()
1861 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n", in check_exports()
1862 basename, exp->name); in check_exports()
1877 sym->used = true; in handle_white_list_exports()
1883 static void check_modname_len(struct module *mod) in check_modname_len() argument
1887 mod_name = strrchr(mod->name, '/'); in check_modname_len()
1889 mod_name = mod->name; in check_modname_len()
1893 error("module name is too long [%s.ko]\n", mod->name); in check_modname_len()
1899 static void add_header(struct buffer *b, struct module *mod) in add_header() argument
1901 buf_printf(b, "#include <linux/module.h>\n"); in add_header()
1903 * Include build-salt.h after module.h in order to in add_header()
1906 buf_printf(b, "#define INCLUDE_VERMAGIC\n"); in add_header()
1907 buf_printf(b, "#include <linux/build-salt.h>\n"); in add_header()
1908 buf_printf(b, "#include <linux/elfnote-lto.h>\n"); in add_header()
1909 buf_printf(b, "#include <linux/export-internal.h>\n"); in add_header()
1910 buf_printf(b, "#include <linux/vermagic.h>\n"); in add_header()
1911 buf_printf(b, "#include <linux/compiler.h>\n"); in add_header()
1912 buf_printf(b, "\n"); in add_header()
1913 buf_printf(b, "#ifdef CONFIG_UNWINDER_ORC\n"); in add_header()
1914 buf_printf(b, "#include <asm/orc_header.h>\n"); in add_header()
1915 buf_printf(b, "ORC_HEADER;\n"); in add_header()
1916 buf_printf(b, "#endif\n"); in add_header()
1917 buf_printf(b, "\n"); in add_header()
1918 buf_printf(b, "BUILD_SALT;\n"); in add_header()
1919 buf_printf(b, "BUILD_LTO_INFO;\n"); in add_header()
1920 buf_printf(b, "\n"); in add_header()
1921 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); in add_header()
1922 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); in add_header()
1923 buf_printf(b, "\n"); in add_header()
1924 buf_printf(b, "__visible struct module __this_module\n"); in add_header()
1925 buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n"); in add_header()
1926 buf_printf(b, "\t.name = KBUILD_MODNAME,\n"); in add_header()
1927 if (mod->has_init) in add_header()
1928 buf_printf(b, "\t.init = init_module,\n"); in add_header()
1929 if (mod->has_cleanup) in add_header()
1930 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n" in add_header()
1933 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n"); in add_header()
1934 buf_printf(b, "};\n"); in add_header()
1937 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); in add_header()
1939 buf_printf(b, in add_header()
1945 if (strstarts(mod->name, "drivers/staging")) in add_header()
1946 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); in add_header()
1948 if (strstarts(mod->name, "tools/testing")) in add_header()
1949 buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n"); in add_header()
1952 static void add_exported_symbols(struct buffer *buf, struct module *mod) in add_exported_symbols() argument
1958 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1959 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1963 sym->is_func ? "FUNC" : "DATA", sym->name, in add_exported_symbols()
1964 sym->is_gpl_only ? "_gpl" : "", sym->namespace); in add_exported_symbols()
1972 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1973 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1976 if (!sym->crc_valid) in add_exported_symbols()
1978 "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n", in add_exported_symbols()
1979 sym->name, mod->name, mod->is_vmlinux ? "" : ".ko", in add_exported_symbols()
1980 sym->name); in add_exported_symbols()
1983 sym->name, sym->crc, sym->is_gpl_only ? "_gpl" : ""); in add_exported_symbols()
1990 static void add_versions(struct buffer *b, struct module *mod) in add_versions() argument
1997 buf_printf(b, "\n"); in add_versions()
1998 buf_printf(b, "static const struct modversion_info ____versions[]\n"); in add_versions()
1999 buf_printf(b, "__used __section(\"__versions\") = {\n"); in add_versions()
2001 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_versions()
2002 if (!s->module) in add_versions()
2004 if (!s->crc_valid) { in add_versions()
2006 s->name, mod->name); in add_versions()
2009 if (strlen(s->name) >= MODULE_NAME_LEN) { in add_versions()
2011 s->name, mod->name); in add_versions()
2014 buf_printf(b, "\t{ %#8x, \"%s\" },\n", in add_versions()
2015 s->crc, s->name); in add_versions()
2018 buf_printf(b, "};\n"); in add_versions()
2021 static void add_depends(struct buffer *b, struct module *mod) in add_depends() argument
2026 /* Clear ->seen flag of modules that own symbols needed by this. */ in add_depends()
2027 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
2028 if (s->module) in add_depends()
2029 s->module->seen = s->module->is_vmlinux; in add_depends()
2032 buf_printf(b, "\n"); in add_depends()
2033 buf_printf(b, "MODULE_INFO(depends, \""); in add_depends()
2034 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
2036 if (!s->module) in add_depends()
2039 if (s->module->seen) in add_depends()
2042 s->module->seen = true; in add_depends()
2043 p = strrchr(s->module->name, '/'); in add_depends()
2047 p = s->module->name; in add_depends()
2048 buf_printf(b, "%s%s", first ? "" : ",", p); in add_depends()
2051 buf_printf(b, "\");\n"); in add_depends()
2054 static void add_srcversion(struct buffer *b, struct module *mod) in add_srcversion() argument
2056 if (mod->srcversion[0]) { in add_srcversion()
2057 buf_printf(b, "\n"); in add_srcversion()
2058 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", in add_srcversion()
2059 mod->srcversion); in add_srcversion()
2063 static void write_buf(struct buffer *b, const char *fname) in write_buf() argument
2075 if (fwrite(b->p, 1, b->pos, file) != b->pos) { in write_buf()
2085 static void write_if_changed(struct buffer *b, const char *fname) in write_if_changed() argument
2098 if (st.st_size != b->pos) in write_if_changed()
2101 tmp = NOFAIL(malloc(b->pos)); in write_if_changed()
2102 if (fread(tmp, 1, b->pos, file) != b->pos) in write_if_changed()
2105 if (memcmp(tmp, b->p, b->pos) != 0) in write_if_changed()
2117 write_buf(b, fname); in write_if_changed()
2120 static void write_vmlinux_export_c_file(struct module *mod) in write_vmlinux_export_c_file() argument
2125 "#include <linux/export-internal.h>\n"); in write_vmlinux_export_c_file()
2127 add_exported_symbols(&buf, mod); in write_vmlinux_export_c_file()
2132 /* do sanity checks, and generate *.mod.c file */
2133 static void write_mod_c_file(struct module *mod) in write_mod_c_file() argument
2139 add_header(&buf, mod); in write_mod_c_file()
2140 add_exported_symbols(&buf, mod); in write_mod_c_file()
2141 add_versions(&buf, mod); in write_mod_c_file()
2142 add_depends(&buf, mod); in write_mod_c_file()
2143 add_moddevtable(&buf, mod); in write_mod_c_file()
2144 add_srcversion(&buf, mod); in write_mod_c_file()
2146 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name); in write_mod_c_file()
2175 struct module *mod; in read_dump() local
2205 mod = find_module(modname); in read_dump()
2206 if (!mod) { in read_dump()
2207 mod = new_module(modname, strlen(modname)); in read_dump()
2208 mod->from_dump = true; in read_dump()
2210 s = sym_add_exported(symname, mod, gpl_only, namespace); in read_dump()
2223 struct module *mod; in write_dump() local
2226 list_for_each_entry(mod, &modules, list) { in write_dump()
2227 if (mod->from_dump) in write_dump()
2229 list_for_each_entry(sym, &mod->exported_symbols, list) { in write_dump()
2230 if (trim_unused_exports && !sym->used) in write_dump()
2234 sym->crc, sym->name, mod->name, in write_dump()
2235 sym->is_gpl_only ? "_GPL" : "", in write_dump()
2236 sym->namespace); in write_dump()
2245 struct module *mod; in write_namespace_deps_files() local
2249 list_for_each_entry(mod, &modules, list) { in write_namespace_deps_files()
2251 if (mod->from_dump || list_empty(&mod->missing_namespaces)) in write_namespace_deps_files()
2254 buf_printf(&ns_deps_buf, "%s.ko:", mod->name); in write_namespace_deps_files()
2256 list_for_each_entry(ns, &mod->missing_namespaces, list) in write_namespace_deps_files()
2257 buf_printf(&ns_deps_buf, " %s", ns->namespace); in write_namespace_deps_files()
2273 struct module *mod; in main() local
2281 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:")) != -1) { in main()
2288 dl->file = optarg; in main()
2289 list_add_tail(&dl->list, &dump_lists); in main()
2336 read_dump(dl->file); in main()
2337 list_del(&dl->list); in main()
2347 list_for_each_entry(mod, &modules, list) { in main()
2348 if (mod->from_dump || mod->is_vmlinux) in main()
2351 check_modname_len(mod); in main()
2352 check_exports(mod); in main()
2358 list_for_each_entry(mod, &modules, list) { in main()
2359 if (mod->from_dump) in main()
2362 if (mod->is_vmlinux) in main()
2363 write_vmlinux_export_c_file(mod); in main()
2365 write_mod_c_file(mod); in main()
2379 nr_unresolved - MAX_UNRESOLVED_REPORTS); in main()