genelf.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #elif defined(__sparc__) && defined(__arch64__)
  31. #define GEN_ELF_ARCH EM_SPARCV9
  32. #define GEN_ELF_CLASS ELFCLASS64
  33. #elif defined(__sparc__)
  34. #define GEN_ELF_ARCH EM_SPARC
  35. #define GEN_ELF_CLASS ELFCLASS32
  36. #elif defined(__s390x__)
  37. #define GEN_ELF_ARCH EM_S390
  38. #define GEN_ELF_CLASS ELFCLASS64
  39. #else
  40. #error "unsupported architecture"
  41. #endif
  42. #if __BYTE_ORDER == __BIG_ENDIAN
  43. #define GEN_ELF_ENDIAN ELFDATA2MSB
  44. #else
  45. #define GEN_ELF_ENDIAN ELFDATA2LSB
  46. #endif
  47. #if GEN_ELF_CLASS == ELFCLASS64
  48. #define elf_newehdr elf64_newehdr
  49. #define elf_getshdr elf64_getshdr
  50. #define Elf_Ehdr Elf64_Ehdr
  51. #define Elf_Shdr Elf64_Shdr
  52. #define Elf_Sym Elf64_Sym
  53. #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
  54. #define ELF_ST_BIND(a) ELF64_ST_BIND(a)
  55. #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
  56. #else
  57. #define elf_newehdr elf32_newehdr
  58. #define elf_getshdr elf32_getshdr
  59. #define Elf_Ehdr Elf32_Ehdr
  60. #define Elf_Shdr Elf32_Shdr
  61. #define Elf_Sym Elf32_Sym
  62. #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
  63. #define ELF_ST_BIND(a) ELF32_ST_BIND(a)
  64. #define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a)
  65. #endif
  66. /* The .text section is directly after the ELF header */
  67. #define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
  68. #endif