blob: d4137559be0537fe49e6ef923cdce447619016f0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Stephane Eranian9b07e272015-11-30 10:02:21 +01002#ifndef __GENELF_H__
3#define __GENELF_H__
4
5/* genelf.c */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -03006int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
Stefano Sanfilippo086f9f32016-10-13 03:59:41 -07007 const void *code, int csize, void *debug, int nr_debug_entries,
8 void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size);
Maciej Debski621cb4e2016-10-13 03:59:36 -07009#ifdef HAVE_DWARF_SUPPORT
Stephane Eranian598b7c62015-11-30 10:02:23 +010010/* genelf_debug.c */
Arnaldo Carvalho de Melo3938bad2016-03-23 15:06:35 -030011int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
Maciej Debski621cb4e2016-10-13 03:59:36 -070012#endif
Stephane Eranian9b07e272015-11-30 10:02:21 +010013
14#if defined(__arm__)
15#define GEN_ELF_ARCH EM_ARM
Stephane Eranian9b07e272015-11-30 10:02:21 +010016#define GEN_ELF_CLASS ELFCLASS32
17#elif defined(__aarch64__)
18#define GEN_ELF_ARCH EM_AARCH64
Stephane Eranian9b07e272015-11-30 10:02:21 +010019#define GEN_ELF_CLASS ELFCLASS64
20#elif defined(__x86_64__)
21#define GEN_ELF_ARCH EM_X86_64
Stephane Eranian9b07e272015-11-30 10:02:21 +010022#define GEN_ELF_CLASS ELFCLASS64
23#elif defined(__i386__)
24#define GEN_ELF_ARCH EM_386
Stephane Eranian9b07e272015-11-30 10:02:21 +010025#define GEN_ELF_CLASS ELFCLASS32
Anton Blanchard9f56c092016-03-29 17:59:44 +110026#elif defined(__powerpc64__)
27#define GEN_ELF_ARCH EM_PPC64
Stephane Eranian9b07e272015-11-30 10:02:21 +010028#define GEN_ELF_CLASS ELFCLASS64
29#elif defined(__powerpc__)
Anton Blanchard9f56c092016-03-29 17:59:44 +110030#define GEN_ELF_ARCH EM_PPC
31#define GEN_ELF_CLASS ELFCLASS32
David Millerd87b9792018-10-16 21:15:45 -070032#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
Thomas Richter61bf4ee2019-09-09 13:41:15 +020038#elif defined(__s390x__)
39#define GEN_ELF_ARCH EM_S390
40#define GEN_ELF_CLASS ELFCLASS64
Stephane Eranian9b07e272015-11-30 10:02:21 +010041#else
42#error "unsupported architecture"
43#endif
44
Anton Blanchard9f56c092016-03-29 17:59:44 +110045#if __BYTE_ORDER == __BIG_ENDIAN
46#define GEN_ELF_ENDIAN ELFDATA2MSB
47#else
48#define GEN_ELF_ENDIAN ELFDATA2LSB
49#endif
50
Stephane Eranian9b07e272015-11-30 10:02:21 +010051#if GEN_ELF_CLASS == ELFCLASS64
52#define elf_newehdr elf64_newehdr
53#define elf_getshdr elf64_getshdr
54#define Elf_Ehdr Elf64_Ehdr
55#define Elf_Shdr Elf64_Shdr
56#define Elf_Sym Elf64_Sym
57#define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
58#define ELF_ST_BIND(a) ELF64_ST_BIND(a)
59#define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
60#else
61#define elf_newehdr elf32_newehdr
62#define elf_getshdr elf32_getshdr
63#define Elf_Ehdr Elf32_Ehdr
64#define Elf_Shdr Elf32_Shdr
65#define Elf_Sym Elf32_Sym
66#define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
67#define ELF_ST_BIND(a) ELF32_ST_BIND(a)
68#define ELF_ST_VIS(a) ELF32_ST_VISIBILITY(a)
69#endif
70
71/* The .text section is directly after the ELF header */
72#define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
73
74#endif