4 #include <linux/types.h>
7 /* 32-bit ELF base types. */
8 typedef __u32 Elf32_Addr
;
9 typedef __u16 Elf32_Half
;
10 typedef __u32 Elf32_Off
;
11 typedef __s32 Elf32_Sword
;
12 typedef __u32 Elf32_Word
;
14 /* 64-bit ELF base types. */
15 typedef __u64 Elf64_Addr
;
16 typedef __u16 Elf64_Half
;
17 typedef __s16 Elf64_SHalf
;
18 typedef __u64 Elf64_Off
;
19 typedef __s32 Elf64_Sword
;
20 typedef __u32 Elf64_Word
;
21 typedef __u64 Elf64_Xword
;
22 typedef __s64 Elf64_Sxword
;
24 /* These constants are for the segment types stored in the image headers */
32 #define PT_LOOS 0x60000000
33 #define PT_HIOS 0x6fffffff
34 #define PT_LOPROC 0x70000000
35 #define PT_HIPROC 0x7fffffff
36 #define PT_GNU_EH_FRAME 0x6474e550
38 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
40 /* These constants define the different elf file types */
46 #define ET_LOPROC 0xff00
47 #define ET_HIPROC 0xffff
49 /* These constants define the various ELF target machines */
56 #define EM_486 6 /* Perhaps disused */
59 #define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */
61 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
63 #define EM_PARISC 15 /* HPPA */
65 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
67 #define EM_PPC 20 /* PowerPC */
68 #define EM_PPC64 21 /* PowerPC64 */
70 #define EM_SH 42 /* SuperH */
72 #define EM_SPARCV9 43 /* SPARC v9 64-bit */
74 #define EM_IA_64 50 /* HP/Intel IA-64 */
76 #define EM_X86_64 62 /* AMD x86-64 */
78 #define EM_S390 22 /* IBM S/390 */
80 #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
82 #define EM_V850 87 /* NEC v850 */
84 #define EM_H8_300H 47 /* Hitachi H8/300H */
85 #define EM_H8S 48 /* Hitachi H8S */
88 * This is an interim value that we will use until the committee comes
89 * up with a final number.
91 #define EM_ALPHA 0x9026
93 /* Bogus old v850 magic number, used by old tools. */
94 #define EM_CYGNUS_V850 0x9080
97 * This is the old interim value for S/390 architecture
99 #define EM_S390_OLD 0xA390
101 /* This is the info that is needed to parse the dynamic section of the file */
104 #define DT_PLTRELSZ 2
118 #define DT_SYMBOLIC 16
124 #define DT_TEXTREL 22
126 #define DT_LOPROC 0x70000000
127 #define DT_HIPROC 0x7fffffff
129 /* This info is needed when parsing the symbol table */
137 #define STT_SECTION 3
140 #define ELF_ST_BIND(x) ((x) >> 4)
141 #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
142 #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
143 #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
144 #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
145 #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
147 /* Symbolic values for the entries in the auxiliary table
148 put on the initial stack */
149 #define AT_NULL 0 /* end of vector */
150 #define AT_IGNORE 1 /* entry should be ignored */
151 #define AT_EXECFD 2 /* file descriptor of program */
152 #define AT_PHDR 3 /* program headers for program */
153 #define AT_PHENT 4 /* size of program header entry */
154 #define AT_PHNUM 5 /* number of program headers */
155 #define AT_PAGESZ 6 /* system page size */
156 #define AT_BASE 7 /* base address of interpreter */
157 #define AT_FLAGS 8 /* flags */
158 #define AT_ENTRY 9 /* entry point of program */
159 #define AT_NOTELF 10 /* program is not ELF */
160 #define AT_UID 11 /* real uid */
161 #define AT_EUID 12 /* effective uid */
162 #define AT_GID 13 /* real gid */
163 #define AT_EGID 14 /* effective gid */
164 #define AT_PLATFORM 15 /* string identifying CPU for optimizations */
165 #define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
166 #define AT_CLKTCK 17 /* frequency at which times() increments */
168 #define AT_SECURE 23 /* secure mode boolean */
170 typedef struct dynamic
{
179 Elf64_Sxword d_tag
; /* entry tag value */
186 /* The following are used with relocations */
187 #define ELF32_R_SYM(x) ((x) >> 8)
188 #define ELF32_R_TYPE(x) ((x) & 0xff)
190 #define ELF64_R_SYM(i) ((i) >> 32)
191 #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
193 typedef struct elf32_rel
{
198 typedef struct elf64_rel
{
199 Elf64_Addr r_offset
; /* Location at which to apply the action */
200 Elf64_Xword r_info
; /* index and type of relocation */
203 typedef struct elf32_rela
{
206 Elf32_Sword r_addend
;
209 typedef struct elf64_rela
{
210 Elf64_Addr r_offset
; /* Location at which to apply the action */
211 Elf64_Xword r_info
; /* index and type of relocation */
212 Elf64_Sxword r_addend
; /* Constant addend used to compute value */
215 typedef struct elf32_sym
{
219 unsigned char st_info
;
220 unsigned char st_other
;
224 typedef struct elf64_sym
{
225 Elf64_Word st_name
; /* Symbol name, index in string tbl */
226 unsigned char st_info
; /* Type and binding attributes */
227 unsigned char st_other
; /* No defined meaning, 0 */
228 Elf64_Half st_shndx
; /* Associated section index */
229 Elf64_Addr st_value
; /* Value of the symbol */
230 Elf64_Xword st_size
; /* Associated symbol size */
236 typedef struct elf32_hdr
{
237 unsigned char e_ident
[EI_NIDENT
];
239 Elf32_Half e_machine
;
240 Elf32_Word e_version
;
241 Elf32_Addr e_entry
; /* Entry point */
246 Elf32_Half e_phentsize
;
248 Elf32_Half e_shentsize
;
250 Elf32_Half e_shstrndx
;
253 typedef struct elf64_hdr
{
254 unsigned char e_ident
[16]; /* ELF "magic number" */
256 Elf64_Half e_machine
;
257 Elf64_Word e_version
;
258 Elf64_Addr e_entry
; /* Entry point virtual address */
259 Elf64_Off e_phoff
; /* Program header table file offset */
260 Elf64_Off e_shoff
; /* Section header table file offset */
263 Elf64_Half e_phentsize
;
265 Elf64_Half e_shentsize
;
267 Elf64_Half e_shstrndx
;
270 /* These constants define the permissions on sections in the program
276 typedef struct elf32_phdr
{
287 typedef struct elf64_phdr
{
290 Elf64_Off p_offset
; /* Segment file offset */
291 Elf64_Addr p_vaddr
; /* Segment virtual address */
292 Elf64_Addr p_paddr
; /* Segment physical address */
293 Elf64_Xword p_filesz
; /* Segment size in file */
294 Elf64_Xword p_memsz
; /* Segment size in memory */
295 Elf64_Xword p_align
; /* Segment alignment, file & memory */
300 #define SHT_PROGBITS 1
305 #define SHT_DYNAMIC 6
310 #define SHT_DYNSYM 11
312 #define SHT_LOPROC 0x70000000
313 #define SHT_HIPROC 0x7fffffff
314 #define SHT_LOUSER 0x80000000
315 #define SHT_HIUSER 0xffffffff
318 #define SHF_WRITE 0x1
319 #define SHF_ALLOC 0x2
320 #define SHF_EXECINSTR 0x4
321 #define SHF_MASKPROC 0xf0000000
323 /* special section indexes */
325 #define SHN_LORESERVE 0xff00
326 #define SHN_LOPROC 0xff00
327 #define SHN_HIPROC 0xff1f
328 #define SHN_ABS 0xfff1
329 #define SHN_COMMON 0xfff2
330 #define SHN_HIRESERVE 0xffff
341 Elf32_Word sh_addralign
;
342 Elf32_Word sh_entsize
;
345 typedef struct elf64_shdr
{
346 Elf64_Word sh_name
; /* Section name, index in string tbl */
347 Elf64_Word sh_type
; /* Type of section */
348 Elf64_Xword sh_flags
; /* Miscellaneous section attributes */
349 Elf64_Addr sh_addr
; /* Section virtual addr at execution */
350 Elf64_Off sh_offset
; /* Section file offset */
351 Elf64_Xword sh_size
; /* Size of section in bytes */
352 Elf64_Word sh_link
; /* Index of another section */
353 Elf64_Word sh_info
; /* Additional section information */
354 Elf64_Xword sh_addralign
; /* Section alignment */
355 Elf64_Xword sh_entsize
; /* Entry size if section holds table */
358 #define EI_MAG0 0 /* e_ident[] indexes */
368 #define ELFMAG0 0x7f /* EI_MAG */
372 #define ELFMAG "\177ELF"
375 #define ELFCLASSNONE 0 /* EI_CLASS */
378 #define ELFCLASSNUM 3
380 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
381 #define ELFDATA2LSB 1
382 #define ELFDATA2MSB 2
384 #define EV_NONE 0 /* e_version, EI_VERSION */
388 #define ELFOSABI_NONE 0
389 #define ELFOSABI_LINUX 3
392 #define ELF_OSABI ELFOSABI_NONE
395 /* Notes used in ET_CORE */
396 #define NT_PRSTATUS 1
398 #define NT_PRPSINFO 3
399 #define NT_TASKSTRUCT 4
401 #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
404 /* Note header in a PT_NOTE section */
405 typedef struct elf32_note
{
406 Elf32_Word n_namesz
; /* Name size */
407 Elf32_Word n_descsz
; /* Content size */
408 Elf32_Word n_type
; /* Content type */
411 /* Note header in a PT_NOTE section */
412 typedef struct elf64_note
{
413 Elf64_Word n_namesz
; /* Name size */
414 Elf64_Word n_descsz
; /* Content size */
415 Elf64_Word n_type
; /* Content type */
418 #if ELF_CLASS == ELFCLASS32
420 extern Elf32_Dyn _DYNAMIC
[];
421 #define elfhdr elf32_hdr
422 #define elf_phdr elf32_phdr
423 #define elf_note elf32_note
427 extern Elf64_Dyn _DYNAMIC
[];
428 #define elfhdr elf64_hdr
429 #define elf_phdr elf64_phdr
430 #define elf_note elf64_note
435 #endif /* _LINUX_ELF_H */