BR 2826669: update licensing information in README
[nasm.git] / output / elf32.h
blobb40a9ffa992eb14677106c6beca58d917aac3a4d
1 /* ----------------------------------------------------------------------- *
2 *
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_ELF32_H
35 #define OUTPUT_ELF32_H
37 #include "output/elfcommon.h"
39 /* ELF standard typedefs (yet more proof that <stdint.h> was way overdue) */
40 typedef uint16_t Elf32_Half;
41 typedef int16_t Elf32_SHalf;
42 typedef uint32_t Elf32_Word;
43 typedef int32_t Elf32_Sword;
44 typedef uint64_t Elf32_Xword;
45 typedef int64_t Elf32_Sxword;
47 typedef uint32_t Elf32_Off;
48 typedef uint32_t Elf32_Addr;
49 typedef uint16_t Elf32_Section;
51 /* Dynamic header */
53 typedef struct elf32_dyn {
54 Elf32_Sword d_tag;
55 union {
56 Elf32_Sword d_val;
57 Elf32_Addr d_ptr;
58 } d_un;
59 } Elf32_Dyn;
61 /* Relocations */
63 #define ELF32_R_SYM(x) ((x) >> 8)
64 #define ELF32_R_TYPE(x) ((x) & 0xff)
66 typedef struct elf32_rel {
67 Elf32_Addr r_offset;
68 Elf32_Word r_info;
69 } Elf32_Rel;
71 typedef struct elf32_rela {
72 Elf32_Addr r_offset;
73 Elf32_Word r_info;
74 Elf32_Sword r_addend;
75 } Elf32_Rela;
77 enum reloc32_type {
78 R_386_32 = 1, /* ordinary absolute relocation */
79 R_386_PC32 = 2, /* PC-relative relocation */
80 R_386_GOT32 = 3, /* an offset into GOT */
81 R_386_PLT32 = 4, /* a PC-relative offset into PLT */
82 R_386_COPY = 5, /* ??? */
83 R_386_GLOB_DAT = 6, /* ??? */
84 R_386_JUMP_SLOT = 7, /* ??? */
85 R_386_RELATIVE = 8, /* ??? */
86 R_386_GOTOFF = 9, /* an offset from GOT base */
87 R_386_GOTPC = 10, /* a PC-relative offset _to_ GOT */
88 R_386_TLS_TPOFF = 14, /* Offset in static TLS block */
89 R_386_TLS_IE = 15, /* Address of GOT entry for static TLS
90 block offset */
91 /* These are GNU extensions, but useful */
92 R_386_16 = 20, /* A 16-bit absolute relocation */
93 R_386_PC16 = 21, /* A 16-bit PC-relative relocation */
94 R_386_8 = 22, /* An 8-bit absolute relocation */
95 R_386_PC8 = 23 /* An 8-bit PC-relative relocation */
98 /* Symbol */
100 typedef struct elf32_sym {
101 Elf32_Word st_name;
102 Elf32_Addr st_value;
103 Elf32_Word st_size;
104 unsigned char st_info;
105 unsigned char st_other;
106 Elf32_Half st_shndx;
107 } Elf32_Sym;
109 /* Main file header */
111 typedef struct elf32_hdr {
112 unsigned char e_ident[EI_NIDENT];
113 Elf32_Half e_type;
114 Elf32_Half e_machine;
115 Elf32_Word e_version;
116 Elf32_Addr e_entry;
117 Elf32_Off e_phoff;
118 Elf32_Off e_shoff;
119 Elf32_Word e_flags;
120 Elf32_Half e_ehsize;
121 Elf32_Half e_phentsize;
122 Elf32_Half e_phnum;
123 Elf32_Half e_shentsize;
124 Elf32_Half e_shnum;
125 Elf32_Half e_shstrndx;
126 } Elf32_Ehdr;
128 /* Program header */
130 typedef struct elf32_phdr {
131 Elf32_Word p_type;
132 Elf32_Off p_offset;
133 Elf32_Addr p_vaddr;
134 Elf32_Addr p_paddr;
135 Elf32_Word p_filesz;
136 Elf32_Word p_memsz;
137 Elf32_Word p_flags;
138 Elf32_Word p_align;
139 } Elf32_Phdr;
141 /* Section header */
143 typedef struct elf32_shdr {
144 Elf32_Word sh_name;
145 Elf32_Word sh_type;
146 Elf32_Word sh_flags;
147 Elf32_Addr sh_addr;
148 Elf32_Off sh_offset;
149 Elf32_Word sh_size;
150 Elf32_Word sh_link;
151 Elf32_Word sh_info;
152 Elf32_Word sh_addralign;
153 Elf32_Word sh_entsize;
154 } Elf32_Shdr;
156 /* Note header */
157 typedef struct elf32_note {
158 Elf32_Word n_namesz; /* Name size */
159 Elf32_Word n_descsz; /* Content size */
160 Elf32_Word n_type; /* Content type */
161 } Elf32_Nhdr;
163 /* How to extract and insert information held in the st_info field. */
164 #define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4)
165 #define ELF32_ST_TYPE(val) ((val) & 0xf)
167 #endif /* OUTPUT_ELF32_H */