030-modpost-add-a-helper-to-get-data-pointed-by-a-symbol.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From afa0459daa7b08c7b2c879705b69d39b734a11d0 Mon Sep 17 00:00:00 2001
  2. From: Masahiro Yamada <[email protected]>
  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. When CONFIG_MODULE_REL_CRCS is enabled, the value of __crc_* is not
  6. an absolute value, but the address to the CRC data embedded in the
  7. .rodata section.
  8. Getting the data pointed by the symbol value is somewhat complex.
  9. Split it out into a new helper, sym_get_data().
  10. I will reuse it to refactor namespace_from_kstrtabns() in the next
  11. commit.
  12. Signed-off-by: Masahiro Yamada <[email protected]>
  13. ---
  14. scripts/mod/modpost.c | 17 +++++++++++++----
  15. 1 file changed, 13 insertions(+), 4 deletions(-)
  16. --- a/scripts/mod/modpost.c
  17. +++ b/scripts/mod/modpost.c
  18. @@ -312,6 +312,18 @@ static const char *sec_name(struct elf_i
  19. return sech_name(elf, &elf->sechdrs[secindex]);
  20. }
  21. +static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
  22. +{
  23. + Elf_Shdr *sechdr = &info->sechdrs[sym->st_shndx];
  24. + unsigned long offset;
  25. +
  26. + offset = sym->st_value;
  27. + if (info->hdr->e_type != ET_REL)
  28. + offset -= sechdr->sh_addr;
  29. +
  30. + return (void *)info->hdr + sechdr->sh_offset + offset;
  31. +}
  32. +
  33. #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
  34. static enum export export_from_secname(struct elf_info *elf, unsigned int sec)
  35. @@ -701,10 +713,7 @@ static void handle_modversions(struct mo
  36. unsigned int *crcp;
  37. /* symbol points to the CRC in the ELF object */
  38. - crcp = (void *)info->hdr + sym->st_value +
  39. - info->sechdrs[sym->st_shndx].sh_offset -
  40. - (info->hdr->e_type != ET_REL ?
  41. - info->sechdrs[sym->st_shndx].sh_addr : 0);
  42. + crcp = sym_get_data(info, sym);
  43. crc = TO_NATIVE(*crcp);
  44. }
  45. sym_update_crc(symname + strlen("__crc_"), mod, crc,