xref: /openbmc/linux/tools/perf/util/genelf.h (revision 3e26a691)
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 /* genelf_debug.c */
8 int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
9 
10 #if   defined(__arm__)
11 #define GEN_ELF_ARCH	EM_ARM
12 #define GEN_ELF_ENDIAN	ELFDATA2LSB
13 #define GEN_ELF_CLASS	ELFCLASS32
14 #elif defined(__aarch64__)
15 #define GEN_ELF_ARCH	EM_AARCH64
16 #define GEN_ELF_ENDIAN	ELFDATA2LSB
17 #define GEN_ELF_CLASS	ELFCLASS64
18 #elif defined(__x86_64__)
19 #define GEN_ELF_ARCH	EM_X86_64
20 #define GEN_ELF_ENDIAN	ELFDATA2LSB
21 #define GEN_ELF_CLASS	ELFCLASS64
22 #elif defined(__i386__)
23 #define GEN_ELF_ARCH	EM_386
24 #define GEN_ELF_ENDIAN	ELFDATA2LSB
25 #define GEN_ELF_CLASS	ELFCLASS32
26 #elif defined(__ppcle__)
27 #define GEN_ELF_ARCH	EM_PPC
28 #define GEN_ELF_ENDIAN	ELFDATA2LSB
29 #define GEN_ELF_CLASS	ELFCLASS64
30 #elif defined(__powerpc__)
31 #define GEN_ELF_ARCH	EM_PPC64
32 #define GEN_ELF_ENDIAN	ELFDATA2MSB
33 #define GEN_ELF_CLASS	ELFCLASS64
34 #elif defined(__powerpcle__)
35 #define GEN_ELF_ARCH	EM_PPC64
36 #define GEN_ELF_ENDIAN	ELFDATA2LSB
37 #define GEN_ELF_CLASS	ELFCLASS64
38 #else
39 #error "unsupported architecture"
40 #endif
41 
42 #if GEN_ELF_CLASS == ELFCLASS64
43 #define elf_newehdr	elf64_newehdr
44 #define elf_getshdr	elf64_getshdr
45 #define Elf_Ehdr	Elf64_Ehdr
46 #define Elf_Shdr	Elf64_Shdr
47 #define Elf_Sym		Elf64_Sym
48 #define ELF_ST_TYPE(a)	ELF64_ST_TYPE(a)
49 #define ELF_ST_BIND(a)	ELF64_ST_BIND(a)
50 #define ELF_ST_VIS(a)	ELF64_ST_VISIBILITY(a)
51 #else
52 #define elf_newehdr	elf32_newehdr
53 #define elf_getshdr	elf32_getshdr
54 #define Elf_Ehdr	Elf32_Ehdr
55 #define Elf_Shdr	Elf32_Shdr
56 #define Elf_Sym		Elf32_Sym
57 #define ELF_ST_TYPE(a)	ELF32_ST_TYPE(a)
58 #define ELF_ST_BIND(a)	ELF32_ST_BIND(a)
59 #define ELF_ST_VIS(a)	ELF32_ST_VISIBILITY(a)
60 #endif
61 
62 /* The .text section is directly after the ELF header */
63 #define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
64 
65 #endif
66