4 #include <linux/types.h>
5 #include <linux/auxvec.h>
6 #include <linux/elf-em.h>
11 #ifndef elf_read_implies_exec
12 /* Executables for which elf_read_implies_exec() returns TRUE will
13 have the READ_IMPLIES_EXEC personality flag set automatically.
14 Override in asm/elf.h as needed. */
15 # define elf_read_implies_exec(ex, have_pt_gnu_stack) 0
18 /* 32-bit ELF base types. */
19 typedef __u32 Elf32_Addr;
20 typedef __u16 Elf32_Half;
21 typedef __u32 Elf32_Off;
22 typedef __s32 Elf32_Sword;
23 typedef __u32 Elf32_Word;
25 /* 64-bit ELF base types. */
26 typedef __u64 Elf64_Addr;
27 typedef __u16 Elf64_Half;
28 typedef __s16 Elf64_SHalf;
29 typedef __u64 Elf64_Off;
30 typedef __s32 Elf64_Sword;
31 typedef __u32 Elf64_Word;
32 typedef __u64 Elf64_Xword;
33 typedef __s64 Elf64_Sxword;
35 /* These constants are for the segment types stored in the image headers */
43 #define PT_TLS 7 /* Thread local storage segment */
44 #define PT_LOOS 0x60000000 /* OS-specific */
45 #define PT_HIOS 0x6fffffff /* OS-specific */
46 #define PT_LOPROC 0x70000000
47 #define PT_HIPROC 0x7fffffff
48 #define PT_GNU_EH_FRAME 0x6474e550
50 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
52 /* These constants define the different elf file types */
58 #define ET_LOPROC 0xff00
59 #define ET_HIPROC 0xffff
61 /* This is the info that is needed to parse the dynamic section of the file */
78 #define DT_SYMBOLIC 16
86 #define DT_ENCODING 32
87 #define OLD_DT_LOOS 0x60000000
88 #define DT_LOOS 0x6000000d
89 #define DT_HIOS 0x6ffff000
90 #define DT_VALRNGLO 0x6ffffd00
91 #define DT_VALRNGHI 0x6ffffdff
92 #define DT_ADDRRNGLO 0x6ffffe00
93 #define DT_ADDRRNGHI 0x6ffffeff
94 #define DT_VERSYM 0x6ffffff0
95 #define DT_RELACOUNT 0x6ffffff9
96 #define DT_RELCOUNT 0x6ffffffa
97 #define DT_FLAGS_1 0x6ffffffb
98 #define DT_VERDEF 0x6ffffffc
99 #define DT_VERDEFNUM 0x6ffffffd
100 #define DT_VERNEED 0x6ffffffe
101 #define DT_VERNEEDNUM 0x6fffffff
102 #define OLD_DT_HIOS 0x6fffffff
103 #define DT_LOPROC 0x70000000
104 #define DT_HIPROC 0x7fffffff
106 /* This info is needed when parsing the symbol table */
114 #define STT_SECTION 3
119 #define ELF_ST_BIND(x) ((x) >> 4)
120 #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
121 #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
122 #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
123 #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
124 #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
126 typedef struct dynamic{
135 Elf64_Sxword d_tag; /* entry tag value */
142 /* The following are used with relocations */
143 #define ELF32_R_SYM(x) ((x) >> 8)
144 #define ELF32_R_TYPE(x) ((x) & 0xff)
146 #define ELF64_R_SYM(i) ((i) >> 32)
147 #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
149 typedef struct elf32_rel {
154 typedef struct elf64_rel {
155 Elf64_Addr r_offset; /* Location at which to apply the action */
156 Elf64_Xword r_info; /* index and type of relocation */
159 typedef struct elf32_rela{
162 Elf32_Sword r_addend;
165 typedef struct elf64_rela {
166 Elf64_Addr r_offset; /* Location at which to apply the action */
167 Elf64_Xword r_info; /* index and type of relocation */
168 Elf64_Sxword r_addend; /* Constant addend used to compute value */
171 typedef struct elf32_sym{
175 unsigned char st_info;
176 unsigned char st_other;
180 typedef struct elf64_sym {
181 Elf64_Word st_name; /* Symbol name, index in string tbl */
182 unsigned char st_info; /* Type and binding attributes */
183 unsigned char st_other; /* No defined meaning, 0 */
184 Elf64_Half st_shndx; /* Associated section index */
185 Elf64_Addr st_value; /* Value of the symbol */
186 Elf64_Xword st_size; /* Associated symbol size */
192 typedef struct elf32_hdr{
193 unsigned char e_ident[EI_NIDENT];
195 Elf32_Half e_machine;
196 Elf32_Word e_version;
197 Elf32_Addr e_entry; /* Entry point */
202 Elf32_Half e_phentsize;
204 Elf32_Half e_shentsize;
206 Elf32_Half e_shstrndx;
209 typedef struct elf64_hdr {
210 unsigned char e_ident[16]; /* ELF "magic number" */
212 Elf64_Half e_machine;
213 Elf64_Word e_version;
214 Elf64_Addr e_entry; /* Entry point virtual address */
215 Elf64_Off e_phoff; /* Program header table file offset */
216 Elf64_Off e_shoff; /* Section header table file offset */
219 Elf64_Half e_phentsize;
221 Elf64_Half e_shentsize;
223 Elf64_Half e_shstrndx;
226 /* These constants define the permissions on sections in the program
232 typedef struct elf32_phdr{
243 typedef struct elf64_phdr {
246 Elf64_Off p_offset; /* Segment file offset */
247 Elf64_Addr p_vaddr; /* Segment virtual address */
248 Elf64_Addr p_paddr; /* Segment physical address */
249 Elf64_Xword p_filesz; /* Segment size in file */
250 Elf64_Xword p_memsz; /* Segment size in memory */
251 Elf64_Xword p_align; /* Segment alignment, file & memory */
256 #define SHT_PROGBITS 1
261 #define SHT_DYNAMIC 6
266 #define SHT_DYNSYM 11
268 #define SHT_LOPROC 0x70000000
269 #define SHT_HIPROC 0x7fffffff
270 #define SHT_LOUSER 0x80000000
271 #define SHT_HIUSER 0xffffffff
274 #define SHF_WRITE 0x1
275 #define SHF_ALLOC 0x2
276 #define SHF_EXECINSTR 0x4
277 #define SHF_MASKPROC 0xf0000000
279 /* special section indexes */
281 #define SHN_LORESERVE 0xff00
282 #define SHN_LOPROC 0xff00
283 #define SHN_HIPROC 0xff1f
284 #define SHN_ABS 0xfff1
285 #define SHN_COMMON 0xfff2
286 #define SHN_HIRESERVE 0xffff
297 Elf32_Word sh_addralign;
298 Elf32_Word sh_entsize;
301 typedef struct elf64_shdr {
302 Elf64_Word sh_name; /* Section name, index in string tbl */
303 Elf64_Word sh_type; /* Type of section */
304 Elf64_Xword sh_flags; /* Miscellaneous section attributes */
305 Elf64_Addr sh_addr; /* Section virtual addr at execution */
306 Elf64_Off sh_offset; /* Section file offset */
307 Elf64_Xword sh_size; /* Size of section in bytes */
308 Elf64_Word sh_link; /* Index of another section */
309 Elf64_Word sh_info; /* Additional section information */
310 Elf64_Xword sh_addralign; /* Section alignment */
311 Elf64_Xword sh_entsize; /* Entry size if section holds table */
314 #define EI_MAG0 0 /* e_ident[] indexes */
324 #define ELFMAG0 0x7f /* EI_MAG */
328 #define ELFMAG "\177ELF"
331 #define ELFCLASSNONE 0 /* EI_CLASS */
334 #define ELFCLASSNUM 3
336 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
337 #define ELFDATA2LSB 1
338 #define ELFDATA2MSB 2
340 #define EV_NONE 0 /* e_version, EI_VERSION */
344 #define ELFOSABI_NONE 0
345 #define ELFOSABI_LINUX 3
348 #define ELF_OSABI ELFOSABI_NONE
351 /* Notes used in ET_CORE */
352 #define NT_PRSTATUS 1
354 #define NT_PRPSINFO 3
355 #define NT_TASKSTRUCT 4
357 #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
360 /* Note header in a PT_NOTE section */
361 typedef struct elf32_note {
362 Elf32_Word n_namesz; /* Name size */
363 Elf32_Word n_descsz; /* Content size */
364 Elf32_Word n_type; /* Content type */
367 /* Note header in a PT_NOTE section */
368 typedef struct elf64_note {
369 Elf64_Word n_namesz; /* Name size */
370 Elf64_Word n_descsz; /* Content size */
371 Elf64_Word n_type; /* Content type */
374 #if ELF_CLASS == ELFCLASS32
376 extern Elf32_Dyn _DYNAMIC [];
377 #define elfhdr elf32_hdr
378 #define elf_phdr elf32_phdr
379 #define elf_note elf32_note
380 #define elf_addr_t Elf32_Off
384 extern Elf64_Dyn _DYNAMIC [];
385 #define elfhdr elf64_hdr
386 #define elf_phdr elf64_phdr
387 #define elf_note elf64_note
388 #define elf_addr_t Elf64_Off
392 #ifndef ARCH_HAVE_EXTRA_ELF_NOTES
393 static inline int arch_notes_size(void) { return 0; }
394 static inline void arch_write_notes(struct file *file) { }
396 #define ELF_CORE_EXTRA_NOTES_SIZE arch_notes_size()
397 #define ELF_CORE_WRITE_EXTRA_NOTES arch_write_notes(file)
398 #endif /* ARCH_HAVE_EXTRA_ELF_NOTES */
400 #endif /* _LINUX_ELF_H */