blob: 2424bd9862a309381ad4748f674114f4a31b2678 [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,
Stefano Sanfilippo086f9f32016-10-13 03:59:41 -07006 const void *code, int csize, void *debug, int nr_debug_entries,
7 void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size);
Maciej Debski621cb4e2016-10-13 03:59:36 -07008#ifdef HAVE_DWARF_SUPPORT
Stephane Eranian598b7c62015-11-30 10:02:23 +01009/* genelf_debug.c */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030010int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
Maciej Debski621cb4e2016-10-13 03:59:36 -070011#endif
Stephane Eranian9b07e272015-11-30 10:02:21 +010012
13#if defined(__arm__)
14#define GEN_ELF_ARCH EM_ARM
Stephane Eranian9b07e272015-11-30 10:02:21 +010015#define GEN_ELF_CLASS ELFCLASS32
16#elif defined(__aarch64__)
17#define GEN_ELF_ARCH EM_AARCH64
Stephane Eranian9b07e272015-11-30 10:02:21 +010018#define GEN_ELF_CLASS ELFCLASS64
19#elif defined(__x86_64__)
20#define GEN_ELF_ARCH EM_X86_64
Stephane Eranian9b07e272015-11-30 10:02:21 +010021#define GEN_ELF_CLASS ELFCLASS64
22#elif defined(__i386__)
23#define GEN_ELF_ARCH EM_386
Stephane Eranian9b07e272015-11-30 10:02:21 +010024#define GEN_ELF_CLASS ELFCLASS32
Anton Blanchard9f56c092016-03-29 17:59:44 +110025#elif defined(__powerpc64__)
26#define GEN_ELF_ARCH EM_PPC64
Stephane Eranian9b07e272015-11-30 10:02:21 +010027#define GEN_ELF_CLASS ELFCLASS64
28#elif defined(__powerpc__)
Anton Blanchard9f56c092016-03-29 17:59:44 +110029#define GEN_ELF_ARCH EM_PPC
30#define GEN_ELF_CLASS ELFCLASS32
Stephane Eranian9b07e272015-11-30 10:02:21 +010031#else
32#error "unsupported architecture"
33#endif
34
Anton Blanchard9f56c092016-03-29 17:59:44 +110035#if __BYTE_ORDER == __BIG_ENDIAN
36#define GEN_ELF_ENDIAN ELFDATA2MSB
37#else
38#define GEN_ELF_ENDIAN ELFDATA2LSB
39#endif
40
Stephane Eranian9b07e272015-11-30 10:02:21 +010041#if GEN_ELF_CLASS == ELFCLASS64
42#define elf_newehdr elf64_newehdr
43#define elf_getshdr elf64_getshdr
44#define Elf_Ehdr Elf64_Ehdr
45#define Elf_Shdr Elf64_Shdr
46#define Elf_Sym Elf64_Sym
47#define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
48#define ELF_ST_BIND(a) ELF64_ST_BIND(a)
49#define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
50#else
51#define elf_newehdr elf32_newehdr
52#define elf_getshdr elf32_getshdr
53#define Elf_Ehdr Elf32_Ehdr
54#define Elf_Shdr Elf32_Shdr
55#define Elf_Sym Elf32_Sym
56#define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
57#define ELF_ST_BIND(a) ELF32_ST_BIND(a)
58#define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a)
59#endif
60
61/* The .text section is directly after the ELF header */
62#define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
63
64#endif