else if (strcmp(secname, "__ksymtab_unused") == 0) info->export_unused_sec = i; else if (strcmp(secname, "__ksymtab_gpl") == 0) info->export_gpl_sec = i; else if (strcmp(secname, "__ksymtab_unused_gpl") == 0) info->export_unused_gpl_sec = i; else if (strcmp(secname, "__ksymtab_gpl_future") == 0) info->export_gpl_future_sec = i; if (sechdrs[i].sh_type == SHT_SYMTAB) { unsigned int sh_link_idx; symtab_idx = i; info->symtab_start = (void *)hdr + sechdrs[i].sh_offset; info->symtab_stop = (void *)hdr + sechdrs[i].sh_offset + sechdrs[i].sh_size; sh_link_idx = sechdrs[i].sh_link; info->strtab = (void *)hdr + sechdrs[sh_link_idx].sh_offset; } /* 32bit section no. table? ("more than 64k sections") */ if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) { symtab_shndx_idx = i; info->symtab_shndx_start = (void *)hdr + sechdrs[i].sh_offset; info->symtab_shndx_stop = (void *)hdr + sechdrs[i].sh_offset + sechdrs[i].sh_size; } } if (!info->symtab_start) fatal("%s has no symtab?\n", filename); /* Fix endianness in symbols */ for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { sym->st_shndx = TO_NATIVE(sym->st_shndx); sym->st_name = TO_NATIVE(sym->st_name); sym->st_value = TO_NATIVE(sym->st_value); sym->st_size = TO_NATIVE(sym->st_size); } if (symtab_shndx_idx != ~0U) { Elf32_Word *p; if (symtab_idx != sechdrs[symtab_shndx_idx].sh_link) fatal("%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n", filename, sechdrs[symtab_shndx_idx].sh_link, symtab_idx); /* Fix endianness */ for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; p++) *p = TO_NATIVE(*p); } return 1;} static void parse_elf_finish(struct elf_info *info){ release_file(info->hdr, info->size);} static int ignore_undef_symbol(struct elf_info *info, const char *symname){ /* ignore __this_module, it will be resolved shortly */ if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0) return 1; /* ignore global offset table */ if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0) return 1; if (info->hdr->e_machine == EM_PPC) /* Special register function linked on all modules during final link of .ko */ if (strncmp(symname, "_restgpr_", sizeof("_restgpr_") - 1) == 0 || strncmp(symname, "_savegpr_", sizeof("_savegpr_") - 1) == 0 || strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 || strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0) return 1; if (info->hdr->e_machine == EM_PPC64) /* Special register function linked on all modules during final link of .ko */ if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 || strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0) return 1; /* Do not ignore this symbol */ return 0;} #define CRC_PFX MODULE_SYMBOL_PREFIX "__crc_"#define KSYMTAB_PFX MODULE_SYMBOL_PREFIX "__ksymtab_" static void handle_modversions(struct module *mod, struct elf_info *info, Elf_Sym *sym, const char *symname){ unsigned int crc; enum export export; if ((!is_vmlinux(mod->name) || mod->is_dot_o) && strncmp(symname, "__ksymtab", 9) == 0) export = export_from_secname(info, get_secindex(info, sym)); else export = export_from_sec(info, get_secindex(info, sym)); switch (sym->st_shndx) { case SHN_COMMON: warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); break; case SHN_ABS: /* CRC'd symbol */ if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { crc = (unsigned int) sym->st_value; sym_update_crc(symname + strlen(CRC_PFX), mod, crc, export); } break; case SHN_UNDEF: /* undefined symbol */ if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && ELF_ST_BIND(sym->st_info) != STB_WEAK) break; if (ignore_undef_symbol(info, symname)) break;/* cope with newer glibc (2.3.4 or higher) STT_ definition in elf.h */#if defined(STT_REGISTER) || defined(STT_SPARC_REGISTER)/* add compatibility with older glibc */#ifndef STT_SPARC_REGISTER#define STT_SPARC_REGISTER STT_REGISTER#endif if (info->hdr->e_machine == EM_SPARC || info->hdr->e_machine == EM_SPARCV9) { /* Ignore register directives. */ if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) break; if (symname[0] == '.') { char *munged = strdup(symname); munged[0] = '_'; munged[1] = toupper(munged[1]); symname = munged; } }#endif if (memcmp(symname, MODULE_SYMBOL_PREFIX, strlen(MODULE_SYMBOL_PREFIX)) == 0) { mod->unres = alloc_symbol(symname + strlen(MODULE_SYMBOL_PREFIX), ELF_ST_BIND(sym->st_info) == STB_WEAK, mod->unres); } break; default: /* All exported symbols */ if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, export); } if (strcmp(symname, MODULE_SYMBOL_PREFIX "init_module") == 0) mod->has_init = 1; if (strcmp(symname, MODULE_SYMBOL_PREFIX "cleanup_module") == 0) mod->has_cleanup = 1; break; }} /** * Parse tag=value strings from .modinfo section **/static char *next_string(char *string, unsigned long *secsize){ /* Skip non-zero chars */ while (string[0]) { string++; if ((*secsize)-- <= 1) return NULL; } /* Skip any zero padding. */ while (!string[0]) { string++; if ((*secsize)-- <= 1) return NULL; } return string;} static char *get_next_modinfo(void *modinfo, unsigned long modinfo_len, const char *tag, char *info){ char *p; unsigned int taglen = strlen(tag); unsigned long size = modinfo_len; if (info) { size -= info - (char *)modinfo; modinfo = next_string(info, &size); } for (p = modinfo; p; p = next_string(p, &size)) { if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') return p + taglen + 1; } return NULL;} static char *get_modinfo(void *modinfo, unsigned long modinfo_len, const char *tag) { return get_next_modinfo(modinfo, modinfo_len, tag, NULL);} /** * Test if string s ends in string sub * return 0 if match **/static int strrcmp(const char *s, const char *sub){ int slen, sublen; if (!s || !sub) return 1; slen = strlen(s); sublen = strlen(sub); if ((slen == 0) || (sublen == 0)) return 1; if (sublen > slen) return 1; return memcmp(s + slen - sublen, sub, sublen);} static const char *sym_name(struct elf_info *elf, Elf_Sym *sym){ if (sym) return elf->strtab + sym->st_name; else return "(unknown)";} static const char *sec_name(struct elf_info *elf, int secindex){ Elf_Shdr *sechdrs = elf->sechdrs; return (void *)elf->hdr + elf->sechdrs[elf->secindex_strings].sh_offset + sechdrs[secindex].sh_name;} static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr){ return (void *)elf->hdr + elf->sechdrs[elf->secindex_strings].sh_offset + sechdr->sh_name;} /* if sym is empty or point to a string * like ".[0-9]+" then return 1. * This is the optional prefix added by ld to some sections */static int number_prefix(const char *sym){ if (*sym++ == '\0') return 1; if (*sym != '.') return 0; do { char c = *sym++; if (c < '0' || c > '9') return 0; } while (*sym); return 1;} /* The pattern is an array of simple patterns. * "foo" will match an exact string equal to "foo" * "*foo" will match a string that ends with "foo" * "foo*" will match a string that begins with "foo" * "foo$" will match a string equal to "foo" or "foo.1" * where the '1' can be any number including several digits. * The $ syntax is for sections where ld append a dot number * to make section name unique. */static int match(const char *sym, const char * const pat[]){ const char *p; while (*pat) { p = *pat++; const char *endp = p + strlen(p) - 1; /* "*foo" */ if (*p == '*') { if (strrcmp(sym, p + 1) == 0) return 1; } /* "foo*" */ else if (*endp == '*') { if (strncmp(sym, p, strlen(p) - 1) == 0) return 1; } /* "foo$" */ else if (*endp == '$') { if (strncmp(sym, p, strlen(p) - 1) == 0) { if (number_prefix(sym + strlen(p) - 1)) return 1; } } /* no wildcards */ else { if (strcmp(p, sym) == 0) return 1; } } /* no match */ return 0;} /* sections that we do not want to do full section mismatch check on */static const char *section_white_list[] ={ ".comment*", ".debug*", ".zdebug*", /* Compressed debug sections. */ ".GCC-command-line", /* mn10300 */ ".mdebug*", /* alpha, score, mips etc. */ ".pdr", /* alpha, score, mips etc. */ ".stab*", ".note*", ".got*", ".toc*", NULL}; /* * This is used to find sections missing the SHF_ALLOC flag. * The cause of this is often a section specified in assembler * without "ax" / "aw". */static void check_section(const char *modname, struct elf_info *elf, Elf_Shdr *sechdr){ const char *sec = sech_name(elf, sechdr); if (sechdr->sh_type == SHT_PROGBITS && !(sechdr->sh_flags & SHF_ALLOC) && !match(sec, section_white_list)) { warn("%s (%s): unexpected non-allocatable section.\n" "Did you forget to use \"ax\"/\"aw\" in a .S file?\n" "Note that for example <linux/init.h> contains\n" "section definitions for use in .S files.\n\n", modname, sec); }} #define ALL_INIT_DATA_SECTIONS \ ".init.setup$", ".init.rodata$", \ ".devinit.rodata$", ".cpuinit.rodata$", ".meminit.rodata$", \ ".init.data$", ".devinit.data$", ".cpuinit.data$", ".meminit.data$"#define ALL_EXIT_DATA_SECTIONS \ ".exit.data$", ".devexit.data$", ".cpuexit.data$", ".memexit.data$" #define ALL_INIT_TEXT_SECTIONS \ ".init.text$", ".devinit.text$", ".cpuinit.text$", ".meminit.text$"#define ALL_EXIT_TEXT_SECTIONS \ ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$" #define ALL_XXXINIT_SECTIONS DEV_INIT_SECTIONS, CPU_INIT_SECTIONS, \ MEM_INIT_SECTIONS#define ALL_XXXEXIT_SECTIONS DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, \ MEM_EXIT_SECTIONS #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS#define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS #define DATA_SECTIONS ".data$", ".data.rel$"#define TEXT_SECTIONS ".text$" #define INIT_SECTIONS ".init.*"#define DEV_INIT_SECTIONS ".devinit.*"#define CPU_INIT_SECTIONS ".cpuinit.*"#define MEM_INIT_SECTIONS ".meminit.*" #define EXIT_SECTIONS ".exit.*"#define DEV_EXIT_SECTIONS ".devexit.*"#define CPU_EXIT_SECTIONS ".cpuexit.*"#define MEM_EXIT_SECTIONS ".memexit.*" /* init data sections */static const char *init_data_sections[] = { ALL_INIT_DATA_SECTIONS, NULL }; /* all init sections */static const char *init_sections[] = { ALL_INIT_SECTIONS, NULL }; /* All init and exit sections (code + data) */static const char *init_exit_sections[] = {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL }; /* data section */static const char *data_sections[] = { DATA_SECTIONS, NULL }; /* symbols in .data that may refer to init/exit sections */#define DEFAULT_SYMBOL_WHITE_LIST \ "*driver", \ "*_template", /* scsi uses *_template a lot */ \ "*_timer", /* arm uses ops structures named _timer a lot */ \ "*_sht", /* scsi also used *_sht to some extent */ \ "*_ops", \ "*_probe", \ "*_probe_one", \ "*_console" static const char *head_sections[] = { ".head.text*", NULL };static const char *linker_symbols[] = { "__init_begin", "_sinittext", "_einittext", NULL }; enum mismatch { TEXT_TO_ANY_INIT, DATA_TO_ANY_INIT, TEXT_TO_ANY_EXIT, DATA_TO_ANY_EXIT, XXXINIT_TO_SOME_INIT, XXXEXIT_TO_SOME_EXIT, ANY_INIT_TO_ANY_EXIT, ANY_EXIT_TO_ANY_INIT, EXPORT_TO_INIT_EXIT,}; struct sectioncheck { const char *fromsec[20]; const char *tosec[20]; enum mismatch mismatch; const char *symbol_white_list[20];}; const struct sectioncheck sectioncheck[] = {/* Do not reference init/exit code/data from * normal code and data */{ .fromsec = { TEXT_SECTIONS, NULL }, .tosec = { ALL_INIT_SECTIONS, NULL }, .mismatch = TEXT_TO_ANY_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },},{ .fromsec = { DATA_SECTIONS, NULL }, .tosec = { ALL_XXXINIT_SECTIONS, NULL }, .mismatch = DATA_TO_ANY_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },},{ .fromsec = { DATA_SECTIONS, NULL }, .tosec = { INIT_SECTIONS, NULL }, .mismatch = DATA_TO_ANY_INIT, .symbol_white_list = { "*_template", "*_timer", "*_sht", "*_ops", "*_probe", "*_probe_one", "*_console", NULL },},{ .fromsec = { TEXT_SECTIONS, NULL }, .tosec = { ALL_EXIT_SECTIONS, NULL }, .mismatch = TEXT_TO_ANY_EXIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },},{ .fromsec = { DATA_SECTIONS, NULL }, .tosec = { ALL_EXIT_SECTIONS, NULL }, .mismatch = DATA_TO_ANY_EXIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },},/* Do not reference init code/data from devinit/cpuinit/meminit code/data */{ .fromsec = { ALL_XXXINIT_SECTIONS, NULL }, .tosec = { INIT_SECTIONS, NULL }, .mismatch = XXXINIT_TO_SOME_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },},/* Do not reference cpuinit code/data from meminit code/data */{ .fromsec = { MEM_INIT_SECTIONS, NULL }, .tosec = { CPU_INIT_SECTIONS, NULL }, .mismatch = XXXINIT_TO_SOME_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },},/* Do not reference meminit code/data from cpuinit code/data */{ .fromsec = { CPU_INIT_SECTIONS, NULL }, .tosec = { MEM_INIT_SECTIONS, NULL }, .mismatch = XXXINIT_TO_SOME_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },},/* Do not reference exit code/data from devexit/cpuexit/memexit code/data */{ .fromsec = { ALL_XXXEXIT_SECTIONS, NULL }, .tosec = { EXIT_SECTIONS, NULL }, .mismatch = XXXEXIT_TO_SOME_EXIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },Lines 501–1000 of 2213. Previous lines Load more
else if (strcmp(secname, "__ksymtab_unused") == 0) info->export_unused_sec = i; else if (strcmp(secname, "__ksymtab_gpl") == 0) info->export_gpl_sec = i; else if (strcmp(secname, "__ksymtab_unused_gpl") == 0) info->export_unused_gpl_sec = i; else if (strcmp(secname, "__ksymtab_gpl_future") == 0) info->export_gpl_future_sec = i; if (sechdrs[i].sh_type == SHT_SYMTAB) { unsigned int sh_link_idx; symtab_idx = i; info->symtab_start = (void *)hdr + sechdrs[i].sh_offset; info->symtab_stop = (void *)hdr + sechdrs[i].sh_offset + sechdrs[i].sh_size; sh_link_idx = sechdrs[i].sh_link; info->strtab = (void *)hdr + sechdrs[sh_link_idx].sh_offset; } /* 32bit section no. table? ("more than 64k sections") */ if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) { symtab_shndx_idx = i; info->symtab_shndx_start = (void *)hdr + sechdrs[i].sh_offset; info->symtab_shndx_stop = (void *)hdr + sechdrs[i].sh_offset + sechdrs[i].sh_size; } } if (!info->symtab_start) fatal("%s has no symtab?\n", filename); /* Fix endianness in symbols */ for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { sym->st_shndx = TO_NATIVE(sym->st_shndx); sym->st_name = TO_NATIVE(sym->st_name); sym->st_value = TO_NATIVE(sym->st_value); sym->st_size = TO_NATIVE(sym->st_size); } if (symtab_shndx_idx != ~0U) { Elf32_Word *p; if (symtab_idx != sechdrs[symtab_shndx_idx].sh_link) fatal("%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n", filename, sechdrs[symtab_shndx_idx].sh_link, symtab_idx); /* Fix endianness */ for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; p++) *p = TO_NATIVE(*p); } return 1; } static void parse_elf_finish(struct elf_info *info) { release_file(info->hdr, info->size); } static int ignore_undef_symbol(struct elf_info *info, const char *symname) { /* ignore __this_module, it will be resolved shortly */ if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0) return 1; /* ignore global offset table */ if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0) return 1; if (info->hdr->e_machine == EM_PPC) /* Special register function linked on all modules during final link of .ko */ if (strncmp(symname, "_restgpr_", sizeof("_restgpr_") - 1) == 0 || strncmp(symname, "_savegpr_", sizeof("_savegpr_") - 1) == 0 || strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 || strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0) return 1; if (info->hdr->e_machine == EM_PPC64) /* Special register function linked on all modules during final link of .ko */ if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 || strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0) return 1; /* Do not ignore this symbol */ return 0; } #define CRC_PFX MODULE_SYMBOL_PREFIX "__crc_" #define KSYMTAB_PFX MODULE_SYMBOL_PREFIX "__ksymtab_" static void handle_modversions(struct module *mod, struct elf_info *info, Elf_Sym *sym, const char *symname) { unsigned int crc; enum export export; if ((!is_vmlinux(mod->name) || mod->is_dot_o) && strncmp(symname, "__ksymtab", 9) == 0) export = export_from_secname(info, get_secindex(info, sym)); else export = export_from_sec(info, get_secindex(info, sym)); switch (sym->st_shndx) { case SHN_COMMON: warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); break; case SHN_ABS: /* CRC'd symbol */ if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { crc = (unsigned int) sym->st_value; sym_update_crc(symname + strlen(CRC_PFX), mod, crc, export); } break; case SHN_UNDEF: /* undefined symbol */ if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && ELF_ST_BIND(sym->st_info) != STB_WEAK) break; if (ignore_undef_symbol(info, symname)) break; /* cope with newer glibc (2.3.4 or higher) STT_ definition in elf.h */ #if defined(STT_REGISTER) || defined(STT_SPARC_REGISTER) /* add compatibility with older glibc */ #ifndef STT_SPARC_REGISTER #define STT_SPARC_REGISTER STT_REGISTER #endif if (info->hdr->e_machine == EM_SPARC || info->hdr->e_machine == EM_SPARCV9) { /* Ignore register directives. */ if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) break; if (symname[0] == '.') { char *munged = strdup(symname); munged[0] = '_'; munged[1] = toupper(munged[1]); symname = munged; } } #endif if (memcmp(symname, MODULE_SYMBOL_PREFIX, strlen(MODULE_SYMBOL_PREFIX)) == 0) { mod->unres = alloc_symbol(symname + strlen(MODULE_SYMBOL_PREFIX), ELF_ST_BIND(sym->st_info) == STB_WEAK, mod->unres); } break; default: /* All exported symbols */ if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, export); } if (strcmp(symname, MODULE_SYMBOL_PREFIX "init_module") == 0) mod->has_init = 1; if (strcmp(symname, MODULE_SYMBOL_PREFIX "cleanup_module") == 0) mod->has_cleanup = 1; break; } } /** * Parse tag=value strings from .modinfo section **/ static char *next_string(char *string, unsigned long *secsize) { /* Skip non-zero chars */ while (string[0]) { string++; if ((*secsize)-- <= 1) return NULL; } /* Skip any zero padding. */ while (!string[0]) { string++; if ((*secsize)-- <= 1) return NULL; } return string; } static char *get_next_modinfo(void *modinfo, unsigned long modinfo_len, const char *tag, char *info) { char *p; unsigned int taglen = strlen(tag); unsigned long size = modinfo_len; if (info) { size -= info - (char *)modinfo; modinfo = next_string(info, &size); } for (p = modinfo; p; p = next_string(p, &size)) { if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') return p + taglen + 1; } return NULL; } static char *get_modinfo(void *modinfo, unsigned long modinfo_len, const char *tag) { return get_next_modinfo(modinfo, modinfo_len, tag, NULL); } /** * Test if string s ends in string sub * return 0 if match **/ static int strrcmp(const char *s, const char *sub) { int slen, sublen; if (!s || !sub) return 1; slen = strlen(s); sublen = strlen(sub); if ((slen == 0) || (sublen == 0)) return 1; if (sublen > slen) return 1; return memcmp(s + slen - sublen, sub, sublen); } static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) { if (sym) return elf->strtab + sym->st_name; else return "(unknown)"; } static const char *sec_name(struct elf_info *elf, int secindex) { Elf_Shdr *sechdrs = elf->sechdrs; return (void *)elf->hdr + elf->sechdrs[elf->secindex_strings].sh_offset + sechdrs[secindex].sh_name; } static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr) { return (void *)elf->hdr + elf->sechdrs[elf->secindex_strings].sh_offset + sechdr->sh_name; } /* if sym is empty or point to a string * like ".[0-9]+" then return 1. * This is the optional prefix added by ld to some sections */ static int number_prefix(const char *sym) { if (*sym++ == '\0') return 1; if (*sym != '.') return 0; do { char c = *sym++; if (c < '0' || c > '9') return 0; } while (*sym); return 1; } /* The pattern is an array of simple patterns. * "foo" will match an exact string equal to "foo" * "*foo" will match a string that ends with "foo" * "foo*" will match a string that begins with "foo" * "foo$" will match a string equal to "foo" or "foo.1" * where the '1' can be any number including several digits. * The $ syntax is for sections where ld append a dot number * to make section name unique. */ static int match(const char *sym, const char * const pat[]) { const char *p; while (*pat) { p = *pat++; const char *endp = p + strlen(p) - 1; /* "*foo" */ if (*p == '*') { if (strrcmp(sym, p + 1) == 0) return 1; } /* "foo*" */ else if (*endp == '*') { if (strncmp(sym, p, strlen(p) - 1) == 0) return 1; } /* "foo$" */ else if (*endp == '$') { if (strncmp(sym, p, strlen(p) - 1) == 0) { if (number_prefix(sym + strlen(p) - 1)) return 1; } } /* no wildcards */ else { if (strcmp(p, sym) == 0) return 1; } } /* no match */ return 0; } /* sections that we do not want to do full section mismatch check on */ static const char *section_white_list[] = { ".comment*", ".debug*", ".zdebug*", /* Compressed debug sections. */ ".GCC-command-line", /* mn10300 */ ".mdebug*", /* alpha, score, mips etc. */ ".pdr", /* alpha, score, mips etc. */ ".stab*", ".note*", ".got*", ".toc*", NULL }; /* * This is used to find sections missing the SHF_ALLOC flag. * The cause of this is often a section specified in assembler * without "ax" / "aw". */ static void check_section(const char *modname, struct elf_info *elf, Elf_Shdr *sechdr) { const char *sec = sech_name(elf, sechdr); if (sechdr->sh_type == SHT_PROGBITS && !(sechdr->sh_flags & SHF_ALLOC) && !match(sec, section_white_list)) { warn("%s (%s): unexpected non-allocatable section.\n" "Did you forget to use \"ax\"/\"aw\" in a .S file?\n" "Note that for example <linux/init.h> contains\n" "section definitions for use in .S files.\n\n", modname, sec); } } #define ALL_INIT_DATA_SECTIONS \ ".init.setup$", ".init.rodata$", \ ".devinit.rodata$", ".cpuinit.rodata$", ".meminit.rodata$", \ ".init.data$", ".devinit.data$", ".cpuinit.data$", ".meminit.data$" #define ALL_EXIT_DATA_SECTIONS \ ".exit.data$", ".devexit.data$", ".cpuexit.data$", ".memexit.data$" #define ALL_INIT_TEXT_SECTIONS \ ".init.text$", ".devinit.text$", ".cpuinit.text$", ".meminit.text$" #define ALL_EXIT_TEXT_SECTIONS \ ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$" #define ALL_XXXINIT_SECTIONS DEV_INIT_SECTIONS, CPU_INIT_SECTIONS, \ MEM_INIT_SECTIONS #define ALL_XXXEXIT_SECTIONS DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, \ MEM_EXIT_SECTIONS #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS #define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS #define DATA_SECTIONS ".data$", ".data.rel$" #define TEXT_SECTIONS ".text$" #define INIT_SECTIONS ".init.*" #define DEV_INIT_SECTIONS ".devinit.*" #define CPU_INIT_SECTIONS ".cpuinit.*" #define MEM_INIT_SECTIONS ".meminit.*" #define EXIT_SECTIONS ".exit.*" #define DEV_EXIT_SECTIONS ".devexit.*" #define CPU_EXIT_SECTIONS ".cpuexit.*" #define MEM_EXIT_SECTIONS ".memexit.*" /* init data sections */ static const char *init_data_sections[] = { ALL_INIT_DATA_SECTIONS, NULL }; /* all init sections */ static const char *init_sections[] = { ALL_INIT_SECTIONS, NULL }; /* All init and exit sections (code + data) */ static const char *init_exit_sections[] = {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL }; /* data section */ static const char *data_sections[] = { DATA_SECTIONS, NULL }; /* symbols in .data that may refer to init/exit sections */ #define DEFAULT_SYMBOL_WHITE_LIST \ "*driver", \ "*_template", /* scsi uses *_template a lot */ \ "*_timer", /* arm uses ops structures named _timer a lot */ \ "*_sht", /* scsi also used *_sht to some extent */ \ "*_ops", \ "*_probe", \ "*_probe_one", \ "*_console" static const char *head_sections[] = { ".head.text*", NULL }; static const char *linker_symbols[] = { "__init_begin", "_sinittext", "_einittext", NULL }; enum mismatch { TEXT_TO_ANY_INIT, DATA_TO_ANY_INIT, TEXT_TO_ANY_EXIT, DATA_TO_ANY_EXIT, XXXINIT_TO_SOME_INIT, XXXEXIT_TO_SOME_EXIT, ANY_INIT_TO_ANY_EXIT, ANY_EXIT_TO_ANY_INIT, EXPORT_TO_INIT_EXIT, }; struct sectioncheck { const char *fromsec[20]; const char *tosec[20]; enum mismatch mismatch; const char *symbol_white_list[20]; }; const struct sectioncheck sectioncheck[] = { /* Do not reference init/exit code/data from * normal code and data */ { .fromsec = { TEXT_SECTIONS, NULL }, .tosec = { ALL_INIT_SECTIONS, NULL }, .mismatch = TEXT_TO_ANY_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, }, { .fromsec = { DATA_SECTIONS, NULL }, .tosec = { ALL_XXXINIT_SECTIONS, NULL }, .mismatch = DATA_TO_ANY_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, }, { .fromsec = { DATA_SECTIONS, NULL }, .tosec = { INIT_SECTIONS, NULL }, .mismatch = DATA_TO_ANY_INIT, .symbol_white_list = { "*_template", "*_timer", "*_sht", "*_ops", "*_probe", "*_probe_one", "*_console", NULL }, }, { .fromsec = { TEXT_SECTIONS, NULL }, .tosec = { ALL_EXIT_SECTIONS, NULL }, .mismatch = TEXT_TO_ANY_EXIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, }, { .fromsec = { DATA_SECTIONS, NULL }, .tosec = { ALL_EXIT_SECTIONS, NULL }, .mismatch = DATA_TO_ANY_EXIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, }, /* Do not reference init code/data from devinit/cpuinit/meminit code/data */ { .fromsec = { ALL_XXXINIT_SECTIONS, NULL }, .tosec = { INIT_SECTIONS, NULL }, .mismatch = XXXINIT_TO_SOME_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, }, /* Do not reference cpuinit code/data from meminit code/data */ { .fromsec = { MEM_INIT_SECTIONS, NULL }, .tosec = { CPU_INIT_SECTIONS, NULL }, .mismatch = XXXINIT_TO_SOME_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, }, /* Do not reference meminit code/data from cpuinit code/data */ { .fromsec = { CPU_INIT_SECTIONS, NULL }, .tosec = { MEM_INIT_SECTIONS, NULL }, .mismatch = XXXINIT_TO_SOME_INIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, }, /* Do not reference exit code/data from devexit/cpuexit/memexit code/data */ { .fromsec = { ALL_XXXEXIT_SECTIONS, NULL }, .tosec = { EXIT_SECTIONS, NULL }, .mismatch = XXXEXIT_TO_SOME_EXIT, .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },