module.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. */
  5. #ifndef __ASM_MODULE_H
  6. #define __ASM_MODULE_H
  7. #include <asm-generic/module.h>
  8. struct mod_plt_sec {
  9. int plt_shndx;
  10. int plt_num_entries;
  11. int plt_max_entries;
  12. };
  13. struct mod_arch_specific {
  14. struct mod_plt_sec core;
  15. struct mod_plt_sec init;
  16. /* for CONFIG_DYNAMIC_FTRACE */
  17. struct plt_entry *ftrace_trampolines;
  18. struct plt_entry *init_ftrace_trampolines;
  19. };
  20. u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
  21. void *loc, const Elf64_Rela *rela,
  22. Elf64_Sym *sym);
  23. u64 module_emit_veneer_for_adrp(struct module *mod, Elf64_Shdr *sechdrs,
  24. void *loc, u64 val);
  25. struct plt_entry {
  26. /*
  27. * A program that conforms to the AArch64 Procedure Call Standard
  28. * (AAPCS64) must assume that a veneer that alters IP0 (x16) and/or
  29. * IP1 (x17) may be inserted at any branch instruction that is
  30. * exposed to a relocation that supports long branches. Since that
  31. * is exactly what we are dealing with here, we are free to use x16
  32. * as a scratch register in the PLT veneers.
  33. */
  34. __le32 adrp; /* adrp x16, .... */
  35. __le32 add; /* add x16, x16, #0x.... */
  36. __le32 br; /* br x16 */
  37. };
  38. static inline bool is_forbidden_offset_for_adrp(void *place)
  39. {
  40. return cpus_have_final_cap(ARM64_WORKAROUND_843419) &&
  41. ((u64)place & 0xfff) >= 0xff8;
  42. }
  43. struct plt_entry get_plt_entry(u64 dst, void *pc);
  44. static inline const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
  45. const Elf_Shdr *sechdrs,
  46. const char *name)
  47. {
  48. const Elf_Shdr *s, *se;
  49. const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
  50. for (s = sechdrs, se = sechdrs + hdr->e_shnum; s < se; s++) {
  51. if (strcmp(name, secstrs + s->sh_name) == 0)
  52. return s;
  53. }
  54. return NULL;
  55. }
  56. #endif /* __ASM_MODULE_H */