module.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. };
  19. u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
  20. void *loc, const Elf64_Rela *rela,
  21. Elf64_Sym *sym);
  22. u64 module_emit_veneer_for_adrp(struct module *mod, Elf64_Shdr *sechdrs,
  23. void *loc, u64 val);
  24. struct plt_entry {
  25. /*
  26. * A program that conforms to the AArch64 Procedure Call Standard
  27. * (AAPCS64) must assume that a veneer that alters IP0 (x16) and/or
  28. * IP1 (x17) may be inserted at any branch instruction that is
  29. * exposed to a relocation that supports long branches. Since that
  30. * is exactly what we are dealing with here, we are free to use x16
  31. * as a scratch register in the PLT veneers.
  32. */
  33. __le32 adrp; /* adrp x16, .... */
  34. __le32 add; /* add x16, x16, #0x.... */
  35. __le32 br; /* br x16 */
  36. };
  37. static inline bool is_forbidden_offset_for_adrp(void *place)
  38. {
  39. return cpus_have_final_cap(ARM64_WORKAROUND_843419) &&
  40. ((u64)place & 0xfff) >= 0xff8;
  41. }
  42. struct plt_entry get_plt_entry(u64 dst, void *pc);
  43. static inline const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
  44. const Elf_Shdr *sechdrs,
  45. const char *name)
  46. {
  47. const Elf_Shdr *s, *se;
  48. const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
  49. for (s = sechdrs, se = sechdrs + hdr->e_shnum; s < se; s++) {
  50. if (strcmp(name, secstrs + s->sh_name) == 0)
  51. return s;
  52. }
  53. return NULL;
  54. }
  55. #endif /* __ASM_MODULE_H */