xref: /kvm-unit-tests/lib/elf.h (revision 1d0f08f40d53daa39566842ec46a112db5f7e524)
1 /* SPDX-License-Identifier: LGPL-2.0-or-later */
2 /*
3  * Relevant definitions from uapi/linux/elf.h and asm/elf.h
4  */
5 
6 #ifndef _ELF_H_
7 #define _ELF_H_
8 
9 #include <libcflat.h>
10 
11 /* 64-bit ELF base types. */
12 typedef u64	Elf64_Addr;
13 typedef u64	Elf64_Xword;
14 typedef s64	Elf64_Sxword;
15 
16 typedef struct {
17 	Elf64_Sxword d_tag;             /* entry tag value */
18 	union {
19 		Elf64_Xword d_val;
20 		Elf64_Addr d_ptr;
21 	} d_un;
22 } Elf64_Dyn;
23 
24 typedef struct elf64_rel {
25 	Elf64_Addr r_offset;    /* Location at which to apply the action */
26 	Elf64_Xword r_info;     /* index and type of relocation */
27 } Elf64_Rel;
28 
29 typedef struct elf64_rela {
30 	Elf64_Addr r_offset;    /* Location at which to apply the action */
31 	Elf64_Xword r_info;     /* index and type of relocation */
32 	Elf64_Sxword r_addend;  /* Constant addend used to compute value */
33 } Elf64_Rela;
34 
35 /* This is the info that is needed to parse the dynamic section of the file */
36 #define DT_NULL		0
37 #define DT_RELA		7
38 #define DT_RELASZ	8
39 #define DT_RELAENT	9
40 
41 /* x86 relocation types. */
42 #define R_X86_64_NONE		0       /* No reloc */
43 #define R_X86_64_RELATIVE	8       /* Adjust by program base */
44 
45 
46 /*
47  * AArch64 static relocation types.
48  */
49 
50 /* Miscellaneous. */
51 #define R_AARCH64_NONE		256
52 #define R_AARCH64_RELATIVE	1027
53 
54 /* The following are used with relocations */
55 #define ELF64_R_TYPE(i)		((i) & 0xffffffff)
56 
57 #endif /* _ELF_H_ */
58