genelf.h 1.8 KB

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