From b2c5cdcfd4bcc1fbf1caefe7f3ff909bcee10a6c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 9 May 2018 16:23:45 +0900 Subject: modpost: remove symbol prefix support CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX was selected by BLACKFIN, METAG. They were removed by commit 4ba66a976072 ("arch: remove blackfin port"), commit bb6fb6dfcc17 ("metag: Remove arch/metag/"), respectively. No more architecture enables CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX, hence VMLINUX_SYMBOL_STR(foo) can be simplify replaced with "foo". Signed-off-by: Masahiro Yamada Reviewed-by: Sam Ravnborg --- scripts/mod/modpost.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'scripts/mod') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 4ff08a0ef5d3..bc71925d4e9b 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -19,9 +19,7 @@ #include #include #include "modpost.h" -#include "../../include/generated/autoconf.h" #include "../../include/linux/license.h" -#include "../../include/linux/export.h" /* Are we using CONFIG_MODVERSIONS? */ static int modversions = 0; @@ -591,7 +589,7 @@ static void parse_elf_finish(struct elf_info *info) static int ignore_undef_symbol(struct elf_info *info, const char *symname) { /* ignore __this_module, it will be resolved shortly */ - if (strcmp(symname, VMLINUX_SYMBOL_STR(__this_module)) == 0) + if (strcmp(symname, "__this_module") == 0) return 1; /* ignore global offset table */ if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0) @@ -617,9 +615,6 @@ static int ignore_undef_symbol(struct elf_info *info, const char *symname) return 0; } -#define CRC_PFX VMLINUX_SYMBOL_STR(__crc_) -#define KSYMTAB_PFX VMLINUX_SYMBOL_STR(__ksymtab_) - static void handle_modversions(struct module *mod, struct elf_info *info, Elf_Sym *sym, const char *symname) { @@ -634,7 +629,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, export = export_from_sec(info, get_secindex(info, sym)); /* CRC'd symbol */ - if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { + if (strncmp(symname, "__crc_", strlen("__crc_")) == 0) { is_crc = true; crc = (unsigned int) sym->st_value; if (sym->st_shndx != SHN_UNDEF && sym->st_shndx != SHN_ABS) { @@ -647,7 +642,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, info->sechdrs[sym->st_shndx].sh_addr : 0); crc = *crcp; } - sym_update_crc(symname + strlen(CRC_PFX), mod, crc, + sym_update_crc(symname + strlen("__crc_"), mod, crc, export); } @@ -685,15 +680,10 @@ static void handle_modversions(struct module *mod, struct elf_info *info, } #endif -#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX - if (symname[0] != '_') - break; - else - symname++; -#endif if (is_crc) { const char *e = is_vmlinux(mod->name) ?"":".ko"; - warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n", symname + strlen(CRC_PFX), mod->name, e); + warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n", + symname + strlen("__crc_"), mod->name, e); } mod->unres = alloc_symbol(symname, ELF_ST_BIND(sym->st_info) == STB_WEAK, @@ -701,13 +691,13 @@ static void handle_modversions(struct module *mod, struct elf_info *info, break; default: /* All exported symbols */ - if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { - sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, + if (strncmp(symname, "__ksymtab_", strlen("__ksymtab_")) == 0) { + sym_add_exported(symname + strlen("__ksymtab_"), mod, export); } - if (strcmp(symname, VMLINUX_SYMBOL_STR(init_module)) == 0) + if (strcmp(symname, "init_module") == 0) mod->has_init = 1; - if (strcmp(symname, VMLINUX_SYMBOL_STR(cleanup_module)) == 0) + if (strcmp(symname, "cleanup_module") == 0) mod->has_cleanup = 1; break; } @@ -2230,7 +2220,7 @@ static int add_versions(struct buffer *b, struct module *mod) err = 1; break; } - buf_printf(b, "\t{ %#8x, __VMLINUX_SYMBOL_STR(%s) },\n", + buf_printf(b, "\t{ %#8x, \"%s\" },\n", s->crc, s->name); } -- cgit v1.2.3-59-g8ed1b From bca2ccee4c4ac69496d3c8655d7869122fe5aeab Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 9 May 2018 18:50:37 +0900 Subject: modpost: pass struct elf_info pointer to get_modinfo() get_(next_)modinfo takes a pointer and length pair of the .modinfo section. Instead, pass struct elf_info pointer to reduce the number of function arguments. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'scripts/mod') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index bc71925d4e9b..37a6a0b42846 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -724,16 +724,17 @@ static char *next_string(char *string, unsigned long *secsize) return string; } -static char *get_next_modinfo(void *modinfo, unsigned long modinfo_len, - const char *tag, char *info) +static char *get_next_modinfo(struct elf_info *info, const char *tag, + char *prev) { char *p; unsigned int taglen = strlen(tag); - unsigned long size = modinfo_len; + char *modinfo = info->modinfo; + unsigned long size = info->modinfo_len; - if (info) { - size -= info - (char *)modinfo; - modinfo = next_string(info, &size); + if (prev) { + size -= prev - modinfo; + modinfo = next_string(prev, &size); } for (p = modinfo; p; p = next_string(p, &size)) { @@ -743,11 +744,10 @@ static char *get_next_modinfo(void *modinfo, unsigned long modinfo_len, return NULL; } -static char *get_modinfo(void *modinfo, unsigned long modinfo_len, - const char *tag) +static char *get_modinfo(struct elf_info *info, const char *tag) { - return get_next_modinfo(modinfo, modinfo_len, tag, NULL); + return get_next_modinfo(info, tag, NULL); } /** @@ -1951,7 +1951,7 @@ static void read_symbols(char *modname) mod->skip = 1; } - license = get_modinfo(info.modinfo, info.modinfo_len, "license"); + license = get_modinfo(&info, "license"); if (!license && !is_vmlinux(modname)) warn("modpost: missing MODULE_LICENSE() in %s\n" "see include/linux/module.h for " @@ -1963,8 +1963,7 @@ static void read_symbols(char *modname) mod->gpl_compatible = 0; break; } - license = get_next_modinfo(info.modinfo, info.modinfo_len, - "license", license); + license = get_next_modinfo(&info, "license", license); } for (sym = info.symtab_start; sym < info.symtab_stop; sym++) { @@ -1977,7 +1976,7 @@ static void read_symbols(char *modname) (is_vmlinux(modname) && vmlinux_section_warnings)) check_sec_ref(mod, modname, &info); - version = get_modinfo(info.modinfo, info.modinfo_len, "version"); + version = get_modinfo(&info, "version"); if (version) maybe_frob_rcs_version(modname, version, info.modinfo, version - (char *)info.hdr); -- cgit v1.2.3-59-g8ed1b From d62c476521a63053cb28d76ac50e02c2d13b1619 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 9 May 2018 18:50:38 +0900 Subject: modpost: use strstarts() helper more widely Currently, strstarts() is only used in export_from_secname(). Use it more widely to improve the code readability. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'scripts/mod') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 37a6a0b42846..8606b6caa21b 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -596,19 +596,19 @@ static int ignore_undef_symbol(struct elf_info *info, const char *symname) 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 || - strncmp(symname, "_restvr_", sizeof("_restvr_") - 1) == 0 || - strncmp(symname, "_savevr_", sizeof("_savevr_") - 1) == 0) + if (strstarts(symname, "_restgpr_") || + strstarts(symname, "_savegpr_") || + strstarts(symname, "_rest32gpr_") || + strstarts(symname, "_save32gpr_") || + strstarts(symname, "_restvr_") || + strstarts(symname, "_savevr_")) 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 || - strncmp(symname, "_restvr_", sizeof("_restvr_") - 1) == 0 || - strncmp(symname, "_savevr_", sizeof("_savevr_") - 1) == 0 || + if (strstarts(symname, "_restgpr0_") || + strstarts(symname, "_savegpr0_") || + strstarts(symname, "_restvr_") || + strstarts(symname, "_savevr_") || strcmp(symname, ".TOC.") == 0) return 1; /* Do not ignore this symbol */ @@ -623,13 +623,13 @@ static void handle_modversions(struct module *mod, struct elf_info *info, bool is_crc = false; if ((!is_vmlinux(mod->name) || mod->is_dot_o) && - strncmp(symname, "__ksymtab", 9) == 0) + strstarts(symname, "__ksymtab")) export = export_from_secname(info, get_secindex(info, sym)); else export = export_from_sec(info, get_secindex(info, sym)); /* CRC'd symbol */ - if (strncmp(symname, "__crc_", strlen("__crc_")) == 0) { + if (strstarts(symname, "__crc_")) { is_crc = true; crc = (unsigned int) sym->st_value; if (sym->st_shndx != SHN_UNDEF && sym->st_shndx != SHN_ABS) { @@ -648,7 +648,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, switch (sym->st_shndx) { case SHN_COMMON: - if (!strncmp(symname, "__gnu_lto_", sizeof("__gnu_lto_")-1)) { + if (strstarts(symname, "__gnu_lto_")) { /* Should warn here, but modpost runs before the linker */ } else warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); @@ -691,7 +691,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, break; default: /* All exported symbols */ - if (strncmp(symname, "__ksymtab_", strlen("__ksymtab_")) == 0) { + if (strstarts(symname, "__ksymtab_")) { sym_add_exported(symname + strlen("__ksymtab_"), mod, export); } @@ -1171,13 +1171,13 @@ static int secref_whitelist(const struct sectioncheck *mismatch, /* Check for pattern 1 */ if (match(tosec, init_data_sections) && match(fromsec, data_sections) && - (strncmp(fromsym, "__param", strlen("__param")) == 0)) + strstarts(fromsym, "__param")) return 0; /* Check for pattern 1a */ if (strcmp(tosec, ".init.text") == 0 && match(fromsec, data_sections) && - (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0)) + strstarts(fromsym, "__param_ops_")) return 0; /* Check for pattern 2 */ @@ -1532,8 +1532,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, from = find_elf_symbol2(elf, r->r_offset, fromsec); fromsym = sym_name(elf, from); - if (!strncmp(fromsym, "reference___initcall", - sizeof("reference___initcall")-1)) + if (strstarts(fromsym, "reference___initcall")) return; tosec = sec_name(elf, get_secindex(elf, sym)); @@ -2163,9 +2162,7 @@ static void add_retpoline(struct buffer *b) static void add_staging_flag(struct buffer *b, const char *name) { - static const char *staging_dir = "drivers/staging"; - - if (strncmp(staging_dir, name, strlen(staging_dir)) == 0) + if (strstarts(name, "drivers/staging")) buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); } -- cgit v1.2.3-59-g8ed1b From 074a04f572effefe410d7ee452cf3755e828c031 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 9 May 2018 18:50:39 +0900 Subject: modpost: remove redundant is_vmlinux() test The second test of is_vmlinux() is redundant. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'scripts/mod') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 8606b6caa21b..9e70a6ac1fcb 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1971,8 +1971,7 @@ static void read_symbols(char *modname) handle_modversions(mod, &info, sym, symname); handle_moddevtable(mod, &info, sym, symname); } - if (!is_vmlinux(modname) || - (is_vmlinux(modname) && vmlinux_section_warnings)) + if (!is_vmlinux(modname) || vmlinux_section_warnings) check_sec_ref(mod, modname, &info); version = get_modinfo(&info, "version"); -- cgit v1.2.3-59-g8ed1b From 8b1857436baa2b9b6d7330715180aa47a63b15ca Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 9 May 2018 18:50:40 +0900 Subject: modpost: constify *modname function argument where possible Neither find_module() nor read_symbols() does change *modname. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/mod') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 9e70a6ac1fcb..1663fb19343a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -121,7 +121,7 @@ void *do_nofail(void *ptr, const char *expr) /* A list of all modules we processed */ static struct module *modules; -static struct module *find_module(char *modname) +static struct module *find_module(const char *modname) { struct module *mod; @@ -1929,7 +1929,7 @@ static char *remove_dot(char *s) return s; } -static void read_symbols(char *modname) +static void read_symbols(const char *modname) { const char *symname; char *version; -- cgit v1.2.3-59-g8ed1b