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
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
10 Getting the data pointed by the symbol value is somewhat complex.
11 Split it out into a new helper, sym_get_data().
13 I will reuse it to refactor namespace_from_kstrtabns() in the next
16 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
18 scripts/mod/modpost.c | 17 +++++++++++++----
19 1 file changed, 13 insertions(+), 4 deletions(-)
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]);
27 +static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
29 + Elf_Shdr *sechdr = &info->sechdrs[sym->st_shndx];
30 + unsigned long offset;
32 + offset = sym->st_value;
33 + if (info->hdr->e_type != ET_REL)
34 + offset -= sechdr->sh_addr;
36 + return (void *)info->hdr + sechdr->sh_offset + offset;
39 #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
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
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);
53 sym_update_crc(symname + strlen("__crc_"), mod, crc,