031-modpost-refactor-namespace_from_kstrtabns-to-not-har.patch 2.1 KB

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