spec: update to match requirements of Fedora 14+
[nasm/sigaren-mirror.git] / output / elf.h
blobed3467eb0961839cbb8afbfe8784a52f3fbeab99
1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2009 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
34 #ifndef OUTPUT_ELF_H
35 #define OUTPUT_ELF_H
38 * Since NASM support both Elf32/64 file formats
39 * we need to cover all types, structures, typedefs and etc
42 #include "compiler.h"
43 #include <inttypes.h>
45 /* Segment types */
46 #define PT_NULL 0
47 #define PT_LOAD 1
48 #define PT_DYNAMIC 2
49 #define PT_INTERP 3
50 #define PT_NOTE 4
51 #define PT_SHLIB 5
52 #define PT_PHDR 6
53 #define PT_LOOS 0x60000000
54 #define PT_HIOS 0x6fffffff
55 #define PT_LOPROC 0x70000000
56 #define PT_HIPROC 0x7fffffff
57 #define PT_GNU_EH_FRAME 0x6474e550 /* Extension, eh? */
59 /* ELF file types */
60 #define ET_NONE 0
61 #define ET_REL 1
62 #define ET_EXEC 2
63 #define ET_DYN 3
64 #define ET_CORE 4
65 #define ET_LOPROC 0xff00
66 #define ET_HIPROC 0xffff
68 /* ELF machine types */
69 #define EM_NONE 0
70 #define EM_M32 1
71 #define EM_SPARC 2
72 #define EM_386 3
73 #define EM_68K 4
74 #define EM_88K 5
75 #define EM_486 6 /* Not used in Linux at least */
76 #define EM_860 7
77 #define EM_MIPS 8 /* R3k, bigendian(?) */
78 #define EM_MIPS_RS4_BE 10 /* R4k BE */
79 #define EM_PARISC 15
80 #define EM_SPARC32PLUS 18
81 #define EM_PPC 20
82 #define EM_PPC64 21
83 #define EM_S390 22
84 #define EM_SH 42
85 #define EM_SPARCV9 43 /* v9 = SPARC64 */
86 #define EM_H8_300H 47
87 #define EM_H8S 48
88 #define EM_IA_64 50
89 #define EM_X86_64 62
90 #define EM_CRIS 76
91 #define EM_V850 87
92 #define EM_ALPHA 0x9026 /* Interrim Alpha that stuck around */
93 #define EM_CYGNUS_V850 0x9080 /* Old v850 ID used by Cygnus */
94 #define EM_S390_OLD 0xA390 /* Obsolete interrim value for S/390 */
96 /* Dynamic type values */
97 #define DT_NULL 0
98 #define DT_NEEDED 1
99 #define DT_PLTRELSZ 2
100 #define DT_PLTGOT 3
101 #define DT_HASH 4
102 #define DT_STRTAB 5
103 #define DT_SYMTAB 6
104 #define DT_RELA 7
105 #define DT_RELASZ 8
106 #define DT_RELAENT 9
107 #define DT_STRSZ 10
108 #define DT_SYMENT 11
109 #define DT_INIT 12
110 #define DT_FINI 13
111 #define DT_SONAME 14
112 #define DT_RPATH 15
113 #define DT_SYMBOLIC 16
114 #define DT_REL 17
115 #define DT_RELSZ 18
116 #define DT_RELENT 19
117 #define DT_PLTREL 20
118 #define DT_DEBUG 21
119 #define DT_TEXTREL 22
120 #define DT_JMPREL 23
121 #define DT_LOPROC 0x70000000
122 #define DT_HIPROC 0x7fffffff
124 /* Auxilliary table entries */
125 #define AT_NULL 0 /* end of vector */
126 #define AT_IGNORE 1 /* entry should be ignored */
127 #define AT_EXECFD 2 /* file descriptor of program */
128 #define AT_PHDR 3 /* program headers for program */
129 #define AT_PHENT 4 /* size of program header entry */
130 #define AT_PHNUM 5 /* number of program headers */
131 #define AT_PAGESZ 6 /* system page size */
132 #define AT_BASE 7 /* base address of interpreter */
133 #define AT_FLAGS 8 /* flags */
134 #define AT_ENTRY 9 /* entry point of program */
135 #define AT_NOTELF 10 /* program is not ELF */
136 #define AT_UID 11 /* real uid */
137 #define AT_EUID 12 /* effective uid */
138 #define AT_GID 13 /* real gid */
139 #define AT_EGID 14 /* effective gid */
140 #define AT_PLATFORM 15 /* string identifying CPU for optimizations */
141 #define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
142 #define AT_CLKTCK 17 /* frequency at which times() increments */
143 /* 18..22 = ? */
144 #define AT_SECURE 23 /* secure mode boolean */
146 /* Program header permission flags */
147 #define PF_X 0x1
148 #define PF_W 0x2
149 #define PF_R 0x4
151 /* Section header types */
152 #define SHT_NULL 0
153 #define SHT_PROGBITS 1
154 #define SHT_SYMTAB 2
155 #define SHT_STRTAB 3
156 #define SHT_RELA 4
157 #define SHT_HASH 5
158 #define SHT_DYNAMIC 6
159 #define SHT_NOTE 7
160 #define SHT_NOBITS 8
161 #define SHT_REL 9
162 #define SHT_SHLIB 10
163 #define SHT_DYNSYM 11
164 #define SHT_NUM 12
165 #define SHT_LOPROC 0x70000000
166 #define SHT_HIPROC 0x7fffffff
167 #define SHT_LOUSER 0x80000000
168 #define SHT_HIUSER 0xffffffff
170 /* Section header flags */
171 #define SHF_WRITE (1 << 0) /* Writable */
172 #define SHF_ALLOC (1 << 1) /* Occupies memory during execution */
173 #define SHF_EXECINSTR (1 << 2) /* Executable */
174 #define SHF_MERGE (1 << 4) /* Might be merged */
175 #define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */
176 #define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */
177 #define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */
178 #define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling required */
179 #define SHF_GROUP (1 << 9) /* Section is member of a group. */
180 #define SHF_TLS (1 << 10) /* Section hold thread-local data. */
182 /* Special section numbers */
183 #define SHN_UNDEF 0
184 #define SHN_LORESERVE 0xff00
185 #define SHN_LOPROC 0xff00
186 #define SHN_HIPROC 0xff1f
187 #define SHN_ABS 0xfff1
188 #define SHN_COMMON 0xfff2
189 #define SHN_HIRESERVE 0xffff
191 /* Section align flag */
192 #define SHA_ANY 1 /* No alignment constraint */
194 /* Lenght of magic at the start of a file */
195 #define EI_NIDENT 16
197 /* Magic number constants... */
198 #define EI_MAG0 0 /* e_ident[] indexes */
199 #define EI_MAG1 1
200 #define EI_MAG2 2
201 #define EI_MAG3 3
202 #define EI_CLASS 4
203 #define EI_DATA 5
204 #define EI_VERSION 6
205 #define EI_OSABI 7
206 #define EI_PAD 8
208 #define ELFMAG0 0x7f /* EI_MAG */
209 #define ELFMAG1 'E'
210 #define ELFMAG2 'L'
211 #define ELFMAG3 'F'
212 #define ELFMAG "\177ELF"
213 #define SELFMAG 4
215 #define ELFCLASSNONE 0 /* EI_CLASS */
216 #define ELFCLASS32 1
217 #define ELFCLASS64 2
218 #define ELFCLASSNUM 3
220 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
221 #define ELFDATA2LSB 1
222 #define ELFDATA2MSB 2
224 #define EV_NONE 0 /* e_version, EI_VERSION */
225 #define EV_CURRENT 1
226 #define EV_NUM 2
228 #define ELFOSABI_NONE 0
229 #define ELFOSABI_LINUX 3
231 /* Legal values for ST_BIND subfield of st_info (symbol binding). */
232 #define STB_LOCAL 0 /* Local symbol */
233 #define STB_GLOBAL 1 /* Global symbol */
234 #define STB_WEAK 2 /* Weak symbol */
235 #define STB_NUM 3 /* Number of defined types. */
236 #define STB_LOOS 10 /* Start of OS-specific */
237 #define STB_HIOS 12 /* End of OS-specific */
238 #define STB_LOPROC 13 /* Start of processor-specific */
239 #define STB_HIPROC 15 /* End of processor-specific */
241 /* Symbol types */
242 #define STT_NOTYPE 0 /* Symbol type is unspecified */
243 #define STT_OBJECT 1 /* Symbol is a data object */
244 #define STT_FUNC 2 /* Symbol is a code object */
245 #define STT_SECTION 3 /* Symbol associated with a section */
246 #define STT_FILE 4 /* Symbol's name is file name */
247 #define STT_COMMON 5 /* Symbol is a common data object */
248 #define STT_TLS 6 /* Symbol is thread-local data object*/
249 #define STT_NUM 7 /* Number of defined types. */
251 /* Symbol visibilities */
252 #define STV_DEFAULT 0 /* Default symbol visibility rules */
253 #define STV_INTERNAL 1 /* Processor specific hidden class */
254 #define STV_HIDDEN 2 /* Sym unavailable in other modules */
255 #define STV_PROTECTED 3 /* Not preemptible, not exported */
257 /* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field */
258 #define ELF32_ST_BIND(i) ((i) >> 4)
259 #define ELF32_ST_MKBIND(i) ((i) << 4) /* just a helper */
260 #define ELF32_ST_TYPE(i) ((i) & 0xf)
261 #define ELF32_ST_INFO(b, i) (ELF_ST_MKBIND(b) + ELF_ST_TYPE(i))
263 #define ELF64_ST_BIND(i) ELF32_ST_BIND(i)
264 #define ELF64_ST_MKBIND(i) ELF32_ST_MKBIND(i)
265 #define ELF64_ST_TYPE(i) ELF32_ST_TYPE(i)
266 #define ELF64_ST_INFO(b, i) ELF32_ST_INFO(b, i)
269 * ELF standard typedefs (yet more proof that <stdint.h> was way overdue)
272 typedef uint16_t Elf32_Half;
273 typedef int16_t Elf32_SHalf;
274 typedef uint32_t Elf32_Word;
275 typedef int32_t Elf32_Sword;
276 typedef uint64_t Elf32_Xword;
277 typedef int64_t Elf32_Sxword;
279 typedef uint32_t Elf32_Off;
280 typedef uint32_t Elf32_Addr;
281 typedef uint16_t Elf32_Section;
283 typedef uint16_t Elf64_Half;
284 typedef int16_t Elf64_SHalf;
285 typedef uint32_t Elf64_Word;
286 typedef int32_t Elf64_Sword;
287 typedef uint64_t Elf64_Xword;
288 typedef int64_t Elf64_Sxword;
290 typedef uint64_t Elf64_Off;
291 typedef uint64_t Elf64_Addr;
292 typedef uint16_t Elf64_Section;
295 * Dynamic header
298 typedef struct elf32_dyn {
299 Elf32_Sword d_tag;
300 union {
301 Elf32_Sword d_val;
302 Elf32_Addr d_ptr;
303 } d_un;
304 } Elf32_Dyn;
306 typedef struct elf64_dyn {
307 Elf64_Sxword d_tag;
308 union {
309 Elf64_Xword d_val;
310 Elf64_Addr d_ptr;
311 } d_un;
312 } Elf64_Dyn;
315 * Relocations
318 #define ELF32_R_SYM(x) ((x) >> 8)
319 #define ELF32_R_TYPE(x) ((x) & 0xff)
321 typedef struct elf32_rel {
322 Elf32_Addr r_offset;
323 Elf32_Word r_info;
324 } Elf32_Rel;
326 typedef struct elf32_rela {
327 Elf32_Addr r_offset;
328 Elf32_Word r_info;
329 Elf32_Sword r_addend;
330 } Elf32_Rela;
332 enum reloc32_type {
333 R_386_32 = 1, /* ordinary absolute relocation */
334 R_386_PC32 = 2, /* PC-relative relocation */
335 R_386_GOT32 = 3, /* an offset into GOT */
336 R_386_PLT32 = 4, /* a PC-relative offset into PLT */
337 R_386_COPY = 5, /* ??? */
338 R_386_GLOB_DAT = 6, /* ??? */
339 R_386_JUMP_SLOT = 7, /* ??? */
340 R_386_RELATIVE = 8, /* ??? */
341 R_386_GOTOFF = 9, /* an offset from GOT base */
342 R_386_GOTPC = 10, /* a PC-relative offset _to_ GOT */
343 R_386_TLS_TPOFF = 14, /* Offset in static TLS block */
344 R_386_TLS_IE = 15, /* Address of GOT entry for static TLS block offset */
345 /* These are GNU extensions, but useful */
346 R_386_16 = 20, /* A 16-bit absolute relocation */
347 R_386_PC16 = 21, /* A 16-bit PC-relative relocation */
348 R_386_8 = 22, /* An 8-bit absolute relocation */
349 R_386_PC8 = 23 /* An 8-bit PC-relative relocation */
352 #define ELF64_R_SYM(x) ((x) >> 32)
353 #define ELF64_R_TYPE(x) ((x) & 0xffffffff)
355 typedef struct elf64_rel {
356 Elf64_Addr r_offset;
357 Elf64_Xword r_info;
358 } Elf64_Rel;
360 typedef struct elf64_rela {
361 Elf64_Addr r_offset;
362 Elf64_Xword r_info;
363 Elf64_Sxword r_addend;
364 } Elf64_Rela;
366 enum reloc64_type {
367 R_X86_64_NONE = 0, /* No reloc */
368 R_X86_64_64 = 1, /* Direct 64 bit */
369 R_X86_64_PC32 = 2, /* PC relative 32 bit signed */
370 R_X86_64_GOT32 = 3, /* 32 bit GOT entry */
371 R_X86_64_PLT32 = 4, /* 32 bit PLT address */
372 R_X86_64_COPY = 5, /* Copy symbol at runtime */
373 R_X86_64_GLOB_DAT = 6, /* Create GOT entry */
374 R_X86_64_JUMP_SLOT = 7, /* Create PLT entry */
375 R_X86_64_RELATIVE = 8, /* Adjust by program base */
376 R_X86_64_GOTPCREL = 9, /* 32 bit signed PC relative offset to GOT */
377 R_X86_64_32 = 10, /* Direct 32 bit zero extended */
378 R_X86_64_32S = 11, /* Direct 32 bit sign extended */
379 R_X86_64_16 = 12, /* Direct 16 bit zero extended */
380 R_X86_64_PC16 = 13, /* 16 bit sign extended pc relative */
381 R_X86_64_8 = 14, /* Direct 8 bit sign extended */
382 R_X86_64_PC8 = 15, /* 8 bit sign extended pc relative */
383 R_X86_64_DTPMOD64 = 16, /* ID of module containing symbol */
384 R_X86_64_DTPOFF64 = 17, /* Offset in module's TLS block */
385 R_X86_64_TPOFF64 = 18, /* Offset in initial TLS block */
386 R_X86_64_TLSGD = 19, /* 32 bit signed PC relative offset to two GOT entries for GD symbol */
387 R_X86_64_TLSLD = 20, /* 32 bit signed PC relative offset to two GOT entries for LD symbol */
388 R_X86_64_DTPOFF32 = 21, /* Offset in TLS block */
389 R_X86_64_GOTTPOFF = 22, /* 32 bit signed PC relative offset to GOT entry for IE symbol */
390 R_X86_64_TPOFF32 = 23, /* Offset in initial TLS block */
391 R_X86_64_PC64 = 24, /* word64 S + A - P */
392 R_X86_64_GOTOFF64 = 25, /* word64 S + A - GOT */
393 R_X86_64_GOTPC32 = 26, /* word32 GOT + A - P */
394 R_X86_64_GOT64 = 27, /* word64 G + A */
395 R_X86_64_GOTPCREL64 = 28, /* word64 G + GOT - P + A */
396 R_X86_64_GOTPC64 = 29, /* word64 GOT - P + A */
397 R_X86_64_GOTPLT64 = 30, /* word64 G + A */
398 R_X86_64_PLTOFF64 = 31, /* word64 L - GOT + A */
399 R_X86_64_SIZE32 = 32, /* word32 Z + A */
400 R_X86_64_SIZE64 = 33, /* word64 Z + A */
401 R_X86_64_GOTPC32_TLSDESC = 34, /* word32 */
402 R_X86_64_TLSDESC_CALL = 35, /* none */
403 R_X86_64_TLSDESC = 36 /* word64?2 */
407 * Symbol
410 typedef struct elf32_sym {
411 Elf32_Word st_name;
412 Elf32_Addr st_value;
413 Elf32_Word st_size;
414 unsigned char st_info;
415 unsigned char st_other;
416 Elf32_Half st_shndx;
417 } Elf32_Sym;
419 typedef struct elf64_sym {
420 Elf64_Word st_name;
421 unsigned char st_info;
422 unsigned char st_other;
423 Elf64_Half st_shndx;
424 Elf64_Addr st_value;
425 Elf64_Xword st_size;
426 } Elf64_Sym;
429 * Main file header
432 typedef struct elf32_hdr {
433 unsigned char e_ident[EI_NIDENT];
434 Elf32_Half e_type;
435 Elf32_Half e_machine;
436 Elf32_Word e_version;
437 Elf32_Addr e_entry;
438 Elf32_Off e_phoff;
439 Elf32_Off e_shoff;
440 Elf32_Word e_flags;
441 Elf32_Half e_ehsize;
442 Elf32_Half e_phentsize;
443 Elf32_Half e_phnum;
444 Elf32_Half e_shentsize;
445 Elf32_Half e_shnum;
446 Elf32_Half e_shstrndx;
447 } Elf32_Ehdr;
449 typedef struct elf64_hdr {
450 unsigned char e_ident[EI_NIDENT];
451 Elf64_Half e_type;
452 Elf64_Half e_machine;
453 Elf64_Word e_version;
454 Elf64_Addr e_entry;
455 Elf64_Off e_phoff;
456 Elf64_Off e_shoff;
457 Elf64_Word e_flags;
458 Elf64_Half e_ehsize;
459 Elf64_Half e_phentsize;
460 Elf64_Half e_phnum;
461 Elf64_Half e_shentsize;
462 Elf64_Half e_shnum;
463 Elf64_Half e_shstrndx;
464 } Elf64_Ehdr;
467 * Program header
470 typedef struct elf32_phdr {
471 Elf32_Word p_type;
472 Elf32_Off p_offset;
473 Elf32_Addr p_vaddr;
474 Elf32_Addr p_paddr;
475 Elf32_Word p_filesz;
476 Elf32_Word p_memsz;
477 Elf32_Word p_flags;
478 Elf32_Word p_align;
479 } Elf32_Phdr;
481 typedef struct elf64_phdr {
482 Elf64_Word p_type;
483 Elf64_Word p_flags;
484 Elf64_Off p_offset;
485 Elf64_Addr p_vaddr;
486 Elf64_Addr p_paddr;
487 Elf64_Xword p_filesz;
488 Elf64_Xword p_memsz;
489 Elf64_Xword p_align;
490 } Elf64_Phdr;
493 * Section header
496 typedef struct elf32_shdr {
497 Elf32_Word sh_name;
498 Elf32_Word sh_type;
499 Elf32_Word sh_flags;
500 Elf32_Addr sh_addr;
501 Elf32_Off sh_offset;
502 Elf32_Word sh_size;
503 Elf32_Word sh_link;
504 Elf32_Word sh_info;
505 Elf32_Word sh_addralign;
506 Elf32_Word sh_entsize;
507 } Elf32_Shdr;
509 typedef struct elf64_shdr {
510 Elf64_Word sh_name;
511 Elf64_Word sh_type;
512 Elf64_Xword sh_flags;
513 Elf64_Addr sh_addr;
514 Elf64_Off sh_offset;
515 Elf64_Xword sh_size;
516 Elf64_Word sh_link;
517 Elf64_Word sh_info;
518 Elf64_Xword sh_addralign;
519 Elf64_Xword sh_entsize;
520 } Elf64_Shdr;
523 * Note header
525 typedef struct elf32_note {
526 Elf32_Word n_namesz; /* Name size */
527 Elf32_Word n_descsz; /* Content size */
528 Elf32_Word n_type; /* Content type */
529 } Elf32_Nhdr;
531 typedef struct elf64_note {
532 Elf64_Word n_namesz; /* Name size */
533 Elf64_Word n_descsz; /* Content size */
534 Elf64_Word n_type; /* Content type */
535 } Elf64_Nhdr;
537 #endif /* OUTPUT_ELF_H */