Lines Matching +full:test +full:- +full:tab

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;
104 * get_basename - return the last part of a pathname.
146 nbytes -= bytes_read;
181 if (!strcmp(mod->dump_file, filename) &&
182 !strcmp(mod->name, modname))
195 INIT_LIST_HEAD(&mod->exported_symbols);
196 INIT_LIST_HEAD(&mod->unresolved_symbols);
197 INIT_LIST_HEAD(&mod->missing_namespaces);
198 INIT_LIST_HEAD(&mod->imported_namespaces);
199 INIT_LIST_HEAD(&mod->aliases);
201 memcpy(mod->name, name, namelen);
202 mod->name[namelen] = '\0';
203 mod->is_vmlinux = (strcmp(mod->name, "vmlinux") == 0);
206 * Set mod->is_gpl_compatible to true by default. If MODULE_LICENSE()
210 mod->is_gpl_compatible = true;
212 list_add_tail(&mod->list, &modules);
242 strcpy(s->name, name);
249 return sym->is_gpl_only ? KSYM_FLAG_GPL_ONLY : 0;
255 hash_add(symbol_hashtable, &sym->hnode, hash_str(sym->name));
263 sym->weak = weak;
265 list_add_tail(&sym->list, &mod->unresolved_symbols);
277 if (strcmp(s->name, name) == 0 && (!mod || s->module == mod))
305 if (!strcmp(list->namespace, namespace))
318 strcpy(ns_entry->namespace, namespace);
319 list_add_tail(&ns_entry->list, head);
326 Elf_Shdr *sechdr = &info->sechdrs[secindex];
328 return (void *)info->hdr + sechdr->sh_offset + offset;
334 sym->st_value);
339 return sym_get_data_by_offset(info, info->secindex_strings,
340 sechdr->sh_name);
346 * If sym->st_shndx is a special section index, there is no
348 * Return "" if the index is out of range of info->sechdrs[] array.
350 if (secindex >= info->num_sections)
353 return sech_name(info, &info->sechdrs[secindex]);
361 if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) {
363 mod->name, name, s->module->name,
364 s->module->is_vmlinux ? "" : ".ko");
368 s->module = mod;
369 s->is_gpl_only = gpl_only;
370 s->namespace = xstrdup(namespace);
371 list_add_tail(&s->list, &mod->exported_symbols);
379 sym->crc = crc;
380 sym->crc_valid = true;
419 hdr = grab_file(filename, &info->size);
429 info->hdr = hdr;
430 if (info->size < sizeof(*hdr)) {
435 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
436 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
437 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
438 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
439 /* Not an ELF file - silently ignore it */
443 switch (hdr->e_ident[EI_DATA]) {
455 hdr->e_type = TO_NATIVE(hdr->e_type);
456 hdr->e_machine = TO_NATIVE(hdr->e_machine);
457 hdr->e_version = TO_NATIVE(hdr->e_version);
458 hdr->e_entry = TO_NATIVE(hdr->e_entry);
459 hdr->e_phoff = TO_NATIVE(hdr->e_phoff);
460 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
461 hdr->e_flags = TO_NATIVE(hdr->e_flags);
462 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize);
463 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize);
464 hdr->e_phnum = TO_NATIVE(hdr->e_phnum);
465 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize);
466 hdr->e_shnum = TO_NATIVE(hdr->e_shnum);
467 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
468 sechdrs = (void *)hdr + hdr->e_shoff;
469 info->sechdrs = sechdrs;
472 if (hdr->e_type != ET_REL)
476 if (hdr->e_shoff > info->size)
478 (unsigned long)hdr->e_shoff, filename, info->size);
480 if (hdr->e_shnum == SHN_UNDEF) {
485 info->num_sections = TO_NATIVE(sechdrs[0].sh_size);
488 info->num_sections = hdr->e_shnum;
490 if (hdr->e_shstrndx == SHN_XINDEX) {
491 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link);
494 info->secindex_strings = hdr->e_shstrndx;
498 for (i = 0; i < info->num_sections; i++) {
511 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset;
512 for (i = 1; i < info->num_sections; i++) {
516 if (!nobits && sechdrs[i].sh_offset > info->size)
525 info->modinfo = (void *)hdr + sechdrs[i].sh_offset;
526 info->modinfo_len = sechdrs[i].sh_size;
528 info->export_symbol_secndx = i;
530 info->no_trim_symbol = (void *)hdr + sechdrs[i].sh_offset;
531 info->no_trim_symbol_len = sechdrs[i].sh_size;
537 info->symtab_start = (void *)hdr +
539 info->symtab_stop = (void *)hdr +
542 info->strtab = (void *)hdr +
549 info->symtab_shndx_start = (void *)hdr +
551 info->symtab_shndx_stop = (void *)hdr +
555 if (!info->symtab_start)
559 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
560 sym->st_shndx = TO_NATIVE(sym->st_shndx);
561 sym->st_name = TO_NATIVE(sym->st_name);
562 sym->st_value = TO_NATIVE(sym->st_value);
563 sym->st_size = TO_NATIVE(sym->st_size);
573 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop;
586 release_file(info->hdr, info->size);
597 if (info->hdr->e_machine == EM_PPC)
606 if (info->hdr->e_machine == EM_PPC64)
619 /* ignore linker-created section bounds variables */
630 switch (sym->st_shndx) {
635 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name);
639 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
640 ELF_ST_BIND(sym->st_info) != STB_WEAK)
644 if (info->hdr->e_machine == EM_SPARC ||
645 info->hdr->e_machine == EM_SPARCV9) {
647 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
658 ELF_ST_BIND(sym->st_info) == STB_WEAK);
662 mod->has_init = true;
664 mod->has_cleanup = true;
674 /* Skip non-zero chars */
677 if ((*secsize)-- <= 1)
684 if ((*secsize)-- <= 1)
695 char *modinfo = info->modinfo;
696 unsigned long size = info->modinfo_len;
699 size -= prev - modinfo;
718 return sym ? elf->strtab + sym->st_name : "";
752 ".GCC.command.line", /* record-gcc-switches */
767 ".llvm.call-graph-profile", /* call graph */
783 if (sechdr->sh_type == SHT_PROGBITS &&
784 !(sechdr->sh_flags & SHF_ALLOC) &&
786 warn("%s (%s): unexpected non-allocatable section.\n"
832 * this array is forbidden (black-list). Can be empty.
835 * targeting sections in this array (white-list). Can be empty.
874 /* If you're adding any new black-listed sections in here, consider
890 * handling relocations to un-resolved symbols, trying to match it
900 if (match(fromsec, check->fromsec)) {
901 if (check->bad_tosec[0] && match(tosec, check->bad_tosec))
903 if (check->good_tosec[0] && !match(tosec, check->good_tosec))
935 * these from non-init sections as these symbols don't have any memory
944 * in functions like cpumask_empty() -- generating an associated symbol
1018 if (secndx >= elf->num_sections)
1021 return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
1041 /* check whitelist - we may ignore it */
1054 warn("%s: section mismatch in reference: %s%s0x%x (section: %s) -> %s (section: %s)\n",
1056 (unsigned int)(faddr - (fromsym[0] ? from->st_value : 0)),
1059 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
1060 if (match(tosec, mismatch->bad_tosec))
1062 "section \"%s\" which is black-listed.\n"
1077 error("%s+0x%lx references non-executable section '%s'\n",
1092 label = find_fromsym(elf, faddr, elf->export_symbol_secndx);
1097 mod->name, label_name);
1101 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
1102 ELF_ST_BIND(sym->st_info) != STB_WEAK) {
1103 error("%s: local symbol '%s' was exported\n", mod->name,
1111 mod->name, name);
1122 mod->name, data, name);
1133 s->is_func = (ELF_ST_TYPE(sym->st_info) == STT_FUNC);
1139 if (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64 &&
1140 elf->hdr->e_machine == EM_PARISC &&
1141 ELF_ST_TYPE(sym->st_info) == STT_LOPROC)
1142 s->is_func = true;
1146 mod->name, name);
1149 mod->name, name);
1160 if (module_enabled && elf->export_symbol_secndx == fsecndx) {
1169 default_mismatch_handler(mod->name, elf, mismatch, sym,
1183 return (Elf_Addr)(-1);
1188 uint8_t shift = 31 - index;
1202 return inst + sym->st_value;
1208 return offset + sym->st_value;
1214 return offset + sym->st_value + 8;
1224 return offset + sym->st_value;
1245 return offset + sym->st_value + 4;
1271 return offset + sym->st_value + 4;
1274 return (Elf_Addr)(-1);
1290 return (Elf_Addr)(-1);
1328 bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64);
1330 if (elf->hdr->e_machine == EM_MIPS && is_64bit) {
1333 *r_type = mips64_r_info->r_type;
1334 *r_sym = TO_NATIVE(mips64_r_info->r_sym);
1358 r_offset = TO_NATIVE(rela->r_offset);
1359 get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym);
1361 tsym = elf->symtab_start + r_sym;
1362 taddr = tsym->st_value + TO_NATIVE(rela->r_addend);
1364 switch (elf->hdr->e_machine) {
1401 r_offset = TO_NATIVE(rel->r_offset);
1402 get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym);
1405 tsym = elf->symtab_start + r_sym;
1407 switch (elf->hdr->e_machine) {
1428 * either when loaded or when used as built-in.
1431 * Likewise for modules used built-in the sections marked __exit
1433 * only when a module is unloaded which never happens for built-in modules.
1443 for (i = 0; i < elf->num_sections; i++) {
1444 Elf_Shdr *sechdr = &elf->sechdrs[i];
1446 check_section(mod->name, elf, sechdr);
1448 if (sechdr->sh_type == SHT_REL || sechdr->sh_type == SHT_RELA) {
1450 unsigned int secndx = sechdr->sh_info;
1459 stop = start + sechdr->sh_size;
1461 if (sechdr->sh_type == SHT_RELA)
1495 dirlen = base - object;
1497 baselen_without_suffix = strlen(object) - dirlen - strlen(".o");
1500 * When CONFIG_LTO_CLANG_THIN_DIST=y, the ELF is *.thinlto-native.o
1503 if (strends(object, ".thinlto-native.o"))
1504 baselen_without_suffix -= strlen(".thinlto-native");
1528 namelen = p - name;
1564 if (mod->is_vmlinux) {
1568 ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name);
1603 mod = new_module(modname, strlen(modname) - strlen(".o"));
1607 mod->no_trim_symbol = xmalloc(info.no_trim_symbol_len);
1608 memcpy(mod->no_trim_symbol, info.no_trim_symbol,
1610 mod->no_trim_symbol_len = info.no_trim_symbol_len;
1613 if (!mod->is_vmlinux) {
1619 mod->is_gpl_compatible = false;
1630 mod->name, namespace);
1632 add_namespace(&mod->imported_namespaces, namespace);
1640 symname = remove_dot(info.strtab + sym->st_name);
1648 if (!mod->is_vmlinux) {
1651 get_src_version(mod->name, mod->srcversion,
1652 sizeof(mod->srcversion) - 1);
1659 * Our trick to get versioning for module struct etc. - it's
1681 fname[strlen(fname)-1] = '\0';
1718 if (buf->size - buf->pos < len) {
1719 buf->size += len + SZ;
1720 buf->p = xrealloc(buf->p, buf->size);
1722 strncpy(buf->p + buf->pos, s, len);
1723 buf->pos += len;
1727 * verify_module_namespace() - does @modname have access to this symbol's @namespace
1732 * then test if @modname matches any of the comma separated patterns.
1734 * The patterns only support tail-glob.
1748 len = sep - namespace;
1751 if (sep[-1] == '*') {
1752 len--;
1770 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1772 exp = find_symbol(s->name);
1774 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
1777 s->name, mod->name);
1780 if (exp->module == mod) {
1782 s->name, mod->name);
1786 exp->used = true;
1787 s->module = exp->module;
1788 s->crc_valid = exp->crc_valid;
1789 s->crc = exp->crc;
1791 basename = get_basename(mod->name);
1793 if (!verify_module_namespace(exp->namespace, basename) &&
1794 !contains_namespace(&mod->imported_namespaces, exp->namespace)) {
1797 basename, exp->name, exp->namespace);
1798 add_namespace(&mod->missing_namespaces, exp->namespace);
1801 if (!mod->is_gpl_compatible && exp->is_gpl_only)
1802 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
1803 basename, exp->name);
1818 sym->used = true;
1831 unsigned long size = mod->no_trim_symbol_len;
1833 for (char *s = mod->no_trim_symbol; s; s = next_string(s , &size)) {
1842 sym->used = true;
1850 mod_name = get_basename(mod->name);
1853 error("module name is too long [%s.ko]\n", mod->name);
1862 buf_printf(b, "#include <linux/export-internal.h>\n");
1870 if (mod->has_init)
1872 if (mod->has_cleanup)
1882 if (strstarts(mod->name, "drivers/staging"))
1885 if (strstarts(mod->name, "tools/testing"))
1886 buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n");
1895 list_for_each_entry(sym, &mod->exported_symbols, list) {
1896 if (trim_unused_exports && !sym->used)
1900 sym->is_func ? "FUNC" : "DATA", sym->name,
1901 sym->namespace);
1904 sym->name, get_symbol_flags(sym));
1912 list_for_each_entry(sym, &mod->exported_symbols, list) {
1913 if (trim_unused_exports && !sym->used)
1916 if (!sym->crc_valid)
1918 "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n",
1919 sym->name, mod->name, mod->is_vmlinux ? "" : ".ko",
1920 sym->name);
1923 sym->name, sym->crc);
1940 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1941 if (!s->module)
1943 if (!s->crc_valid) {
1945 s->name, mod->name);
1948 buf_printf(b, "\t0x%08x,\n", s->crc);
1954 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1955 if (!s->module)
1957 if (!s->crc_valid)
1965 buf_printf(b, "\t\"%s\\0\"\n", s->name);
1984 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1985 if (!s->module)
1987 if (!s->crc_valid) {
1989 s->name, mod->name);
1992 if (strlen(s->name) >= MODULE_NAME_LEN) {
1998 s->name, mod->name);
2003 s->crc, s->name);
2014 /* Clear ->seen flag of modules that own symbols needed by this. */
2015 list_for_each_entry(s, &mod->unresolved_symbols, list) {
2016 if (s->module)
2017 s->module->seen = s->module->is_vmlinux;
2022 list_for_each_entry(s, &mod->unresolved_symbols, list) {
2024 if (!s->module)
2027 if (s->module->seen)
2030 s->module->seen = true;
2031 p = get_basename(s->module->name);
2040 if (mod->srcversion[0]) {
2043 mod->srcversion);
2059 if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2082 if (st.st_size != b->pos)
2085 tmp = xmalloc(b->pos);
2086 if (fread(tmp, 1, b->pos, file) != b->pos)
2089 if (memcmp(tmp, b->p, b->pos) != 0)
2110 "#include <linux/export-internal.h>\n");
2119 list_for_each_entry_safe(alias, next, &mod->aliases, node) {
2121 alias->builtin_modname, alias->str);
2122 list_del(&alias->node);
2123 free(alias->builtin_modname);
2146 list_for_each_entry_safe(alias, next, &mod->aliases, node) {
2147 buf_printf(&buf, "MODULE_ALIAS(\"%s\");\n", alias->str);
2148 list_del(&alias->node);
2154 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
2167 * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
2216 mod->dump_file = fname;
2235 if (mod->dump_file)
2237 list_for_each_entry(sym, &mod->exported_symbols, list) {
2238 if (trim_unused_exports && !sym->used)
2242 sym->crc, sym->name, mod->name,
2243 sym->is_gpl_only ? "_GPL" : "",
2244 sym->namespace);
2259 if (mod->dump_file || list_empty(&mod->missing_namespaces))
2262 buf_printf(&ns_deps_buf, "%s.ko:", mod->name);
2264 list_for_each_entry(ns, &mod->missing_namespaces, list)
2265 buf_printf(&ns_deps_buf, " %s", ns->namespace);
2308 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:xb")) != -1) {
2315 dl->file = optarg;
2316 list_add_tail(&dl->list, &dump_lists);
2371 read_dump(dl->file);
2372 list_del(&dl->list);
2385 if (mod->dump_file || mod->is_vmlinux)
2396 if (mod->dump_file)
2399 if (mod->is_vmlinux)
2416 nr_unresolved - MAX_UNRESOLVED_REPORTS);