modpost: refactor namespace_from_kstrtabns() to not hard-code section name

Currently, namespace_from_kstrtabns() relies on the fact that
namespace strings are recorded in the __ksymtab_strings section.
Actually, it is coded in include/linux/export.h, but modpost does
not need to hard-code the section name.

Elf_Sym::st_shndx holds the index of the relevant section. Using it is
a more portable way to get the namespace string.

Make namespace_from_kstrtabns() simply call sym_get_data(), and delete
the info->ksymtab_strings .

While I was here, I added more 'const' qualifiers to pointers.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
Masahiro Yamada 2019-11-15 02:42:22 +09:00
parent afa0459daa
commit e84f9fbbec
2 changed files with 3 additions and 8 deletions

View File

@ -356,10 +356,10 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
return export_unknown; return export_unknown;
} }
static const char *namespace_from_kstrtabns(struct elf_info *info, static const char *namespace_from_kstrtabns(const struct elf_info *info,
Elf_Sym *kstrtabns) const Elf_Sym *sym)
{ {
char *value = info->ksymtab_strings + kstrtabns->st_value; const char *value = sym_get_data(info, sym);
return value[0] ? value : NULL; return value[0] ? value : NULL;
} }
@ -601,10 +601,6 @@ 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;

View File

@ -143,7 +143,6 @@ 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;