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
49 /* Trim EXPORT_SYMBOLs that are unused by in-tree modules */
72 * here we use Elf_Addr instead of long for covering cross-compile
75 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
100 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; in strends()
104 * get_basename - return the last part of a pathname.
146 nbytes -= bytes_read; in read_text_file()
178 struct module *mod; in find_module() local
180 list_for_each_entry(mod, &modules, list) { in find_module()
181 if (!strcmp(mod->dump_file, filename) && in find_module()
182 !strcmp(mod->name, modname)) in find_module()
183 return mod; in find_module()
190 struct module *mod; in new_module() local
192 mod = xmalloc(sizeof(*mod) + namelen + 1); in new_module()
193 memset(mod, 0, sizeof(*mod)); in new_module()
195 INIT_LIST_HEAD(&mod->exported_symbols); in new_module()
196 INIT_LIST_HEAD(&mod->unresolved_symbols); in new_module()
197 INIT_LIST_HEAD(&mod->missing_namespaces); in new_module()
198 INIT_LIST_HEAD(&mod->imported_namespaces); in new_module()
199 INIT_LIST_HEAD(&mod->aliases); in new_module()
201 memcpy(mod->name, name, namelen); in new_module()
202 mod->name[namelen] = '\0'; in new_module()
203 mod->is_vmlinux = (strcmp(mod->name, "vmlinux") == 0); in new_module()
206 * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE() in new_module()
210 mod->is_gpl_compatible = true; in new_module()
212 list_add_tail(&mod->list, &modules); in new_module()
214 return mod; in new_module()
242 strcpy(s->name, name); in alloc_symbol()
250 hash_add(symbol_hashtable, &sym->hnode, hash_str(sym->name)); in hash_add_symbol()
253 static void sym_add_unresolved(const char *name, struct module *mod, bool weak) in sym_add_unresolved() argument
258 sym->weak = weak; in sym_add_unresolved()
260 list_add_tail(&sym->list, &mod->unresolved_symbols); in sym_add_unresolved()
263 static struct symbol *sym_find_with_module(const char *name, struct module *mod) in sym_find_with_module() argument
272 if (strcmp(s->name, name) == 0 && (!mod || s->module == mod)) in sym_find_with_module()
300 if (!strcmp(list->namespace, namespace)) in contains_namespace()
313 strcpy(ns_entry->namespace, namespace); in add_namespace()
314 list_add_tail(&ns_entry->list, head); in add_namespace()
321 Elf_Shdr *sechdr = &info->sechdrs[secindex]; in sym_get_data_by_offset()
323 return (void *)info->hdr + sechdr->sh_offset + offset; in sym_get_data_by_offset()
329 sym->st_value); in sym_get_data()
334 return sym_get_data_by_offset(info, info->secindex_strings, in sech_name()
335 sechdr->sh_name); in sech_name()
341 * If sym->st_shndx is a special section index, there is no in sec_name()
343 * Return "" if the index is out of range of info->sechdrs[] array. in sec_name()
345 if (secindex >= info->num_sections) in sec_name()
348 return sech_name(info, &info->sechdrs[secindex]); in sec_name()
351 static struct symbol *sym_add_exported(const char *name, struct module *mod, in sym_add_exported() argument
356 if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) { in sym_add_exported()
358 mod->name, name, s->module->name, in sym_add_exported()
359 s->module->is_vmlinux ? "" : ".ko"); in sym_add_exported()
363 s->module = mod; in sym_add_exported()
364 s->is_gpl_only = gpl_only; in sym_add_exported()
365 s->namespace = xstrdup(namespace); in sym_add_exported()
366 list_add_tail(&s->list, &mod->exported_symbols); in sym_add_exported()
374 sym->crc = crc; in sym_set_crc()
375 sym->crc_valid = true; in sym_set_crc()
414 hdr = grab_file(filename, &info->size); in parse_elf()
424 info->hdr = hdr; in parse_elf()
425 if (info->size < sizeof(*hdr)) { in parse_elf()
430 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) || in parse_elf()
431 (hdr->e_ident[EI_MAG1] != ELFMAG1) || in parse_elf()
432 (hdr->e_ident[EI_MAG2] != ELFMAG2) || in parse_elf()
433 (hdr->e_ident[EI_MAG3] != ELFMAG3)) { in parse_elf()
434 /* Not an ELF file - silently ignore it */ in parse_elf()
438 switch (hdr->e_ident[EI_DATA]) { in parse_elf()
450 hdr->e_type = TO_NATIVE(hdr->e_type); in parse_elf()
451 hdr->e_machine = TO_NATIVE(hdr->e_machine); in parse_elf()
452 hdr->e_version = TO_NATIVE(hdr->e_version); in parse_elf()
453 hdr->e_entry = TO_NATIVE(hdr->e_entry); in parse_elf()
454 hdr->e_phoff = TO_NATIVE(hdr->e_phoff); in parse_elf()
455 hdr->e_shoff = TO_NATIVE(hdr->e_shoff); in parse_elf()
456 hdr->e_flags = TO_NATIVE(hdr->e_flags); in parse_elf()
457 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize); in parse_elf()
458 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize); in parse_elf()
459 hdr->e_phnum = TO_NATIVE(hdr->e_phnum); in parse_elf()
460 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize); in parse_elf()
461 hdr->e_shnum = TO_NATIVE(hdr->e_shnum); in parse_elf()
462 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); in parse_elf()
463 sechdrs = (void *)hdr + hdr->e_shoff; in parse_elf()
464 info->sechdrs = sechdrs; in parse_elf()
467 if (hdr->e_type != ET_REL) in parse_elf()
471 if (hdr->e_shoff > info->size) in parse_elf()
473 (unsigned long)hdr->e_shoff, filename, info->size); in parse_elf()
475 if (hdr->e_shnum == SHN_UNDEF) { in parse_elf()
480 info->num_sections = TO_NATIVE(sechdrs[0].sh_size); in parse_elf()
483 info->num_sections = hdr->e_shnum; in parse_elf()
485 if (hdr->e_shstrndx == SHN_XINDEX) { in parse_elf()
486 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link); in parse_elf()
489 info->secindex_strings = hdr->e_shstrndx; in parse_elf()
493 for (i = 0; i < info->num_sections; i++) { in parse_elf()
506 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset; in parse_elf()
507 for (i = 1; i < info->num_sections; i++) { in parse_elf()
511 if (!nobits && sechdrs[i].sh_offset > info->size) in parse_elf()
520 info->modinfo = (void *)hdr + sechdrs[i].sh_offset; in parse_elf()
521 info->modinfo_len = sechdrs[i].sh_size; in parse_elf()
523 info->export_symbol_secndx = i; in parse_elf()
525 info->no_trim_symbol = (void *)hdr + sechdrs[i].sh_offset; in parse_elf()
526 info->no_trim_symbol_len = sechdrs[i].sh_size; in parse_elf()
532 info->symtab_start = (void *)hdr + in parse_elf()
534 info->symtab_stop = (void *)hdr + in parse_elf()
537 info->strtab = (void *)hdr + in parse_elf()
544 info->symtab_shndx_start = (void *)hdr + in parse_elf()
546 info->symtab_shndx_stop = (void *)hdr + in parse_elf()
550 if (!info->symtab_start) in parse_elf()
554 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { in parse_elf()
555 sym->st_shndx = TO_NATIVE(sym->st_shndx); in parse_elf()
556 sym->st_name = TO_NATIVE(sym->st_name); in parse_elf()
557 sym->st_value = TO_NATIVE(sym->st_value); in parse_elf()
558 sym->st_size = TO_NATIVE(sym->st_size); in parse_elf()
568 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; in parse_elf()
581 release_file(info->hdr, info->size); in parse_elf_finish()
592 if (info->hdr->e_machine == EM_PPC) in ignore_undef_symbol()
601 if (info->hdr->e_machine == EM_PPC64) in ignore_undef_symbol()
613 static void handle_symbol(struct module *mod, struct elf_info *info, in handle_symbol() argument
616 switch (sym->st_shndx) { in handle_symbol()
621 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); in handle_symbol()
625 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in handle_symbol()
626 ELF_ST_BIND(sym->st_info) != STB_WEAK) in handle_symbol()
630 if (info->hdr->e_machine == EM_SPARC || in handle_symbol()
631 info->hdr->e_machine == EM_SPARCV9) { in handle_symbol()
633 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) in handle_symbol()
643 sym_add_unresolved(symname, mod, in handle_symbol()
644 ELF_ST_BIND(sym->st_info) == STB_WEAK); in handle_symbol()
648 mod->has_init = true; in handle_symbol()
650 mod->has_cleanup = true; in handle_symbol()
660 /* Skip non-zero chars */ in next_string()
663 if ((*secsize)-- <= 1) in next_string()
670 if ((*secsize)-- <= 1) in next_string()
681 char *modinfo = info->modinfo; in get_next_modinfo()
682 unsigned long size = info->modinfo_len; in get_next_modinfo()
685 size -= prev - modinfo; in get_next_modinfo()
704 return sym ? elf->strtab + sym->st_name : ""; in sym_name()
738 ".GCC.command.line", /* record-gcc-switches */
753 ".llvm.call-graph-profile", /* call graph */
767 if (sechdr->sh_type == SHT_PROGBITS && in check_section()
768 !(sechdr->sh_flags & SHF_ALLOC) && in check_section()
770 warn("%s (%s): unexpected non-allocatable section.\n" in check_section()
816 * this array is forbidden (black-list). Can be empty.
819 * targeting sections in this array (white-list). Can be empty.
858 /* If you're adding any new black-listed sections in here, consider
874 * handling relocations to un-resolved symbols, trying to match it in section_mismatch()
884 if (match(fromsec, check->fromsec)) { in section_mismatch()
885 if (check->bad_tosec[0] && match(tosec, check->bad_tosec)) in section_mismatch()
887 if (check->good_tosec[0] && !match(tosec, check->good_tosec)) in section_mismatch()
919 * these from non-init sections as these symbols don't have any memory
928 * in functions like cpumask_empty() -- generating an associated symbol
1002 if (secndx >= elf->num_sections) in is_executable_section()
1005 return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0; in is_executable_section()
1025 /* check whitelist - we may ignore it */ in default_mismatch_handler()
1038 warn("%s: section mismatch in reference: %s%s0x%x (section: %s) -> %s (section: %s)\n", in default_mismatch_handler()
1040 (unsigned int)(faddr - (fromsym[0] ? from->st_value : 0)), in default_mismatch_handler()
1043 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { in default_mismatch_handler()
1044 if (match(tosec, mismatch->bad_tosec)) in default_mismatch_handler()
1046 "section \"%s\" which is black-listed.\n" in default_mismatch_handler()
1058 "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n", in default_mismatch_handler()
1061 error("%s+0x%lx references non-executable section '%s'\n", in default_mismatch_handler()
1066 static void check_export_symbol(struct module *mod, struct elf_info *elf, in check_export_symbol() argument
1076 label = find_fromsym(elf, faddr, elf->export_symbol_secndx); in check_export_symbol()
1081 mod->name, label_name); in check_export_symbol()
1085 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in check_export_symbol()
1086 ELF_ST_BIND(sym->st_info) != STB_WEAK) { in check_export_symbol()
1087 error("%s: local symbol '%s' was exported\n", mod->name, in check_export_symbol()
1095 mod->name, name); in check_export_symbol()
1106 mod->name, data, name); in check_export_symbol()
1111 s = sym_add_exported(name, mod, is_gpl, data); in check_export_symbol()
1117 s->is_func = (ELF_ST_TYPE(sym->st_info) == STT_FUNC); in check_export_symbol()
1123 if (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64 && in check_export_symbol()
1124 elf->hdr->e_machine == EM_PARISC && in check_export_symbol()
1125 ELF_ST_TYPE(sym->st_info) == STT_LOPROC) in check_export_symbol()
1126 s->is_func = true; in check_export_symbol()
1130 mod->name, name); in check_export_symbol()
1133 mod->name, name); in check_export_symbol()
1136 static void check_section_mismatch(struct module *mod, struct elf_info *elf, in check_section_mismatch() argument
1144 if (module_enabled && elf->export_symbol_secndx == fsecndx) { in check_section_mismatch()
1145 check_export_symbol(mod, elf, faddr, tosec, sym); in check_section_mismatch()
1153 default_mismatch_handler(mod->name, elf, mismatch, sym, in check_section_mismatch()
1167 return (Elf_Addr)(-1); in addend_386_rel()
1172 uint8_t shift = 31 - index; in sign_extend32()
1186 return inst + sym->st_value; in addend_arm_rel()
1192 return offset + sym->st_value; in addend_arm_rel()
1198 return offset + sym->st_value + 8; in addend_arm_rel()
1203 offset = sign_extend32(((upper & 0x000f) << 12) | in addend_arm_rel()
1208 return offset + sym->st_value; in addend_arm_rel()
1226 ((upper & 0x03f) << 12) | in addend_arm_rel()
1229 return offset + sym->st_value + 4; in addend_arm_rel()
1252 ((upper & 0x03ff) << 12) | in addend_arm_rel()
1255 return offset + sym->st_value + 4; in addend_arm_rel()
1258 return (Elf_Addr)(-1); in addend_arm_rel()
1274 return (Elf_Addr)(-1); in addend_mips_rel()
1312 bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64); in get_rel_type_and_sym()
1314 if (elf->hdr->e_machine == EM_MIPS && is_64bit) { in get_rel_type_and_sym()
1317 *r_type = mips64_r_info->r_type; in get_rel_type_and_sym()
1318 *r_sym = TO_NATIVE(mips64_r_info->r_sym); in get_rel_type_and_sym()
1331 static void section_rela(struct module *mod, struct elf_info *elf, in section_rela() argument
1342 r_offset = TO_NATIVE(rela->r_offset); in section_rela()
1343 get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); in section_rela()
1345 tsym = elf->symtab_start + r_sym; in section_rela()
1346 taddr = tsym->st_value + TO_NATIVE(rela->r_addend); in section_rela()
1348 switch (elf->hdr->e_machine) { in section_rela()
1368 check_section_mismatch(mod, elf, tsym, in section_rela()
1373 static void section_rel(struct module *mod, struct elf_info *elf, in section_rel() argument
1385 r_offset = TO_NATIVE(rel->r_offset); in section_rel()
1386 get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); in section_rel()
1389 tsym = elf->symtab_start + r_sym; in section_rel()
1391 switch (elf->hdr->e_machine) { in section_rel()
1405 check_section_mismatch(mod, elf, tsym, in section_rel()
1412 * either when loaded or when used as built-in.
1415 * Likewise for modules used built-in the sections marked __exit
1417 * only when a module is unloaded which never happens for built-in modules.
1422 static void check_sec_ref(struct module *mod, struct elf_info *elf) in check_sec_ref() argument
1427 for (i = 0; i < elf->num_sections; i++) { in check_sec_ref()
1428 Elf_Shdr *sechdr = &elf->sechdrs[i]; in check_sec_ref()
1430 check_section(mod->name, elf, sechdr); in check_sec_ref()
1432 if (sechdr->sh_type == SHT_REL || sechdr->sh_type == SHT_RELA) { in check_sec_ref()
1434 unsigned int secndx = sechdr->sh_info; in check_sec_ref()
1443 stop = start + sechdr->sh_size; in check_sec_ref()
1445 if (sechdr->sh_type == SHT_RELA) in check_sec_ref()
1446 section_rela(mod, elf, secndx, secname, in check_sec_ref()
1449 section_rel(mod, elf, secndx, secname, in check_sec_ref()
1471 static void extract_crcs_for_object(const char *object, struct module *mod) in extract_crcs_for_object() argument
1479 dirlen = base - object; in extract_crcs_for_object()
1503 namelen = p - name; in extract_crcs_for_object()
1521 sym = sym_find_with_module(name, mod); in extract_crcs_for_object()
1533 static void mod_set_crcs(struct module *mod) in mod_set_crcs() argument
1539 if (mod->is_vmlinux) { in mod_set_crcs()
1542 /* objects for a module are listed in the *.mod file. */ in mod_set_crcs()
1543 ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name); in mod_set_crcs()
1554 extract_crcs_for_object(obj, mod); in mod_set_crcs()
1565 struct module *mod; in read_symbols() local
1578 mod = new_module(modname, strlen(modname) - strlen(".o")); in read_symbols()
1582 mod->no_trim_symbol = xmalloc(info.no_trim_symbol_len); in read_symbols()
1583 memcpy(mod->no_trim_symbol, info.no_trim_symbol, in read_symbols()
1585 mod->no_trim_symbol_len = info.no_trim_symbol_len; in read_symbols()
1588 if (!mod->is_vmlinux) { in read_symbols()
1594 mod->is_gpl_compatible = false; in read_symbols()
1605 mod->name, namespace); in read_symbols()
1607 add_namespace(&mod->imported_namespaces, namespace); in read_symbols()
1615 symname = remove_dot(info.strtab + sym->st_name); in read_symbols()
1617 handle_symbol(mod, &info, sym, symname); in read_symbols()
1618 handle_moddevtable(mod, &info, sym, symname); in read_symbols()
1621 check_sec_ref(mod, &info); in read_symbols()
1623 if (!mod->is_vmlinux) { in read_symbols()
1626 get_src_version(mod->name, mod->srcversion, in read_symbols()
1627 sizeof(mod->srcversion) - 1); in read_symbols()
1634 * Our trick to get versioning for module struct etc. - it's in read_symbols()
1639 sym_add_unresolved("module_layout", mod, false); in read_symbols()
1641 mod_set_crcs(mod); in read_symbols()
1656 fname[strlen(fname)-1] = '\0'; in read_symbols_from_files()
1684 if (buf->size - buf->pos < len) { in buf_write()
1685 buf->size += len + SZ; in buf_write()
1686 buf->p = xrealloc(buf->p, buf->size); in buf_write()
1688 strncpy(buf->p + buf->pos, s, len); in buf_write()
1689 buf->pos += len; in buf_write()
1693 * verify_module_namespace() - does @modname have access to this symbol's @namespace
1700 * The patterns only support tail-glob.
1714 len = sep - namespace; in verify_module_namespace()
1717 if (sep[-1] == '*') { in verify_module_namespace()
1718 len--; in verify_module_namespace()
1732 static void check_exports(struct module *mod) in check_exports() argument
1736 list_for_each_entry(s, &mod->unresolved_symbols, list) { in check_exports()
1738 exp = find_symbol(s->name); in check_exports()
1740 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS) in check_exports()
1743 s->name, mod->name); in check_exports()
1746 if (exp->module == mod) { in check_exports()
1748 s->name, mod->name); in check_exports()
1752 exp->used = true; in check_exports()
1753 s->module = exp->module; in check_exports()
1754 s->crc_valid = exp->crc_valid; in check_exports()
1755 s->crc = exp->crc; in check_exports()
1757 basename = get_basename(mod->name); in check_exports()
1759 if (!verify_module_namespace(exp->namespace, basename) && in check_exports()
1760 !contains_namespace(&mod->imported_namespaces, exp->namespace)) { in check_exports()
1763 basename, exp->name, exp->namespace); in check_exports()
1764 add_namespace(&mod->missing_namespaces, exp->namespace); in check_exports()
1767 if (!mod->is_gpl_compatible && exp->is_gpl_only) in check_exports()
1768 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n", in check_exports()
1769 basename, exp->name); in check_exports()
1784 sym->used = true; in handle_white_list_exports()
1795 static void keep_no_trim_symbols(struct module *mod) in keep_no_trim_symbols() argument
1797 unsigned long size = mod->no_trim_symbol_len; in keep_no_trim_symbols()
1799 for (char *s = mod->no_trim_symbol; s; s = next_string(s , &size)) { in keep_no_trim_symbols()
1808 sym->used = true; in keep_no_trim_symbols()
1812 static void check_modname_len(struct module *mod) in check_modname_len() argument
1816 mod_name = get_basename(mod->name); in check_modname_len()
1819 error("module name is too long [%s.ko]\n", mod->name); in check_modname_len()
1825 static void add_header(struct buffer *b, struct module *mod) in add_header() argument
1827 buf_printf(b, "#include <linux/module.h>\n"); in add_header()
1828 buf_printf(b, "#include <linux/export-internal.h>\n"); in add_header()
1829 buf_printf(b, "#include <linux/compiler.h>\n"); in add_header()
1830 buf_printf(b, "\n"); in add_header()
1831 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); in add_header()
1832 buf_printf(b, "\n"); in add_header()
1833 buf_printf(b, "__visible struct module __this_module\n"); in add_header()
1834 buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n"); in add_header()
1835 buf_printf(b, "\t.name = KBUILD_MODNAME,\n"); in add_header()
1836 if (mod->has_init) in add_header()
1837 buf_printf(b, "\t.init = init_module,\n"); in add_header()
1838 if (mod->has_cleanup) in add_header()
1839 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n" in add_header()
1842 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n"); in add_header()
1843 buf_printf(b, "};\n"); in add_header()
1846 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); in add_header()
1848 if (strstarts(mod->name, "drivers/staging")) in add_header()
1849 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); in add_header()
1851 if (strstarts(mod->name, "tools/testing")) in add_header()
1852 buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n"); in add_header()
1855 static void add_exported_symbols(struct buffer *buf, struct module *mod) in add_exported_symbols() argument
1861 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1862 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1866 sym->is_func ? "FUNC" : "DATA", sym->name, in add_exported_symbols()
1867 sym->is_gpl_only ? "_gpl" : "", sym->namespace); in add_exported_symbols()
1875 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1876 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1879 if (!sym->crc_valid) in add_exported_symbols()
1881 "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n", in add_exported_symbols()
1882 sym->name, mod->name, mod->is_vmlinux ? "" : ".ko", in add_exported_symbols()
1883 sym->name); in add_exported_symbols()
1886 sym->name, sym->crc, sym->is_gpl_only ? "_gpl" : ""); in add_exported_symbols()
1893 static void add_extended_versions(struct buffer *b, struct module *mod) in add_extended_versions() argument
1900 buf_printf(b, "\n"); in add_extended_versions()
1901 buf_printf(b, "static const u32 ____version_ext_crcs[]\n"); in add_extended_versions()
1902 buf_printf(b, "__used __section(\"__version_ext_crcs\") = {\n"); in add_extended_versions()
1903 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_extended_versions()
1904 if (!s->module) in add_extended_versions()
1906 if (!s->crc_valid) { in add_extended_versions()
1908 s->name, mod->name); in add_extended_versions()
1911 buf_printf(b, "\t0x%08x,\n", s->crc); in add_extended_versions()
1913 buf_printf(b, "};\n"); in add_extended_versions()
1915 buf_printf(b, "static const char ____version_ext_names[]\n"); in add_extended_versions()
1916 buf_printf(b, "__used __section(\"__version_ext_names\") =\n"); in add_extended_versions()
1917 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_extended_versions()
1918 if (!s->module) in add_extended_versions()
1920 if (!s->crc_valid) in add_extended_versions()
1928 buf_printf(b, "\t\"%s\\0\"\n", s->name); in add_extended_versions()
1930 buf_printf(b, ";\n"); in add_extended_versions()
1936 static void add_versions(struct buffer *b, struct module *mod) in add_versions() argument
1943 buf_printf(b, "\n"); in add_versions()
1944 buf_printf(b, "static const struct modversion_info ____versions[]\n"); in add_versions()
1945 buf_printf(b, "__used __section(\"__versions\") = {\n"); in add_versions()
1947 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_versions()
1948 if (!s->module) in add_versions()
1950 if (!s->crc_valid) { in add_versions()
1952 s->name, mod->name); in add_versions()
1955 if (strlen(s->name) >= MODULE_NAME_LEN) { in add_versions()
1961 s->name, mod->name); in add_versions()
1965 buf_printf(b, "\t{ 0x%08x, \"%s\" },\n", in add_versions()
1966 s->crc, s->name); in add_versions()
1969 buf_printf(b, "};\n"); in add_versions()
1972 static void add_depends(struct buffer *b, struct module *mod) in add_depends() argument
1977 /* Clear ->seen flag of modules that own symbols needed by this. */ in add_depends()
1978 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
1979 if (s->module) in add_depends()
1980 s->module->seen = s->module->is_vmlinux; in add_depends()
1983 buf_printf(b, "\n"); in add_depends()
1984 buf_printf(b, "MODULE_INFO(depends, \""); in add_depends()
1985 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
1987 if (!s->module) in add_depends()
1990 if (s->module->seen) in add_depends()
1993 s->module->seen = true; in add_depends()
1994 p = get_basename(s->module->name); in add_depends()
1995 buf_printf(b, "%s%s", first ? "" : ",", p); in add_depends()
1998 buf_printf(b, "\");\n"); in add_depends()
2001 static void add_srcversion(struct buffer *b, struct module *mod) in add_srcversion() argument
2003 if (mod->srcversion[0]) { in add_srcversion()
2004 buf_printf(b, "\n"); in add_srcversion()
2005 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", in add_srcversion()
2006 mod->srcversion); in add_srcversion()
2010 static void write_buf(struct buffer *b, const char *fname) in write_buf() argument
2022 if (fwrite(b->p, 1, b->pos, file) != b->pos) { in write_buf()
2032 static void write_if_changed(struct buffer *b, const char *fname) in write_if_changed() argument
2045 if (st.st_size != b->pos) in write_if_changed()
2048 tmp = xmalloc(b->pos); in write_if_changed()
2049 if (fread(tmp, 1, b->pos, file) != b->pos) in write_if_changed()
2052 if (memcmp(tmp, b->p, b->pos) != 0) in write_if_changed()
2064 write_buf(b, fname); in write_if_changed()
2067 static void write_vmlinux_export_c_file(struct module *mod) in write_vmlinux_export_c_file() argument
2072 "#include <linux/export-internal.h>\n"); in write_vmlinux_export_c_file()
2074 add_exported_symbols(&buf, mod); in write_vmlinux_export_c_file()
2079 /* do sanity checks, and generate *.mod.c file */
2080 static void write_mod_c_file(struct module *mod) in write_mod_c_file() argument
2087 add_header(&buf, mod); in write_mod_c_file()
2088 add_exported_symbols(&buf, mod); in write_mod_c_file()
2089 add_versions(&buf, mod); in write_mod_c_file()
2090 add_extended_versions(&buf, mod); in write_mod_c_file()
2091 add_depends(&buf, mod); in write_mod_c_file()
2094 list_for_each_entry_safe(alias, next, &mod->aliases, node) { in write_mod_c_file()
2095 buf_printf(&buf, "MODULE_ALIAS(\"%s\");\n", alias->str); in write_mod_c_file()
2096 list_del(&alias->node); in write_mod_c_file()
2100 add_srcversion(&buf, mod); in write_mod_c_file()
2102 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name); in write_mod_c_file()
2131 struct module *mod; in read_dump() local
2161 mod = find_module(fname, modname); in read_dump()
2162 if (!mod) { in read_dump()
2163 mod = new_module(modname, strlen(modname)); in read_dump()
2164 mod->dump_file = fname; in read_dump()
2166 s = sym_add_exported(symname, mod, gpl_only, namespace); in read_dump()
2179 struct module *mod; in write_dump() local
2182 list_for_each_entry(mod, &modules, list) { in write_dump()
2183 if (mod->dump_file) in write_dump()
2185 list_for_each_entry(sym, &mod->exported_symbols, list) { in write_dump()
2186 if (trim_unused_exports && !sym->used) in write_dump()
2190 sym->crc, sym->name, mod->name, in write_dump()
2191 sym->is_gpl_only ? "_GPL" : "", in write_dump()
2192 sym->namespace); in write_dump()
2201 struct module *mod; in write_namespace_deps_files() local
2205 list_for_each_entry(mod, &modules, list) { in write_namespace_deps_files()
2207 if (mod->dump_file || list_empty(&mod->missing_namespaces)) in write_namespace_deps_files()
2210 buf_printf(&ns_deps_buf, "%s.ko:", mod->name); in write_namespace_deps_files()
2212 list_for_each_entry(ns, &mod->missing_namespaces, list) in write_namespace_deps_files()
2213 buf_printf(&ns_deps_buf, " %s", ns->namespace); in write_namespace_deps_files()
2248 struct module *mod; in main() local
2256 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:xb")) != -1) { in main()
2263 dl->file = optarg; in main()
2264 list_add_tail(&dl->list, &dump_lists); in main()
2305 case 'b': in main()
2319 read_dump(dl->file); in main()
2320 list_del(&dl->list); in main()
2330 list_for_each_entry(mod, &modules, list) { in main()
2331 keep_no_trim_symbols(mod); in main()
2333 if (mod->dump_file || mod->is_vmlinux) in main()
2336 check_modname_len(mod); in main()
2337 check_exports(mod); in main()
2343 list_for_each_entry(mod, &modules, list) { in main()
2344 if (mod->dump_file) in main()
2347 if (mod->is_vmlinux) in main()
2348 write_vmlinux_export_c_file(mod); in main()
2350 write_mod_c_file(mod); in main()
2364 nr_unresolved - MAX_UNRESOLVED_REPORTS); in main()