Lines Matching +full:lower +full:- +full:case
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);
250 hash_add(symbol_hashtable, &sym->hnode, hash_str(sym->name));
258 sym->weak = weak;
260 list_add_tail(&sym->list, &mod->unresolved_symbols);
272 if (strcmp(s->name, name) == 0 && (!mod || s->module == mod))
300 if (!strcmp(list->namespace, namespace))
313 strcpy(ns_entry->namespace, namespace);
314 list_add_tail(&ns_entry->list, head);
321 Elf_Shdr *sechdr = &info->sechdrs[secindex];
323 return (void *)info->hdr + sechdr->sh_offset + offset;
329 sym->st_value);
334 return sym_get_data_by_offset(info, info->secindex_strings,
335 sechdr->sh_name);
341 * If sym->st_shndx is a special section index, there is no
343 * Return "" if the index is out of range of info->sechdrs[] array.
345 if (secindex >= info->num_sections)
348 return sech_name(info, &info->sechdrs[secindex]);
356 if (s && (!external_module || s->module->is_vmlinux || s->module == mod)) {
358 mod->name, name, s->module->name,
359 s->module->is_vmlinux ? "" : ".ko");
363 s->module = mod;
364 s->is_gpl_only = gpl_only;
365 s->namespace = xstrdup(namespace);
366 list_add_tail(&s->list, &mod->exported_symbols);
374 sym->crc = crc;
375 sym->crc_valid = true;
414 hdr = grab_file(filename, &info->size);
424 info->hdr = hdr;
425 if (info->size < sizeof(*hdr)) {
430 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
431 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
432 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
433 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
434 /* Not an ELF file - silently ignore it */
438 switch (hdr->e_ident[EI_DATA]) {
439 case ELFDATA2LSB:
442 case ELFDATA2MSB:
450 hdr->e_type = TO_NATIVE(hdr->e_type);
451 hdr->e_machine = TO_NATIVE(hdr->e_machine);
452 hdr->e_version = TO_NATIVE(hdr->e_version);
453 hdr->e_entry = TO_NATIVE(hdr->e_entry);
454 hdr->e_phoff = TO_NATIVE(hdr->e_phoff);
455 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
456 hdr->e_flags = TO_NATIVE(hdr->e_flags);
457 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize);
458 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize);
459 hdr->e_phnum = TO_NATIVE(hdr->e_phnum);
460 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize);
461 hdr->e_shnum = TO_NATIVE(hdr->e_shnum);
462 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
463 sechdrs = (void *)hdr + hdr->e_shoff;
464 info->sechdrs = sechdrs;
467 if (hdr->e_type != ET_REL)
471 if (hdr->e_shoff > info->size)
473 (unsigned long)hdr->e_shoff, filename, info->size);
475 if (hdr->e_shnum == SHN_UNDEF) {
480 info->num_sections = TO_NATIVE(sechdrs[0].sh_size);
483 info->num_sections = hdr->e_shnum;
485 if (hdr->e_shstrndx == SHN_XINDEX) {
486 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link);
489 info->secindex_strings = hdr->e_shstrndx;
493 for (i = 0; i < info->num_sections; i++) {
506 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset;
507 for (i = 1; i < info->num_sections; i++) {
511 if (!nobits && sechdrs[i].sh_offset > info->size)
520 info->modinfo = (void *)hdr + sechdrs[i].sh_offset;
521 info->modinfo_len = sechdrs[i].sh_size;
523 info->export_symbol_secndx = i;
525 info->no_trim_symbol = (void *)hdr + sechdrs[i].sh_offset;
526 info->no_trim_symbol_len = sechdrs[i].sh_size;
532 info->symtab_start = (void *)hdr +
534 info->symtab_stop = (void *)hdr +
537 info->strtab = (void *)hdr +
544 info->symtab_shndx_start = (void *)hdr +
546 info->symtab_shndx_stop = (void *)hdr +
550 if (!info->symtab_start)
554 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
555 sym->st_shndx = TO_NATIVE(sym->st_shndx);
556 sym->st_name = TO_NATIVE(sym->st_name);
557 sym->st_value = TO_NATIVE(sym->st_value);
558 sym->st_size = TO_NATIVE(sym->st_size);
568 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop;
581 release_file(info->hdr, info->size);
592 if (info->hdr->e_machine == EM_PPC)
601 if (info->hdr->e_machine == EM_PPC64)
616 switch (sym->st_shndx) {
617 case SHN_COMMON:
621 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name);
623 case SHN_UNDEF:
625 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
626 ELF_ST_BIND(sym->st_info) != STB_WEAK)
630 if (info->hdr->e_machine == EM_SPARC ||
631 info->hdr->e_machine == EM_SPARCV9) {
633 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
644 ELF_ST_BIND(sym->st_info) == STB_WEAK);
648 mod->has_init = true;
650 mod->has_cleanup = true;
660 /* Skip non-zero chars */
663 if ((*secsize)-- <= 1)
670 if ((*secsize)-- <= 1)
681 char *modinfo = info->modinfo;
682 unsigned long size = info->modinfo_len;
685 size -= prev - modinfo;
704 return sym ? elf->strtab + sym->st_name : "";
738 ".GCC.command.line", /* record-gcc-switches */
753 ".llvm.call-graph-profile", /* call graph */
767 if (sechdr->sh_type == SHT_PROGBITS &&
768 !(sechdr->sh_flags & SHF_ALLOC) &&
770 warn("%s (%s): unexpected non-allocatable section.\n"
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
884 if (match(fromsec, check->fromsec)) {
885 if (check->bad_tosec[0] && match(tosec, check->bad_tosec))
887 if (check->good_tosec[0] && !match(tosec, check->good_tosec))
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)
1005 return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
1025 /* check whitelist - we may ignore it */
1038 warn("%s: section mismatch in reference: %s%s0x%x (section: %s) -> %s (section: %s)\n",
1040 (unsigned int)(faddr - (fromsym[0] ? from->st_value : 0)),
1043 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
1044 if (match(tosec, mismatch->bad_tosec))
1046 "section \"%s\" which is black-listed.\n"
1061 error("%s+0x%lx references non-executable section '%s'\n",
1076 label = find_fromsym(elf, faddr, elf->export_symbol_secndx);
1081 mod->name, label_name);
1085 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
1086 ELF_ST_BIND(sym->st_info) != STB_WEAK) {
1087 error("%s: local symbol '%s' was exported\n", mod->name,
1095 mod->name, name);
1106 mod->name, data, name);
1117 s->is_func = (ELF_ST_TYPE(sym->st_info) == STT_FUNC);
1123 if (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64 &&
1124 elf->hdr->e_machine == EM_PARISC &&
1125 ELF_ST_TYPE(sym->st_info) == STT_LOPROC)
1126 s->is_func = true;
1130 mod->name, name);
1133 mod->name, name);
1144 if (module_enabled && elf->export_symbol_secndx == fsecndx) {
1153 default_mismatch_handler(mod->name, elf, mismatch, sym,
1161 case R_386_32:
1163 case R_386_PC32:
1167 return (Elf_Addr)(-1);
1172 uint8_t shift = 31 - index;
1179 uint32_t inst, upper, lower, sign, j1, j2;
1183 case R_ARM_ABS32:
1184 case R_ARM_REL32:
1186 return inst + sym->st_value;
1187 case R_ARM_MOVW_ABS_NC:
1188 case R_ARM_MOVT_ABS:
1192 return offset + sym->st_value;
1193 case R_ARM_PC24:
1194 case R_ARM_CALL:
1195 case R_ARM_JUMP24:
1198 return offset + sym->st_value + 8;
1199 case R_ARM_THM_MOVW_ABS_NC:
1200 case R_ARM_THM_MOVT_ABS:
1202 lower = get_unaligned_native((uint16_t *)loc + 1);
1205 ((lower & 0x7000) >> 4) |
1206 (lower & 0x00ff),
1208 return offset + sym->st_value;
1209 case R_ARM_THM_JUMP19:
1214 * J1 = lower[13]
1215 * J2 = lower[11]
1216 * imm11 = lower[10:0]
1220 lower = get_unaligned_native((uint16_t *)loc + 1);
1223 j1 = (lower >> 13) & 1;
1224 j2 = (lower >> 11) & 1;
1227 ((lower & 0x07ff) << 1),
1229 return offset + sym->st_value + 4;
1230 case R_ARM_THM_PC22:
1231 case R_ARM_THM_JUMP24:
1236 * J1 = lower[13]
1237 * J2 = lower[11]
1238 * imm11 = lower[10:0]
1244 lower = get_unaligned_native((uint16_t *)loc + 1);
1247 j1 = (lower >> 13) & 1;
1248 j2 = (lower >> 11) & 1;
1253 ((lower & 0x07ff) << 1),
1255 return offset + sym->st_value + 4;
1258 return (Elf_Addr)(-1);
1267 case R_MIPS_LO16:
1269 case R_MIPS_26:
1271 case R_MIPS_32:
1274 return (Elf_Addr)(-1);
1312 bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64);
1314 if (elf->hdr->e_machine == EM_MIPS && is_64bit) {
1317 *r_type = mips64_r_info->r_type;
1318 *r_sym = TO_NATIVE(mips64_r_info->r_sym);
1342 r_offset = TO_NATIVE(rela->r_offset);
1343 get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym);
1345 tsym = elf->symtab_start + r_sym;
1346 taddr = tsym->st_value + TO_NATIVE(rela->r_addend);
1348 switch (elf->hdr->e_machine) {
1349 case EM_RISCV:
1354 case EM_LOONGARCH:
1356 case R_LARCH_SUB32:
1360 case R_LARCH_RELAX:
1361 case R_LARCH_ALIGN:
1385 r_offset = TO_NATIVE(rel->r_offset);
1386 get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym);
1389 tsym = elf->symtab_start + r_sym;
1391 switch (elf->hdr->e_machine) {
1392 case EM_386:
1395 case EM_ARM:
1398 case EM_MIPS:
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.
1427 for (i = 0; i < elf->num_sections; i++) {
1428 Elf_Shdr *sechdr = &elf->sechdrs[i];
1430 check_section(mod->name, elf, sechdr);
1432 if (sechdr->sh_type == SHT_REL || sechdr->sh_type == SHT_RELA) {
1434 unsigned int secndx = sechdr->sh_info;
1443 stop = start + sechdr->sh_size;
1445 if (sechdr->sh_type == SHT_RELA)
1479 dirlen = base - object;
1503 namelen = p - name;
1539 if (mod->is_vmlinux) {
1543 ret = snprintf(objlist, sizeof(objlist), "%s.mod", mod->name);
1578 mod = new_module(modname, strlen(modname) - strlen(".o"));
1582 mod->no_trim_symbol = xmalloc(info.no_trim_symbol_len);
1583 memcpy(mod->no_trim_symbol, info.no_trim_symbol,
1585 mod->no_trim_symbol_len = info.no_trim_symbol_len;
1588 if (!mod->is_vmlinux) {
1594 mod->is_gpl_compatible = false;
1605 mod->name, namespace);
1607 add_namespace(&mod->imported_namespaces, namespace);
1615 symname = remove_dot(info.strtab + sym->st_name);
1623 if (!mod->is_vmlinux) {
1626 get_src_version(mod->name, mod->srcversion,
1627 sizeof(mod->srcversion) - 1);
1634 * Our trick to get versioning for module struct etc. - it's
1656 fname[strlen(fname)-1] = '\0';
1684 if (buf->size - buf->pos < len) {
1685 buf->size += len + SZ;
1686 buf->p = xrealloc(buf->p, buf->size);
1688 strncpy(buf->p + buf->pos, s, len);
1689 buf->pos += len;
1693 * verify_module_namespace() - does @modname have access to this symbol's @namespace
1700 * The patterns only support tail-glob.
1714 len = sep - namespace;
1717 if (sep[-1] == '*') {
1718 len--;
1736 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1738 exp = find_symbol(s->name);
1740 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
1743 s->name, mod->name);
1746 if (exp->module == mod) {
1748 s->name, mod->name);
1752 exp->used = true;
1753 s->module = exp->module;
1754 s->crc_valid = exp->crc_valid;
1755 s->crc = exp->crc;
1757 basename = get_basename(mod->name);
1759 if (!verify_module_namespace(exp->namespace, basename) &&
1760 !contains_namespace(&mod->imported_namespaces, exp->namespace)) {
1763 basename, exp->name, exp->namespace);
1764 add_namespace(&mod->missing_namespaces, exp->namespace);
1767 if (!mod->is_gpl_compatible && exp->is_gpl_only)
1768 error("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n",
1769 basename, exp->name);
1784 sym->used = true;
1797 unsigned long size = mod->no_trim_symbol_len;
1799 for (char *s = mod->no_trim_symbol; s; s = next_string(s , &size)) {
1808 sym->used = true;
1816 mod_name = get_basename(mod->name);
1819 error("module name is too long [%s.ko]\n", mod->name);
1828 buf_printf(b, "#include <linux/export-internal.h>\n");
1836 if (mod->has_init)
1838 if (mod->has_cleanup)
1848 if (strstarts(mod->name, "drivers/staging"))
1851 if (strstarts(mod->name, "tools/testing"))
1861 list_for_each_entry(sym, &mod->exported_symbols, list) {
1862 if (trim_unused_exports && !sym->used)
1866 sym->is_func ? "FUNC" : "DATA", sym->name,
1867 sym->is_gpl_only ? "_gpl" : "", sym->namespace);
1875 list_for_each_entry(sym, &mod->exported_symbols, list) {
1876 if (trim_unused_exports && !sym->used)
1879 if (!sym->crc_valid)
1881 "Is \"%s\" prototyped in <asm/asm-prototypes.h>?\n",
1882 sym->name, mod->name, mod->is_vmlinux ? "" : ".ko",
1883 sym->name);
1886 sym->name, sym->crc, sym->is_gpl_only ? "_gpl" : "");
1903 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1904 if (!s->module)
1906 if (!s->crc_valid) {
1908 s->name, mod->name);
1911 buf_printf(b, "\t0x%08x,\n", s->crc);
1917 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1918 if (!s->module)
1920 if (!s->crc_valid)
1928 buf_printf(b, "\t\"%s\\0\"\n", s->name);
1947 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1948 if (!s->module)
1950 if (!s->crc_valid) {
1952 s->name, mod->name);
1955 if (strlen(s->name) >= MODULE_NAME_LEN) {
1961 s->name, mod->name);
1966 s->crc, s->name);
1977 /* Clear ->seen flag of modules that own symbols needed by this. */
1978 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1979 if (s->module)
1980 s->module->seen = s->module->is_vmlinux;
1985 list_for_each_entry(s, &mod->unresolved_symbols, list) {
1987 if (!s->module)
1990 if (s->module->seen)
1993 s->module->seen = true;
1994 p = get_basename(s->module->name);
2003 if (mod->srcversion[0]) {
2006 mod->srcversion);
2022 if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2045 if (st.st_size != b->pos)
2048 tmp = xmalloc(b->pos);
2049 if (fread(tmp, 1, b->pos, file) != b->pos)
2052 if (memcmp(tmp, b->p, b->pos) != 0)
2073 "#include <linux/export-internal.h>\n");
2082 list_for_each_entry_safe(alias, next, &mod->aliases, node) {
2084 alias->builtin_modname, alias->str);
2085 list_del(&alias->node);
2086 free(alias->builtin_modname);
2109 list_for_each_entry_safe(alias, next, &mod->aliases, node) {
2110 buf_printf(&buf, "MODULE_ALIAS(\"%s\");\n", alias->str);
2111 list_del(&alias->node);
2117 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
2179 mod->dump_file = fname;
2198 if (mod->dump_file)
2200 list_for_each_entry(sym, &mod->exported_symbols, list) {
2201 if (trim_unused_exports && !sym->used)
2205 sym->crc, sym->name, mod->name,
2206 sym->is_gpl_only ? "_GPL" : "",
2207 sym->namespace);
2222 if (mod->dump_file || list_empty(&mod->missing_namespaces))
2225 buf_printf(&ns_deps_buf, "%s.ko:", mod->name);
2227 list_for_each_entry(ns, &mod->missing_namespaces, list)
2228 buf_printf(&ns_deps_buf, " %s", ns->namespace);
2250 case 0x0102:
2253 case 0x0201:
2271 while ((opt = getopt(argc, argv, "ei:MmnT:to:au:WwENd:xb")) != -1) {
2273 case 'e':
2276 case 'i':
2278 dl->file = optarg;
2279 list_add_tail(&dl->list, &dump_lists);
2281 case 'M':
2284 case 'm':
2287 case 'n':
2290 case 'o':
2293 case 'a':
2296 case 'T':
2299 case 't':
2302 case 'u':
2305 case 'W':
2308 case 'w':
2311 case 'E':
2314 case 'N':
2317 case 'd':
2320 case 'b':
2323 case 'x':
2334 read_dump(dl->file);
2335 list_del(&dl->list);
2348 if (mod->dump_file || mod->is_vmlinux)
2359 if (mod->dump_file)
2362 if (mod->is_vmlinux)
2379 nr_unresolved - MAX_UNRESOLVED_REPORTS);