Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 1 | #ifndef __GENELF_H__ |
| 2 | #define __GENELF_H__ |
| 3 | |
| 4 | /* genelf.c */ |
Arnaldo Carvalho de Melo | 3938bad | 2016-03-23 15:06:35 -0300 | [diff] [blame] | 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); |
Maciej Debski | 03f5be2 | 2016-10-13 03:59:36 -0700 | [diff] [blame^] | 7 | #ifdef HAVE_DWARF_SUPPORT |
Stephane Eranian | 598b7c6 | 2015-11-30 10:02:23 +0100 | [diff] [blame] | 8 | /* genelf_debug.c */ |
Arnaldo Carvalho de Melo | 3938bad | 2016-03-23 15:06:35 -0300 | [diff] [blame] | 9 | int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries); |
Maciej Debski | 03f5be2 | 2016-10-13 03:59:36 -0700 | [diff] [blame^] | 10 | #endif |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 11 | |
| 12 | #if defined(__arm__) |
| 13 | #define GEN_ELF_ARCH EM_ARM |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 14 | #define GEN_ELF_CLASS ELFCLASS32 |
| 15 | #elif defined(__aarch64__) |
| 16 | #define GEN_ELF_ARCH EM_AARCH64 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 17 | #define GEN_ELF_CLASS ELFCLASS64 |
| 18 | #elif defined(__x86_64__) |
| 19 | #define GEN_ELF_ARCH EM_X86_64 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 20 | #define GEN_ELF_CLASS ELFCLASS64 |
| 21 | #elif defined(__i386__) |
| 22 | #define GEN_ELF_ARCH EM_386 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 23 | #define GEN_ELF_CLASS ELFCLASS32 |
Anton Blanchard | 9f56c09 | 2016-03-29 17:59:44 +1100 | [diff] [blame] | 24 | #elif defined(__powerpc64__) |
| 25 | #define GEN_ELF_ARCH EM_PPC64 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 26 | #define GEN_ELF_CLASS ELFCLASS64 |
| 27 | #elif defined(__powerpc__) |
Anton Blanchard | 9f56c09 | 2016-03-29 17:59:44 +1100 | [diff] [blame] | 28 | #define GEN_ELF_ARCH EM_PPC |
| 29 | #define GEN_ELF_CLASS ELFCLASS32 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 30 | #else |
| 31 | #error "unsupported architecture" |
| 32 | #endif |
| 33 | |
Anton Blanchard | 9f56c09 | 2016-03-29 17:59:44 +1100 | [diff] [blame] | 34 | #if __BYTE_ORDER == __BIG_ENDIAN |
| 35 | #define GEN_ELF_ENDIAN ELFDATA2MSB |
| 36 | #else |
| 37 | #define GEN_ELF_ENDIAN ELFDATA2LSB |
| 38 | #endif |
| 39 | |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 40 | #if GEN_ELF_CLASS == ELFCLASS64 |
| 41 | #define elf_newehdr elf64_newehdr |
| 42 | #define elf_getshdr elf64_getshdr |
| 43 | #define Elf_Ehdr Elf64_Ehdr |
| 44 | #define Elf_Shdr Elf64_Shdr |
| 45 | #define Elf_Sym Elf64_Sym |
| 46 | #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a) |
| 47 | #define ELF_ST_BIND(a) ELF64_ST_BIND(a) |
| 48 | #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a) |
| 49 | #else |
| 50 | #define elf_newehdr elf32_newehdr |
| 51 | #define elf_getshdr elf32_getshdr |
| 52 | #define Elf_Ehdr Elf32_Ehdr |
| 53 | #define Elf_Shdr Elf32_Shdr |
| 54 | #define Elf_Sym Elf32_Sym |
| 55 | #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a) |
| 56 | #define ELF_ST_BIND(a) ELF32_ST_BIND(a) |
| 57 | #define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a) |
| 58 | #endif |
| 59 | |
| 60 | /* The .text section is directly after the ELF header */ |
| 61 | #define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr) |
| 62 | |
| 63 | #endif |