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
47 /* Trim EXPORT_SYMBOLs that are unused by in-tree modules */
70 * here we use Elf_Addr instead of long for covering cross-compile
73 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
98 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; in strends()
132 nbytes -= bytes_read; in read_text_file()
164 struct module *mod; in find_module() local
166 list_for_each_entry(mod, &modules, list) { in find_module()
167 if (!strcmp(mod->dump_file, filename) && in find_module()
168 !strcmp(mod->name, modname)) in find_module()
169 return mod; in find_module()
176 struct module *mod; in new_module() local
178 mod = xmalloc(sizeof(*mod) + namelen + 1); in new_module()
179 memset(mod, 0, sizeof(*mod)); in new_module()
181 INIT_LIST_HEAD(&mod->exported_symbols); in new_module()
182 INIT_LIST_HEAD(&mod->unresolved_symbols); in new_module()
183 INIT_LIST_HEAD(&mod->missing_namespaces); in new_module()
184 INIT_LIST_HEAD(&mod->imported_namespaces); in new_module()
185 INIT_LIST_HEAD(&mod->aliases); in new_module()
187 memcpy(mod->name, name, namelen); in new_module()
188 mod->name[namelen] = '\0'; in new_module()
189 mod->is_vmlinux = (strcmp(mod->name, "vmlinux") == 0); in new_module()
192 * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE() in new_module()
196 mod->is_gpl_compatible = true; in new_module()
198 list_add_tail(&mod->list, &modules); in new_module()
200 return mod; in new_module()
228 strcpy(s->name, name); in alloc_symbol()
236 hash_add(symbol_hashtable, &sym->hnode, hash_str(sym->name)); in hash_add_symbol()
239 static void sym_add_unresolved(const char *name, struct module *mod, bool weak) in sym_add_unresolved() argument
244 sym->weak = weak; in sym_add_unresolved()
246 list_add_tail(&sym->list, &mod->unresolved_symbols); in sym_add_unresolved()
249 static struct symbol *sym_find_with_module(const char *name, struct module *mod) in sym_find_with_module() argument
258 if (strcmp(s->name, name) == 0 && (!mod || s->module == mod)) in sym_find_with_module()
286 if (!strcmp(list->namespace, namespace)) in contains_namespace()
299 strcpy(ns_entry->namespace, namespace); in add_namespace()
300 list_add_tail(&ns_entry->list, head); in add_namespace()
307 Elf_Shdr *sechdr = &info->sechdrs[secindex]; in sym_get_data_by_offset()
309 return (void *)info->hdr + sechdr->sh_offset + offset; in sym_get_data_by_offset()
315 sym->st_value); in sym_get_data()
320 return sym_get_data_by_offset(info, info->secindex_strings, in sech_name()
321 sechdr->sh_name); in sech_name()
327 * If sym->st_shndx is a special section index, there is no in sec_name()
329 * Return "" if the index is out of range of info->sechdrs[] array. in sec_name()
331 if (secindex >= info->num_sections) in sec_name()
334 return sech_name(info, &info->sechdrs[secindex]); in sec_name()
337 static struct symbol *sym_add_exported(const char *name, struct module *mod, in sym_add_exported() argument
342 if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) { in sym_add_exported()
344 mod->name, name, s->module->name, in sym_add_exported()
345 s->module->is_vmlinux ? "" : ".ko"); in sym_add_exported()
349 s->module = mod; in sym_add_exported()
350 s->is_gpl_only = gpl_only; in sym_add_exported()
351 s->namespace = xstrdup(namespace); in sym_add_exported()
352 list_add_tail(&s->list, &mod->exported_symbols); in sym_add_exported()
360 sym->crc = crc; in sym_set_crc()
361 sym->crc_valid = true; in sym_set_crc()
400 hdr = grab_file(filename, &info->size); in parse_elf()
410 info->hdr = hdr; in parse_elf()
411 if (info->size < sizeof(*hdr)) { in parse_elf()
416 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) || in parse_elf()
417 (hdr->e_ident[EI_MAG1] != ELFMAG1) || in parse_elf()
418 (hdr->e_ident[EI_MAG2] != ELFMAG2) || in parse_elf()
419 (hdr->e_ident[EI_MAG3] != ELFMAG3)) { in parse_elf()
420 /* Not an ELF file - silently ignore it */ in parse_elf()
424 switch (hdr->e_ident[EI_DATA]) { in parse_elf()
436 hdr->e_type = TO_NATIVE(hdr->e_type); in parse_elf()
437 hdr->e_machine = TO_NATIVE(hdr->e_machine); in parse_elf()
438 hdr->e_version = TO_NATIVE(hdr->e_version); in parse_elf()
439 hdr->e_entry = TO_NATIVE(hdr->e_entry); in parse_elf()
440 hdr->e_phoff = TO_NATIVE(hdr->e_phoff); in parse_elf()
441 hdr->e_shoff = TO_NATIVE(hdr->e_shoff); in parse_elf()
442 hdr->e_flags = TO_NATIVE(hdr->e_flags); in parse_elf()
443 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize); in parse_elf()
444 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize); in parse_elf()
445 hdr->e_phnum = TO_NATIVE(hdr->e_phnum); in parse_elf()
446 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize); in parse_elf()
447 hdr->e_shnum = TO_NATIVE(hdr->e_shnum); in parse_elf()
448 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); in parse_elf()
449 sechdrs = (void *)hdr + hdr->e_shoff; in parse_elf()
450 info->sechdrs = sechdrs; in parse_elf()
453 if (hdr->e_type != ET_REL) in parse_elf()
457 if (hdr->e_shoff > info->size) in parse_elf()
459 (unsigned long)hdr->e_shoff, filename, info->size); in parse_elf()
461 if (hdr->e_shnum == SHN_UNDEF) { in parse_elf()
466 info->num_sections = TO_NATIVE(sechdrs[0].sh_size); in parse_elf()
469 info->num_sections = hdr->e_shnum; in parse_elf()
471 if (hdr->e_shstrndx == SHN_XINDEX) { in parse_elf()
472 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link); in parse_elf()
475 info->secindex_strings = hdr->e_shstrndx; in parse_elf()
479 for (i = 0; i < info->num_sections; i++) { in parse_elf()
492 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset; in parse_elf()
493 for (i = 1; i < info->num_sections; i++) { in parse_elf()
497 if (!nobits && sechdrs[i].sh_offset > info->size) in parse_elf()
506 info->modinfo = (void *)hdr + sechdrs[i].sh_offset; in parse_elf()
507 info->modinfo_len = sechdrs[i].sh_size; in parse_elf()
509 info->export_symbol_secndx = i; in parse_elf()
511 info->no_trim_symbol = (void *)hdr + sechdrs[i].sh_offset; in parse_elf()
512 info->no_trim_symbol_len = sechdrs[i].sh_size; in parse_elf()
518 info->symtab_start = (void *)hdr + in parse_elf()
520 info->symtab_stop = (void *)hdr + in parse_elf()
523 info->strtab = (void *)hdr + in parse_elf()
530 info->symtab_shndx_start = (void *)hdr + in parse_elf()
532 info->symtab_shndx_stop = (void *)hdr + in parse_elf()
536 if (!info->symtab_start) in parse_elf()
540 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { in parse_elf()
541 sym->st_shndx = TO_NATIVE(sym->st_shndx); in parse_elf()
542 sym->st_name = TO_NATIVE(sym->st_name); in parse_elf()
543 sym->st_value = TO_NATIVE(sym->st_value); in parse_elf()
544 sym->st_size = TO_NATIVE(sym->st_size); in parse_elf()
554 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; in parse_elf()
567 release_file(info->hdr, info->size); in parse_elf_finish()
578 if (info->hdr->e_machine == EM_PPC) in ignore_undef_symbol()
587 if (info->hdr->e_machine == EM_PPC64) in ignore_undef_symbol()
599 static void handle_symbol(struct module *mod, struct elf_info *info, in handle_symbol() argument
602 switch (sym->st_shndx) { in handle_symbol()
607 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); in handle_symbol()
611 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in handle_symbol()
612 ELF_ST_BIND(sym->st_info) != STB_WEAK) in handle_symbol()
616 if (info->hdr->e_machine == EM_SPARC || in handle_symbol()
617 info->hdr->e_machine == EM_SPARCV9) { in handle_symbol()
619 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) in handle_symbol()
629 sym_add_unresolved(symname, mod, in handle_symbol()
630 ELF_ST_BIND(sym->st_info) == STB_WEAK); in handle_symbol()
634 mod->has_init = true; in handle_symbol()
636 mod->has_cleanup = true; in handle_symbol()
646 /* Skip non-zero chars */ in next_string()
649 if ((*secsize)-- <= 1) in next_string()
656 if ((*secsize)-- <= 1) in next_string()
667 char *modinfo = info->modinfo; in get_next_modinfo()
668 unsigned long size = info->modinfo_len; in get_next_modinfo()
671 size -= prev - modinfo; in get_next_modinfo()
690 return sym ? elf->strtab + sym->st_name : ""; in sym_name()
724 ".GCC.command.line", /* record-gcc-switches */
739 ".llvm.call-graph-profile", /* call graph */
753 if (sechdr->sh_type == SHT_PROGBITS && in check_section()
754 !(sechdr->sh_flags & SHF_ALLOC) && in check_section()
756 warn("%s (%s): unexpected non-allocatable section.\n" in check_section()
802 * this array is forbidden (black-list). Can be empty.
805 * targeting sections in this array (white-list). Can be empty.
844 /* If you're adding any new black-listed sections in here, consider
860 * handling relocations to un-resolved symbols, trying to match it in section_mismatch()
870 if (match(fromsec, check->fromsec)) { in section_mismatch()
871 if (check->bad_tosec[0] && match(tosec, check->bad_tosec)) in section_mismatch()
873 if (check->good_tosec[0] && !match(tosec, check->good_tosec)) in section_mismatch()
905 * these from non-init sections as these symbols don't have any memory
914 * in functions like cpumask_empty() -- generating an associated symbol
988 if (secndx >= elf->num_sections) in is_executable_section()
991 return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0; in is_executable_section()
1011 /* check whitelist - we may ignore it */ in default_mismatch_handler()
1024 warn("%s: section mismatch in reference: %s%s0x%x (section: %s) -> %s (section: %s)\n", in default_mismatch_handler()
1026 (unsigned int)(faddr - (fromsym[0] ? from->st_value : 0)), in default_mismatch_handler()
1029 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { in default_mismatch_handler()
1030 if (match(tosec, mismatch->bad_tosec)) in default_mismatch_handler()
1032 "section \"%s\" which is black-listed.\n" in default_mismatch_handler()
1044 "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n", in default_mismatch_handler()
1047 error("%s+0x%lx references non-executable section '%s'\n", in default_mismatch_handler()
1052 static void check_export_symbol(struct module *mod, struct elf_info *elf, in check_export_symbol() argument
1062 label = find_fromsym(elf, faddr, elf->export_symbol_secndx); in check_export_symbol()
1067 mod->name, label_name); in check_export_symbol()
1071 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in check_export_symbol()
1072 ELF_ST_BIND(sym->st_info) != STB_WEAK) { in check_export_symbol()
1073 error("%s: local symbol '%s' was exported\n", mod->name, in check_export_symbol()
1081 mod->name, name); in check_export_symbol()
1092 mod->name, data, name); in check_export_symbol()
1097 s = sym_add_exported(name, mod, is_gpl, data); in check_export_symbol()
1103 s->is_func = (ELF_ST_TYPE(sym->st_info) == STT_FUNC); in check_export_symbol()
1109 if (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64 && in check_export_symbol()
1110 elf->hdr->e_machine == EM_PARISC && in check_export_symbol()
1111 ELF_ST_TYPE(sym->st_info) == STT_LOPROC) in check_export_symbol()
1112 s->is_func = true; in check_export_symbol()
1116 mod->name, name); in check_export_symbol()
1119 mod->name, name); in check_export_symbol()
1122 static void check_section_mismatch(struct module *mod, struct elf_info *elf, in check_section_mismatch() argument
1130 if (module_enabled && elf->export_symbol_secndx == fsecndx) { in check_section_mismatch()
1131 check_export_symbol(mod, elf, faddr, tosec, sym); in check_section_mismatch()
1139 default_mismatch_handler(mod->name, elf, mismatch, sym, in check_section_mismatch()
1153 return (Elf_Addr)(-1); in addend_386_rel()
1158 uint8_t shift = 31 - index; in sign_extend32()
1172 return inst + sym->st_value; in addend_arm_rel()
1178 return offset + sym->st_value; in addend_arm_rel()
1184 return offset + sym->st_value + 8; in addend_arm_rel()
1189 offset = sign_extend32(((upper & 0x000f) << 12) | in addend_arm_rel()
1194 return offset + sym->st_value; in addend_arm_rel()
1212 ((upper & 0x03f) << 12) | in addend_arm_rel()
1215 return offset + sym->st_value + 4; in addend_arm_rel()
1238 ((upper & 0x03ff) << 12) | in addend_arm_rel()
1241 return offset + sym->st_value + 4; in addend_arm_rel()
1244 return (Elf_Addr)(-1); in addend_arm_rel()
1260 return (Elf_Addr)(-1); in addend_mips_rel()
1298 bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64); in get_rel_type_and_sym()
1300 if (elf->hdr->e_machine == EM_MIPS && is_64bit) { in get_rel_type_and_sym()
1303 *r_type = mips64_r_info->r_type; in get_rel_type_and_sym()
1304 *r_sym = TO_NATIVE(mips64_r_info->r_sym); in get_rel_type_and_sym()
1317 static void section_rela(struct module *mod, struct elf_info *elf, in section_rela() argument
1328 r_offset = TO_NATIVE(rela->r_offset); in section_rela()
1329 get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); in section_rela()
1331 tsym = elf->symtab_start + r_sym; in section_rela()
1332 taddr = tsym->st_value + TO_NATIVE(rela->r_addend); in section_rela()
1334 switch (elf->hdr->e_machine) { in section_rela()
1354 check_section_mismatch(mod, elf, tsym, in section_rela()
1359 static void section_rel(struct module *mod, struct elf_info *elf, in section_rel() argument
1371 r_offset = TO_NATIVE(rel->r_offset); in section_rel()
1372 get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); in section_rel()
1375 tsym = elf->symtab_start + r_sym; in section_rel()
1377 switch (elf->hdr->e_machine) { in section_rel()
1391 check_section_mismatch(mod, elf, tsym, in section_rel()
1398 * either when loaded or when used as built-in.
1401 * Likewise for modules used built-in the sections marked __exit
1403 * only when a module is unloaded which never happens for built-in modules.
1408 static void check_sec_ref(struct module *mod, struct elf_info *elf) in check_sec_ref() argument
1413 for (i = 0; i < elf->num_sections; i++) { in check_sec_ref()
1414 Elf_Shdr *sechdr = &elf->sechdrs[i]; in check_sec_ref()
1416 check_section(mod->name, elf, sechdr); in check_sec_ref()
1418 if (sechdr->sh_type == SHT_REL || sechdr->sh_type == SHT_RELA) { in check_sec_ref()
1420 unsigned int secndx = sechdr->sh_info; in check_sec_ref()
1429 stop = start + sechdr->sh_size; in check_sec_ref()
1431 if (sechdr->sh_type == SHT_RELA) in check_sec_ref()
1432 section_rela(mod, elf, secndx, secname, in check_sec_ref()
1435 section_rel(mod, elf, secndx, secname, in check_sec_ref()
1457 static void extract_crcs_for_object(const char *object, struct module *mod) in extract_crcs_for_object() argument
1467 dirlen = base - object; in extract_crcs_for_object()
1495 namelen = p - name; in extract_crcs_for_object()
1513 sym = sym_find_with_module(name, mod); in extract_crcs_for_object()
1525 static void mod_set_crcs(struct module *mod) in mod_set_crcs() argument
1531 if (mod->is_vmlinux) { in mod_set_crcs()
1534 /* objects for a module are listed in the *.mod file. */ in mod_set_crcs()
1535 ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name); in mod_set_crcs()
1546 extract_crcs_for_object(obj, mod); in mod_set_crcs()
1557 struct module *mod; in read_symbols() local
1570 mod = new_module(modname, strlen(modname) - strlen(".o")); in read_symbols()
1574 mod->no_trim_symbol = xmalloc(info.no_trim_symbol_len); in read_symbols()
1575 memcpy(mod->no_trim_symbol, info.no_trim_symbol, in read_symbols()
1577 mod->no_trim_symbol_len = info.no_trim_symbol_len; in read_symbols()
1580 if (!mod->is_vmlinux) { in read_symbols()
1586 mod->is_gpl_compatible = false; in read_symbols()
1594 add_namespace(&mod->imported_namespaces, namespace); in read_symbols()
1604 symname = remove_dot(info.strtab + sym->st_name); in read_symbols()
1606 handle_symbol(mod, &info, sym, symname); in read_symbols()
1607 handle_moddevtable(mod, &info, sym, symname); in read_symbols()
1610 check_sec_ref(mod, &info); in read_symbols()
1612 if (!mod->is_vmlinux) { in read_symbols()
1615 get_src_version(mod->name, mod->srcversion, in read_symbols()
1616 sizeof(mod->srcversion) - 1); in read_symbols()
1623 * Our trick to get versioning for module struct etc. - it's in read_symbols()
1628 sym_add_unresolved("module_layout", mod, false); in read_symbols()
1630 mod_set_crcs(mod); in read_symbols()
1645 fname[strlen(fname)-1] = '\0'; in read_symbols_from_files()
1673 if (buf->size - buf->pos < len) { in buf_write()
1674 buf->size += len + SZ; in buf_write()
1675 buf->p = xrealloc(buf->p, buf->size); in buf_write()
1677 strncpy(buf->p + buf->pos, s, len); in buf_write()
1678 buf->pos += len; in buf_write()
1681 static void check_exports(struct module *mod) in check_exports() argument
1685 list_for_each_entry(s, &mod->unresolved_symbols, list) { in check_exports()
1687 exp = find_symbol(s->name); in check_exports()
1689 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS) in check_exports()
1692 s->name, mod->name); in check_exports()
1695 if (exp->module == mod) { in check_exports()
1697 s->name, mod->name); in check_exports()
1701 exp->used = true; in check_exports()
1702 s->module = exp->module; in check_exports()
1703 s->crc_valid = exp->crc_valid; in check_exports()
1704 s->crc = exp->crc; in check_exports()
1706 basename = strrchr(mod->name, '/'); in check_exports()
1710 basename = mod->name; in check_exports()
1712 if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) { in check_exports()
1715 basename, exp->name, exp->namespace); in check_exports()
1716 add_namespace(&mod->missing_namespaces, exp->namespace); in check_exports()
1719 if (!mod->is_gpl_compatible && exp->is_gpl_only) in check_exports()
1720 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n", in check_exports()
1721 basename, exp->name); in check_exports()
1736 sym->used = true; in handle_white_list_exports()
1747 static void keep_no_trim_symbols(struct module *mod) in keep_no_trim_symbols() argument
1749 unsigned long size = mod->no_trim_symbol_len; in keep_no_trim_symbols()
1751 for (char *s = mod->no_trim_symbol; s; s = next_string(s , &size)) { in keep_no_trim_symbols()
1760 sym->used = true; in keep_no_trim_symbols()
1764 static void check_modname_len(struct module *mod) in check_modname_len() argument
1768 mod_name = strrchr(mod->name, '/'); in check_modname_len()
1770 mod_name = mod->name; in check_modname_len()
1774 error("module name is too long [%s.ko]\n", mod->name); in check_modname_len()
1780 static void add_header(struct buffer *b, struct module *mod) in add_header() argument
1782 buf_printf(b, "#include <linux/module.h>\n"); in add_header()
1783 buf_printf(b, "#include <linux/export-internal.h>\n"); in add_header()
1784 buf_printf(b, "#include <linux/compiler.h>\n"); in add_header()
1785 buf_printf(b, "\n"); in add_header()
1786 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); in add_header()
1787 buf_printf(b, "\n"); in add_header()
1788 buf_printf(b, "__visible struct module __this_module\n"); in add_header()
1789 buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n"); in add_header()
1790 buf_printf(b, "\t.name = KBUILD_MODNAME,\n"); in add_header()
1791 if (mod->has_init) in add_header()
1792 buf_printf(b, "\t.init = init_module,\n"); in add_header()
1793 if (mod->has_cleanup) in add_header()
1794 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n" in add_header()
1797 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n"); in add_header()
1798 buf_printf(b, "};\n"); in add_header()
1801 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); in add_header()
1803 if (strstarts(mod->name, "drivers/staging")) in add_header()
1804 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); in add_header()
1806 if (strstarts(mod->name, "tools/testing")) in add_header()
1807 buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n"); in add_header()
1810 static void add_exported_symbols(struct buffer *buf, struct module *mod) in add_exported_symbols() argument
1816 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1817 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1821 sym->is_func ? "FUNC" : "DATA", sym->name, in add_exported_symbols()
1822 sym->is_gpl_only ? "_gpl" : "", sym->namespace); in add_exported_symbols()
1830 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1831 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1834 if (!sym->crc_valid) in add_exported_symbols()
1836 "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n", in add_exported_symbols()
1837 sym->name, mod->name, mod->is_vmlinux ? "" : ".ko", in add_exported_symbols()
1838 sym->name); in add_exported_symbols()
1841 sym->name, sym->crc, sym->is_gpl_only ? "_gpl" : ""); in add_exported_symbols()
1848 static void add_extended_versions(struct buffer *b, struct module *mod) in add_extended_versions() argument
1855 buf_printf(b, "\n"); in add_extended_versions()
1856 buf_printf(b, "static const u32 ____version_ext_crcs[]\n"); in add_extended_versions()
1857 buf_printf(b, "__used __section(\"__version_ext_crcs\") = {\n"); in add_extended_versions()
1858 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_extended_versions()
1859 if (!s->module) in add_extended_versions()
1861 if (!s->crc_valid) { in add_extended_versions()
1863 s->name, mod->name); in add_extended_versions()
1866 buf_printf(b, "\t0x%08x,\n", s->crc); in add_extended_versions()
1868 buf_printf(b, "};\n"); in add_extended_versions()
1870 buf_printf(b, "static const char ____version_ext_names[]\n"); in add_extended_versions()
1871 buf_printf(b, "__used __section(\"__version_ext_names\") =\n"); in add_extended_versions()
1872 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_extended_versions()
1873 if (!s->module) in add_extended_versions()
1875 if (!s->crc_valid) in add_extended_versions()
1883 buf_printf(b, "\t\"%s\\0\"\n", s->name); in add_extended_versions()
1885 buf_printf(b, ";\n"); in add_extended_versions()
1891 static void add_versions(struct buffer *b, struct module *mod) in add_versions() argument
1898 buf_printf(b, "\n"); in add_versions()
1899 buf_printf(b, "static const struct modversion_info ____versions[]\n"); in add_versions()
1900 buf_printf(b, "__used __section(\"__versions\") = {\n"); in add_versions()
1902 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_versions()
1903 if (!s->module) in add_versions()
1905 if (!s->crc_valid) { in add_versions()
1907 s->name, mod->name); in add_versions()
1910 if (strlen(s->name) >= MODULE_NAME_LEN) { in add_versions()
1916 s->name, mod->name); in add_versions()
1920 buf_printf(b, "\t{ 0x%08x, \"%s\" },\n", in add_versions()
1921 s->crc, s->name); in add_versions()
1924 buf_printf(b, "};\n"); in add_versions()
1927 static void add_depends(struct buffer *b, struct module *mod) in add_depends() argument
1932 /* Clear ->seen flag of modules that own symbols needed by this. */ in add_depends()
1933 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
1934 if (s->module) in add_depends()
1935 s->module->seen = s->module->is_vmlinux; in add_depends()
1938 buf_printf(b, "\n"); in add_depends()
1939 buf_printf(b, "MODULE_INFO(depends, \""); in add_depends()
1940 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
1942 if (!s->module) in add_depends()
1945 if (s->module->seen) in add_depends()
1948 s->module->seen = true; in add_depends()
1949 p = strrchr(s->module->name, '/'); in add_depends()
1953 p = s->module->name; in add_depends()
1954 buf_printf(b, "%s%s", first ? "" : ",", p); in add_depends()
1957 buf_printf(b, "\");\n"); in add_depends()
1960 static void add_srcversion(struct buffer *b, struct module *mod) in add_srcversion() argument
1962 if (mod->srcversion[0]) { in add_srcversion()
1963 buf_printf(b, "\n"); in add_srcversion()
1964 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", in add_srcversion()
1965 mod->srcversion); in add_srcversion()
1969 static void write_buf(struct buffer *b, const char *fname) in write_buf() argument
1981 if (fwrite(b->p, 1, b->pos, file) != b->pos) { in write_buf()
1991 static void write_if_changed(struct buffer *b, const char *fname) in write_if_changed() argument
2004 if (st.st_size != b->pos) in write_if_changed()
2007 tmp = xmalloc(b->pos); in write_if_changed()
2008 if (fread(tmp, 1, b->pos, file) != b->pos) in write_if_changed()
2011 if (memcmp(tmp, b->p, b->pos) != 0) in write_if_changed()
2023 write_buf(b, fname); in write_if_changed()
2026 static void write_vmlinux_export_c_file(struct module *mod) in write_vmlinux_export_c_file() argument
2031 "#include <linux/export-internal.h>\n"); in write_vmlinux_export_c_file()
2033 add_exported_symbols(&buf, mod); in write_vmlinux_export_c_file()
2038 /* do sanity checks, and generate *.mod.c file */
2039 static void write_mod_c_file(struct module *mod) in write_mod_c_file() argument
2046 add_header(&buf, mod); in write_mod_c_file()
2047 add_exported_symbols(&buf, mod); in write_mod_c_file()
2048 add_versions(&buf, mod); in write_mod_c_file()
2049 add_extended_versions(&buf, mod); in write_mod_c_file()
2050 add_depends(&buf, mod); in write_mod_c_file()
2053 list_for_each_entry_safe(alias, next, &mod->aliases, node) { in write_mod_c_file()
2054 buf_printf(&buf, "MODULE_ALIAS(\"%s\");\n", alias->str); in write_mod_c_file()
2055 list_del(&alias->node); in write_mod_c_file()
2059 add_srcversion(&buf, mod); in write_mod_c_file()
2061 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name); in write_mod_c_file()
2090 struct module *mod; in read_dump() local
2120 mod = find_module(fname, modname); in read_dump()
2121 if (!mod) { in read_dump()
2122 mod = new_module(modname, strlen(modname)); in read_dump()
2123 mod->dump_file = fname; in read_dump()
2125 s = sym_add_exported(symname, mod, gpl_only, namespace); in read_dump()
2138 struct module *mod; in write_dump() local
2141 list_for_each_entry(mod, &modules, list) { in write_dump()
2142 if (mod->dump_file) in write_dump()
2144 list_for_each_entry(sym, &mod->exported_symbols, list) { in write_dump()
2145 if (trim_unused_exports && !sym->used) in write_dump()
2149 sym->crc, sym->name, mod->name, in write_dump()
2150 sym->is_gpl_only ? "_GPL" : "", in write_dump()
2151 sym->namespace); in write_dump()
2160 struct module *mod; in write_namespace_deps_files() local
2164 list_for_each_entry(mod, &modules, list) { in write_namespace_deps_files()
2166 if (mod->dump_file || list_empty(&mod->missing_namespaces)) in write_namespace_deps_files()
2169 buf_printf(&ns_deps_buf, "%s.ko:", mod->name); in write_namespace_deps_files()
2171 list_for_each_entry(ns, &mod->missing_namespaces, list) in write_namespace_deps_files()
2172 buf_printf(&ns_deps_buf, " %s", ns->namespace); in write_namespace_deps_files()
2207 struct module *mod; in main() local
2215 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:xb")) != -1) { in main()
2222 dl->file = optarg; in main()
2223 list_add_tail(&dl->list, &dump_lists); in main()
2264 case 'b': in main()
2278 read_dump(dl->file); in main()
2279 list_del(&dl->list); in main()
2289 list_for_each_entry(mod, &modules, list) { in main()
2290 keep_no_trim_symbols(mod); in main()
2292 if (mod->dump_file || mod->is_vmlinux) in main()
2295 check_modname_len(mod); in main()
2296 check_exports(mod); in main()
2302 list_for_each_entry(mod, &modules, list) { in main()
2303 if (mod->dump_file) in main()
2306 if (mod->is_vmlinux) in main()
2307 write_vmlinux_export_c_file(mod); in main()
2309 write_mod_c_file(mod); in main()
2323 nr_unresolved - MAX_UNRESOLVED_REPORTS); in main()