symbol namespaces: revert to previous __ksymtab name scheme

The introduction of Symbol Namespaces changed the naming schema of the
__ksymtab entries from __kysmtab__symbol to __ksymtab_NAMESPACE.symbol.

That caused some breakages in tools that depend on the name layout in
either the binaries(vmlinux,*.ko) or in System.map. E.g. kmod's depmod
would not be able to read System.map without a patch to support symbol
namespaces. A warning reported by depmod for namespaced symbols would
look like

  depmod: WARNING: [...]/uas.ko needs unknown symbol usb_stor_adjust_quirks

In order to address this issue, revert to the original naming scheme and
rather read the __kstrtabns_<symbol> entries and their corresponding
values from __ksymtab_strings to update the namespace values for
symbols. After having read all symbols and handled them in
handle_modversions(), the symbols are created. In a second pass, read
the __kstrtabns_ entries and update the namespaces accordingly.

Fixes: 8651ec01da ("module: add support for symbol namespaces.")
Reported-by: Stefan Wahren <stefan.wahren@i2se.com>
Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Will Deacon <will@kernel.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
This commit is contained in:
Matthias Maennich 2019-10-18 10:31:42 +01:00 committed by Jessica Yu
parent 9ae5bd1847
commit 6992320843
3 changed files with 24 additions and 24 deletions

View File

@ -18,8 +18,6 @@ extern struct module __this_module;
#define THIS_MODULE ((struct module *)0) #define THIS_MODULE ((struct module *)0)
#endif #endif
#define NS_SEPARATOR "."
#ifdef CONFIG_MODVERSIONS #ifdef CONFIG_MODVERSIONS
/* Mark the CRC weak since genksyms apparently decides not to /* Mark the CRC weak since genksyms apparently decides not to
* generate a checksums for some symbols */ * generate a checksums for some symbols */
@ -48,11 +46,11 @@ extern struct module __this_module;
* absolute relocations that require runtime processing on relocatable * absolute relocations that require runtime processing on relocatable
* kernels. * kernels.
*/ */
#define __KSYMTAB_ENTRY_NS(sym, sec, ns) \ #define __KSYMTAB_ENTRY_NS(sym, sec) \
__ADDRESSABLE(sym) \ __ADDRESSABLE(sym) \
asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
" .balign 4 \n" \ " .balign 4 \n" \
"__ksymtab_" #ns NS_SEPARATOR #sym ": \n" \ "__ksymtab_" #sym ": \n" \
" .long " #sym "- . \n" \ " .long " #sym "- . \n" \
" .long __kstrtab_" #sym "- . \n" \ " .long __kstrtab_" #sym "- . \n" \
" .long __kstrtabns_" #sym "- . \n" \ " .long __kstrtabns_" #sym "- . \n" \
@ -74,16 +72,14 @@ struct kernel_symbol {
int namespace_offset; int namespace_offset;
}; };
#else #else
#define __KSYMTAB_ENTRY_NS(sym, sec, ns) \ #define __KSYMTAB_ENTRY_NS(sym, sec) \
static const struct kernel_symbol __ksymtab_##sym##__##ns \ static const struct kernel_symbol __ksymtab_##sym \
asm("__ksymtab_" #ns NS_SEPARATOR #sym) \
__attribute__((section("___ksymtab" sec "+" #sym), used)) \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \
__aligned(sizeof(void *)) \ __aligned(sizeof(void *)) \
= { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym } = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
#define __KSYMTAB_ENTRY(sym, sec) \ #define __KSYMTAB_ENTRY(sym, sec) \
static const struct kernel_symbol __ksymtab_##sym \ static const struct kernel_symbol __ksymtab_##sym \
asm("__ksymtab_" #sym) \
__attribute__((section("___ksymtab" sec "+" #sym), used)) \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \
__aligned(sizeof(void *)) \ __aligned(sizeof(void *)) \
= { (unsigned long)&sym, __kstrtab_##sym, NULL } = { (unsigned long)&sym, __kstrtab_##sym, NULL }
@ -115,7 +111,7 @@ struct kernel_symbol {
static const char __kstrtabns_##sym[] \ static const char __kstrtabns_##sym[] \
__attribute__((section("__ksymtab_strings"), used, aligned(1))) \ __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
= #ns; \ = #ns; \
__KSYMTAB_ENTRY_NS(sym, sec, ns) __KSYMTAB_ENTRY_NS(sym, sec)
#define ___EXPORT_SYMBOL(sym, sec) \ #define ___EXPORT_SYMBOL(sym, sec) \
___export_symbol_common(sym, sec); \ ___export_symbol_common(sym, sec); \

View File

@ -348,18 +348,11 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
return export_unknown; return export_unknown;
} }
static char *sym_extract_namespace(const char **symname) static const char *namespace_from_kstrtabns(struct elf_info *info,
Elf_Sym *kstrtabns)
{ {
char *namespace = NULL; char *value = info->ksymtab_strings + kstrtabns->st_value;
char *ns_separator; return value[0] ? value : NULL;
ns_separator = strchr(*symname, '.');
if (ns_separator) {
namespace = NOFAIL(strndup(*symname, ns_separator - *symname));
*symname = ns_separator + 1;
}
return namespace;
} }
static void sym_update_namespace(const char *symname, const char *namespace) static void sym_update_namespace(const char *symname, const char *namespace)
@ -600,6 +593,10 @@ static int parse_elf(struct elf_info *info, const char *filename)
info->export_unused_gpl_sec = i; info->export_unused_gpl_sec = i;
else if (strcmp(secname, "__ksymtab_gpl_future") == 0) else if (strcmp(secname, "__ksymtab_gpl_future") == 0)
info->export_gpl_future_sec = i; info->export_gpl_future_sec = i;
else if (strcmp(secname, "__ksymtab_strings") == 0)
info->ksymtab_strings = (void *)hdr +
sechdrs[i].sh_offset -
sechdrs[i].sh_addr;
if (sechdrs[i].sh_type == SHT_SYMTAB) { if (sechdrs[i].sh_type == SHT_SYMTAB) {
unsigned int sh_link_idx; unsigned int sh_link_idx;
@ -689,7 +686,6 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
enum export export; enum export export;
bool is_crc = false; bool is_crc = false;
const char *name; const char *name;
char *namespace;
if ((!is_vmlinux(mod->name) || mod->is_dot_o) && if ((!is_vmlinux(mod->name) || mod->is_dot_o) &&
strstarts(symname, "__ksymtab")) strstarts(symname, "__ksymtab"))
@ -762,10 +758,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
/* All exported symbols */ /* All exported symbols */
if (strstarts(symname, "__ksymtab_")) { if (strstarts(symname, "__ksymtab_")) {
name = symname + strlen("__ksymtab_"); name = symname + strlen("__ksymtab_");
namespace = sym_extract_namespace(&name);
sym_add_exported(name, mod, export); sym_add_exported(name, mod, export);
sym_update_namespace(name, namespace);
free(namespace);
} }
if (strcmp(symname, "init_module") == 0) if (strcmp(symname, "init_module") == 0)
mod->has_init = 1; mod->has_init = 1;
@ -2061,6 +2054,16 @@ static void read_symbols(const char *modname)
handle_moddevtable(mod, &info, sym, symname); handle_moddevtable(mod, &info, sym, symname);
} }
/* Apply symbol namespaces from __kstrtabns_<symbol> entries. */
for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
symname = remove_dot(info.strtab + sym->st_name);
if (strstarts(symname, "__kstrtabns_"))
sym_update_namespace(symname + strlen("__kstrtabns_"),
namespace_from_kstrtabns(&info,
sym));
}
// check for static EXPORT_SYMBOL_* functions && global vars // check for static EXPORT_SYMBOL_* functions && global vars
for (sym = info.symtab_start; sym < info.symtab_stop; sym++) { for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
unsigned char bind = ELF_ST_BIND(sym->st_info); unsigned char bind = ELF_ST_BIND(sym->st_info);

View File

@ -143,6 +143,7 @@ struct elf_info {
Elf_Section export_gpl_sec; Elf_Section export_gpl_sec;
Elf_Section export_unused_gpl_sec; Elf_Section export_unused_gpl_sec;
Elf_Section export_gpl_future_sec; Elf_Section export_gpl_future_sec;
char *ksymtab_strings;
char *strtab; char *strtab;
char *modinfo; char *modinfo;
unsigned int modinfo_len; unsigned int modinfo_len;