genelf.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /* genelf_debug.c */
  7. int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
  8. #if defined(__arm__)
  9. #define GEN_ELF_ARCH EM_ARM
  10. #define GEN_ELF_ENDIAN ELFDATA2LSB
  11. #define GEN_ELF_CLASS ELFCLASS32
  12. #elif defined(__aarch64__)
  13. #define GEN_ELF_ARCH EM_AARCH64
  14. #define GEN_ELF_ENDIAN ELFDATA2LSB
  15. #define GEN_ELF_CLASS ELFCLASS64
  16. #elif defined(__x86_64__)
  17. #define GEN_ELF_ARCH EM_X86_64
  18. #define GEN_ELF_ENDIAN ELFDATA2LSB
  19. #define GEN_ELF_CLASS ELFCLASS64
  20. #elif defined(__i386__)
  21. #define GEN_ELF_ARCH EM_386
  22. #define GEN_ELF_ENDIAN ELFDATA2LSB
  23. #define GEN_ELF_CLASS ELFCLASS32
  24. #elif defined(__ppcle__)
  25. #define GEN_ELF_ARCH EM_PPC
  26. #define GEN_ELF_ENDIAN ELFDATA2LSB
  27. #define GEN_ELF_CLASS ELFCLASS64
  28. #elif defined(__powerpc__)
  29. #define GEN_ELF_ARCH EM_PPC64
  30. #define GEN_ELF_ENDIAN ELFDATA2MSB
  31. #define GEN_ELF_CLASS ELFCLASS64
  32. #elif defined(__powerpcle__)
  33. #define GEN_ELF_ARCH EM_PPC64
  34. #define GEN_ELF_ENDIAN ELFDATA2LSB
  35. #define GEN_ELF_CLASS ELFCLASS64
  36. #else
  37. #error "unsupported architecture"
  38. #endif
  39. #if GEN_ELF_CLASS == ELFCLASS64
  40. #define elf_newehdr elf64_newehdr
  41. #define elf_getshdr elf64_getshdr
  42. #define Elf_Ehdr Elf64_Ehdr
  43. #define Elf_Shdr Elf64_Shdr
  44. #define Elf_Sym Elf64_Sym
  45. #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
  46. #define ELF_ST_BIND(a) ELF64_ST_BIND(a)
  47. #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
  48. #else
  49. #define elf_newehdr elf32_newehdr
  50. #define elf_getshdr elf32_getshdr
  51. #define Elf_Ehdr Elf32_Ehdr
  52. #define Elf_Shdr Elf32_Shdr
  53. #define Elf_Sym Elf32_Sym
  54. #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
  55. #define ELF_ST_BIND(a) ELF32_ST_BIND(a)
  56. #define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a)
  57. #endif
  58. /* The .text section is directly after the ELF header */
  59. #define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
  60. #endif