xref: /openbmc/linux/tools/perf/util/genelf.h (revision e6dec923)
1 #ifndef __GENELF_H__
2 #define __GENELF_H__
3 
4 /* genelf.c */
5 int jit_write_elf(int fd, uint64_t code_addr, const char *sym,
6 		  const void *code, int csize, void *debug, int nr_debug_entries,
7 		  void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size);
8 #ifdef HAVE_DWARF_SUPPORT
9 /* genelf_debug.c */
10 int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
11 #endif
12 
13 #if   defined(__arm__)
14 #define GEN_ELF_ARCH	EM_ARM
15 #define GEN_ELF_CLASS	ELFCLASS32
16 #elif defined(__aarch64__)
17 #define GEN_ELF_ARCH	EM_AARCH64
18 #define GEN_ELF_CLASS	ELFCLASS64
19 #elif defined(__x86_64__)
20 #define GEN_ELF_ARCH	EM_X86_64
21 #define GEN_ELF_CLASS	ELFCLASS64
22 #elif defined(__i386__)
23 #define GEN_ELF_ARCH	EM_386
24 #define GEN_ELF_CLASS	ELFCLASS32
25 #elif defined(__powerpc64__)
26 #define GEN_ELF_ARCH	EM_PPC64
27 #define GEN_ELF_CLASS	ELFCLASS64
28 #elif defined(__powerpc__)
29 #define GEN_ELF_ARCH	EM_PPC
30 #define GEN_ELF_CLASS	ELFCLASS32
31 #else
32 #error "unsupported architecture"
33 #endif
34 
35 #if __BYTE_ORDER == __BIG_ENDIAN
36 #define GEN_ELF_ENDIAN	ELFDATA2MSB
37 #else
38 #define GEN_ELF_ENDIAN	ELFDATA2LSB
39 #endif
40 
41 #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
65