Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 2 | #ifndef __GENELF_H__ |
| 3 | #define __GENELF_H__ |
| 4 | |
| 5 | /* genelf.c */ |
Arnaldo Carvalho de Melo | 3938bad | 2016-03-23 15:06:35 -0300 | [diff] [blame] | 6 | int jit_write_elf(int fd, uint64_t code_addr, const char *sym, |
Stefano Sanfilippo | 086f9f3 | 2016-10-13 03:59:41 -0700 | [diff] [blame] | 7 | const void *code, int csize, void *debug, int nr_debug_entries, |
| 8 | void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size); |
Maciej Debski | 621cb4e | 2016-10-13 03:59:36 -0700 | [diff] [blame] | 9 | #ifdef HAVE_DWARF_SUPPORT |
Stephane Eranian | 598b7c6 | 2015-11-30 10:02:23 +0100 | [diff] [blame] | 10 | /* genelf_debug.c */ |
Arnaldo Carvalho de Melo | 3938bad | 2016-03-23 15:06:35 -0300 | [diff] [blame] | 11 | int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries); |
Maciej Debski | 621cb4e | 2016-10-13 03:59:36 -0700 | [diff] [blame] | 12 | #endif |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 13 | |
| 14 | #if defined(__arm__) |
| 15 | #define GEN_ELF_ARCH EM_ARM |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 16 | #define GEN_ELF_CLASS ELFCLASS32 |
| 17 | #elif defined(__aarch64__) |
| 18 | #define GEN_ELF_ARCH EM_AARCH64 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 19 | #define GEN_ELF_CLASS ELFCLASS64 |
| 20 | #elif defined(__x86_64__) |
| 21 | #define GEN_ELF_ARCH EM_X86_64 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 22 | #define GEN_ELF_CLASS ELFCLASS64 |
| 23 | #elif defined(__i386__) |
| 24 | #define GEN_ELF_ARCH EM_386 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 25 | #define GEN_ELF_CLASS ELFCLASS32 |
Anton Blanchard | 9f56c09 | 2016-03-29 17:59:44 +1100 | [diff] [blame] | 26 | #elif defined(__powerpc64__) |
| 27 | #define GEN_ELF_ARCH EM_PPC64 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 28 | #define GEN_ELF_CLASS ELFCLASS64 |
| 29 | #elif defined(__powerpc__) |
Anton Blanchard | 9f56c09 | 2016-03-29 17:59:44 +1100 | [diff] [blame] | 30 | #define GEN_ELF_ARCH EM_PPC |
| 31 | #define GEN_ELF_CLASS ELFCLASS32 |
David Miller | d87b979 | 2018-10-16 21:15:45 -0700 | [diff] [blame] | 32 | #elif defined(__sparc__) && defined(__arch64__) |
| 33 | #define GEN_ELF_ARCH EM_SPARCV9 |
| 34 | #define GEN_ELF_CLASS ELFCLASS64 |
| 35 | #elif defined(__sparc__) |
| 36 | #define GEN_ELF_ARCH EM_SPARC |
| 37 | #define GEN_ELF_CLASS ELFCLASS32 |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 38 | #else |
| 39 | #error "unsupported architecture" |
| 40 | #endif |
| 41 | |
Anton Blanchard | 9f56c09 | 2016-03-29 17:59:44 +1100 | [diff] [blame] | 42 | #if __BYTE_ORDER == __BIG_ENDIAN |
| 43 | #define GEN_ELF_ENDIAN ELFDATA2MSB |
| 44 | #else |
| 45 | #define GEN_ELF_ENDIAN ELFDATA2LSB |
| 46 | #endif |
| 47 | |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 48 | #if GEN_ELF_CLASS == ELFCLASS64 |
| 49 | #define elf_newehdr elf64_newehdr |
| 50 | #define elf_getshdr elf64_getshdr |
| 51 | #define Elf_Ehdr Elf64_Ehdr |
| 52 | #define Elf_Shdr Elf64_Shdr |
| 53 | #define Elf_Sym Elf64_Sym |
| 54 | #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a) |
| 55 | #define ELF_ST_BIND(a) ELF64_ST_BIND(a) |
| 56 | #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a) |
| 57 | #else |
| 58 | #define elf_newehdr elf32_newehdr |
| 59 | #define elf_getshdr elf32_getshdr |
| 60 | #define Elf_Ehdr Elf32_Ehdr |
| 61 | #define Elf_Shdr Elf32_Shdr |
| 62 | #define Elf_Sym Elf32_Sym |
| 63 | #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a) |
| 64 | #define ELF_ST_BIND(a) ELF32_ST_BIND(a) |
| 65 | #define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a) |
| 66 | #endif |
| 67 | |
| 68 | /* The .text section is directly after the ELF header */ |
| 69 | #define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr) |
| 70 | |
| 71 | #endif |