blob: 2fbeb59c4bdd91b2b9de943d153c3674c46ca125 [file] [log] [blame]
Stephane Eranian9b07e272015-11-30 10:02:21 +01001#ifndef __GENELF_H__
2#define __GENELF_H__
3
4/* genelf.c */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -03005int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
6 const void *code, int csize, void *debug, int nr_debug_entries);
Stephane Eranian598b7c62015-11-30 10:02:23 +01007/* genelf_debug.c */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -03008int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
Stephane Eranian9b07e272015-11-30 10:02:21 +01009
10#if defined(__arm__)
11#define GEN_ELF_ARCH EM_ARM
Stephane Eranian9b07e272015-11-30 10:02:21 +010012#define GEN_ELF_CLASS ELFCLASS32
13#elif defined(__aarch64__)
14#define GEN_ELF_ARCH EM_AARCH64
Stephane Eranian9b07e272015-11-30 10:02:21 +010015#define GEN_ELF_CLASS ELFCLASS64
16#elif defined(__x86_64__)
17#define GEN_ELF_ARCH EM_X86_64
Stephane Eranian9b07e272015-11-30 10:02:21 +010018#define GEN_ELF_CLASS ELFCLASS64
19#elif defined(__i386__)
20#define GEN_ELF_ARCH EM_386
Stephane Eranian9b07e272015-11-30 10:02:21 +010021#define GEN_ELF_CLASS ELFCLASS32
Anton Blanchard9f56c092016-03-29 17:59:44 +110022#elif defined(__powerpc64__)
23#define GEN_ELF_ARCH EM_PPC64
Stephane Eranian9b07e272015-11-30 10:02:21 +010024#define GEN_ELF_CLASS ELFCLASS64
25#elif defined(__powerpc__)
Anton Blanchard9f56c092016-03-29 17:59:44 +110026#define GEN_ELF_ARCH EM_PPC
27#define GEN_ELF_CLASS ELFCLASS32
Stephane Eranian9b07e272015-11-30 10:02:21 +010028#else
29#error "unsupported architecture"
30#endif
31
Anton Blanchard9f56c092016-03-29 17:59:44 +110032#if __BYTE_ORDER == __BIG_ENDIAN
33#define GEN_ELF_ENDIAN ELFDATA2MSB
34#else
35#define GEN_ELF_ENDIAN ELFDATA2LSB
36#endif
37
Stephane Eranian9b07e272015-11-30 10:02:21 +010038#if GEN_ELF_CLASS == ELFCLASS64
39#define elf_newehdr elf64_newehdr
40#define elf_getshdr elf64_getshdr
41#define Elf_Ehdr Elf64_Ehdr
42#define Elf_Shdr Elf64_Shdr
43#define Elf_Sym Elf64_Sym
44#define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
45#define ELF_ST_BIND(a) ELF64_ST_BIND(a)
46#define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
47#else
48#define elf_newehdr elf32_newehdr
49#define elf_getshdr elf32_getshdr
50#define Elf_Ehdr Elf32_Ehdr
51#define Elf_Shdr Elf32_Shdr
52#define Elf_Sym Elf32_Sym
53#define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
54#define ELF_ST_BIND(a) ELF32_ST_BIND(a)
55#define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a)
56#endif
57
58/* The .text section is directly after the ELF header */
59#define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
60
61#endif