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_LOPROC 0x70000000
87 #define DT_HIPROC 0x7fffffff
89 /* This info is needed when parsing the symbol table */
102 #define ELF_ST_BIND(x) ((x) >> 4)
103 #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
104 #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
105 #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
106 #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
107 #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
109 typedef struct dynamic{
118 Elf64_Sxword d_tag; /* entry tag value */
125 /* The following are used with relocations */
126 #define ELF32_R_SYM(x) ((x) >> 8)
127 #define ELF32_R_TYPE(x) ((x) & 0xff)
129 #define ELF64_R_SYM(i) ((i) >> 32)
130 #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
132 typedef struct elf32_rel {
137 typedef struct elf64_rel {
138 Elf64_Addr r_offset; /* Location at which to apply the action */
139 Elf64_Xword r_info; /* index and type of relocation */
142 typedef struct elf32_rela{
145 Elf32_Sword r_addend;
148 typedef struct elf64_rela {
149 Elf64_Addr r_offset; /* Location at which to apply the action */
150 Elf64_Xword r_info; /* index and type of relocation */
151 Elf64_Sxword r_addend; /* Constant addend used to compute value */
154 typedef struct elf32_sym{
158 unsigned char st_info;
159 unsigned char st_other;
163 typedef struct elf64_sym {
164 Elf64_Word st_name; /* Symbol name, index in string tbl */
165 unsigned char st_info; /* Type and binding attributes */
166 unsigned char st_other; /* No defined meaning, 0 */
167 Elf64_Half st_shndx; /* Associated section index */
168 Elf64_Addr st_value; /* Value of the symbol */
169 Elf64_Xword st_size; /* Associated symbol size */
175 typedef struct elf32_hdr{
176 unsigned char e_ident[EI_NIDENT];
178 Elf32_Half e_machine;
179 Elf32_Word e_version;
180 Elf32_Addr e_entry; /* Entry point */
185 Elf32_Half e_phentsize;
187 Elf32_Half e_shentsize;
189 Elf32_Half e_shstrndx;
192 typedef struct elf64_hdr {
193 unsigned char e_ident[16]; /* ELF "magic number" */
195 Elf64_Half e_machine;
196 Elf64_Word e_version;
197 Elf64_Addr e_entry; /* Entry point virtual address */
198 Elf64_Off e_phoff; /* Program header table file offset */
199 Elf64_Off e_shoff; /* Section header table file offset */
202 Elf64_Half e_phentsize;
204 Elf64_Half e_shentsize;
206 Elf64_Half e_shstrndx;
209 /* These constants define the permissions on sections in the program
215 typedef struct elf32_phdr{
226 typedef struct elf64_phdr {
229 Elf64_Off p_offset; /* Segment file offset */
230 Elf64_Addr p_vaddr; /* Segment virtual address */
231 Elf64_Addr p_paddr; /* Segment physical address */
232 Elf64_Xword p_filesz; /* Segment size in file */
233 Elf64_Xword p_memsz; /* Segment size in memory */
234 Elf64_Xword p_align; /* Segment alignment, file & memory */
239 #define SHT_PROGBITS 1
244 #define SHT_DYNAMIC 6
249 #define SHT_DYNSYM 11
251 #define SHT_LOPROC 0x70000000
252 #define SHT_HIPROC 0x7fffffff
253 #define SHT_LOUSER 0x80000000
254 #define SHT_HIUSER 0xffffffff
257 #define SHF_WRITE 0x1
258 #define SHF_ALLOC 0x2
259 #define SHF_EXECINSTR 0x4
260 #define SHF_MASKPROC 0xf0000000
262 /* special section indexes */
264 #define SHN_LORESERVE 0xff00
265 #define SHN_LOPROC 0xff00
266 #define SHN_HIPROC 0xff1f
267 #define SHN_ABS 0xfff1
268 #define SHN_COMMON 0xfff2
269 #define SHN_HIRESERVE 0xffff
280 Elf32_Word sh_addralign;
281 Elf32_Word sh_entsize;
284 typedef struct elf64_shdr {
285 Elf64_Word sh_name; /* Section name, index in string tbl */
286 Elf64_Word sh_type; /* Type of section */
287 Elf64_Xword sh_flags; /* Miscellaneous section attributes */
288 Elf64_Addr sh_addr; /* Section virtual addr at execution */
289 Elf64_Off sh_offset; /* Section file offset */
290 Elf64_Xword sh_size; /* Size of section in bytes */
291 Elf64_Word sh_link; /* Index of another section */
292 Elf64_Word sh_info; /* Additional section information */
293 Elf64_Xword sh_addralign; /* Section alignment */
294 Elf64_Xword sh_entsize; /* Entry size if section holds table */
297 #define EI_MAG0 0 /* e_ident[] indexes */
307 #define ELFMAG0 0x7f /* EI_MAG */
311 #define ELFMAG "\177ELF"
314 #define ELFCLASSNONE 0 /* EI_CLASS */
317 #define ELFCLASSNUM 3
319 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
320 #define ELFDATA2LSB 1
321 #define ELFDATA2MSB 2
323 #define EV_NONE 0 /* e_version, EI_VERSION */
327 #define ELFOSABI_NONE 0
328 #define ELFOSABI_LINUX 3
331 #define ELF_OSABI ELFOSABI_NONE
334 /* Notes used in ET_CORE */
335 #define NT_PRSTATUS 1
337 #define NT_PRPSINFO 3
338 #define NT_TASKSTRUCT 4
340 #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
343 /* Note header in a PT_NOTE section */
344 typedef struct elf32_note {
345 Elf32_Word n_namesz; /* Name size */
346 Elf32_Word n_descsz; /* Content size */
347 Elf32_Word n_type; /* Content type */
350 /* Note header in a PT_NOTE section */
351 typedef struct elf64_note {
352 Elf64_Word n_namesz; /* Name size */
353 Elf64_Word n_descsz; /* Content size */
354 Elf64_Word n_type; /* Content type */
357 #if ELF_CLASS == ELFCLASS32
359 extern Elf32_Dyn _DYNAMIC [];
360 #define elfhdr elf32_hdr
361 #define elf_phdr elf32_phdr
362 #define elf_note elf32_note
363 #define elf_addr_t Elf32_Off
367 extern Elf64_Dyn _DYNAMIC [];
368 #define elfhdr elf64_hdr
369 #define elf_phdr elf64_phdr
370 #define elf_note elf64_note
371 #define elf_addr_t Elf64_Off
375 #ifndef ARCH_HAVE_EXTRA_ELF_NOTES
376 static inline int arch_notes_size(void) { return 0; }
377 static inline void arch_write_notes(struct file *file) { }
379 #define ELF_CORE_EXTRA_NOTES_SIZE arch_notes_size()
380 #define ELF_CORE_WRITE_EXTRA_NOTES arch_write_notes(file)
381 #endif /* ARCH_HAVE_EXTRA_ELF_NOTES */
383 #endif /* _LINUX_ELF_H */