blob: edc3dac3f02f446802136b6ad65bbc39cbd6996a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_ELF_H
2#define _LINUX_ELF_H
3
4#include <linux/types.h>
David Woodhousef001e472006-04-27 00:11:01 +01005#include <linux/elf-em.h>
Kirill A. Shutemov6cc931b2008-02-07 00:15:55 -08006#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/elf.h>
Kirill A. Shutemov6cc931b2008-02-07 00:15:55 -08008#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Andrew Morton6cf24f02006-12-06 20:41:39 -080010struct file;
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#ifndef elf_read_implies_exec
13 /* Executables for which elf_read_implies_exec() returns TRUE will
14 have the READ_IMPLIES_EXEC personality flag set automatically.
15 Override in asm/elf.h as needed. */
16# define elf_read_implies_exec(ex, have_pt_gnu_stack) 0
17#endif
18
19/* 32-bit ELF base types. */
20typedef __u32 Elf32_Addr;
21typedef __u16 Elf32_Half;
22typedef __u32 Elf32_Off;
23typedef __s32 Elf32_Sword;
24typedef __u32 Elf32_Word;
25
26/* 64-bit ELF base types. */
27typedef __u64 Elf64_Addr;
28typedef __u16 Elf64_Half;
29typedef __s16 Elf64_SHalf;
30typedef __u64 Elf64_Off;
31typedef __s32 Elf64_Sword;
32typedef __u32 Elf64_Word;
33typedef __u64 Elf64_Xword;
34typedef __s64 Elf64_Sxword;
35
36/* These constants are for the segment types stored in the image headers */
37#define PT_NULL 0
38#define PT_LOAD 1
39#define PT_DYNAMIC 2
40#define PT_INTERP 3
41#define PT_NOTE 4
42#define PT_SHLIB 5
43#define PT_PHDR 6
44#define PT_TLS 7 /* Thread local storage segment */
45#define PT_LOOS 0x60000000 /* OS-specific */
46#define PT_HIOS 0x6fffffff /* OS-specific */
47#define PT_LOPROC 0x70000000
48#define PT_HIPROC 0x7fffffff
49#define PT_GNU_EH_FRAME 0x6474e550
50
51#define PT_GNU_STACK (PT_LOOS + 0x474e551)
52
53/* These constants define the different elf file types */
54#define ET_NONE 0
55#define ET_REL 1
56#define ET_EXEC 2
57#define ET_DYN 3
58#define ET_CORE 4
59#define ET_LOPROC 0xff00
60#define ET_HIPROC 0xffff
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/* This is the info that is needed to parse the dynamic section of the file */
63#define DT_NULL 0
64#define DT_NEEDED 1
65#define DT_PLTRELSZ 2
66#define DT_PLTGOT 3
67#define DT_HASH 4
68#define DT_STRTAB 5
69#define DT_SYMTAB 6
70#define DT_RELA 7
71#define DT_RELASZ 8
72#define DT_RELAENT 9
73#define DT_STRSZ 10
74#define DT_SYMENT 11
75#define DT_INIT 12
76#define DT_FINI 13
77#define DT_SONAME 14
78#define DT_RPATH 15
79#define DT_SYMBOLIC 16
80#define DT_REL 17
81#define DT_RELSZ 18
82#define DT_RELENT 19
83#define DT_PLTREL 20
84#define DT_DEBUG 21
85#define DT_TEXTREL 22
86#define DT_JMPREL 23
Jeremy Fitzhardinged4f7a2c2007-05-02 19:27:12 +020087#define DT_ENCODING 32
88#define OLD_DT_LOOS 0x60000000
89#define DT_LOOS 0x6000000d
90#define DT_HIOS 0x6ffff000
91#define DT_VALRNGLO 0x6ffffd00
92#define DT_VALRNGHI 0x6ffffdff
93#define DT_ADDRRNGLO 0x6ffffe00
94#define DT_ADDRRNGHI 0x6ffffeff
95#define DT_VERSYM 0x6ffffff0
96#define DT_RELACOUNT 0x6ffffff9
97#define DT_RELCOUNT 0x6ffffffa
98#define DT_FLAGS_1 0x6ffffffb
99#define DT_VERDEF 0x6ffffffc
100#define DT_VERDEFNUM 0x6ffffffd
101#define DT_VERNEED 0x6ffffffe
102#define DT_VERNEEDNUM 0x6fffffff
103#define OLD_DT_HIOS 0x6fffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#define DT_LOPROC 0x70000000
105#define DT_HIPROC 0x7fffffff
106
107/* This info is needed when parsing the symbol table */
108#define STB_LOCAL 0
109#define STB_GLOBAL 1
110#define STB_WEAK 2
111
112#define STT_NOTYPE 0
113#define STT_OBJECT 1
114#define STT_FUNC 2
115#define STT_SECTION 3
116#define STT_FILE 4
Jan Beulichb3f3d612006-01-08 01:02:20 -0800117#define STT_COMMON 5
118#define STT_TLS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120#define ELF_ST_BIND(x) ((x) >> 4)
121#define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
122#define ELF32_ST_BIND(x) ELF_ST_BIND(x)
123#define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
124#define ELF64_ST_BIND(x) ELF_ST_BIND(x)
125#define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127typedef struct dynamic{
128 Elf32_Sword d_tag;
129 union{
130 Elf32_Sword d_val;
131 Elf32_Addr d_ptr;
132 } d_un;
133} Elf32_Dyn;
134
135typedef struct {
136 Elf64_Sxword d_tag; /* entry tag value */
137 union {
138 Elf64_Xword d_val;
139 Elf64_Addr d_ptr;
140 } d_un;
141} Elf64_Dyn;
142
143/* The following are used with relocations */
144#define ELF32_R_SYM(x) ((x) >> 8)
145#define ELF32_R_TYPE(x) ((x) & 0xff)
146
147#define ELF64_R_SYM(i) ((i) >> 32)
148#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
149
150typedef struct elf32_rel {
151 Elf32_Addr r_offset;
152 Elf32_Word r_info;
153} Elf32_Rel;
154
155typedef struct elf64_rel {
156 Elf64_Addr r_offset; /* Location at which to apply the action */
157 Elf64_Xword r_info; /* index and type of relocation */
158} Elf64_Rel;
159
160typedef struct elf32_rela{
161 Elf32_Addr r_offset;
162 Elf32_Word r_info;
163 Elf32_Sword r_addend;
164} Elf32_Rela;
165
166typedef struct elf64_rela {
167 Elf64_Addr r_offset; /* Location at which to apply the action */
168 Elf64_Xword r_info; /* index and type of relocation */
169 Elf64_Sxword r_addend; /* Constant addend used to compute value */
170} Elf64_Rela;
171
172typedef struct elf32_sym{
173 Elf32_Word st_name;
174 Elf32_Addr st_value;
175 Elf32_Word st_size;
176 unsigned char st_info;
177 unsigned char st_other;
178 Elf32_Half st_shndx;
179} Elf32_Sym;
180
181typedef struct elf64_sym {
182 Elf64_Word st_name; /* Symbol name, index in string tbl */
183 unsigned char st_info; /* Type and binding attributes */
184 unsigned char st_other; /* No defined meaning, 0 */
185 Elf64_Half st_shndx; /* Associated section index */
186 Elf64_Addr st_value; /* Value of the symbol */
187 Elf64_Xword st_size; /* Associated symbol size */
188} Elf64_Sym;
189
190
191#define EI_NIDENT 16
192
193typedef struct elf32_hdr{
194 unsigned char e_ident[EI_NIDENT];
195 Elf32_Half e_type;
196 Elf32_Half e_machine;
197 Elf32_Word e_version;
198 Elf32_Addr e_entry; /* Entry point */
199 Elf32_Off e_phoff;
200 Elf32_Off e_shoff;
201 Elf32_Word e_flags;
202 Elf32_Half e_ehsize;
203 Elf32_Half e_phentsize;
204 Elf32_Half e_phnum;
205 Elf32_Half e_shentsize;
206 Elf32_Half e_shnum;
207 Elf32_Half e_shstrndx;
208} Elf32_Ehdr;
209
210typedef struct elf64_hdr {
Cyrill Gorcunoveb6900f2008-04-29 01:01:17 -0700211 unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 Elf64_Half e_type;
213 Elf64_Half e_machine;
214 Elf64_Word e_version;
215 Elf64_Addr e_entry; /* Entry point virtual address */
216 Elf64_Off e_phoff; /* Program header table file offset */
217 Elf64_Off e_shoff; /* Section header table file offset */
218 Elf64_Word e_flags;
219 Elf64_Half e_ehsize;
220 Elf64_Half e_phentsize;
221 Elf64_Half e_phnum;
222 Elf64_Half e_shentsize;
223 Elf64_Half e_shnum;
224 Elf64_Half e_shstrndx;
225} Elf64_Ehdr;
226
227/* These constants define the permissions on sections in the program
228 header, p_flags. */
229#define PF_R 0x4
230#define PF_W 0x2
231#define PF_X 0x1
232
233typedef struct elf32_phdr{
234 Elf32_Word p_type;
235 Elf32_Off p_offset;
236 Elf32_Addr p_vaddr;
237 Elf32_Addr p_paddr;
238 Elf32_Word p_filesz;
239 Elf32_Word p_memsz;
240 Elf32_Word p_flags;
241 Elf32_Word p_align;
242} Elf32_Phdr;
243
244typedef struct elf64_phdr {
245 Elf64_Word p_type;
246 Elf64_Word p_flags;
247 Elf64_Off p_offset; /* Segment file offset */
248 Elf64_Addr p_vaddr; /* Segment virtual address */
249 Elf64_Addr p_paddr; /* Segment physical address */
250 Elf64_Xword p_filesz; /* Segment size in file */
251 Elf64_Xword p_memsz; /* Segment size in memory */
252 Elf64_Xword p_align; /* Segment alignment, file & memory */
253} Elf64_Phdr;
254
255/* sh_type */
256#define SHT_NULL 0
257#define SHT_PROGBITS 1
258#define SHT_SYMTAB 2
259#define SHT_STRTAB 3
260#define SHT_RELA 4
261#define SHT_HASH 5
262#define SHT_DYNAMIC 6
263#define SHT_NOTE 7
264#define SHT_NOBITS 8
265#define SHT_REL 9
266#define SHT_SHLIB 10
267#define SHT_DYNSYM 11
268#define SHT_NUM 12
269#define SHT_LOPROC 0x70000000
270#define SHT_HIPROC 0x7fffffff
271#define SHT_LOUSER 0x80000000
272#define SHT_HIUSER 0xffffffff
273
274/* sh_flags */
275#define SHF_WRITE 0x1
276#define SHF_ALLOC 0x2
277#define SHF_EXECINSTR 0x4
278#define SHF_MASKPROC 0xf0000000
279
280/* special section indexes */
281#define SHN_UNDEF 0
282#define SHN_LORESERVE 0xff00
283#define SHN_LOPROC 0xff00
284#define SHN_HIPROC 0xff1f
285#define SHN_ABS 0xfff1
286#define SHN_COMMON 0xfff2
287#define SHN_HIRESERVE 0xffff
288
289typedef struct {
290 Elf32_Word sh_name;
291 Elf32_Word sh_type;
292 Elf32_Word sh_flags;
293 Elf32_Addr sh_addr;
294 Elf32_Off sh_offset;
295 Elf32_Word sh_size;
296 Elf32_Word sh_link;
297 Elf32_Word sh_info;
298 Elf32_Word sh_addralign;
299 Elf32_Word sh_entsize;
300} Elf32_Shdr;
301
302typedef struct elf64_shdr {
303 Elf64_Word sh_name; /* Section name, index in string tbl */
304 Elf64_Word sh_type; /* Type of section */
305 Elf64_Xword sh_flags; /* Miscellaneous section attributes */
306 Elf64_Addr sh_addr; /* Section virtual addr at execution */
307 Elf64_Off sh_offset; /* Section file offset */
308 Elf64_Xword sh_size; /* Size of section in bytes */
309 Elf64_Word sh_link; /* Index of another section */
310 Elf64_Word sh_info; /* Additional section information */
311 Elf64_Xword sh_addralign; /* Section alignment */
312 Elf64_Xword sh_entsize; /* Entry size if section holds table */
313} Elf64_Shdr;
314
315#define EI_MAG0 0 /* e_ident[] indexes */
316#define EI_MAG1 1
317#define EI_MAG2 2
318#define EI_MAG3 3
319#define EI_CLASS 4
320#define EI_DATA 5
321#define EI_VERSION 6
322#define EI_OSABI 7
323#define EI_PAD 8
324
325#define ELFMAG0 0x7f /* EI_MAG */
326#define ELFMAG1 'E'
327#define ELFMAG2 'L'
328#define ELFMAG3 'F'
329#define ELFMAG "\177ELF"
330#define SELFMAG 4
331
332#define ELFCLASSNONE 0 /* EI_CLASS */
333#define ELFCLASS32 1
334#define ELFCLASS64 2
335#define ELFCLASSNUM 3
336
337#define ELFDATANONE 0 /* e_ident[EI_DATA] */
338#define ELFDATA2LSB 1
339#define ELFDATA2MSB 2
340
341#define EV_NONE 0 /* e_version, EI_VERSION */
342#define EV_CURRENT 1
343#define EV_NUM 2
344
345#define ELFOSABI_NONE 0
346#define ELFOSABI_LINUX 3
347
348#ifndef ELF_OSABI
349#define ELF_OSABI ELFOSABI_NONE
350#endif
351
352/* Notes used in ET_CORE */
353#define NT_PRSTATUS 1
354#define NT_PRFPREG 2
355#define NT_PRPSINFO 3
356#define NT_TASKSTRUCT 4
357#define NT_AUXV 6
358#define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
Mark Nelson1f7d6662007-10-16 23:25:40 -0700359#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
Roland McGrath24f1a842008-01-02 17:05:48 -0800360#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
Michael Neulingf3e909c2008-07-01 14:01:39 +1000361#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
Roland McGrathbb616822008-01-30 13:31:56 +0100362#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364
365/* Note header in a PT_NOTE section */
366typedef struct elf32_note {
367 Elf32_Word n_namesz; /* Name size */
368 Elf32_Word n_descsz; /* Content size */
369 Elf32_Word n_type; /* Content type */
370} Elf32_Nhdr;
371
372/* Note header in a PT_NOTE section */
373typedef struct elf64_note {
374 Elf64_Word n_namesz; /* Name size */
375 Elf64_Word n_descsz; /* Content size */
376 Elf64_Word n_type; /* Content type */
377} Elf64_Nhdr;
378
379#if ELF_CLASS == ELFCLASS32
380
381extern Elf32_Dyn _DYNAMIC [];
382#define elfhdr elf32_hdr
383#define elf_phdr elf32_phdr
384#define elf_note elf32_note
Magnus Damm386d9a72006-12-06 20:37:53 -0800385#define elf_addr_t Elf32_Off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387#else
388
389extern Elf64_Dyn _DYNAMIC [];
390#define elfhdr elf64_hdr
391#define elf_phdr elf64_phdr
392#define elf_note elf64_note
Magnus Damm386d9a72006-12-06 20:37:53 -0800393#define elf_addr_t Elf64_Off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395#endif
396
Michael Ellermane5501492007-09-19 14:38:12 +1000397/* Optional callbacks to write extra ELF notes. */
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100398#ifndef ARCH_HAVE_EXTRA_ELF_NOTES
Michael Ellermane5501492007-09-19 14:38:12 +1000399static inline int elf_coredump_extra_notes_size(void) { return 0; }
400static inline int elf_coredump_extra_notes_write(struct file *file,
401 loff_t *foffset) { return 0; }
402#else
403extern int elf_coredump_extra_notes_size(void);
404extern int elf_coredump_extra_notes_write(struct file *file, loff_t *foffset);
405#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407#endif /* _LINUX_ELF_H */