generic: backport at803x fixes
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 031-modpost-refactor-namespace_from_kstrtabns-to-not-har.patch
1 From e84f9fbbece1585f45a03ccc11eeabe121cadc1b Mon Sep 17 00:00:00 2001
2 From: Masahiro Yamada <yamada.masahiro@socionext.com>
3 Date: Fri, 15 Nov 2019 02:42:22 +0900
4 Subject: [PATCH] modpost: refactor namespace_from_kstrtabns() to not hard-code
5 section name
6
7 Currently, namespace_from_kstrtabns() relies on the fact that
8 namespace strings are recorded in the __ksymtab_strings section.
9 Actually, it is coded in include/linux/export.h, but modpost does
10 not need to hard-code the section name.
11
12 Elf_Sym::st_shndx holds the index of the relevant section. Using it is
13 a more portable way to get the namespace string.
14
15 Make namespace_from_kstrtabns() simply call sym_get_data(), and delete
16 the info->ksymtab_strings .
17
18 While I was here, I added more 'const' qualifiers to pointers.
19
20 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
21 ---
22 scripts/mod/modpost.c | 10 +++-------
23 scripts/mod/modpost.h | 1 -
24 2 files changed, 3 insertions(+), 8 deletions(-)
25
26 --- a/scripts/mod/modpost.c
27 +++ b/scripts/mod/modpost.c
28 @@ -360,10 +360,10 @@ static enum export export_from_sec(struc
29 return export_unknown;
30 }
31
32 -static const char *namespace_from_kstrtabns(struct elf_info *info,
33 - Elf_Sym *kstrtabns)
34 +static const char *namespace_from_kstrtabns(const struct elf_info *info,
35 + const Elf_Sym *sym)
36 {
37 - char *value = info->ksymtab_strings + kstrtabns->st_value;
38 + const char *value = sym_get_data(info, sym);
39 return value[0] ? value : NULL;
40 }
41
42 @@ -605,10 +605,6 @@ static int parse_elf(struct elf_info *in
43 info->export_unused_gpl_sec = i;
44 else if (strcmp(secname, "__ksymtab_gpl_future") == 0)
45 info->export_gpl_future_sec = i;
46 - else if (strcmp(secname, "__ksymtab_strings") == 0)
47 - info->ksymtab_strings = (void *)hdr +
48 - sechdrs[i].sh_offset -
49 - sechdrs[i].sh_addr;
50
51 if (sechdrs[i].sh_type == SHT_SYMTAB) {
52 unsigned int sh_link_idx;
53 --- a/scripts/mod/modpost.h
54 +++ b/scripts/mod/modpost.h
55 @@ -143,7 +143,6 @@ struct elf_info {
56 Elf_Section export_gpl_sec;
57 Elf_Section export_unused_gpl_sec;
58 Elf_Section export_gpl_future_sec;
59 - char *ksymtab_strings;
60 char *strtab;
61 char *modinfo;
62 unsigned int modinfo_len;