mediatek: Add support for Xiaomi Redmi Router AX6S
[openwrt/staging/mkresin.git] / target / linux / generic / backport-5.4 / 030-modpost-add-a-helper-to-get-data-pointed-by-a-symbol.patch
1 From afa0459daa7b08c7b2c879705b69d39b734a11d0 Mon Sep 17 00:00:00 2001
2 From: Masahiro Yamada <yamada.masahiro@socionext.com>
3 Date: Fri, 15 Nov 2019 02:42:21 +0900
4 Subject: [PATCH] modpost: add a helper to get data pointed by a symbol
5
6 When CONFIG_MODULE_REL_CRCS is enabled, the value of __crc_* is not
7 an absolute value, but the address to the CRC data embedded in the
8 .rodata section.
9
10 Getting the data pointed by the symbol value is somewhat complex.
11 Split it out into a new helper, sym_get_data().
12
13 I will reuse it to refactor namespace_from_kstrtabns() in the next
14 commit.
15
16 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
17 ---
18 scripts/mod/modpost.c | 17 +++++++++++++----
19 1 file changed, 13 insertions(+), 4 deletions(-)
20
21 --- a/scripts/mod/modpost.c
22 +++ b/scripts/mod/modpost.c
23 @@ -312,6 +312,18 @@ static const char *sec_name(struct elf_i
24 return sech_name(elf, &elf->sechdrs[secindex]);
25 }
26
27 +static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
28 +{
29 + Elf_Shdr *sechdr = &info->sechdrs[sym->st_shndx];
30 + unsigned long offset;
31 +
32 + offset = sym->st_value;
33 + if (info->hdr->e_type != ET_REL)
34 + offset -= sechdr->sh_addr;
35 +
36 + return (void *)info->hdr + sechdr->sh_offset + offset;
37 +}
38 +
39 #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
40
41 static enum export export_from_secname(struct elf_info *elf, unsigned int sec)
42 @@ -701,10 +713,7 @@ static void handle_modversions(struct mo
43 unsigned int *crcp;
44
45 /* symbol points to the CRC in the ELF object */
46 - crcp = (void *)info->hdr + sym->st_value +
47 - info->sechdrs[sym->st_shndx].sh_offset -
48 - (info->hdr->e_type != ET_REL ?
49 - info->sechdrs[sym->st_shndx].sh_addr : 0);
50 + crcp = sym_get_data(info, sym);
51 crc = TO_NATIVE(*crcp);
52 }
53 sym_update_crc(symname + strlen("__crc_"), mod, crc,