module.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* Kernel module help for powerpc.
  3. Copyright (C) 2001, 2003 Rusty Russell IBM Corporation.
  4. Copyright (C) 2008 Freescale Semiconductor, Inc.
  5. */
  6. #include <linux/elf.h>
  7. #include <linux/moduleloader.h>
  8. #include <linux/err.h>
  9. #include <linux/mm.h>
  10. #include <linux/bug.h>
  11. #include <asm/module.h>
  12. #include <linux/uaccess.h>
  13. #include <asm/firmware.h>
  14. #include <linux/sort.h>
  15. #include <asm/setup.h>
  16. #include <asm/sections.h>
  17. static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
  18. const Elf_Shdr *sechdrs,
  19. const char *name)
  20. {
  21. char *secstrings;
  22. unsigned int i;
  23. secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
  24. for (i = 1; i < hdr->e_shnum; i++)
  25. if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
  26. return &sechdrs[i];
  27. return NULL;
  28. }
  29. int module_finalize(const Elf_Ehdr *hdr,
  30. const Elf_Shdr *sechdrs, struct module *me)
  31. {
  32. const Elf_Shdr *sect;
  33. int rc;
  34. rc = module_finalize_ftrace(me, sechdrs);
  35. if (rc)
  36. return rc;
  37. /* Apply feature fixups */
  38. sect = find_section(hdr, sechdrs, "__ftr_fixup");
  39. if (sect != NULL)
  40. do_feature_fixups(cur_cpu_spec->cpu_features,
  41. (void *)sect->sh_addr,
  42. (void *)sect->sh_addr + sect->sh_size);
  43. sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup");
  44. if (sect != NULL)
  45. do_feature_fixups(cur_cpu_spec->mmu_features,
  46. (void *)sect->sh_addr,
  47. (void *)sect->sh_addr + sect->sh_size);
  48. #ifdef CONFIG_PPC64
  49. sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
  50. if (sect != NULL)
  51. do_feature_fixups(powerpc_firmware_features,
  52. (void *)sect->sh_addr,
  53. (void *)sect->sh_addr + sect->sh_size);
  54. #endif /* CONFIG_PPC64 */
  55. #ifdef CONFIG_PPC64_ELF_ABI_V1
  56. sect = find_section(hdr, sechdrs, ".opd");
  57. if (sect != NULL) {
  58. me->arch.start_opd = sect->sh_addr;
  59. me->arch.end_opd = sect->sh_addr + sect->sh_size;
  60. }
  61. #endif /* CONFIG_PPC64_ELF_ABI_V1 */
  62. #ifdef CONFIG_PPC_BARRIER_NOSPEC
  63. sect = find_section(hdr, sechdrs, "__spec_barrier_fixup");
  64. if (sect != NULL)
  65. do_barrier_nospec_fixups_range(barrier_nospec_enabled,
  66. (void *)sect->sh_addr,
  67. (void *)sect->sh_addr + sect->sh_size);
  68. #endif /* CONFIG_PPC_BARRIER_NOSPEC */
  69. sect = find_section(hdr, sechdrs, "__lwsync_fixup");
  70. if (sect != NULL)
  71. do_lwsync_fixups(cur_cpu_spec->cpu_features,
  72. (void *)sect->sh_addr,
  73. (void *)sect->sh_addr + sect->sh_size);
  74. return 0;
  75. }