Lines Matching +full:- +full:- +full:- +full:module2
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
11 * Usage: modpost vmlinux module1.o module2.o ...
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()
102 * get_basename - return the last part of a pathname.
144 nbytes -= bytes_read; in read_text_file()
179 if (!strcmp(mod->dump_file, filename) && in find_module()
180 !strcmp(mod->name, modname)) in find_module()
193 INIT_LIST_HEAD(&mod->exported_symbols); in new_module()
194 INIT_LIST_HEAD(&mod->unresolved_symbols); in new_module()
195 INIT_LIST_HEAD(&mod->missing_namespaces); in new_module()
196 INIT_LIST_HEAD(&mod->imported_namespaces); in new_module()
197 INIT_LIST_HEAD(&mod->aliases); in new_module()
199 memcpy(mod->name, name, namelen); in new_module()
200 mod->name[namelen] = '\0'; in new_module()
201 mod->is_vmlinux = (strcmp(mod->name, "vmlinux") == 0); in new_module()
204 * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE() in new_module()
208 mod->is_gpl_compatible = true; in new_module()
210 list_add_tail(&mod->list, &modules); in new_module()
240 strcpy(s->name, name); in alloc_symbol()
248 hash_add(symbol_hashtable, &sym->hnode, hash_str(sym->name)); in hash_add_symbol()
256 sym->weak = weak; in sym_add_unresolved()
258 list_add_tail(&sym->list, &mod->unresolved_symbols); in sym_add_unresolved()
270 if (strcmp(s->name, name) == 0 && (!mod || s->module == mod)) in sym_find_with_module()
298 if (!strcmp(list->namespace, namespace)) in contains_namespace()
311 strcpy(ns_entry->namespace, namespace); in add_namespace()
312 list_add_tail(&ns_entry->list, head); in add_namespace()
319 Elf_Shdr *sechdr = &info->sechdrs[secindex]; in sym_get_data_by_offset()
321 return (void *)info->hdr + sechdr->sh_offset + offset; in sym_get_data_by_offset()
327 sym->st_value); in sym_get_data()
332 return sym_get_data_by_offset(info, info->secindex_strings, in sech_name()
333 sechdr->sh_name); in sech_name()
339 * If sym->st_shndx is a special section index, there is no in sec_name()
341 * Return "" if the index is out of range of info->sechdrs[] array. in sec_name()
343 if (secindex >= info->num_sections) in sec_name()
346 return sech_name(info, &info->sechdrs[secindex]); in sec_name()
354 if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) { in sym_add_exported()
356 mod->name, name, s->module->name, in sym_add_exported()
357 s->module->is_vmlinux ? "" : ".ko"); in sym_add_exported()
361 s->module = mod; in sym_add_exported()
362 s->is_gpl_only = gpl_only; in sym_add_exported()
363 s->namespace = xstrdup(namespace); in sym_add_exported()
364 list_add_tail(&s->list, &mod->exported_symbols); in sym_add_exported()
372 sym->crc = crc; in sym_set_crc()
373 sym->crc_valid = true; in sym_set_crc()
412 hdr = grab_file(filename, &info->size); in parse_elf()
422 info->hdr = hdr; in parse_elf()
423 if (info->size < sizeof(*hdr)) { in parse_elf()
428 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) || in parse_elf()
429 (hdr->e_ident[EI_MAG1] != ELFMAG1) || in parse_elf()
430 (hdr->e_ident[EI_MAG2] != ELFMAG2) || in parse_elf()
431 (hdr->e_ident[EI_MAG3] != ELFMAG3)) { in parse_elf()
432 /* Not an ELF file - silently ignore it */ in parse_elf()
436 switch (hdr->e_ident[EI_DATA]) { in parse_elf()
448 hdr->e_type = TO_NATIVE(hdr->e_type); in parse_elf()
449 hdr->e_machine = TO_NATIVE(hdr->e_machine); in parse_elf()
450 hdr->e_version = TO_NATIVE(hdr->e_version); in parse_elf()
451 hdr->e_entry = TO_NATIVE(hdr->e_entry); in parse_elf()
452 hdr->e_phoff = TO_NATIVE(hdr->e_phoff); in parse_elf()
453 hdr->e_shoff = TO_NATIVE(hdr->e_shoff); in parse_elf()
454 hdr->e_flags = TO_NATIVE(hdr->e_flags); in parse_elf()
455 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize); in parse_elf()
456 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize); in parse_elf()
457 hdr->e_phnum = TO_NATIVE(hdr->e_phnum); in parse_elf()
458 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize); in parse_elf()
459 hdr->e_shnum = TO_NATIVE(hdr->e_shnum); in parse_elf()
460 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); in parse_elf()
461 sechdrs = (void *)hdr + hdr->e_shoff; in parse_elf()
462 info->sechdrs = sechdrs; in parse_elf()
465 if (hdr->e_type != ET_REL) in parse_elf()
469 if (hdr->e_shoff > info->size) in parse_elf()
471 (unsigned long)hdr->e_shoff, filename, info->size); in parse_elf()
473 if (hdr->e_shnum == SHN_UNDEF) { in parse_elf()
478 info->num_sections = TO_NATIVE(sechdrs[0].sh_size); in parse_elf()
481 info->num_sections = hdr->e_shnum; in parse_elf()
483 if (hdr->e_shstrndx == SHN_XINDEX) { in parse_elf()
484 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link); in parse_elf()
487 info->secindex_strings = hdr->e_shstrndx; in parse_elf()
491 for (i = 0; i < info->num_sections; i++) { in parse_elf()
504 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset; in parse_elf()
505 for (i = 1; i < info->num_sections; i++) { in parse_elf()
509 if (!nobits && sechdrs[i].sh_offset > info->size) in parse_elf()
518 info->modinfo = (void *)hdr + sechdrs[i].sh_offset; in parse_elf()
519 info->modinfo_len = sechdrs[i].sh_size; in parse_elf()
521 info->export_symbol_secndx = i; in parse_elf()
523 info->no_trim_symbol = (void *)hdr + sechdrs[i].sh_offset; in parse_elf()
524 info->no_trim_symbol_len = sechdrs[i].sh_size; in parse_elf()
530 info->symtab_start = (void *)hdr + in parse_elf()
532 info->symtab_stop = (void *)hdr + in parse_elf()
535 info->strtab = (void *)hdr + in parse_elf()
542 info->symtab_shndx_start = (void *)hdr + in parse_elf()
544 info->symtab_shndx_stop = (void *)hdr + in parse_elf()
548 if (!info->symtab_start) in parse_elf()
552 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { in parse_elf()
553 sym->st_shndx = TO_NATIVE(sym->st_shndx); in parse_elf()
554 sym->st_name = TO_NATIVE(sym->st_name); in parse_elf()
555 sym->st_value = TO_NATIVE(sym->st_value); in parse_elf()
556 sym->st_size = TO_NATIVE(sym->st_size); in parse_elf()
566 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; in parse_elf()
579 release_file(info->hdr, info->size); in parse_elf_finish()
590 if (info->hdr->e_machine == EM_PPC) in ignore_undef_symbol()
599 if (info->hdr->e_machine == EM_PPC64) in ignore_undef_symbol()
614 switch (sym->st_shndx) { in handle_symbol()
619 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); in handle_symbol()
623 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in handle_symbol()
624 ELF_ST_BIND(sym->st_info) != STB_WEAK) in handle_symbol()
628 if (info->hdr->e_machine == EM_SPARC || in handle_symbol()
629 info->hdr->e_machine == EM_SPARCV9) { in handle_symbol()
631 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) in handle_symbol()
642 ELF_ST_BIND(sym->st_info) == STB_WEAK); in handle_symbol()
646 mod->has_init = true; in handle_symbol()
648 mod->has_cleanup = true; in handle_symbol()
658 /* Skip non-zero chars */ in next_string()
661 if ((*secsize)-- <= 1) in next_string()
668 if ((*secsize)-- <= 1) in next_string()
679 char *modinfo = info->modinfo; in get_next_modinfo()
680 unsigned long size = info->modinfo_len; in get_next_modinfo()
683 size -= prev - modinfo; in get_next_modinfo()
702 return sym ? elf->strtab + sym->st_name : ""; in sym_name()
736 ".GCC.command.line", /* record-gcc-switches */
751 ".llvm.call-graph-profile", /* call graph */
765 if (sechdr->sh_type == SHT_PROGBITS && in check_section()
766 !(sechdr->sh_flags & SHF_ALLOC) && in check_section()
768 warn("%s (%s): unexpected non-allocatable section.\n" in check_section()
814 * this array is forbidden (black-list). Can be empty.
817 * targeting sections in this array (white-list). Can be empty.
856 /* If you're adding any new black-listed sections in here, consider
872 * handling relocations to un-resolved symbols, trying to match it in section_mismatch()
882 if (match(fromsec, check->fromsec)) { in section_mismatch()
883 if (check->bad_tosec[0] && match(tosec, check->bad_tosec)) in section_mismatch()
885 if (check->good_tosec[0] && !match(tosec, check->good_tosec)) in section_mismatch()
917 * these from non-init sections as these symbols don't have any memory
926 * in functions like cpumask_empty() -- generating an associated symbol
1000 if (secndx >= elf->num_sections) in is_executable_section()
1003 return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0; in is_executable_section()
1023 /* check whitelist - we may ignore it */ in default_mismatch_handler()
1036 warn("%s: section mismatch in reference: %s%s0x%x (section: %s) -> %s (section: %s)\n", in default_mismatch_handler()
1038 (unsigned int)(faddr - (fromsym[0] ? from->st_value : 0)), in default_mismatch_handler()
1041 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { in default_mismatch_handler()
1042 if (match(tosec, mismatch->bad_tosec)) in default_mismatch_handler()
1044 "section \"%s\" which is black-listed.\n" in default_mismatch_handler()
1059 error("%s+0x%lx references non-executable section '%s'\n", in default_mismatch_handler()
1074 label = find_fromsym(elf, faddr, elf->export_symbol_secndx); in check_export_symbol()
1079 mod->name, label_name); in check_export_symbol()
1083 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && in check_export_symbol()
1084 ELF_ST_BIND(sym->st_info) != STB_WEAK) { in check_export_symbol()
1085 error("%s: local symbol '%s' was exported\n", mod->name, in check_export_symbol()
1093 mod->name, name); in check_export_symbol()
1104 mod->name, data, name); in check_export_symbol()
1115 s->is_func = (ELF_ST_TYPE(sym->st_info) == STT_FUNC); in check_export_symbol()
1121 if (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64 && in check_export_symbol()
1122 elf->hdr->e_machine == EM_PARISC && in check_export_symbol()
1123 ELF_ST_TYPE(sym->st_info) == STT_LOPROC) in check_export_symbol()
1124 s->is_func = true; in check_export_symbol()
1128 mod->name, name); in check_export_symbol()
1131 mod->name, name); in check_export_symbol()
1142 if (module_enabled && elf->export_symbol_secndx == fsecndx) { in check_section_mismatch()
1151 default_mismatch_handler(mod->name, elf, mismatch, sym, in check_section_mismatch()
1165 return (Elf_Addr)(-1); in addend_386_rel()
1170 uint8_t shift = 31 - index; in sign_extend32()
1184 return inst + sym->st_value; in addend_arm_rel()
1190 return offset + sym->st_value; in addend_arm_rel()
1196 return offset + sym->st_value + 8; in addend_arm_rel()
1206 return offset + sym->st_value; in addend_arm_rel()
1227 return offset + sym->st_value + 4; in addend_arm_rel()
1253 return offset + sym->st_value + 4; in addend_arm_rel()
1256 return (Elf_Addr)(-1); in addend_arm_rel()
1272 return (Elf_Addr)(-1); in addend_mips_rel()
1310 bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64); in get_rel_type_and_sym()
1312 if (elf->hdr->e_machine == EM_MIPS && is_64bit) { in get_rel_type_and_sym()
1315 *r_type = mips64_r_info->r_type; in get_rel_type_and_sym()
1316 *r_sym = TO_NATIVE(mips64_r_info->r_sym); in get_rel_type_and_sym()
1340 r_offset = TO_NATIVE(rela->r_offset); in section_rela()
1341 get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); in section_rela()
1343 tsym = elf->symtab_start + r_sym; in section_rela()
1344 taddr = tsym->st_value + TO_NATIVE(rela->r_addend); in section_rela()
1346 switch (elf->hdr->e_machine) { in section_rela()
1383 r_offset = TO_NATIVE(rel->r_offset); in section_rel()
1384 get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); in section_rel()
1387 tsym = elf->symtab_start + r_sym; in section_rel()
1389 switch (elf->hdr->e_machine) { in section_rel()
1410 * either when loaded or when used as built-in.
1413 * Likewise for modules used built-in the sections marked __exit
1415 * only when a module is unloaded which never happens for built-in modules.
1425 for (i = 0; i < elf->num_sections; i++) { in check_sec_ref()
1426 Elf_Shdr *sechdr = &elf->sechdrs[i]; in check_sec_ref()
1428 check_section(mod->name, elf, sechdr); in check_sec_ref()
1430 if (sechdr->sh_type == SHT_REL || sechdr->sh_type == SHT_RELA) { in check_sec_ref()
1432 unsigned int secndx = sechdr->sh_info; in check_sec_ref()
1441 stop = start + sechdr->sh_size; in check_sec_ref()
1443 if (sechdr->sh_type == SHT_RELA) in check_sec_ref()
1477 dirlen = base - object; in extract_crcs_for_object()
1501 namelen = p - name; in extract_crcs_for_object()
1537 if (mod->is_vmlinux) { in mod_set_crcs()
1541 ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name); in mod_set_crcs()
1576 mod = new_module(modname, strlen(modname) - strlen(".o")); in read_symbols()
1580 mod->no_trim_symbol = xmalloc(info.no_trim_symbol_len); in read_symbols()
1581 memcpy(mod->no_trim_symbol, info.no_trim_symbol, in read_symbols()
1583 mod->no_trim_symbol_len = info.no_trim_symbol_len; in read_symbols()
1586 if (!mod->is_vmlinux) { in read_symbols()
1592 mod->is_gpl_compatible = false; in read_symbols()
1600 add_namespace(&mod->imported_namespaces, namespace); in read_symbols()
1610 symname = remove_dot(info.strtab + sym->st_name); in read_symbols()
1618 if (!mod->is_vmlinux) { in read_symbols()
1621 get_src_version(mod->name, mod->srcversion, in read_symbols()
1622 sizeof(mod->srcversion) - 1); in read_symbols()
1629 * Our trick to get versioning for module struct etc. - it's in read_symbols()
1651 fname[strlen(fname)-1] = '\0'; in read_symbols_from_files()
1679 if (buf->size - buf->pos < len) { in buf_write()
1680 buf->size += len + SZ; in buf_write()
1681 buf->p = xrealloc(buf->p, buf->size); in buf_write()
1683 strncpy(buf->p + buf->pos, s, len); in buf_write()
1684 buf->pos += len; in buf_write()
1691 list_for_each_entry(s, &mod->unresolved_symbols, list) { in check_exports()
1693 exp = find_symbol(s->name); in check_exports()
1695 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS) in check_exports()
1698 s->name, mod->name); in check_exports()
1701 if (exp->module == mod) { in check_exports()
1703 s->name, mod->name); in check_exports()
1707 exp->used = true; in check_exports()
1708 s->module = exp->module; in check_exports()
1709 s->crc_valid = exp->crc_valid; in check_exports()
1710 s->crc = exp->crc; in check_exports()
1712 basename = get_basename(mod->name); in check_exports()
1714 if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) { in check_exports()
1717 basename, exp->name, exp->namespace); in check_exports()
1718 add_namespace(&mod->missing_namespaces, exp->namespace); in check_exports()
1721 if (!mod->is_gpl_compatible && exp->is_gpl_only) in check_exports()
1722 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n", in check_exports()
1723 basename, exp->name); in check_exports()
1738 sym->used = true; in handle_white_list_exports()
1751 unsigned long size = mod->no_trim_symbol_len; in keep_no_trim_symbols()
1753 for (char *s = mod->no_trim_symbol; s; s = next_string(s , &size)) { in keep_no_trim_symbols()
1762 sym->used = true; in keep_no_trim_symbols()
1770 mod_name = get_basename(mod->name); in check_modname_len()
1773 error("module name is too long [%s.ko]\n", mod->name); in check_modname_len()
1782 buf_printf(b, "#include <linux/export-internal.h>\n"); in add_header()
1790 if (mod->has_init) in add_header()
1792 if (mod->has_cleanup) in add_header()
1802 if (strstarts(mod->name, "drivers/staging")) in add_header()
1805 if (strstarts(mod->name, "tools/testing")) in add_header()
1815 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1816 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1820 sym->is_func ? "FUNC" : "DATA", sym->name, in add_exported_symbols()
1821 sym->is_gpl_only ? "_gpl" : "", sym->namespace); in add_exported_symbols()
1829 list_for_each_entry(sym, &mod->exported_symbols, list) { in add_exported_symbols()
1830 if (trim_unused_exports && !sym->used) in add_exported_symbols()
1833 if (!sym->crc_valid) in add_exported_symbols()
1835 "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n", in add_exported_symbols()
1836 sym->name, mod->name, mod->is_vmlinux ? "" : ".ko", in add_exported_symbols()
1837 sym->name); in add_exported_symbols()
1840 sym->name, sym->crc, sym->is_gpl_only ? "_gpl" : ""); in add_exported_symbols()
1857 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_extended_versions()
1858 if (!s->module) in add_extended_versions()
1860 if (!s->crc_valid) { in add_extended_versions()
1862 s->name, mod->name); in add_extended_versions()
1865 buf_printf(b, "\t0x%08x,\n", s->crc); in add_extended_versions()
1871 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_extended_versions()
1872 if (!s->module) in add_extended_versions()
1874 if (!s->crc_valid) in add_extended_versions()
1882 buf_printf(b, "\t\"%s\\0\"\n", s->name); in add_extended_versions()
1901 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_versions()
1902 if (!s->module) in add_versions()
1904 if (!s->crc_valid) { in add_versions()
1906 s->name, mod->name); in add_versions()
1909 if (strlen(s->name) >= MODULE_NAME_LEN) { in add_versions()
1915 s->name, mod->name); in add_versions()
1920 s->crc, s->name); in add_versions()
1931 /* Clear ->seen flag of modules that own symbols needed by this. */ in add_depends()
1932 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
1933 if (s->module) in add_depends()
1934 s->module->seen = s->module->is_vmlinux; in add_depends()
1939 list_for_each_entry(s, &mod->unresolved_symbols, list) { in add_depends()
1941 if (!s->module) in add_depends()
1944 if (s->module->seen) in add_depends()
1947 s->module->seen = true; in add_depends()
1948 p = get_basename(s->module->name); in add_depends()
1957 if (mod->srcversion[0]) { in add_srcversion()
1960 mod->srcversion); in add_srcversion()
1976 if (fwrite(b->p, 1, b->pos, file) != b->pos) { in write_buf()
1999 if (st.st_size != b->pos) in write_if_changed()
2002 tmp = xmalloc(b->pos); in write_if_changed()
2003 if (fread(tmp, 1, b->pos, file) != b->pos) in write_if_changed()
2006 if (memcmp(tmp, b->p, b->pos) != 0) in write_if_changed()
2026 "#include <linux/export-internal.h>\n"); in write_vmlinux_export_c_file()
2048 list_for_each_entry_safe(alias, next, &mod->aliases, node) { in write_mod_c_file()
2049 buf_printf(&buf, "MODULE_ALIAS(\"%s\");\n", alias->str); in write_mod_c_file()
2050 list_del(&alias->node); in write_mod_c_file()
2056 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name); in write_mod_c_file()
2118 mod->dump_file = fname; in read_dump()
2137 if (mod->dump_file) in write_dump()
2139 list_for_each_entry(sym, &mod->exported_symbols, list) { in write_dump()
2140 if (trim_unused_exports && !sym->used) in write_dump()
2144 sym->crc, sym->name, mod->name, in write_dump()
2145 sym->is_gpl_only ? "_GPL" : "", in write_dump()
2146 sym->namespace); in write_dump()
2161 if (mod->dump_file || list_empty(&mod->missing_namespaces)) in write_namespace_deps_files()
2164 buf_printf(&ns_deps_buf, "%s.ko:", mod->name); in write_namespace_deps_files()
2166 list_for_each_entry(ns, &mod->missing_namespaces, list) in write_namespace_deps_files()
2167 buf_printf(&ns_deps_buf, " %s", ns->namespace); in write_namespace_deps_files()
2210 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:xb")) != -1) { in main()
2217 dl->file = optarg; in main()
2218 list_add_tail(&dl->list, &dump_lists); in main()
2273 read_dump(dl->file); in main()
2274 list_del(&dl->list); in main()
2287 if (mod->dump_file || mod->is_vmlinux) in main()
2298 if (mod->dump_file) in main()
2301 if (mod->is_vmlinux) in main()
2318 nr_unresolved - MAX_UNRESOLVED_REPORTS); in main()