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
38 /* Trim EXPORT_SYMBOLs that are unused by in-tree modules */
58 * here we use Elf_Addr instead of long for covering cross-compile
61 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
99 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; in strends()
141 nbytes -= bytes_read; in read_text_file()
173 struct module *mod; in find_module() local
175 list_for_each_entry(mod, &modules, list) { in find_module()
176 if (strcmp(mod->name, modname) == 0) in find_module()
177 return mod; in find_module()
184 struct module *mod; in new_module() local
186 mod = NOFAIL(malloc(sizeof(*mod) + namelen + 1)); in new_module()
187 memset(mod, 0, sizeof(*mod)); in new_module()
189 INIT_LIST_HEAD(&mod->exported_symbols); in new_module()
190 INIT_LIST_HEAD(&mod->unresolved_symbols); in new_module()
191 INIT_LIST_HEAD(&mod->missing_namespaces); in new_module()
192 INIT_LIST_HEAD(&mod->imported_namespaces); in new_module()
194 memcpy(mod->name, name, namelen); in new_module()
195 mod->name[namelen] = '\0'; in new_module()
196 mod->is_vmlinux = (strcmp(mod->name, "vmlinux") == 0); in new_module()
199 * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE() in new_module()
203 mod->is_gpl_compatible = true; in new_module()
205 list_add_tail(&mod->list, &modules); in new_module()
207 return mod; in new_module()
253 strcpy(s->name, name); in alloc_symbol()
263 hash = tdb_hash(sym->name) % SYMBOL_HASH_SIZE; in hash_add_symbol()
264 sym->next = symbolhash[hash]; in hash_add_symbol()
268 static void sym_add_unresolved(const char *name, struct module *mod, bool weak) in sym_add_unresolved() argument
273 sym->weak = weak; in sym_add_unresolved()
275 list_add_tail(&sym->list, &mod->unresolved_symbols); in sym_add_unresolved()
278 static struct symbol *sym_find_with_module(const char *name, struct module *mod) in sym_find_with_module() argument
286 for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) { in sym_find_with_module()
287 if (strcmp(s->name, name) == 0 && (!mod || s->module == mod)) in sym_find_with_module()
315 if (!strcmp(list->namespace, namespace)) in contains_namespace()
329 strcpy(ns_entry->namespace, namespace); in add_namespace()
330 list_add_tail(&ns_entry->list, head); in add_namespace()
337 Elf_Shdr *sechdr = &info->sechdrs[secindex]; in sym_get_data_by_offset()
339 return (void *)info->hdr + sechdr->sh_offset + offset; in sym_get_data_by_offset()
345 sym->st_value); in sym_get_data()
350 return sym_get_data_by_offset(info, info->secindex_strings, in sech_name()
351 sechdr->sh_name); in sech_name()
357 * If sym->st_shndx is a special section index, there is no in sec_name()
359 * Return "" if the index is out of range of info->sechdrs[] array. in sec_name()
361 if (secindex >= info->num_sections) in sec_name()
364 return sech_name(info, &info->sechdrs[secindex]); in sec_name()
369 static struct symbol *sym_add_exported(const char *name, struct module *mod, in sym_add_exported() argument
374 if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) { in sym_add_exported()
376 mod->name, name, s->module->name, in sym_add_exported()
377 s->module->is_vmlinux ? "" : ".ko"); in sym_add_exported()
381 s->module = mod; in sym_add_exported()
382 s->is_gpl_only = gpl_only; in sym_add_exported()
383 s->namespace = NOFAIL(strdup(namespace)); in sym_add_exported()
384 list_add_tail(&s->list, &mod->exported_symbols); in sym_add_exported()
392 sym->crc = crc; in sym_set_crc()
393 sym->crc_valid = true; in sym_set_crc()
432 hdr = grab_file(filename, &info->size); in parse_elf()
442 info->hdr = hdr; in parse_elf()
443 if (info->size < sizeof(*hdr)) { in parse_elf()
448 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) || in parse_elf()
449 (hdr->e_ident[EI_MAG1] != ELFMAG1) || in parse_elf()
450 (hdr->e_ident[EI_MAG2] != ELFMAG2) || in parse_elf()
451 (hdr->e_ident[EI_MAG3] != ELFMAG3)) { in parse_elf()
452 /* Not an ELF file - silently ignore it */ in parse_elf()
456 hdr->e_type = TO_NATIVE(hdr->e_type); in parse_elf()
457 hdr->e_machine = TO_NATIVE(hdr->e_machine); in parse_elf()
458 hdr->e_version = TO_NATIVE(hdr->e_version); in parse_elf()
459 hdr->e_entry = TO_NATIVE(hdr->e_entry); in parse_elf()
460 hdr->e_phoff = TO_NATIVE(hdr->e_phoff); in parse_elf()
461 hdr->e_shoff = TO_NATIVE(hdr->e_shoff); in parse_elf()
462 hdr->e_flags = TO_NATIVE(hdr->e_flags); in parse_elf()
463 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize); in parse_elf()
464 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize); in parse_elf()
465 hdr->e_phnum = TO_NATIVE(hdr->e_phnum); in parse_elf()
466 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize); in parse_elf()
467 hdr->e_shnum = TO_NATIVE(hdr->e_shnum); in parse_elf()
468 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); in parse_elf()
469 sechdrs = (void *)hdr + hdr->e_shoff; in parse_elf()
470 info->sechdrs = sechdrs; in parse_elf()
473 if (hdr->e_type != ET_REL) in parse_elf()
477 if (hdr->e_shoff > info->size) { in parse_elf()
479 (unsigned long)hdr->e_shoff, filename, info->size); in parse_elf()
483 if (hdr->e_shnum == SHN_UNDEF) { in parse_elf()
488 info->num_sections = TO_NATIVE(sechdrs[0].sh_size); in parse_elf()
491 info->num_sections = hdr->e_shnum; in parse_elf()
493 if (hdr->e_shstrndx == SHN_XINDEX) { in parse_elf()
494 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link); in parse_elf()
497 info->secindex_strings = hdr->e_shstrndx; in parse_elf()
501 for (i = 0; i < info->num_sections; i++) { in parse_elf()
514 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset; in parse_elf()
515 for (i = 1; i < info->num_sections; i++) { in parse_elf()
519 if (!nobits && sechdrs[i].sh_offset > info->size) { in parse_elf()
529 info->modinfo = (void *)hdr + sechdrs[i].sh_offset; in parse_elf()
530 info->modinfo_len = sechdrs[i].sh_size; in parse_elf()
532 info->export_symbol_secndx = i; in parse_elf()
538 info->symtab_start = (void *)hdr + in parse_elf()
540 info->symtab_stop = (void *)hdr + in parse_elf()
543 info->strtab = (void *)hdr + in parse_elf()
550 info->symtab_shndx_start = (void *)hdr + in parse_elf()
552 info->symtab_shndx_stop = (void *)hdr + in parse_elf()
556 if (!info->symtab_start) in parse_elf()
560 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { in parse_elf()
561 sym->st_shndx = TO_NATIVE(sym->st_shndx); in parse_elf()
562 sym->st_name = TO_NATIVE(sym->st_name); in parse_elf()
563 sym->st_value = TO_NATIVE(sym->st_value); in parse_elf()
564 sym->st_size = TO_NATIVE(sym->st_size); in parse_elf()
574 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; in parse_elf()
587 release_file(info->hdr, info->size); in parse_elf_finish()
598 if (info->hdr->e_machine == EM_PPC) in ignore_undef_symbol()
607 if (info->hdr->e_machine == EM_PPC64) in ignore_undef_symbol()
616 if (info->hdr->e_machine == EM_S390) in ignore_undef_symbol()
624 static void handle_symbol(struct module *mod, struct elf_info *info, in handle_symbol() argument
627 switch (sym->st_shndx) { in handle_symbol()
632 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); in handle_symbol()
636 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in handle_symbol()
637 ELF_ST_BIND(sym->st_info) != STB_WEAK) in handle_symbol()
641 if (info->hdr->e_machine == EM_SPARC || in handle_symbol()
642 info->hdr->e_machine == EM_SPARCV9) { in handle_symbol()
644 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) in handle_symbol()
654 sym_add_unresolved(symname, mod, in handle_symbol()
655 ELF_ST_BIND(sym->st_info) == STB_WEAK); in handle_symbol()
659 mod->has_init = true; in handle_symbol()
661 mod->has_cleanup = true; in handle_symbol()
671 /* Skip non-zero chars */ in next_string()
674 if ((*secsize)-- <= 1) in next_string()
681 if ((*secsize)-- <= 1) in next_string()
692 char *modinfo = info->modinfo; in get_next_modinfo()
693 unsigned long size = info->modinfo_len; in get_next_modinfo()
696 size -= prev - modinfo; in get_next_modinfo()
716 return elf->strtab + sym->st_name; in sym_name()
752 ".GCC.command.line", /* record-gcc-switches */
767 ".llvm.call-graph-profile", /* call graph */
781 if (sechdr->sh_type == SHT_PROGBITS && in check_section()
782 !(sechdr->sh_flags & SHF_ALLOC) && in check_section()
784 warn("%s (%s): unexpected non-allocatable section.\n" in check_section()
832 * this array is forbidden (black-list). Can be empty.
835 * targeting sections in this array (white-list). Can be empty.
884 /* If you're adding any new black-listed sections in here, consider
900 * handling relocations to un-resolved symbols, trying to match it in section_mismatch()
910 if (match(fromsec, check->fromsec)) { in section_mismatch()
911 if (check->bad_tosec[0] && match(tosec, check->bad_tosec)) in section_mismatch()
913 if (check->good_tosec[0] && !match(tosec, check->good_tosec)) in section_mismatch()
945 * these from non-init sections as these symbols don't have any memory
954 * in functions like cpumask_empty() -- generating an associated symbol
1045 if (secndx >= elf->num_sections) in is_executable_section()
1048 return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0; in is_executable_section()
1067 /* check whitelist - we may ignore it */ in default_mismatch_handler()
1073 warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n", in default_mismatch_handler()
1075 (unsigned int)(faddr - (from ? from->st_value : 0)), in default_mismatch_handler()
1078 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { in default_mismatch_handler()
1079 if (match(tosec, mismatch->bad_tosec)) in default_mismatch_handler()
1081 "section \"%s\" which is black-listed.\n" in default_mismatch_handler()
1093 "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n", in default_mismatch_handler()
1096 error("%s+0x%lx references non-executable section '%s'\n", in default_mismatch_handler()
1101 static void check_export_symbol(struct module *mod, struct elf_info *elf, in check_export_symbol() argument
1111 label = find_fromsym(elf, faddr, elf->export_symbol_secndx); in check_export_symbol()
1116 mod->name, label_name); in check_export_symbol()
1120 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in check_export_symbol()
1121 ELF_ST_BIND(sym->st_info) != STB_WEAK) { in check_export_symbol()
1122 error("%s: local symbol '%s' was exported\n", mod->name, in check_export_symbol()
1130 mod->name, name); in check_export_symbol()
1141 mod->name, data, name); in check_export_symbol()
1146 s = sym_add_exported(name, mod, is_gpl, data); in check_export_symbol()
1152 s->is_func = (ELF_ST_TYPE(sym->st_info) == STT_FUNC); in check_export_symbol()
1158 if (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64 && in check_export_symbol()
1159 elf->hdr->e_machine == EM_PARISC && in check_export_symbol()
1160 ELF_ST_TYPE(sym->st_info) == STT_LOPROC) in check_export_symbol()
1161 s->is_func = true; in check_export_symbol()
1165 mod->name, name); in check_export_symbol()
1168 mod->name, name); in check_export_symbol()
1171 static void check_section_mismatch(struct module *mod, struct elf_info *elf, in check_section_mismatch() argument
1179 if (module_enabled && elf->export_symbol_secndx == fsecndx) { in check_section_mismatch()
1180 check_export_symbol(mod, elf, faddr, tosec, sym); in check_section_mismatch()
1188 default_mismatch_handler(mod->name, elf, mismatch, sym, in check_section_mismatch()
1202 return (Elf_Addr)(-1); in addend_386_rel()
1241 uint8_t shift = 31 - index; in sign_extend32()
1255 return inst + sym->st_value; in addend_arm_rel()
1261 return offset + sym->st_value; in addend_arm_rel()
1267 return offset + sym->st_value + 8; in addend_arm_rel()
1272 offset = sign_extend32(((upper & 0x000f) << 12) | in addend_arm_rel()
1277 return offset + sym->st_value; in addend_arm_rel()
1295 ((upper & 0x03f) << 12) | in addend_arm_rel()
1298 return offset + sym->st_value + 4; in addend_arm_rel()
1321 ((upper & 0x03ff) << 12) | in addend_arm_rel()
1324 return offset + sym->st_value + 4; in addend_arm_rel()
1327 return (Elf_Addr)(-1); in addend_arm_rel()
1343 return (Elf_Addr)(-1); in addend_mips_rel()
1373 bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64); in get_rel_type_and_sym()
1375 if (elf->hdr->e_machine == EM_MIPS && is_64bit) { in get_rel_type_and_sym()
1378 *r_type = mips64_r_info->r_type; in get_rel_type_and_sym()
1379 *r_sym = TO_NATIVE(mips64_r_info->r_sym); in get_rel_type_and_sym()
1397 static void section_rela(struct module *mod, struct elf_info *elf, in section_rela() argument
1401 unsigned int fsecndx = sechdr->sh_info; in section_rela()
1403 Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset; in section_rela()
1404 Elf_Rela *stop = (void *)start + sechdr->sh_size; in section_rela()
1415 r_offset = TO_NATIVE(rela->r_offset); in section_rela()
1416 get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); in section_rela()
1418 tsym = elf->symtab_start + r_sym; in section_rela()
1419 taddr = tsym->st_value + TO_NATIVE(rela->r_addend); in section_rela()
1421 switch (elf->hdr->e_machine) { in section_rela()
1434 check_section_mismatch(mod, elf, tsym, in section_rela()
1439 static void section_rel(struct module *mod, struct elf_info *elf, in section_rel() argument
1443 unsigned int fsecndx = sechdr->sh_info; in section_rel()
1445 Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset; in section_rel()
1446 Elf_Rel *stop = (void *)start + sechdr->sh_size; in section_rel()
1458 r_offset = TO_NATIVE(rel->r_offset); in section_rel()
1459 get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); in section_rel()
1462 tsym = elf->symtab_start + r_sym; in section_rel()
1464 switch (elf->hdr->e_machine) { in section_rel()
1478 check_section_mismatch(mod, elf, tsym, in section_rel()
1485 * either when loaded or when used as built-in.
1488 * Likewise for modules used built-in the sections marked __exit
1490 * only when a module is unloaded which never happens for built-in modules.
1495 static void check_sec_ref(struct module *mod, struct elf_info *elf) in check_sec_ref() argument
1498 Elf_Shdr *sechdrs = elf->sechdrs; in check_sec_ref()
1501 for (i = 0; i < elf->num_sections; i++) { in check_sec_ref()
1502 check_section(mod->name, elf, &elf->sechdrs[i]); in check_sec_ref()
1505 section_rela(mod, elf, &elf->sechdrs[i]); in check_sec_ref()
1507 section_rel(mod, elf, &elf->sechdrs[i]); in check_sec_ref()
1527 static void extract_crcs_for_object(const char *object, struct module *mod) in extract_crcs_for_object() argument
1537 dirlen = base - object; in extract_crcs_for_object()
1565 namelen = p - name; in extract_crcs_for_object()
1583 sym = sym_find_with_module(name, mod); in extract_crcs_for_object()
1595 static void mod_set_crcs(struct module *mod) in mod_set_crcs() argument
1601 if (mod->is_vmlinux) { in mod_set_crcs()
1604 /* objects for a module are listed in the *.mod file. */ in mod_set_crcs()
1605 ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name); in mod_set_crcs()
1616 extract_crcs_for_object(obj, mod); in mod_set_crcs()
1627 struct module *mod; in read_symbols() local
1640 mod = new_module(modname, strlen(modname) - strlen(".o")); in read_symbols()
1642 if (!mod->is_vmlinux) { in read_symbols()
1648 mod->is_gpl_compatible = false; in read_symbols()
1656 add_namespace(&mod->imported_namespaces, namespace); in read_symbols()
1666 symname = remove_dot(info.strtab + sym->st_name); in read_symbols()
1668 handle_symbol(mod, &info, sym, symname); in read_symbols()
1669 handle_moddevtable(mod, &info, sym, symname); in read_symbols()
1672 check_sec_ref(mod, &info); in read_symbols()
1674 if (!mod->is_vmlinux) { in read_symbols()
1677 get_src_version(mod->name, mod->srcversion, in read_symbols()
1678 sizeof(mod->srcversion) - 1); in read_symbols()
1685 * Our trick to get versioning for module struct etc. - it's in read_symbols()
1690 sym_add_unresolved("module_layout", mod, false); in read_symbols()
1692 mod_set_crcs(mod); in read_symbols()
1707 fname[strlen(fname)-1] = '\0'; in read_symbols_from_files()
1735 if (buf->size - buf->pos < len) { in buf_write()
1736 buf->size += len + SZ; in buf_write()
1737 buf->p = NOFAIL(realloc(buf->p, buf->size)); in buf_write()
1739 strncpy(buf->p + buf->pos, s, len); in buf_write()
1740 buf->pos += len; in buf_write()
1743 static void check_exports(struct module *mod) in check_exports() argument
1747 list_for_each_entry(s, &mod->unresolved_symbols, list) { in check_exports()
1749 exp = find_symbol(s->name); in check_exports()
1751 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS) in check_exports()
1754 s->name, mod->name); in check_exports()
1757 if (exp->module == mod) { in check_exports()
1759 s->name, mod->name); in check_exports()
1763 exp->used = true; in check_exports()
1764 s->module = exp->module; in check_exports()
1765 s->crc_valid = exp->crc_valid; in check_exports()
1766 s->crc = exp->crc; in check_exports()
1768 basename = strrchr(mod->name, '/'); in check_exports()
1772 basename = mod->name; in check_exports()
1774 if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) { in check_exports()
1777 basename, exp->name, exp->namespace); in check_exports()
1778 add_namespace(&mod->missing_namespaces, exp->namespace); in check_exports()
1781 if (!mod->is_gpl_compatible && exp->is_gpl_only) in check_exports()
1782 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n", in check_exports()
1783 basename, exp->name); in check_exports()
1798 sym->used = true; in handle_white_list_exports()
1804 static void check_modname_len(struct module *mod) in check_modname_len() argument
1808 mod_name = strrchr(mod->name, '/'); in check_modname_len()
1810 mod_name = mod->name; in check_modname_len()
1814 error("module name is too long [%s.ko]\n", mod->name); in check_modname_len()
1820 static void add_header(struct buffer *b, struct module *mod) in add_header() argument
1822 buf_printf(b, "#include <linux/module.h>\n"); in add_header()
1824 * Include build-salt.h after module.h in order to in add_header()
1827 buf_printf(b, "#define INCLUDE_VERMAGIC\n"); in add_header()
1828 buf_printf(b, "#include <linux/build-salt.h>\n"); in add_header()
1829 buf_printf(b, "#include <linux/elfnote-lto.h>\n"); in add_header()
1830 buf_printf(b, "#include <linux/export-internal.h>\n"); in add_header()
1831 buf_printf(b, "#include <linux/vermagic.h>\n"); in add_header()
1832 buf_printf(b, "#include <linux/compiler.h>\n"); in add_header()
1833 buf_printf(b, "\n"); in add_header()
1834 buf_printf(b, "#ifdef CONFIG_UNWINDER_ORC\n"); in add_header()
1835 buf_printf(b, "#include <asm/orc_header.h>\n"); in add_header()
1836 buf_printf(b, "ORC_HEADER;\n"); in add_header()
1837 buf_printf(b, "#endif\n"); in add_header()
1838 buf_printf(b, "\n"); in add_header()
1839 buf_printf(b, "BUILD_SALT;\n"); in add_header()
1840 buf_printf(b, "BUILD_LTO_INFO;\n"); in add_header()
1841 buf_printf(b, "\n"); in add_header()
1842 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); in add_header()
1843 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); in add_header()
1844 buf_printf(b, "\n"); in add_header()
1845 buf_printf(b, "__visible struct module __this_module\n"); in add_header()
1846 buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n"); in add_header()
1847 buf_printf(b, "\t.name = KBUILD_MODNAME,\n"); in add_header()
1848 if (mod->has_init) in add_header()
1849 buf_printf(b, "\t.init = init_module,\n"); in add_header()
1850 if (mod->has_cleanup) in add_header()
1851 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n" in add_header()
1854 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n"); in add_header()
1855 buf_printf(b, "};\n"); in add_header()
1858 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); in add_header()
1860 buf_printf(b, in add_header()
1866 if (strstarts(mod->name, "drivers/staging")) in add_header()
1867 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); in add_header()
1869 if (strstarts(mod->name, "tools/testing")) in add_header()
1870 buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n"); in add_header()
1873 static void add_exported_symbols(struct buffer *buf, struct module *mod) in add_exported_symbols() argument
1879 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1880 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1884 sym->is_func ? "FUNC" : "DATA", sym->name, in add_exported_symbols()
1885 sym->is_gpl_only ? "_gpl" : "", sym->namespace); in add_exported_symbols()
1893 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1894 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1897 if (!sym->crc_valid) in add_exported_symbols()
1899 "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n", in add_exported_symbols()
1900 sym->name, mod->name, mod->is_vmlinux ? "" : ".ko", in add_exported_symbols()
1901 sym->name); in add_exported_symbols()
1904 sym->name, sym->crc, sym->is_gpl_only ? "_gpl" : ""); in add_exported_symbols()
1911 static void add_versions(struct buffer *b, struct module *mod) in add_versions() argument
1918 buf_printf(b, "\n"); in add_versions()
1919 buf_printf(b, "static const struct modversion_info ____versions[]\n"); in add_versions()
1920 buf_printf(b, "__used __section(\"__versions\") = {\n"); in add_versions()
1922 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_versions()
1923 if (!s->module) in add_versions()
1925 if (!s->crc_valid) { in add_versions()
1927 s->name, mod->name); in add_versions()
1930 if (strlen(s->name) >= MODULE_NAME_LEN) { in add_versions()
1932 s->name, mod->name); in add_versions()
1935 buf_printf(b, "\t{ %#8x, \"%s\" },\n", in add_versions()
1936 s->crc, s->name); in add_versions()
1939 buf_printf(b, "};\n"); in add_versions()
1942 static void add_depends(struct buffer *b, struct module *mod) in add_depends() argument
1947 /* Clear ->seen flag of modules that own symbols needed by this. */ in add_depends()
1948 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
1949 if (s->module) in add_depends()
1950 s->module->seen = s->module->is_vmlinux; in add_depends()
1953 buf_printf(b, "\n"); in add_depends()
1954 buf_printf(b, "MODULE_INFO(depends, \""); in add_depends()
1955 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
1957 if (!s->module) in add_depends()
1960 if (s->module->seen) in add_depends()
1963 s->module->seen = true; in add_depends()
1964 p = strrchr(s->module->name, '/'); in add_depends()
1968 p = s->module->name; in add_depends()
1969 buf_printf(b, "%s%s", first ? "" : ",", p); in add_depends()
1972 buf_printf(b, "\");\n"); in add_depends()
1975 static void add_srcversion(struct buffer *b, struct module *mod) in add_srcversion() argument
1977 if (mod->srcversion[0]) { in add_srcversion()
1978 buf_printf(b, "\n"); in add_srcversion()
1979 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", in add_srcversion()
1980 mod->srcversion); in add_srcversion()
1984 static void write_buf(struct buffer *b, const char *fname) in write_buf() argument
1996 if (fwrite(b->p, 1, b->pos, file) != b->pos) { in write_buf()
2006 static void write_if_changed(struct buffer *b, const char *fname) in write_if_changed() argument
2019 if (st.st_size != b->pos) in write_if_changed()
2022 tmp = NOFAIL(malloc(b->pos)); in write_if_changed()
2023 if (fread(tmp, 1, b->pos, file) != b->pos) in write_if_changed()
2026 if (memcmp(tmp, b->p, b->pos) != 0) in write_if_changed()
2038 write_buf(b, fname); in write_if_changed()
2041 static void write_vmlinux_export_c_file(struct module *mod) in write_vmlinux_export_c_file() argument
2046 "#include <linux/export-internal.h>\n"); in write_vmlinux_export_c_file()
2048 add_exported_symbols(&buf, mod); in write_vmlinux_export_c_file()
2053 /* do sanity checks, and generate *.mod.c file */
2054 static void write_mod_c_file(struct module *mod) in write_mod_c_file() argument
2060 add_header(&buf, mod); in write_mod_c_file()
2061 add_exported_symbols(&buf, mod); in write_mod_c_file()
2062 add_versions(&buf, mod); in write_mod_c_file()
2063 add_depends(&buf, mod); in write_mod_c_file()
2064 add_moddevtable(&buf, mod); in write_mod_c_file()
2065 add_srcversion(&buf, mod); in write_mod_c_file()
2067 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name); in write_mod_c_file()
2096 struct module *mod; in read_dump() local
2126 mod = find_module(modname); in read_dump()
2127 if (!mod) { in read_dump()
2128 mod = new_module(modname, strlen(modname)); in read_dump()
2129 mod->from_dump = true; in read_dump()
2131 s = sym_add_exported(symname, mod, gpl_only, namespace); in read_dump()
2144 struct module *mod; in write_dump() local
2147 list_for_each_entry(mod, &modules, list) { in write_dump()
2148 if (mod->from_dump) in write_dump()
2150 list_for_each_entry(sym, &mod->exported_symbols, list) { in write_dump()
2151 if (trim_unused_exports && !sym->used) in write_dump()
2155 sym->crc, sym->name, mod->name, in write_dump()
2156 sym->is_gpl_only ? "_GPL" : "", in write_dump()
2157 sym->namespace); in write_dump()
2166 struct module *mod; in write_namespace_deps_files() local
2170 list_for_each_entry(mod, &modules, list) { in write_namespace_deps_files()
2172 if (mod->from_dump || list_empty(&mod->missing_namespaces)) in write_namespace_deps_files()
2175 buf_printf(&ns_deps_buf, "%s.ko:", mod->name); in write_namespace_deps_files()
2177 list_for_each_entry(ns, &mod->missing_namespaces, list) in write_namespace_deps_files()
2178 buf_printf(&ns_deps_buf, " %s", ns->namespace); in write_namespace_deps_files()
2194 struct module *mod; in main() local
2202 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:")) != -1) { in main()
2209 dl->file = optarg; in main()
2210 list_add_tail(&dl->list, &dump_lists); in main()
2257 read_dump(dl->file); in main()
2258 list_del(&dl->list); in main()
2268 list_for_each_entry(mod, &modules, list) { in main()
2269 if (mod->from_dump || mod->is_vmlinux) in main()
2272 check_modname_len(mod); in main()
2273 check_exports(mod); in main()
2279 list_for_each_entry(mod, &modules, list) { in main()
2280 if (mod->from_dump) in main()
2283 if (mod->is_vmlinux) in main()
2284 write_vmlinux_export_c_file(mod); in main()
2286 write_mod_c_file(mod); in main()
2300 nr_unresolved - MAX_UNRESOLVED_REPORTS); in main()