1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
2 | #ifndef _LINUX_ELF_H |
3 | #define _LINUX_ELF_H |
4 | |
5 | #include <linux/types.h> |
6 | #include <linux/elf-em.h> |
7 | |
8 | /* 32-bit ELF base types. */ |
9 | typedef __u32 Elf32_Addr; |
10 | typedef __u16 Elf32_Half; |
11 | typedef __u32 Elf32_Off; |
12 | typedef __s32 Elf32_Sword; |
13 | typedef __u32 Elf32_Word; |
14 | |
15 | /* 64-bit ELF base types. */ |
16 | typedef __u64 Elf64_Addr; |
17 | typedef __u16 Elf64_Half; |
18 | typedef __s16 Elf64_SHalf; |
19 | typedef __u64 Elf64_Off; |
20 | typedef __s32 Elf64_Sword; |
21 | typedef __u32 Elf64_Word; |
22 | typedef __u64 Elf64_Xword; |
23 | typedef __s64 Elf64_Sxword; |
24 | |
25 | /* These constants are for the segment types stored in the image headers */ |
26 | #define PT_NULL 0 |
27 | #define PT_LOAD 1 |
28 | #define PT_DYNAMIC 2 |
29 | #define PT_INTERP 3 |
30 | #define PT_NOTE 4 |
31 | #define PT_SHLIB 5 |
32 | #define PT_PHDR 6 |
33 | #define PT_TLS 7 /* Thread local storage segment */ |
34 | #define PT_LOOS 0x60000000 /* OS-specific */ |
35 | #define PT_HIOS 0x6fffffff /* OS-specific */ |
36 | #define PT_LOPROC 0x70000000 |
37 | #define PT_HIPROC 0x7fffffff |
38 | #define PT_GNU_EH_FRAME 0x6474e550 |
39 | #define PT_GNU_PROPERTY 0x6474e553 |
40 | |
41 | #define PT_GNU_STACK (PT_LOOS + 0x474e551) |
42 | |
43 | /* |
44 | * Extended Numbering |
45 | * |
46 | * If the real number of program header table entries is larger than |
47 | * or equal to PN_XNUM(0xffff), it is set to sh_info field of the |
48 | * section header at index 0, and PN_XNUM is set to e_phnum |
49 | * field. Otherwise, the section header at index 0 is zero |
50 | * initialized, if it exists. |
51 | * |
52 | * Specifications are available in: |
53 | * |
54 | * - Oracle: Linker and Libraries. |
55 | * Part No: 817–1984–19, August 2011. |
56 | * https://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf |
57 | * |
58 | * - System V ABI AMD64 Architecture Processor Supplement |
59 | * Draft Version 0.99.4, |
60 | * January 13, 2010. |
61 | * http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf |
62 | */ |
63 | #define PN_XNUM 0xffff |
64 | |
65 | /* These constants define the different elf file types */ |
66 | #define ET_NONE 0 |
67 | #define ET_REL 1 |
68 | #define ET_EXEC 2 |
69 | #define ET_DYN 3 |
70 | #define ET_CORE 4 |
71 | #define ET_LOPROC 0xff00 |
72 | #define ET_HIPROC 0xffff |
73 | |
74 | /* This is the info that is needed to parse the dynamic section of the file */ |
75 | #define DT_NULL 0 |
76 | #define DT_NEEDED 1 |
77 | #define DT_PLTRELSZ 2 |
78 | #define DT_PLTGOT 3 |
79 | #define DT_HASH 4 |
80 | #define DT_STRTAB 5 |
81 | #define DT_SYMTAB 6 |
82 | #define DT_RELA 7 |
83 | #define DT_RELASZ 8 |
84 | #define DT_RELAENT 9 |
85 | #define DT_STRSZ 10 |
86 | #define DT_SYMENT 11 |
87 | #define DT_INIT 12 |
88 | #define DT_FINI 13 |
89 | #define DT_SONAME 14 |
90 | #define DT_RPATH 15 |
91 | #define DT_SYMBOLIC 16 |
92 | #define DT_REL 17 |
93 | #define DT_RELSZ 18 |
94 | #define DT_RELENT 19 |
95 | #define DT_PLTREL 20 |
96 | #define DT_DEBUG 21 |
97 | #define DT_TEXTREL 22 |
98 | #define DT_JMPREL 23 |
99 | #define DT_ENCODING 32 |
100 | #define OLD_DT_LOOS 0x60000000 |
101 | #define DT_LOOS 0x6000000d |
102 | #define DT_HIOS 0x6ffff000 |
103 | #define DT_VALRNGLO 0x6ffffd00 |
104 | #define DT_VALRNGHI 0x6ffffdff |
105 | #define DT_ADDRRNGLO 0x6ffffe00 |
106 | #define DT_ADDRRNGHI 0x6ffffeff |
107 | #define DT_VERSYM 0x6ffffff0 |
108 | #define DT_RELACOUNT 0x6ffffff9 |
109 | #define DT_RELCOUNT 0x6ffffffa |
110 | #define DT_FLAGS_1 0x6ffffffb |
111 | #define DT_VERDEF 0x6ffffffc |
112 | #define DT_VERDEFNUM 0x6ffffffd |
113 | #define DT_VERNEED 0x6ffffffe |
114 | #define DT_VERNEEDNUM 0x6fffffff |
115 | #define OLD_DT_HIOS 0x6fffffff |
116 | #define DT_LOPROC 0x70000000 |
117 | #define DT_HIPROC 0x7fffffff |
118 | |
119 | /* This info is needed when parsing the symbol table */ |
120 | #define STB_LOCAL 0 |
121 | #define STB_GLOBAL 1 |
122 | #define STB_WEAK 2 |
123 | |
124 | #define STT_NOTYPE 0 |
125 | #define STT_OBJECT 1 |
126 | #define STT_FUNC 2 |
127 | #define STT_SECTION 3 |
128 | #define STT_FILE 4 |
129 | #define STT_COMMON 5 |
130 | #define STT_TLS 6 |
131 | |
132 | #define ELF_ST_BIND(x) ((x) >> 4) |
133 | #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf) |
134 | #define ELF32_ST_BIND(x) ELF_ST_BIND(x) |
135 | #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x) |
136 | #define ELF64_ST_BIND(x) ELF_ST_BIND(x) |
137 | #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x) |
138 | |
139 | typedef struct dynamic{ |
140 | Elf32_Sword d_tag; |
141 | union{ |
142 | Elf32_Sword d_val; |
143 | Elf32_Addr d_ptr; |
144 | } d_un; |
145 | } Elf32_Dyn; |
146 | |
147 | typedef struct { |
148 | Elf64_Sxword d_tag; /* entry tag value */ |
149 | union { |
150 | Elf64_Xword d_val; |
151 | Elf64_Addr d_ptr; |
152 | } d_un; |
153 | } Elf64_Dyn; |
154 | |
155 | /* The following are used with relocations */ |
156 | #define ELF32_R_SYM(x) ((x) >> 8) |
157 | #define ELF32_R_TYPE(x) ((x) & 0xff) |
158 | |
159 | #define ELF64_R_SYM(i) ((i) >> 32) |
160 | #define ELF64_R_TYPE(i) ((i) & 0xffffffff) |
161 | |
162 | typedef struct elf32_rel { |
163 | Elf32_Addr r_offset; |
164 | Elf32_Word r_info; |
165 | } Elf32_Rel; |
166 | |
167 | typedef struct elf64_rel { |
168 | Elf64_Addr r_offset; /* Location at which to apply the action */ |
169 | Elf64_Xword r_info; /* index and type of relocation */ |
170 | } Elf64_Rel; |
171 | |
172 | typedef struct elf32_rela{ |
173 | Elf32_Addr r_offset; |
174 | Elf32_Word r_info; |
175 | Elf32_Sword r_addend; |
176 | } Elf32_Rela; |
177 | |
178 | typedef struct elf64_rela { |
179 | Elf64_Addr r_offset; /* Location at which to apply the action */ |
180 | Elf64_Xword r_info; /* index and type of relocation */ |
181 | Elf64_Sxword r_addend; /* Constant addend used to compute value */ |
182 | } Elf64_Rela; |
183 | |
184 | typedef struct elf32_sym{ |
185 | Elf32_Word st_name; |
186 | Elf32_Addr st_value; |
187 | Elf32_Word st_size; |
188 | unsigned char st_info; |
189 | unsigned char st_other; |
190 | Elf32_Half st_shndx; |
191 | } Elf32_Sym; |
192 | |
193 | typedef struct elf64_sym { |
194 | Elf64_Word st_name; /* Symbol name, index in string tbl */ |
195 | unsigned char st_info; /* Type and binding attributes */ |
196 | unsigned char st_other; /* No defined meaning, 0 */ |
197 | Elf64_Half st_shndx; /* Associated section index */ |
198 | Elf64_Addr st_value; /* Value of the symbol */ |
199 | Elf64_Xword st_size; /* Associated symbol size */ |
200 | } Elf64_Sym; |
201 | |
202 | |
203 | #define EI_NIDENT 16 |
204 | |
205 | typedef struct elf32_hdr{ |
206 | unsigned char e_ident[EI_NIDENT]; |
207 | Elf32_Half e_type; |
208 | Elf32_Half e_machine; |
209 | Elf32_Word e_version; |
210 | Elf32_Addr e_entry; /* Entry point */ |
211 | Elf32_Off e_phoff; |
212 | Elf32_Off e_shoff; |
213 | Elf32_Word e_flags; |
214 | Elf32_Half e_ehsize; |
215 | Elf32_Half e_phentsize; |
216 | Elf32_Half e_phnum; |
217 | Elf32_Half e_shentsize; |
218 | Elf32_Half e_shnum; |
219 | Elf32_Half e_shstrndx; |
220 | } Elf32_Ehdr; |
221 | |
222 | typedef struct elf64_hdr { |
223 | unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */ |
224 | Elf64_Half e_type; |
225 | Elf64_Half e_machine; |
226 | Elf64_Word e_version; |
227 | Elf64_Addr e_entry; /* Entry point virtual address */ |
228 | Elf64_Off e_phoff; /* Program header table file offset */ |
229 | Elf64_Off e_shoff; /* Section header table file offset */ |
230 | Elf64_Word e_flags; |
231 | Elf64_Half e_ehsize; |
232 | Elf64_Half e_phentsize; |
233 | Elf64_Half e_phnum; |
234 | Elf64_Half e_shentsize; |
235 | Elf64_Half e_shnum; |
236 | Elf64_Half e_shstrndx; |
237 | } Elf64_Ehdr; |
238 | |
239 | /* These constants define the permissions on sections in the program |
240 | header, p_flags. */ |
241 | #define PF_R 0x4 |
242 | #define PF_W 0x2 |
243 | #define PF_X 0x1 |
244 | |
245 | typedef struct elf32_phdr{ |
246 | Elf32_Word p_type; |
247 | Elf32_Off p_offset; |
248 | Elf32_Addr p_vaddr; |
249 | Elf32_Addr p_paddr; |
250 | Elf32_Word p_filesz; |
251 | Elf32_Word p_memsz; |
252 | Elf32_Word p_flags; |
253 | Elf32_Word p_align; |
254 | } Elf32_Phdr; |
255 | |
256 | typedef struct elf64_phdr { |
257 | Elf64_Word p_type; |
258 | Elf64_Word p_flags; |
259 | Elf64_Off p_offset; /* Segment file offset */ |
260 | Elf64_Addr p_vaddr; /* Segment virtual address */ |
261 | Elf64_Addr p_paddr; /* Segment physical address */ |
262 | Elf64_Xword p_filesz; /* Segment size in file */ |
263 | Elf64_Xword p_memsz; /* Segment size in memory */ |
264 | Elf64_Xword p_align; /* Segment alignment, file & memory */ |
265 | } Elf64_Phdr; |
266 | |
267 | /* sh_type */ |
268 | #define SHT_NULL 0 |
269 | #define SHT_PROGBITS 1 |
270 | #define SHT_SYMTAB 2 |
271 | #define SHT_STRTAB 3 |
272 | #define SHT_RELA 4 |
273 | #define SHT_HASH 5 |
274 | #define SHT_DYNAMIC 6 |
275 | #define SHT_NOTE 7 |
276 | #define SHT_NOBITS 8 |
277 | #define SHT_REL 9 |
278 | #define SHT_SHLIB 10 |
279 | #define SHT_DYNSYM 11 |
280 | #define SHT_NUM 12 |
281 | #define SHT_LOPROC 0x70000000 |
282 | #define SHT_HIPROC 0x7fffffff |
283 | #define SHT_LOUSER 0x80000000 |
284 | #define SHT_HIUSER 0xffffffff |
285 | |
286 | /* sh_flags */ |
287 | #define SHF_WRITE 0x1 |
288 | #define SHF_ALLOC 0x2 |
289 | #define SHF_EXECINSTR 0x4 |
290 | #define SHF_RELA_LIVEPATCH 0x00100000 |
291 | #define SHF_RO_AFTER_INIT 0x00200000 |
292 | #define SHF_MASKPROC 0xf0000000 |
293 | |
294 | /* special section indexes */ |
295 | #define SHN_UNDEF 0 |
296 | #define SHN_LORESERVE 0xff00 |
297 | #define SHN_LOPROC 0xff00 |
298 | #define SHN_HIPROC 0xff1f |
299 | #define SHN_LIVEPATCH 0xff20 |
300 | #define SHN_ABS 0xfff1 |
301 | #define SHN_COMMON 0xfff2 |
302 | #define SHN_HIRESERVE 0xffff |
303 | |
304 | typedef struct elf32_shdr { |
305 | Elf32_Word sh_name; |
306 | Elf32_Word sh_type; |
307 | Elf32_Word sh_flags; |
308 | Elf32_Addr sh_addr; |
309 | Elf32_Off sh_offset; |
310 | Elf32_Word sh_size; |
311 | Elf32_Word sh_link; |
312 | Elf32_Word sh_info; |
313 | Elf32_Word sh_addralign; |
314 | Elf32_Word sh_entsize; |
315 | } Elf32_Shdr; |
316 | |
317 | typedef struct elf64_shdr { |
318 | Elf64_Word sh_name; /* Section name, index in string tbl */ |
319 | Elf64_Word sh_type; /* Type of section */ |
320 | Elf64_Xword sh_flags; /* Miscellaneous section attributes */ |
321 | Elf64_Addr sh_addr; /* Section virtual addr at execution */ |
322 | Elf64_Off sh_offset; /* Section file offset */ |
323 | Elf64_Xword sh_size; /* Size of section in bytes */ |
324 | Elf64_Word sh_link; /* Index of another section */ |
325 | Elf64_Word sh_info; /* Additional section information */ |
326 | Elf64_Xword sh_addralign; /* Section alignment */ |
327 | Elf64_Xword sh_entsize; /* Entry size if section holds table */ |
328 | } Elf64_Shdr; |
329 | |
330 | #define EI_MAG0 0 /* e_ident[] indexes */ |
331 | #define EI_MAG1 1 |
332 | #define EI_MAG2 2 |
333 | #define EI_MAG3 3 |
334 | #define EI_CLASS 4 |
335 | #define EI_DATA 5 |
336 | #define EI_VERSION 6 |
337 | #define EI_OSABI 7 |
338 | #define EI_PAD 8 |
339 | |
340 | #define ELFMAG0 0x7f /* EI_MAG */ |
341 | #define ELFMAG1 'E' |
342 | #define ELFMAG2 'L' |
343 | #define ELFMAG3 'F' |
344 | #define ELFMAG "\177ELF" |
345 | #define SELFMAG 4 |
346 | |
347 | #define ELFCLASSNONE 0 /* EI_CLASS */ |
348 | #define ELFCLASS32 1 |
349 | #define ELFCLASS64 2 |
350 | #define ELFCLASSNUM 3 |
351 | |
352 | #define ELFDATANONE 0 /* e_ident[EI_DATA] */ |
353 | #define ELFDATA2LSB 1 |
354 | #define ELFDATA2MSB 2 |
355 | |
356 | #define EV_NONE 0 /* e_version, EI_VERSION */ |
357 | #define EV_CURRENT 1 |
358 | #define EV_NUM 2 |
359 | |
360 | #define ELFOSABI_NONE 0 |
361 | #define ELFOSABI_LINUX 3 |
362 | |
363 | #ifndef ELF_OSABI |
364 | #define ELF_OSABI ELFOSABI_NONE |
365 | #endif |
366 | |
367 | /* |
368 | * Notes used in ET_CORE. Architectures export some of the arch register sets |
369 | * using the corresponding note types via the PTRACE_GETREGSET and |
370 | * PTRACE_SETREGSET requests. |
371 | * The note name for all these is "LINUX". |
372 | */ |
373 | #define NT_PRSTATUS 1 |
374 | #define NT_PRFPREG 2 |
375 | #define NT_PRPSINFO 3 |
376 | #define NT_TASKSTRUCT 4 |
377 | #define NT_AUXV 6 |
378 | /* |
379 | * Note to userspace developers: size of NT_SIGINFO note may increase |
380 | * in the future to accomodate more fields, don't assume it is fixed! |
381 | */ |
382 | #define NT_SIGINFO 0x53494749 |
383 | #define NT_FILE 0x46494c45 |
384 | #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */ |
385 | #define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */ |
386 | #define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */ |
387 | #define NT_PPC_VSX 0x102 /* PowerPC VSX registers */ |
388 | #define NT_PPC_TAR 0x103 /* Target Address Register */ |
389 | #define NT_PPC_PPR 0x104 /* Program Priority Register */ |
390 | #define NT_PPC_DSCR 0x105 /* Data Stream Control Register */ |
391 | #define NT_PPC_EBB 0x106 /* Event Based Branch Registers */ |
392 | #define NT_PPC_PMU 0x107 /* Performance Monitor Registers */ |
393 | #define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */ |
394 | #define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */ |
395 | #define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */ |
396 | #define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */ |
397 | #define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */ |
398 | #define NT_PPC_TM_CTAR 0x10d /* TM checkpointed Target Address Register */ |
399 | #define NT_PPC_TM_CPPR 0x10e /* TM checkpointed Program Priority Register */ |
400 | #define NT_PPC_TM_CDSCR 0x10f /* TM checkpointed Data Stream Control Register */ |
401 | #define NT_PPC_PKEY 0x110 /* Memory Protection Keys registers */ |
402 | #define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */ |
403 | #define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */ |
404 | #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */ |
405 | #define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */ |
406 | #define NT_S390_TIMER 0x301 /* s390 timer register */ |
407 | #define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */ |
408 | #define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */ |
409 | #define NT_S390_CTRS 0x304 /* s390 control registers */ |
410 | #define NT_S390_PREFIX 0x305 /* s390 prefix register */ |
411 | #define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */ |
412 | #define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */ |
413 | #define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */ |
414 | #define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 upper half */ |
415 | #define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31 */ |
416 | #define NT_S390_GS_CB 0x30b /* s390 guarded storage registers */ |
417 | #define NT_S390_GS_BC 0x30c /* s390 guarded storage broadcast control block */ |
418 | #define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation */ |
419 | #define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ |
420 | #define NT_ARM_TLS 0x401 /* ARM TLS register */ |
421 | #define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ |
422 | #define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ |
423 | #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ |
424 | #define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension registers */ |
425 | #define NT_ARM_PAC_MASK 0x406 /* ARM pointer authentication code masks */ |
426 | #define NT_ARM_PACA_KEYS 0x407 /* ARM pointer authentication address keys */ |
427 | #define NT_ARM_PACG_KEYS 0x408 /* ARM pointer authentication generic key */ |
428 | #define NT_ARM_TAGGED_ADDR_CTRL 0x409 /* arm64 tagged address control (prctl()) */ |
429 | #define NT_ARM_PAC_ENABLED_KEYS 0x40a /* arm64 ptr auth enabled keys (prctl()) */ |
430 | #define NT_ARC_V2 0x600 /* ARCv2 accumulator/extra registers */ |
431 | #define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note */ |
432 | #define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers */ |
433 | #define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode */ |
434 | #define NT_MIPS_MSA 0x802 /* MIPS SIMD registers */ |
435 | |
436 | /* Note types with note name "GNU" */ |
437 | #define NT_GNU_PROPERTY_TYPE_0 5 |
438 | |
439 | /* Note header in a PT_NOTE section */ |
440 | typedef struct elf32_note { |
441 | Elf32_Word n_namesz; /* Name size */ |
442 | Elf32_Word n_descsz; /* Content size */ |
443 | Elf32_Word n_type; /* Content type */ |
444 | } Elf32_Nhdr; |
445 | |
446 | /* Note header in a PT_NOTE section */ |
447 | typedef struct elf64_note { |
448 | Elf64_Word n_namesz; /* Name size */ |
449 | Elf64_Word n_descsz; /* Content size */ |
450 | Elf64_Word n_type; /* Content type */ |
451 | } Elf64_Nhdr; |
452 | |
453 | /* .note.gnu.property types for EM_AARCH64: */ |
454 | #define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 |
455 | |
456 | /* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ |
457 | #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) |
458 | |
459 | #endif /* _LINUX_ELF_H */ |
460 | |