xref: /kvm-unit-tests/lib/elf.h (revision 6444ae208ce0085d0f5c5ffb15909ca3bbd49c84)
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 /* 32-bit ELF base types. */
12 typedef u32	Elf32_Addr;
13 typedef u32	Elf32_Xword;
14 typedef s32	Elf32_Sxword;
15 
16 /* 64-bit ELF base types. */
17 typedef u64	Elf64_Addr;
18 typedef u64	Elf64_Xword;
19 typedef s64	Elf64_Sxword;
20 
21 typedef struct {
22 	Elf64_Sxword d_tag;             /* entry tag value */
23 	union {
24 		Elf64_Xword d_val;
25 		Elf64_Addr d_ptr;
26 	} d_un;
27 } Elf64_Dyn;
28 
29 typedef struct elf64_rel {
30 	Elf64_Addr r_offset;    /* Location at which to apply the action */
31 	Elf64_Xword r_info;     /* index and type of relocation */
32 } Elf64_Rel;
33 
34 typedef struct elf32_rela {
35 	Elf32_Addr r_offset;    /* Location at which to apply the action */
36 	Elf32_Xword r_info;     /* index and type of relocation */
37 	Elf32_Sxword r_addend;  /* Constant addend used to compute value */
38 } Elf32_Rela;
39 
40 typedef struct elf64_rela {
41 	Elf64_Addr r_offset;    /* Location at which to apply the action */
42 	Elf64_Xword r_info;     /* index and type of relocation */
43 	Elf64_Sxword r_addend;  /* Constant addend used to compute value */
44 } Elf64_Rela;
45 
46 /* This is the info that is needed to parse the dynamic section of the file */
47 #define DT_NULL		0
48 #define DT_RELA		7
49 #define DT_RELASZ	8
50 #define DT_RELAENT	9
51 
52 /* x86 relocation types. */
53 #define R_X86_64_NONE		0       /* No reloc */
54 #define R_X86_64_RELATIVE	8       /* Adjust by program base */
55 
56 
57 /*
58  * AArch64 static relocation types.
59  */
60 
61 /* Miscellaneous. */
62 #define R_AARCH64_NONE		256
63 #define R_AARCH64_RELATIVE	1027
64 
65 /* The following are used with relocations */
66 #define ELF64_R_TYPE(i)		((i) & 0xffffffff)
67 
68 /*
69  * riscv static relocation types.
70  */
71 #define R_RISCV_RELATIVE	3
72 
73 #endif /* _ELF_H_ */
74