genelf.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __GENELF_H__
  3. #define __GENELF_H__
  4. /* genelf.c */
  5. int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
  6. const void *code, int csize, void *debug, int nr_debug_entries,
  7. void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size);
  8. #ifdef HAVE_DWARF_SUPPORT
  9. /* genelf_debug.c */
  10. int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
  11. #endif
  12. #if defined(__arm__)
  13. #define GEN_ELF_ARCH EM_ARM
  14. #define GEN_ELF_CLASS ELFCLASS32
  15. #elif defined(__aarch64__)
  16. #define GEN_ELF_ARCH EM_AARCH64
  17. #define GEN_ELF_CLASS ELFCLASS64
  18. #elif defined(__x86_64__)
  19. #define GEN_ELF_ARCH EM_X86_64
  20. #define GEN_ELF_CLASS ELFCLASS64
  21. #elif defined(__i386__)
  22. #define GEN_ELF_ARCH EM_386
  23. #define GEN_ELF_CLASS ELFCLASS32
  24. #elif defined(__powerpc64__)
  25. #define GEN_ELF_ARCH EM_PPC64
  26. #define GEN_ELF_CLASS ELFCLASS64
  27. #elif defined(__powerpc__)
  28. #define GEN_ELF_ARCH EM_PPC
  29. #define GEN_ELF_CLASS ELFCLASS32
  30. #else
  31. #error "unsupported architecture"
  32. #endif
  33. #if __BYTE_ORDER == __BIG_ENDIAN
  34. #define GEN_ELF_ENDIAN ELFDATA2MSB
  35. #else
  36. #define GEN_ELF_ENDIAN ELFDATA2LSB
  37. #endif
  38. #if GEN_ELF_CLASS == ELFCLASS64
  39. #define elf_newehdr elf64_newehdr
  40. #define elf_getshdr elf64_getshdr
  41. #define Elf_Ehdr Elf64_Ehdr
  42. #define Elf_Shdr Elf64_Shdr
  43. #define Elf_Sym Elf64_Sym
  44. #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
  45. #define ELF_ST_BIND(a) ELF64_ST_BIND(a)
  46. #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
  47. #else
  48. #define elf_newehdr elf32_newehdr
  49. #define elf_getshdr elf32_getshdr
  50. #define Elf_Ehdr Elf32_Ehdr
  51. #define Elf_Shdr Elf32_Shdr
  52. #define Elf_Sym Elf32_Sym
  53. #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
  54. #define ELF_ST_BIND(a) ELF32_ST_BIND(a)
  55. #define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a)
  56. #endif
  57. /* The .text section is directly after the ELF header */
  58. #define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
  59. #endif