1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __GENELF_H__ 2 #ifndef __GENELF_H__ 3 #define __GENELF_H__ 3 #define __GENELF_H__ 4 4 5 #include <linux/math.h> !! 5 #include <linux/kernel.h> 6 6 7 /* genelf.c */ 7 /* genelf.c */ 8 int jit_write_elf(int fd, uint64_t code_addr, 8 int jit_write_elf(int fd, uint64_t code_addr, const char *sym, 9 const void *code, int csize, 9 const void *code, int csize, void *debug, int nr_debug_entries, 10 void *unwinding, uint64_t un 10 void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size); 11 #ifdef HAVE_DWARF_SUPPORT 11 #ifdef HAVE_DWARF_SUPPORT 12 /* genelf_debug.c */ 12 /* genelf_debug.c */ 13 int jit_add_debug_info(Elf *e, uint64_t code_a 13 int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries); 14 #endif 14 #endif 15 15 16 #if defined(__arm__) 16 #if defined(__arm__) 17 #define GEN_ELF_ARCH EM_ARM 17 #define GEN_ELF_ARCH EM_ARM 18 #define GEN_ELF_CLASS ELFCLASS32 18 #define GEN_ELF_CLASS ELFCLASS32 19 #elif defined(__aarch64__) 19 #elif defined(__aarch64__) 20 #define GEN_ELF_ARCH EM_AARCH64 20 #define GEN_ELF_ARCH EM_AARCH64 21 #define GEN_ELF_CLASS ELFCLASS64 21 #define GEN_ELF_CLASS ELFCLASS64 22 #elif defined(__x86_64__) 22 #elif defined(__x86_64__) 23 #define GEN_ELF_ARCH EM_X86_64 23 #define GEN_ELF_ARCH EM_X86_64 24 #define GEN_ELF_CLASS ELFCLASS64 24 #define GEN_ELF_CLASS ELFCLASS64 25 #elif defined(__i386__) 25 #elif defined(__i386__) 26 #define GEN_ELF_ARCH EM_386 26 #define GEN_ELF_ARCH EM_386 27 #define GEN_ELF_CLASS ELFCLASS32 27 #define GEN_ELF_CLASS ELFCLASS32 28 #elif defined(__powerpc64__) 28 #elif defined(__powerpc64__) 29 #define GEN_ELF_ARCH EM_PPC64 29 #define GEN_ELF_ARCH EM_PPC64 30 #define GEN_ELF_CLASS ELFCLASS64 30 #define GEN_ELF_CLASS ELFCLASS64 31 #elif defined(__powerpc__) 31 #elif defined(__powerpc__) 32 #define GEN_ELF_ARCH EM_PPC 32 #define GEN_ELF_ARCH EM_PPC 33 #define GEN_ELF_CLASS ELFCLASS32 33 #define GEN_ELF_CLASS ELFCLASS32 34 #elif defined(__sparc__) && defined(__arch64__ 34 #elif defined(__sparc__) && defined(__arch64__) 35 #define GEN_ELF_ARCH EM_SPARCV9 35 #define GEN_ELF_ARCH EM_SPARCV9 36 #define GEN_ELF_CLASS ELFCLASS64 36 #define GEN_ELF_CLASS ELFCLASS64 37 #elif defined(__sparc__) 37 #elif defined(__sparc__) 38 #define GEN_ELF_ARCH EM_SPARC 38 #define GEN_ELF_ARCH EM_SPARC 39 #define GEN_ELF_CLASS ELFCLASS32 39 #define GEN_ELF_CLASS ELFCLASS32 40 #elif defined(__s390x__) 40 #elif defined(__s390x__) 41 #define GEN_ELF_ARCH EM_S390 41 #define GEN_ELF_ARCH EM_S390 42 #define GEN_ELF_CLASS ELFCLASS64 42 #define GEN_ELF_CLASS ELFCLASS64 43 #elif defined(__riscv) && __riscv_xlen == 64 << 44 #define GEN_ELF_ARCH EM_RISCV << 45 #define GEN_ELF_CLASS ELFCLASS64 << 46 #elif defined(__riscv) && __riscv_xlen == 32 << 47 #define GEN_ELF_ARCH EM_RISCV << 48 #define GEN_ELF_CLASS ELFCLASS32 << 49 #elif defined(__loongarch__) << 50 #define GEN_ELF_ARCH EM_LOONGARCH << 51 #define GEN_ELF_CLASS ELFCLASS64 << 52 #else 43 #else 53 #error "unsupported architecture" 44 #error "unsupported architecture" 54 #endif 45 #endif 55 46 56 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ !! 47 #if __BYTE_ORDER == __BIG_ENDIAN 57 #define GEN_ELF_ENDIAN ELFDATA2MSB 48 #define GEN_ELF_ENDIAN ELFDATA2MSB 58 #else 49 #else 59 #define GEN_ELF_ENDIAN ELFDATA2LSB 50 #define GEN_ELF_ENDIAN ELFDATA2LSB 60 #endif 51 #endif 61 52 62 #if GEN_ELF_CLASS == ELFCLASS64 53 #if GEN_ELF_CLASS == ELFCLASS64 63 #define elf_newehdr elf64_newehdr 54 #define elf_newehdr elf64_newehdr 64 #define elf_newphdr elf64_newphdr 55 #define elf_newphdr elf64_newphdr 65 #define elf_getshdr elf64_getshdr 56 #define elf_getshdr elf64_getshdr 66 #define Elf_Ehdr Elf64_Ehdr 57 #define Elf_Ehdr Elf64_Ehdr 67 #define Elf_Phdr Elf64_Phdr 58 #define Elf_Phdr Elf64_Phdr 68 #define Elf_Shdr Elf64_Shdr 59 #define Elf_Shdr Elf64_Shdr 69 #define Elf_Sym Elf64_Sym 60 #define Elf_Sym Elf64_Sym 70 #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a) 61 #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a) 71 #define ELF_ST_BIND(a) ELF64_ST_BIND(a) 62 #define ELF_ST_BIND(a) ELF64_ST_BIND(a) 72 #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a) 63 #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a) 73 #else 64 #else 74 #define elf_newehdr elf32_newehdr 65 #define elf_newehdr elf32_newehdr 75 #define elf_newphdr elf32_newphdr 66 #define elf_newphdr elf32_newphdr 76 #define elf_getshdr elf32_getshdr 67 #define elf_getshdr elf32_getshdr 77 #define Elf_Ehdr Elf32_Ehdr 68 #define Elf_Ehdr Elf32_Ehdr 78 #define Elf_Phdr Elf32_Phdr 69 #define Elf_Phdr Elf32_Phdr 79 #define Elf_Shdr Elf32_Shdr 70 #define Elf_Shdr Elf32_Shdr 80 #define Elf_Sym Elf32_Sym 71 #define Elf_Sym Elf32_Sym 81 #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a) 72 #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a) 82 #define ELF_ST_BIND(a) ELF32_ST_BIND(a) 73 #define ELF_ST_BIND(a) ELF32_ST_BIND(a) 83 #define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a) 74 #define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a) 84 #endif 75 #endif 85 76 86 /* The .text section is directly after the ELF 77 /* The .text section is directly after the ELF header */ 87 #define GEN_ELF_TEXT_OFFSET round_up(sizeof(El 78 #define GEN_ELF_TEXT_OFFSET round_up(sizeof(Elf_Ehdr) + sizeof(Elf_Phdr), 16) 88 79 89 #endif 80 #endif 90 81
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.