1 | /* $Id: elf.h,v 1.6 2000-12-11 06:53:51 bird Exp $
|
---|
2 | *
|
---|
3 | * ELF stuff.
|
---|
4 | *
|
---|
5 | * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 |
|
---|
12 | #ifndef _elf_h_
|
---|
13 | #define _elf_h_
|
---|
14 |
|
---|
15 | //#pragma pack(1)
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * Basic ELF types.
|
---|
19 | */
|
---|
20 | typedef unsigned long Elf32_Addr; /* Unsigned program address. */
|
---|
21 | typedef unsigned short Elf32_Half; /* Unsigned medium integer. */
|
---|
22 | typedef signed long Elf32_Off; /* Unsigned file offset. */
|
---|
23 | typedef signed long Elf32_Sword; /* Signed large interger. */
|
---|
24 | typedef unsigned long Elf32_Word; /* Unsigned large integer. */
|
---|
25 | /* unsigned char Unsigned small integer. */
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | /*
|
---|
30 | * ELF Header
|
---|
31 | */
|
---|
32 | #define EI_INDENT 0x10
|
---|
33 |
|
---|
34 | typedef struct /* 0x34 */
|
---|
35 | {
|
---|
36 | unsigned char e_ident[EI_INDENT]; /* 0x00 ELF Indentification */
|
---|
37 | Elf32_Half e_type; /* 0x10 Object file type */
|
---|
38 | Elf32_Half e_machine; /* 0x12 Machine type */
|
---|
39 | Elf32_Word e_version; /* 0x14 ELF format version */
|
---|
40 | Elf32_Addr e_entry; /* 0x18 Entry point address */
|
---|
41 | Elf32_Off e_phoff; /* 0x1c File offset of the program header table */
|
---|
42 | Elf32_Off e_shoff; /* 0x20 File offset of the section header table */
|
---|
43 | Elf32_Word e_flags; /* 0x24 Processor specific flags */
|
---|
44 | Elf32_Half e_ehsize; /* 0x28 Size of the Elf Header (this structure) */
|
---|
45 | Elf32_Half e_phentsize; /* 0x2a Size of one entry in the program header table */
|
---|
46 | Elf32_Half e_phnum; /* 0x2c Number of entries in the program header table */
|
---|
47 | Elf32_Half e_shentsize; /* 0x2e Size of one entry in the section header table */
|
---|
48 | Elf32_Half e_shnum; /* 0x30 Number of entries in the section header table */
|
---|
49 | Elf32_Half e_shstrndx; /* 0x32 Section header table index of the string table */
|
---|
50 | } Elf32_Ehdr;
|
---|
51 |
|
---|
52 | /* e_idnet - ELF Identification */
|
---|
53 | #define EI_MAG0 0 /* File identificator */
|
---|
54 | #define EI_MAG1 1 /* File identificator */
|
---|
55 | #define EI_MAG2 2 /* File identificator */
|
---|
56 | #define EI_MAG3 3 /* File identificator */
|
---|
57 | #define EI_CLASS 4 /* File class */
|
---|
58 | #define EI_DATA 5 /* Data encoding */
|
---|
59 | #define EI_VERSION 6 /* File version */
|
---|
60 | #define EI_PAD 7 /* Start of padding bytes */
|
---|
61 | /* EI_MAG[0-4] */
|
---|
62 | #define ELFMAG0 0x7f
|
---|
63 | #define ELFMAG1 'E'
|
---|
64 | #define ELFMAG2 'L'
|
---|
65 | #define ELFMAG3 'F'
|
---|
66 | #define ELFMAGICLSB ( 0x7f | ('E' << 8) | ('L' << 16) | ('F' << 24))
|
---|
67 | #define ELFMAGICMSB ((0x7f << 24) | ('E' << 16) | ('L' << 8) | 'F' )
|
---|
68 | /* EI_CLASS */
|
---|
69 | #define ELFCLASSNONE 0 /* Invalid class */
|
---|
70 | #define ELFCLASS32 1 /* 32-bit objects */
|
---|
71 | #define ELFCLASS64 2 /* 64-bit objects */
|
---|
72 | #define ELFCLASSNUM 3 /* ? */
|
---|
73 | /* EI_DATA */
|
---|
74 | #define ELFDATANONE 0 /* Invalid data encoding */
|
---|
75 | #define ELFDATA2LSB 1 /* Little endian encoding */
|
---|
76 | #define ELFDATA2MSB 2 /* Big endian encoding */
|
---|
77 |
|
---|
78 | /* e_type contents */
|
---|
79 | #define ET_NONE 0x0000 /* No file type */
|
---|
80 | #define ET_REL 0x0001 /* Relocatable file */
|
---|
81 | #define ET_EXEC 0x0002 /* Executable file */
|
---|
82 | #define ET_DYN 0x0003 /* Shared object file */
|
---|
83 | #define ET_CORE 0x0004 /* Core file */
|
---|
84 | #define ET_LOPROC 0xff00 /* Processor-specific - currect value? */
|
---|
85 | #define ET_HIPROC 0xffff /* Processor-specific - currect value? */
|
---|
86 |
|
---|
87 | /* e_machine contents */
|
---|
88 | #define EM_NONE 0 /* No machine */
|
---|
89 | #define EM_M32 1 /* AT&T WE 32100 */
|
---|
90 | #define EM_SPARC 2 /* SPARC */
|
---|
91 | #define EM_386 3 /* Intel 80386 */
|
---|
92 | #define EM_68K 4 /* Motorola 680000 */
|
---|
93 | #define EM_88K 5 /* Motorola 880000 */
|
---|
94 | #define EM_486 6 /* Intel 80486 - disused? */
|
---|
95 | #define EM_860 7 /* Intel 80860 */
|
---|
96 | #define EM_MIPS 8 /* MIPS RS3000 (big endian...) */
|
---|
97 | #define EM_MIPS_RS4_BE 10 /* MIPS RS4000 (big endian) */
|
---|
98 | #define EM_SPARC64 11 /* SPARC v9 (not official) 64-bit */
|
---|
99 | #define EM_PARISC 15 /* HPPA */
|
---|
100 | #define EM_SPARC32PLUS 18 /* SUN's "v8plus" */
|
---|
101 | #define EM_PPC 20 /* PowerPC */
|
---|
102 | #define EM_ALPHA 0x9026 /* Digital Alpha - NB! Interim number */
|
---|
103 |
|
---|
104 | /* e_version contents */
|
---|
105 | #define EV_NONE 0 /* Invalid version */
|
---|
106 | #define EV_CURRENT 1 /* Current version */
|
---|
107 | #define EV_NUM 2 /* ? */
|
---|
108 |
|
---|
109 | /* e_flags - Machine Information */
|
---|
110 | #define EF_386_NONE 0 /* Intel 80386 has no flags defined */
|
---|
111 | #define EF_486_NONE 0 /* Intel 80486 has no flags defined */
|
---|
112 |
|
---|
113 |
|
---|
114 | /*
|
---|
115 | * ELF Sections
|
---|
116 | */
|
---|
117 | typedef struct /* 0x28 */
|
---|
118 | {
|
---|
119 | Elf32_Word sh_name; /* 0x00 Section name. Index into the section header string table section. */
|
---|
120 | Elf32_Word sh_type; /* 0x04 Section type. Categorizes the contents and semantics. */
|
---|
121 | Elf32_Word sh_flags; /* 0x08 Section flags. */
|
---|
122 | Elf32_Addr sh_addr; /* 0x0c Address to where in memory the section should reside. */
|
---|
123 | Elf32_Off sh_offset; /* 0x10 Offset into the file of the section's data. */
|
---|
124 | Elf32_Word sh_size; /* 0x14 Section's size in bytes. */
|
---|
125 | Elf32_Word sh_link; /* 0x18 Section header table index link. */
|
---|
126 | Elf32_Word sh_info; /* 0x1c Extra information. */
|
---|
127 | Elf32_Word sh_addralign; /* 0x20 Section alignment. */
|
---|
128 | Elf32_Word sh_entsize; /* 0x24 Entry size of some evtentual fixed-sized table entries. */
|
---|
129 | } Elf32_Shdr;
|
---|
130 |
|
---|
131 | /* section indexes (section references) */
|
---|
132 | #define SHN_UNDEF 0 /* Undefined/missing/irrelevant/meaningless section reference. */
|
---|
133 | #define SHN_LORESERVE 0xff00 /* Lower bound of the reserved indexes. */
|
---|
134 | #define SHN_LOPROC 0xff00 /* Processor-specific semantics lower bound. */
|
---|
135 | #define SHN_HIPROC 0xff1f /* Processor-specific semantics upper bound. */
|
---|
136 | #define SHN_ABS 0xfff1 /* Absolute values for the corresponding reference. */
|
---|
137 | #define SHN_COMMON 0xfff2 /* Symbols defined relative to this section are common symbols. */
|
---|
138 | #define SHN_HIRESERVE 0xffff /* Upper bound of the reserved indexes. */
|
---|
139 |
|
---|
140 | /* sh_type */
|
---|
141 | #define SHT_NULL 0 /* Inactive section header. All other members have undefined contents. */
|
---|
142 | #define SHT_PROGBITS 1 /* Program defined information. */
|
---|
143 | #define SHT_SYMTAB 2 /* Symboltable. */
|
---|
144 | #define SHT_STRTAB 3 /* Stringtable. */
|
---|
145 | #define SHT_RELA 4 /* Relocations with explicit addends. */
|
---|
146 | #define SHT_HASH 5 /* Symbol has table. */
|
---|
147 | #define SHT_DYNAMIC 6 /* Dynamic linking information. */
|
---|
148 | #define SHT_NOTE 7 /* Information tat marks the file in some way. */
|
---|
149 | #define SHT_NOBITS 8 /* Occupies no space in the file. */
|
---|
150 | #define SHT_REL 9 /* Relocations. */
|
---|
151 | #define SHT_SHLIB 10 /* reserved. */
|
---|
152 | #define SHT_DYNSYM 11 /* Symboltable used for dynamic loading. */
|
---|
153 | #define SHT_NUM 12 /* ? */
|
---|
154 | #define SHT_LOPROC 0x70000000L /* Processor-spcific semantics lower bound. */
|
---|
155 | #define SHT_HIPROC 0x7fffffffL /* Processor-spcific semantics upper bound. */
|
---|
156 | #define SHT_LOUSER 0x80000000L /* Application program specific lower bound. */
|
---|
157 | #define SHT_HIUSER 0xffffffffL /* Application program specific upper bound. */
|
---|
158 |
|
---|
159 | /* sh_flags */
|
---|
160 | #define SHF_WRITE 0x1 /* Writable during process execution. */
|
---|
161 | #define SHF_ALLOC 0x2 /* The section occupies memory during process execution. */
|
---|
162 | #define SHF_EXECINSTR 0x4 /* Executable machine instructs. */
|
---|
163 | #define SHF_MASKPROC 0xf0000000L /* Processor-specific semantics bits. */
|
---|
164 |
|
---|
165 |
|
---|
166 | /*
|
---|
167 | * ELF Symbol table
|
---|
168 | */
|
---|
169 | typedef struct /* 0x10 */
|
---|
170 | {
|
---|
171 | Elf32_Word st_name; /* 0x00 Symbol name. (index) */
|
---|
172 | Elf32_Addr st_value; /* 0x04 Value associated with the symbol. */
|
---|
173 | Elf32_Word st_size; /* 0x08 Size associated with the symbol. */
|
---|
174 | unsigned char st_info; /* 0x0c Symbol type and binding attributes. */
|
---|
175 | unsigned char st_other; /* 0x0d Reserved. (currently 0?) */
|
---|
176 | Elf32_Half st_shndx; /* 0x0e Section index of related section. */
|
---|
177 | } Elf32_Sym;
|
---|
178 |
|
---|
179 | /* symbol table index(es) */
|
---|
180 | #define STN_UNDEF 0 /* Reserved symboltable entry. */
|
---|
181 |
|
---|
182 | /* st_info macros */
|
---|
183 | #define ELF32_ST_BIND(i) ((i) >> 4) /* Get the symbol binding attributes from the st_info member. */
|
---|
184 | #define ELF32_ST_TYPE(i) ((i) & 0x0f)/* Get the symbol type from the st_info member. */
|
---|
185 | #define ELF32_ST_INFO(b,t) ((b << 4) | (t & 0x0f)) /* Build a st_info member. */
|
---|
186 |
|
---|
187 | /* st_info - binding attributes */
|
---|
188 | #define STB_LOCAL 0x0 /* Local symbol. Not visible outside the object file. */
|
---|
189 | #define STB_GLOBAL 0x1 /* Global symbol. Visible to everyone. */
|
---|
190 | #define STB_WEAK 0x2 /* Weak symbols resemble global symbols, but their definitions have lower precedence. */
|
---|
191 | #define STB_LOPROC 0xd /* Processor-specific semantics lower bound. */
|
---|
192 | #define STB_HIPROC 0xf /* Processor-specific semantics upper bound. */
|
---|
193 |
|
---|
194 | /* st_info - types */
|
---|
195 | #define STT_NOTYPE 0x0 /* The symbol's type is not defined. */
|
---|
196 | #define STT_OBJECT 0x1 /* The symbol is associated with a data object, such as a variable an array, etc. */
|
---|
197 | #define STT_FUNC 0x2 /* The symbol is associated with a function or other executable code. */
|
---|
198 | #define STT_SECTION 0x3 /* The symbol is associated with a section. */
|
---|
199 | #define STT_FILE 0x4 /* Name of the source file... */
|
---|
200 | #define STT_LOPROC 0xd /* Processor-specific semantics lower bound. */
|
---|
201 | #define STT_HIPROC 0xf /* Processor-specific semantics upper bound. */
|
---|
202 |
|
---|
203 |
|
---|
204 | /*
|
---|
205 | * ELF Relocation
|
---|
206 | */
|
---|
207 | typedef struct /* 0x08 */
|
---|
208 | {
|
---|
209 | Elf32_Addr r_offset; /* 0x00 Offset or virtual address. */
|
---|
210 | Elf32_Word r_info; /* 0x04 Symbolindex/type. */
|
---|
211 | } Elf32_Rel;
|
---|
212 |
|
---|
213 | typedef struct /* 0x0c */
|
---|
214 | {
|
---|
215 | Elf32_Addr r_offset; /* 0x00 Offset or virtual address. */
|
---|
216 | Elf32_Word r_info; /* 0x04 Symbolindex/type. */
|
---|
217 | Elf32_Sword r_addend; /* 0x08 Constant addend. */
|
---|
218 | } Elf32_Rela;
|
---|
219 |
|
---|
220 | /* r_info macro */
|
---|
221 | #define ELF32_R_SYM(i) ((i) >> 8) /* Gets symbol index from the r_info member. */
|
---|
222 | #define ELF32_R_TYPE(i) ((unsigned char)(i)) /* Get the relocation type from the r_info member. */
|
---|
223 | #define ELF32_R_INFO(s,t) (((s) << 8) | (unsigned char)(t)) /* Makes the r_info member. */
|
---|
224 |
|
---|
225 | /* r_info - Intel 80386 relocations */
|
---|
226 | #define R_386_NONE 0 /* */
|
---|
227 | #define R_386_32 1
|
---|
228 | #define R_386_PC32 2
|
---|
229 | #define R_386_GOT32 3
|
---|
230 | #define R_386_PLT32 4
|
---|
231 | #define R_386_COPY 5
|
---|
232 | #define R_386_GLOB_DAT 6
|
---|
233 | #define R_386_JMP_SLOT 7
|
---|
234 | #define R_386_RELATIVE 8
|
---|
235 | #define R_386_GOT_OFF 9
|
---|
236 | #define R_386_GOTPC 10
|
---|
237 | #define R_386_NUM 11
|
---|
238 |
|
---|
239 |
|
---|
240 |
|
---|
241 | /*
|
---|
242 | * ELF Program Header
|
---|
243 | */
|
---|
244 | typedef struct /* 0x20 */
|
---|
245 | {
|
---|
246 | Elf32_Word p_type; /* 0x00 Tells what this header describes or how to interpret it. */
|
---|
247 | Elf32_Off p_offset; /* 0x04 Offset of the first byte of this segment. */
|
---|
248 | Elf32_Addr p_vaddr; /* 0x08 Virtual address of the segment. */
|
---|
249 | Elf32_Addr p_paddr; /* 0x0c Physical address. Usually ignorable. */
|
---|
250 | Elf32_Word p_filesz; /* 0x10 Count of bytes in the file image of this segment. Zero allowed. */
|
---|
251 | Elf32_Word p_memsz; /* 0x14 Count of bytes in the memory image of this segment. Zero allowed. */
|
---|
252 | Elf32_Word p_flags; /* 0x18 Flags relevant to the segement. */
|
---|
253 | Elf32_Word p_align; /* 0x1c Alignment. 0 and 1 means no alignment. */
|
---|
254 | } Elf32_Phdr;
|
---|
255 |
|
---|
256 | /* p_type - segment types */
|
---|
257 | #define PT_NULL 0 /* Unused header. */
|
---|
258 | #define PT_LOAD 1 /* Loadable segment. p_filesz, p_memsz and p_vaddr applies. */
|
---|
259 | #define PT_DYNAMIC 2 /* Dynamic linking information. */
|
---|
260 | #define PT_INTERP 3 /* Interpreter path. */
|
---|
261 | #define PT_NOTE 4 /* Auxiliary information. */
|
---|
262 | #define PT_SHLIB 5 /* Reserved. */
|
---|
263 | #define PT_PHDR 6 /* This header specifies the location and size of the program header table in file and memory. */
|
---|
264 | #define PT_LOPROC 0x70000000 /* Reserved processor-specific semantics range start. */
|
---|
265 | #define PT_HIPROC 0x7fffffff /* Reserved processor-specific semantics range end (included). */
|
---|
266 |
|
---|
267 | /* p_flags - permission flags */
|
---|
268 | #define PF_X 1 /* Executable */
|
---|
269 | #define PF_W 2 /* Writeable */
|
---|
270 | #define PF_R 4 /* Readable */
|
---|
271 |
|
---|
272 |
|
---|
273 | /*
|
---|
274 | * Dynamic Structure
|
---|
275 | */
|
---|
276 | typedef struct /* 0x08 */
|
---|
277 | {
|
---|
278 | Elf32_Sword d_tag; /* 0x00 Tag type. */
|
---|
279 | union
|
---|
280 | {
|
---|
281 | Elf32_Word d_val; /* 0x04 Value, interpreted according to the tag type. */
|
---|
282 | Elf32_Addr d_ptr; /* 0x04 Virtual address, interpreted according to the tag type. */
|
---|
283 | } d_un;
|
---|
284 | } Elf32_Dyn;
|
---|
285 |
|
---|
286 | /* d_tag - tag types */ /* d_un exe so: '-' is ignored; '+' is mandatory; '*' is optional. */
|
---|
287 | #define DT_NULL 0 /* - - - Marks the end of the dynamic array. */
|
---|
288 | #define DT_NEEDED 1 /* d_val * * This element holds the string table offset of a
|
---|
289 | null-terminated string, giving the name of a needed
|
---|
290 | library. The offset is an index into the table
|
---|
291 | recoreded in the DT_STRTAB entry. */
|
---|
292 | #define DT_PLTRELSZ 2 /* d_val * * This element holds the total size, in bytes, of the
|
---|
293 | relocation entries associated with the procedure
|
---|
294 | linkage table. If an entry of type DT_JMPREL is
|
---|
295 | present, a DT_PLTRELSZ must accompany it. */
|
---|
296 | #define DT_PLTGOT 3 /* d_ptr * * */
|
---|
297 | #define DT_HASH 4 /* d_ptr + + */
|
---|
298 | #define DT_STRTAB 5 /* d_ptr + + This element holds the address of the string table.
|
---|
299 | Symbol names, library names, and other strings reside
|
---|
300 | in this table. */
|
---|
301 | #define DT_SYMTAB 6 /* d_ptr + + */
|
---|
302 | #define DT_RELA 7 /* d_ptr + * */
|
---|
303 | #define DT_RELASZ 8 /* d_val + * */
|
---|
304 | #define DT_RELAENT 9 /* d_val + * */
|
---|
305 | #define DT_STRSZ 10 /* d_val + + */
|
---|
306 | #define DT_SYMENT 11 /* d_val + + */
|
---|
307 | #define DT_INIT 12 /* d_ptr * * This element holds the address of the initialization function. */
|
---|
308 | #define DT_FINI 13 /* d_ptr * * This element holds the address of the termination function. */
|
---|
309 | #define DT_SONAME 14 /* d_val - * This element holds the string table offset of a
|
---|
310 | null-terminated string, giving the name of the shared
|
---|
311 | object. The offset is an index into the table recorded
|
---|
312 | in the DT_STRTAB entry. */
|
---|
313 | #define DT_RPATH 15 /* d_val + + This element holds the string table offset of a null-terminated
|
---|
314 | search library search path string. The offset is an index int
|
---|
315 | the table recorded in the DT_STRTAB entry. */
|
---|
316 | #define DT_SYMBOLIC 16 /* - - * This element's presence in a shared object library alters the
|
---|
317 | dynamic linker's symbol resolution algorithm for references
|
---|
318 | within the library. Instead of starting a symbol search with
|
---|
319 | the executable file, the dynamic linker starts from the shared
|
---|
320 | object file itself. If the shared object fails to supply the
|
---|
321 | referenced symbol, the dynamic linker then searches the
|
---|
322 | executable file and other shared objects as usual. */
|
---|
323 | #define DT_REL 17 /* d_ptr + * */
|
---|
324 | #define DT_RELSZ 18 /* d_val + * */
|
---|
325 | #define DT_RELENT 19 /* d_val + * */
|
---|
326 | #define DT_PLTREL 20 /* d_val * * */
|
---|
327 | #define DT_DEBUG 21 /* d_ptr * - */
|
---|
328 | #define DT_TEXTREL 22 /* - * * */
|
---|
329 | #define DT_JMPREL 23 /* d_ptr * * */
|
---|
330 | #define DT_LOPROC 0x70000000 /* Reserved processor-specific semantics range start. */
|
---|
331 | #define DT_HIPROC 0x7fffffff /* Reserved processor-specific semantics range end (included). */
|
---|
332 |
|
---|
333 | #pragma pack()
|
---|
334 | #endif /*_elf_h_*/
|
---|