0001
0002 #ifndef __GENELF_H__
0003 #define __GENELF_H__
0004
0005
0006 int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
0007 const void *code, int csize, void *debug, int nr_debug_entries,
0008 void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size);
0009 #ifdef HAVE_DWARF_SUPPORT
0010
0011 int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
0012 #endif
0013
0014 #if defined(__arm__)
0015 #define GEN_ELF_ARCH EM_ARM
0016 #define GEN_ELF_CLASS ELFCLASS32
0017 #elif defined(__aarch64__)
0018 #define GEN_ELF_ARCH EM_AARCH64
0019 #define GEN_ELF_CLASS ELFCLASS64
0020 #elif defined(__x86_64__)
0021 #define GEN_ELF_ARCH EM_X86_64
0022 #define GEN_ELF_CLASS ELFCLASS64
0023 #elif defined(__i386__)
0024 #define GEN_ELF_ARCH EM_386
0025 #define GEN_ELF_CLASS ELFCLASS32
0026 #elif defined(__powerpc64__)
0027 #define GEN_ELF_ARCH EM_PPC64
0028 #define GEN_ELF_CLASS ELFCLASS64
0029 #elif defined(__powerpc__)
0030 #define GEN_ELF_ARCH EM_PPC
0031 #define GEN_ELF_CLASS ELFCLASS32
0032 #elif defined(__sparc__) && defined(__arch64__)
0033 #define GEN_ELF_ARCH EM_SPARCV9
0034 #define GEN_ELF_CLASS ELFCLASS64
0035 #elif defined(__sparc__)
0036 #define GEN_ELF_ARCH EM_SPARC
0037 #define GEN_ELF_CLASS ELFCLASS32
0038 #elif defined(__s390x__)
0039 #define GEN_ELF_ARCH EM_S390
0040 #define GEN_ELF_CLASS ELFCLASS64
0041 #elif defined(__riscv) && __riscv_xlen == 64
0042 #define GEN_ELF_ARCH EM_RISCV
0043 #define GEN_ELF_CLASS ELFCLASS64
0044 #else
0045 #error "unsupported architecture"
0046 #endif
0047
0048 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
0049 #define GEN_ELF_ENDIAN ELFDATA2MSB
0050 #else
0051 #define GEN_ELF_ENDIAN ELFDATA2LSB
0052 #endif
0053
0054 #if GEN_ELF_CLASS == ELFCLASS64
0055 #define elf_newehdr elf64_newehdr
0056 #define elf_newphdr elf64_newphdr
0057 #define elf_getshdr elf64_getshdr
0058 #define Elf_Ehdr Elf64_Ehdr
0059 #define Elf_Phdr Elf64_Phdr
0060 #define Elf_Shdr Elf64_Shdr
0061 #define Elf_Sym Elf64_Sym
0062 #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
0063 #define ELF_ST_BIND(a) ELF64_ST_BIND(a)
0064 #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
0065 #else
0066 #define elf_newehdr elf32_newehdr
0067 #define elf_newphdr elf32_newphdr
0068 #define elf_getshdr elf32_getshdr
0069 #define Elf_Ehdr Elf32_Ehdr
0070 #define Elf_Phdr Elf32_Phdr
0071 #define Elf_Shdr Elf32_Shdr
0072 #define Elf_Sym Elf32_Sym
0073 #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
0074 #define ELF_ST_BIND(a) ELF32_ST_BIND(a)
0075 #define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a)
0076 #endif
0077
0078
0079 #define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
0080
0081 #endif