1 |
/* gxemul: $Id: exec_elf.h,v 1.6 2005/09/08 20:06:49 debug Exp $ */ |
2 |
|
3 |
#ifndef __EXEC_ELF_H |
4 |
#define __EXEC_ELF_H |
5 |
|
6 |
#include <inttypes.h> |
7 |
|
8 |
/* $NetBSD: exec_elf.h,v 1.37.4.2 2001/05/01 12:05:43 he Exp $ */ |
9 |
|
10 |
/*- |
11 |
* Copyright (c) 1994 The NetBSD Foundation, Inc. |
12 |
* All rights reserved. |
13 |
* |
14 |
* This code is derived from software contributed to The NetBSD Foundation |
15 |
* by Christos Zoulas. |
16 |
* |
17 |
* Redistribution and use in source and binary forms, with or without |
18 |
* modification, are permitted provided that the following conditions |
19 |
* are met: |
20 |
* 1. Redistributions of source code must retain the above copyright |
21 |
* notice, this list of conditions and the following disclaimer. |
22 |
* 2. Redistributions in binary form must reproduce the above copyright |
23 |
* notice, this list of conditions and the following disclaimer in the |
24 |
* documentation and/or other materials provided with the distribution. |
25 |
* 3. All advertising materials mentioning features or use of this software |
26 |
* must display the following acknowledgement: |
27 |
* This product includes software developed by the NetBSD |
28 |
* Foundation, Inc. and its contributors. |
29 |
* 4. Neither the name of The NetBSD Foundation nor the names of its |
30 |
* contributors may be used to endorse or promote products derived |
31 |
* from this software without specific prior written permission. |
32 |
* |
33 |
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
34 |
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
35 |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
36 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
37 |
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
38 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
39 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
40 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
41 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
42 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
43 |
* POSSIBILITY OF SUCH DAMAGE. |
44 |
*/ |
45 |
|
46 |
|
47 |
typedef uint8_t Elf_Byte; |
48 |
|
49 |
typedef uint32_t Elf32_Addr; |
50 |
#define ELF32_FSZ_ADDR 4 |
51 |
typedef uint32_t Elf32_Off; |
52 |
#define ELF32_FSZ_OFF 4 |
53 |
typedef int32_t Elf32_Sword; |
54 |
#define ELF32_FSZ_SWORD 4 |
55 |
typedef uint32_t Elf32_Word; |
56 |
#define ELF32_FSZ_WORD 4 |
57 |
typedef uint16_t Elf32_Half; |
58 |
#define ELF32_FSZ_HALF 2 |
59 |
|
60 |
typedef uint64_t Elf64_Addr; |
61 |
#define ELF64_FSZ_ADDR 8 |
62 |
typedef uint64_t Elf64_Off; |
63 |
#define ELF64_FSZ_OFF 8 |
64 |
typedef int32_t Elf64_Shalf; |
65 |
#define ELF64_FSZ_SHALF 4 |
66 |
#ifdef __sparc_v9__ |
67 |
/* #error weird */ |
68 |
typedef int32_t Elf64_Sword; |
69 |
#define ELF64_FSZ_SWORD 4 |
70 |
typedef uint32_t Elf64_Word; |
71 |
#define ELF64_FSZ_WORD 4 |
72 |
#else |
73 |
typedef int64_t Elf64_Sword; |
74 |
#define ELF64_FSZ_SWORD 8 |
75 |
typedef uint64_t Elf64_Word; |
76 |
#define ELF64_FSZ_WORD 8 |
77 |
#endif |
78 |
typedef int64_t Elf64_Sxword; |
79 |
#define ELF64_FSZ_XWORD 8 |
80 |
typedef uint64_t Elf64_Xword; |
81 |
#define ELF64_FSZ_XWORD 8 |
82 |
typedef uint32_t Elf64_Half; |
83 |
#define ELF64_FSZ_HALF 4 |
84 |
typedef uint16_t Elf64_Quarter; |
85 |
#define ELF64_FSZ_QUARTER 2 |
86 |
|
87 |
/* |
88 |
* ELF Header |
89 |
*/ |
90 |
#define ELF_NIDENT 16 |
91 |
|
92 |
typedef struct { |
93 |
unsigned char e_ident[ELF_NIDENT]; /* Id bytes */ |
94 |
Elf32_Half e_type; /* file type */ |
95 |
Elf32_Half e_machine; /* machine type */ |
96 |
Elf32_Word e_version; /* version number */ |
97 |
Elf32_Addr e_entry; /* entry point */ |
98 |
Elf32_Off e_phoff; /* Program hdr offset */ |
99 |
Elf32_Off e_shoff; /* Section hdr offset */ |
100 |
Elf32_Word e_flags; /* Processor flags */ |
101 |
Elf32_Half e_ehsize; /* sizeof ehdr */ |
102 |
Elf32_Half e_phentsize; /* Program header entry size */ |
103 |
Elf32_Half e_phnum; /* Number of program headers */ |
104 |
Elf32_Half e_shentsize; /* Section header entry size */ |
105 |
Elf32_Half e_shnum; /* Number of section headers */ |
106 |
Elf32_Half e_shstrndx; /* String table index */ |
107 |
} Elf32_Ehdr; |
108 |
|
109 |
typedef struct { |
110 |
unsigned char e_ident[ELF_NIDENT]; /* Id bytes */ |
111 |
Elf64_Quarter e_type; /* file type */ |
112 |
Elf64_Quarter e_machine; /* machine type */ |
113 |
Elf64_Half e_version; /* version number */ |
114 |
Elf64_Addr e_entry; /* entry point */ |
115 |
Elf64_Off e_phoff; /* Program hdr offset */ |
116 |
Elf64_Off e_shoff; /* Section hdr offset */ |
117 |
Elf64_Half e_flags; /* Processor flags */ |
118 |
Elf64_Quarter e_ehsize; /* sizeof ehdr */ |
119 |
Elf64_Quarter e_phentsize; /* Program header entry size */ |
120 |
Elf64_Quarter e_phnum; /* Number of program headers */ |
121 |
Elf64_Quarter e_shentsize; /* Section header entry size */ |
122 |
Elf64_Quarter e_shnum; /* Number of section headers */ |
123 |
Elf64_Quarter e_shstrndx; /* String table index */ |
124 |
} Elf64_Ehdr; |
125 |
|
126 |
/* e_ident offsets */ |
127 |
#define EI_MAG0 0 /* '\177' */ |
128 |
#define EI_MAG1 1 /* 'E' */ |
129 |
#define EI_MAG2 2 /* 'L' */ |
130 |
#define EI_MAG3 3 /* 'F' */ |
131 |
#define EI_CLASS 4 /* File class */ |
132 |
#define EI_DATA 5 /* Data encoding */ |
133 |
#define EI_VERSION 6 /* File version */ |
134 |
#define EI_OSABI 7 /* Operating system/ABI identification */ |
135 |
#define EI_ABIVERSION 8 /* ABI version */ |
136 |
#define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/ |
137 |
|
138 |
/* e_ident[ELFMAG0,ELFMAG3] */ |
139 |
#define ELFMAG0 0x7f |
140 |
#define ELFMAG1 'E' |
141 |
#define ELFMAG2 'L' |
142 |
#define ELFMAG3 'F' |
143 |
#define ELFMAG "\177ELF" |
144 |
#define SELFMAG 4 |
145 |
|
146 |
/* e_ident[EI_CLASS] */ |
147 |
#define ELFCLASSNONE 0 /* Invalid class */ |
148 |
#define ELFCLASS32 1 /* 32-bit objects */ |
149 |
#define ELFCLASS64 2 /* 64-bit objects */ |
150 |
#define ELFCLASSNUM 3 |
151 |
|
152 |
/* e_ident[EI_DATA] */ |
153 |
#define ELFDATANONE 0 /* Invalid data encoding */ |
154 |
#define ELFDATA2LSB 1 /* 2's complement values, LSB first */ |
155 |
#define ELFDATA2MSB 2 /* 2's complement values, MSB first */ |
156 |
|
157 |
/* e_ident[EI_VERSION] */ |
158 |
#define EV_NONE 0 /* Invalid version */ |
159 |
#define EV_CURRENT 1 /* Current version */ |
160 |
#define EV_NUM 2 |
161 |
|
162 |
/* e_ident[EI_OSABI] */ |
163 |
#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ |
164 |
#define ELFOSABI_HPUX 1 /* HP-UX operating system */ |
165 |
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ |
166 |
|
167 |
/* e_type */ |
168 |
#define ET_NONE 0 /* No file type */ |
169 |
#define ET_REL 1 /* Relocatable file */ |
170 |
#define ET_EXEC 2 /* Executable file */ |
171 |
#define ET_DYN 3 /* Shared object file */ |
172 |
#define ET_CORE 4 /* Core file */ |
173 |
#define ET_NUM 5 |
174 |
|
175 |
#define ET_LOOS 0xfe00 /* Operating system specific range */ |
176 |
#define ET_HIOS 0xfeff |
177 |
#define ET_LOPROC 0xff00 /* Processor-specific range */ |
178 |
#define ET_HIPROC 0xffff |
179 |
|
180 |
/* e_machine */ |
181 |
#define EM_NONE 0 /* No machine */ |
182 |
#define EM_M32 1 /* AT&T WE 32100 */ |
183 |
#define EM_SPARC 2 /* SPARC */ |
184 |
#define EM_386 3 /* Intel 80386 */ |
185 |
#define EM_68K 4 /* Motorola 68000 */ |
186 |
#define EM_88K 5 /* Motorola 88000 */ |
187 |
#define EM_486 6 /* Intel 80486 */ |
188 |
#define EM_860 7 /* Intel 80860 */ |
189 |
#define EM_MIPS 8 /* MIPS I Architecture */ |
190 |
#define EM_S370 9 /* Amdahl UTS on System/370 */ |
191 |
#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */ |
192 |
#define EM_RS6000 11 /* IBM RS/6000 XXX reserved */ |
193 |
#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */ |
194 |
#define EM_NCUBE 16 /* NCube XXX reserved */ |
195 |
#define EM_VPP500 17 /* Fujitsu VPP500 */ |
196 |
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ |
197 |
#define EM_960 19 /* Intel 80960 */ |
198 |
#define EM_PPC 20 /* PowerPC */ |
199 |
#define EM_PPC64 21 /* PowerPC 64-bit (GXemul addition) */ |
200 |
#define EM_V800 36 /* NEC V800 */ |
201 |
#define EM_FR20 37 /* Fujitsu FR20 */ |
202 |
#define EM_RH32 38 /* TRW RH-32 */ |
203 |
#define EM_RCE 39 /* Motorola RCE */ |
204 |
#define EM_ARM 40 /* Advanced RISC Machines ARM */ |
205 |
#define EM_ALPHA 41 /* DIGITAL Alpha */ |
206 |
#define EM_SH 42 /* Hitachi Super-H */ |
207 |
#define EM_SPARCV9 43 /* SPARC Version 9 */ |
208 |
#define EM_TRICORE 44 /* Siemens Tricore */ |
209 |
#define EM_ARC 45 /* Argonaut RISC Core */ |
210 |
#define EM_H8_300 46 /* Hitachi H8/300 */ |
211 |
#define EM_H8_300H 47 /* Hitachi H8/300H */ |
212 |
#define EM_H8S 48 /* Hitachi H8S */ |
213 |
#define EM_H8_500 49 /* Hitachi H8/500 */ |
214 |
#define EM_IA_64 50 /* Intel Merced Processor */ |
215 |
#define EM_MIPS_X 51 /* Stanford MIPS-X */ |
216 |
#define EM_COLDFIRE 52 /* Motorola Coldfire */ |
217 |
#define EM_68HC12 53 /* Motorola MC68HC12 */ |
218 |
#define EM_AMD64 62 /* AMD64 (GXemul addition) */ |
219 |
#define EM_VAX 75 /* DIGITAL VAX */ |
220 |
#define EM_AVR 83 /* Atmel AVR (GXemul addition) */ |
221 |
#define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */ |
222 |
#define EM_NUM 36903 |
223 |
|
224 |
/* |
225 |
* Program Header |
226 |
*/ |
227 |
typedef struct { |
228 |
Elf32_Word p_type; /* entry type */ |
229 |
Elf32_Off p_offset; /* offset */ |
230 |
Elf32_Addr p_vaddr; /* virtual address */ |
231 |
Elf32_Addr p_paddr; /* physical address */ |
232 |
Elf32_Word p_filesz; /* file size */ |
233 |
Elf32_Word p_memsz; /* memory size */ |
234 |
Elf32_Word p_flags; /* flags */ |
235 |
Elf32_Word p_align; /* memory & file alignment */ |
236 |
} Elf32_Phdr; |
237 |
|
238 |
typedef struct { |
239 |
Elf64_Half p_type; /* entry type */ |
240 |
Elf64_Half p_flags; /* flags */ |
241 |
Elf64_Off p_offset; /* offset */ |
242 |
Elf64_Addr p_vaddr; /* virtual address */ |
243 |
Elf64_Addr p_paddr; /* physical address */ |
244 |
Elf64_Xword p_filesz; /* file size */ |
245 |
Elf64_Xword p_memsz; /* memory size */ |
246 |
Elf64_Xword p_align; /* memory & file alignment */ |
247 |
} Elf64_Phdr; |
248 |
|
249 |
/* p_type */ |
250 |
#define PT_NULL 0 /* Program header table entry unused */ |
251 |
#define PT_LOAD 1 /* Loadable program segment */ |
252 |
#define PT_DYNAMIC 2 /* Dynamic linking information */ |
253 |
#define PT_INTERP 3 /* Program interpreter */ |
254 |
#define PT_NOTE 4 /* Auxiliary information */ |
255 |
#define PT_SHLIB 5 /* Reserved, unspecified semantics */ |
256 |
#define PT_PHDR 6 /* Entry for header table itself */ |
257 |
#define PT_NUM 7 |
258 |
|
259 |
/* p_flags */ |
260 |
#define PF_R 0x4 /* Segment is readable */ |
261 |
#define PF_W 0x2 /* Segment is writable */ |
262 |
#define PF_X 0x1 /* Segment is executable */ |
263 |
|
264 |
#define PF_MASKOS 0x0ff00000 /* Opersting system specific values */ |
265 |
#define PF_MASKPROC 0xf0000000 /* Processor-specific values */ |
266 |
|
267 |
#define PT_LOPROC 0x70000000 /* Processor-specific range */ |
268 |
#define PT_HIPROC 0x7fffffff |
269 |
|
270 |
#define PT_MIPS_REGINFO 0x70000000 |
271 |
|
272 |
/* |
273 |
* Section Headers |
274 |
*/ |
275 |
typedef struct { |
276 |
Elf32_Word sh_name; /* section name (.shstrtab index) */ |
277 |
Elf32_Word sh_type; /* section type */ |
278 |
Elf32_Word sh_flags; /* section flags */ |
279 |
Elf32_Addr sh_addr; /* virtual address */ |
280 |
Elf32_Off sh_offset; /* file offset */ |
281 |
Elf32_Word sh_size; /* section size */ |
282 |
Elf32_Word sh_link; /* link to another */ |
283 |
Elf32_Word sh_info; /* misc info */ |
284 |
Elf32_Word sh_addralign; /* memory alignment */ |
285 |
Elf32_Word sh_entsize; /* table entry size */ |
286 |
} Elf32_Shdr; |
287 |
|
288 |
typedef struct { |
289 |
Elf64_Half sh_name; /* section name (.shstrtab index) */ |
290 |
Elf64_Half sh_type; /* section type */ |
291 |
Elf64_Xword sh_flags; /* section flags */ |
292 |
Elf64_Addr sh_addr; /* virtual address */ |
293 |
Elf64_Off sh_offset; /* file offset */ |
294 |
Elf64_Xword sh_size; /* section size */ |
295 |
Elf64_Half sh_link; /* link to another */ |
296 |
Elf64_Half sh_info; /* misc info */ |
297 |
Elf64_Xword sh_addralign; /* memory alignment */ |
298 |
Elf64_Xword sh_entsize; /* table entry size */ |
299 |
} Elf64_Shdr; |
300 |
|
301 |
/* sh_type */ |
302 |
#define SHT_NULL 0 |
303 |
#define SHT_PROGBITS 1 |
304 |
#define SHT_SYMTAB 2 |
305 |
#define SHT_STRTAB 3 |
306 |
#define SHT_RELA 4 |
307 |
#define SHT_HASH 5 |
308 |
#define SHT_DYNAMIC 6 |
309 |
#define SHT_NOTE 7 |
310 |
#define SHT_NOBITS 8 |
311 |
#define SHT_REL 9 |
312 |
#define SHT_SHLIB 10 |
313 |
#define SHT_DYNSYM 11 |
314 |
#define SHT_NUM 12 |
315 |
|
316 |
#define SHT_LOOS 0x60000000 /* Operating system specific range */ |
317 |
#define SHT_HIOS 0x6fffffff |
318 |
#define SHT_LOPROC 0x70000000 /* Processor-specific range */ |
319 |
#define SHT_HIPROC 0x7fffffff |
320 |
#define SHT_LOUSER 0x80000000 /* Application-specific range */ |
321 |
#define SHT_HIUSER 0xffffffff |
322 |
|
323 |
/* sh_flags */ |
324 |
#define SHF_WRITE 0x1 /* Section contains writable data */ |
325 |
#define SHF_ALLOC 0x2 /* Section occupies memory */ |
326 |
#define SHF_EXECINSTR 0x4 /* Section contains executable insns */ |
327 |
|
328 |
#define SHF_MASKOS 0x0f000000 /* Operating system specific values */ |
329 |
#define SHF_MASKPROC 0xf0000000 /* Processor-specific values */ |
330 |
|
331 |
/* |
332 |
* Symbol Table |
333 |
*/ |
334 |
typedef struct { |
335 |
Elf32_Word st_name; /* Symbol name (.symtab index) */ |
336 |
Elf32_Word st_value; /* value of symbol */ |
337 |
Elf32_Word st_size; /* size of symbol */ |
338 |
Elf_Byte st_info; /* type / binding attrs */ |
339 |
Elf_Byte st_other; /* unused */ |
340 |
Elf32_Half st_shndx; /* section index of symbol */ |
341 |
} Elf32_Sym; |
342 |
|
343 |
typedef struct { |
344 |
Elf64_Half st_name; /* Symbol name (.symtab index) */ |
345 |
Elf_Byte st_info; /* type / binding attrs */ |
346 |
Elf_Byte st_other; /* unused */ |
347 |
Elf64_Quarter st_shndx; /* section index of symbol */ |
348 |
Elf64_Addr st_value; /* value of symbol */ |
349 |
Elf64_Xword st_size; /* size of symbol */ |
350 |
} Elf64_Sym; |
351 |
|
352 |
/* Symbol Table index of the undefined symbol */ |
353 |
#define ELF_SYM_UNDEFINED 0 |
354 |
|
355 |
/* st_info: Symbol Bindings */ |
356 |
#define STB_LOCAL 0 /* local symbol */ |
357 |
#define STB_GLOBAL 1 /* global symbol */ |
358 |
#define STB_WEAK 2 /* weakly defined global symbol */ |
359 |
#define STB_NUM 3 |
360 |
|
361 |
#define STB_LOOS 10 /* Operating system specific range */ |
362 |
#define STB_HIOS 12 |
363 |
#define STB_LOPROC 13 /* Processor-specific range */ |
364 |
#define STB_HIPROC 15 |
365 |
|
366 |
/* st_info: Symbol Types */ |
367 |
#define STT_NOTYPE 0 /* Type not specified */ |
368 |
#define STT_OBJECT 1 /* Associated with a data object */ |
369 |
#define STT_FUNC 2 /* Associated with a function */ |
370 |
#define STT_SECTION 3 /* Associated with a section */ |
371 |
#define STT_FILE 4 /* Associated with a file name */ |
372 |
#define STT_NUM 5 |
373 |
|
374 |
#define STT_LOOS 10 /* Operating system specific range */ |
375 |
#define STT_HIOS 12 |
376 |
#define STT_LOPROC 13 /* Processor-specific range */ |
377 |
#define STT_HIPROC 15 |
378 |
|
379 |
/* st_info utility macros */ |
380 |
#define ELF32_ST_BIND(info) ((Elf32_Word)(info) >> 4) |
381 |
#define ELF32_ST_TYPE(info) ((Elf32_Word)(info) & 0xf) |
382 |
#define ELF32_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | ((type) & 0xf))) |
383 |
|
384 |
#define ELF64_ST_BIND(info) ((Elf64_Xword)(info) >> 4) |
385 |
#define ELF64_ST_TYPE(info) ((Elf64_Xword)(info) & 0xf) |
386 |
#define ELF64_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | ((type) & 0xf))) |
387 |
|
388 |
/* |
389 |
* Special section indexes |
390 |
*/ |
391 |
#define SHN_UNDEF 0 /* Undefined section */ |
392 |
|
393 |
#define SHN_LORESERVE 0xff00 /* Reserved range */ |
394 |
#define SHN_ABS 0xfff1 /* Absolute symbols */ |
395 |
#define SHN_COMMON 0xfff2 /* Common symbols */ |
396 |
#define SHN_HIRESERVE 0xffff |
397 |
|
398 |
#define SHN_LOPROC 0xff00 /* Processor-specific range */ |
399 |
#define SHN_HIPROC 0xff1f |
400 |
#define SHN_LOOS 0xff20 /* Operating system specific range */ |
401 |
#define SHN_HIOS 0xff3f |
402 |
|
403 |
#define SHN_MIPS_ACOMMON 0xff00 |
404 |
#define SHN_MIPS_TEXT 0xff01 |
405 |
#define SHN_MIPS_DATA 0xff02 |
406 |
#define SHN_MIPS_SCOMMON 0xff03 |
407 |
|
408 |
/* |
409 |
* Relocation Entries |
410 |
*/ |
411 |
typedef struct { |
412 |
Elf32_Word r_offset; /* where to do it */ |
413 |
Elf32_Word r_info; /* index & type of relocation */ |
414 |
} Elf32_Rel; |
415 |
|
416 |
typedef struct { |
417 |
Elf32_Word r_offset; /* where to do it */ |
418 |
Elf32_Word r_info; /* index & type of relocation */ |
419 |
Elf32_Sword r_addend; /* adjustment value */ |
420 |
} Elf32_Rela; |
421 |
|
422 |
/* r_info utility macros */ |
423 |
#define ELF32_R_SYM(info) ((info) >> 8) |
424 |
#define ELF32_R_TYPE(info) ((info) & 0xff) |
425 |
#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) |
426 |
|
427 |
typedef struct { |
428 |
Elf64_Addr r_offset; /* where to do it */ |
429 |
Elf64_Xword r_info; /* index & type of relocation */ |
430 |
} Elf64_Rel; |
431 |
|
432 |
typedef struct { |
433 |
Elf64_Addr r_offset; /* where to do it */ |
434 |
Elf64_Xword r_info; /* index & type of relocation */ |
435 |
Elf64_Sxword r_addend; /* adjustment value */ |
436 |
} Elf64_Rela; |
437 |
|
438 |
/* r_info utility macros */ |
439 |
#define ELF64_R_SYM(info) ((info) >> 32) |
440 |
#define ELF64_R_TYPE(info) ((info) & 0xffffffff) |
441 |
#define ELF64_R_INFO(sym,type) (((sym) << 32) + (type)) |
442 |
|
443 |
/* |
444 |
* Dynamic Section structure array |
445 |
*/ |
446 |
typedef struct { |
447 |
Elf32_Word d_tag; /* entry tag value */ |
448 |
union { |
449 |
Elf32_Addr d_ptr; |
450 |
Elf32_Word d_val; |
451 |
} d_un; |
452 |
} Elf32_Dyn; |
453 |
|
454 |
typedef struct { |
455 |
Elf64_Xword d_tag; /* entry tag value */ |
456 |
union { |
457 |
Elf64_Addr d_ptr; |
458 |
Elf64_Xword d_val; |
459 |
} d_un; |
460 |
} Elf64_Dyn; |
461 |
|
462 |
/* d_tag */ |
463 |
#define DT_NULL 0 /* Marks end of dynamic array */ |
464 |
#define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */ |
465 |
#define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */ |
466 |
#define DT_PLTGOT 3 /* Address of PLT and/or GOT */ |
467 |
#define DT_HASH 4 /* Address of symbol hash table */ |
468 |
#define DT_STRTAB 5 /* Address of string table */ |
469 |
#define DT_SYMTAB 6 /* Address of symbol table */ |
470 |
#define DT_RELA 7 /* Address of Rela relocation table */ |
471 |
#define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */ |
472 |
#define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */ |
473 |
#define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */ |
474 |
#define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */ |
475 |
#define DT_INIT 12 /* Address of initialization function */ |
476 |
#define DT_FINI 13 /* Address of termination function */ |
477 |
#define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */ |
478 |
#define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */ |
479 |
#define DT_SYMBOLIC 16 /* Start symbol search within local object */ |
480 |
#define DT_REL 17 /* Address of Rel relocation table */ |
481 |
#define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */ |
482 |
#define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */ |
483 |
#define DT_PLTREL 20 /* Type of PLT relocation entries */ |
484 |
#define DT_DEBUG 21 /* Used for debugging; unspecified */ |
485 |
#define DT_TEXTREL 22 /* Relocations might modify non-writable seg */ |
486 |
#define DT_JMPREL 23 /* Address of relocations associated with PLT */ |
487 |
#define DT_BIND_NOW 24 /* Process all relocations at load-time */ |
488 |
#define DT_INIT_ARRAY 25 /* Address of initialization function array */ |
489 |
#define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */ |
490 |
#define DT_INIT_ARRAYSZ 27 /* Address of termination function array */ |
491 |
#define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/ |
492 |
#define DT_NUM 29 |
493 |
|
494 |
#define DT_LOOS 0x60000000 /* Operating system specific range */ |
495 |
#define DT_HIOS 0x6fffffff |
496 |
#define DT_LOPROC 0x70000000 /* Processor-specific range */ |
497 |
#define DT_HIPROC 0x7fffffff |
498 |
|
499 |
/* |
500 |
* Auxiliary Vectors |
501 |
*/ |
502 |
typedef struct { |
503 |
Elf32_Word a_type; /* 32-bit id */ |
504 |
Elf32_Word a_v; /* 32-bit id */ |
505 |
} Aux32Info; |
506 |
|
507 |
typedef struct { |
508 |
Elf64_Half a_type; /* 32-bit id */ |
509 |
Elf64_Xword a_v; /* 64-bit id */ |
510 |
} Aux64Info; |
511 |
|
512 |
/* a_type */ |
513 |
#define AT_NULL 0 /* Marks end of array */ |
514 |
#define AT_IGNORE 1 /* No meaning, a_un is undefined */ |
515 |
#define AT_EXECFD 2 /* Open file descriptor of object file */ |
516 |
#define AT_PHDR 3 /* &phdr[0] */ |
517 |
#define AT_PHENT 4 /* sizeof(phdr[0]) */ |
518 |
#define AT_PHNUM 5 /* # phdr entries */ |
519 |
#define AT_PAGESZ 6 /* PAGESIZE */ |
520 |
#define AT_BASE 7 /* Interpreter base addr */ |
521 |
#define AT_FLAGS 8 /* Processor flags */ |
522 |
#define AT_ENTRY 9 /* Entry address of executable */ |
523 |
#define AT_DCACHEBSIZE 10 /* Data cache block size */ |
524 |
#define AT_ICACHEBSIZE 11 /* Instruction cache block size */ |
525 |
#define AT_UCACHEBSIZE 12 /* Unified cache block size */ |
526 |
|
527 |
/* Vendor specific */ |
528 |
#define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */ |
529 |
|
530 |
#define AT_SUN_UID 2000 /* euid */ |
531 |
#define AT_SUN_RUID 2001 /* ruid */ |
532 |
#define AT_SUN_GID 2002 /* egid */ |
533 |
#define AT_SUN_RGID 2003 /* rgid */ |
534 |
|
535 |
/* Solaris kernel specific */ |
536 |
#define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */ |
537 |
#define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */ |
538 |
#define AT_SUN_LDNAME 2006 /* dynamic linker's name */ |
539 |
#define AT_SUN_LPGSIZE 2007 /* large pagesize */ |
540 |
|
541 |
/* Other information */ |
542 |
#define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */ |
543 |
#define AT_SUN_HWCAP 2009 /* process hardware capabilities */ |
544 |
#define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */ |
545 |
#define AT_SUN_CPU 2011 /* cpu name */ |
546 |
/* ibcs2 emulation band aid */ |
547 |
#define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */ |
548 |
#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */ |
549 |
/* Executable's fully resolved name */ |
550 |
#define AT_SUN_EXECNAME 2014 |
551 |
|
552 |
/* |
553 |
* Note Headers |
554 |
*/ |
555 |
typedef struct { |
556 |
Elf32_Word n_namesz; |
557 |
Elf32_Word n_descsz; |
558 |
Elf32_Word n_type; |
559 |
} Elf32_Nhdr; |
560 |
|
561 |
typedef struct { |
562 |
Elf64_Half n_namesz; |
563 |
Elf64_Half n_descsz; |
564 |
Elf64_Half n_type; |
565 |
} Elf64_Nhdr; |
566 |
|
567 |
#define ELF_NOTE_TYPE_OSVERSION 1 |
568 |
|
569 |
/* NetBSD-specific note type: OS Version. desc is 4-byte NetBSD integer. */ |
570 |
#define ELF_NOTE_NETBSD_TYPE_OSVERSION ELF_NOTE_TYPE_OSVERSION |
571 |
|
572 |
/* NetBSD-specific note type: Emulation name. desc is emul name string. */ |
573 |
#define ELF_NOTE_NETBSD_TYPE_EMULNAME 2 |
574 |
|
575 |
/* NetBSD-specific note name and description sizes */ |
576 |
#define ELF_NOTE_NETBSD_NAMESZ 7 |
577 |
#define ELF_NOTE_NETBSD_DESCSZ 4 |
578 |
/* NetBSD-specific note name */ |
579 |
#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0" |
580 |
|
581 |
/* GNU-specific note name and description sizes */ |
582 |
#define ELF_NOTE_GNU_NAMESZ 4 |
583 |
#define ELF_NOTE_GNU_DESCSZ 4 |
584 |
/* GNU-specific note name */ |
585 |
#define ELF_NOTE_GNU_NAME "GNU\0" |
586 |
|
587 |
/* GNU-specific OS/version value stuff */ |
588 |
#define ELF_NOTE_GNU_OSMASK (u_int32_t)0xff000000 |
589 |
#define ELF_NOTE_GNU_OSLINUX (u_int32_t)0x01000000 |
590 |
#define ELF_NOTE_GNU_OSMACH (u_int32_t)0x00000000 |
591 |
|
592 |
#if defined(ELFSIZE) |
593 |
#define CONCAT(x,y) __CONCAT(x,y) |
594 |
#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) |
595 |
#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) |
596 |
#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) |
597 |
#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) |
598 |
#endif |
599 |
|
600 |
/* #include <machine/elf_machdep.h> */ |
601 |
|
602 |
#if defined(ELFSIZE) && (ELFSIZE == 32) |
603 |
#define Elf_Ehdr Elf32_Ehdr |
604 |
#define Elf_Phdr Elf32_Phdr |
605 |
#define Elf_Shdr Elf32_Shdr |
606 |
#define Elf_Sym Elf32_Sym |
607 |
#define Elf_Rel Elf32_Rel |
608 |
#define Elf_Rela Elf32_Rela |
609 |
#define Elf_Dyn Elf32_Dyn |
610 |
#define Elf_Word Elf32_Word |
611 |
#define Elf_Sword Elf32_Sword |
612 |
#define Elf_Addr Elf32_Addr |
613 |
#define Elf_Off Elf32_Off |
614 |
#define Elf_Nhdr Elf32_Nhdr |
615 |
|
616 |
#define ELF_R_SYM ELF32_R_SYM |
617 |
#define ELF_R_TYPE ELF32_R_TYPE |
618 |
#define ELFCLASS ELFCLASS32 |
619 |
|
620 |
#define ELF_ST_BIND ELF32_ST_BIND |
621 |
#define ELF_ST_TYPE ELF32_ST_TYPE |
622 |
#define ELF_ST_INFO ELF32_ST_INFO |
623 |
|
624 |
#define AuxInfo Aux32Info |
625 |
#elif defined(ELFSIZE) && (ELFSIZE == 64) |
626 |
#define Elf_Ehdr Elf64_Ehdr |
627 |
#define Elf_Phdr Elf64_Phdr |
628 |
#define Elf_Shdr Elf64_Shdr |
629 |
#define Elf_Sym Elf64_Sym |
630 |
#define Elf_Rel Elf64_Rel |
631 |
#define Elf_Rela Elf64_Rela |
632 |
#define Elf_Dyn Elf64_Dyn |
633 |
#define Elf_Word Elf64_Word |
634 |
#define Elf_Sword Elf64_Sword |
635 |
#define Elf_Addr Elf64_Addr |
636 |
#define Elf_Off Elf64_Off |
637 |
#define Elf_Nhdr Elf64_Nhdr |
638 |
|
639 |
#define ELF_R_SYM ELF64_R_SYM |
640 |
#define ELF_R_TYPE ELF64_R_TYPE |
641 |
#define ELFCLASS ELFCLASS64 |
642 |
|
643 |
#define ELF_ST_BIND ELF64_ST_BIND |
644 |
#define ELF_ST_TYPE ELF64_ST_TYPE |
645 |
#define ELF_ST_INFO ELF64_ST_INFO |
646 |
|
647 |
#define AuxInfo Aux64Info |
648 |
#endif |
649 |
|
650 |
#ifdef _KERNEL |
651 |
|
652 |
#define ELF_AUX_ENTRIES 8 /* Size of aux array passed to loader */ |
653 |
#define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */ |
654 |
#define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */ |
655 |
|
656 |
#if defined(ELFSIZE) && (ELFSIZE == 64) |
657 |
#define ELF_NO_ADDR ELF64_NO_ADDR |
658 |
#elif defined(ELFSIZE) && (ELFSIZE == 32) |
659 |
#define ELF_NO_ADDR ELF32_NO_ADDR |
660 |
#endif |
661 |
|
662 |
#if defined(ELFSIZE) |
663 |
struct elf_args { |
664 |
Elf_Addr arg_entry; /* program entry point */ |
665 |
Elf_Addr arg_interp; /* Interpreter load address */ |
666 |
Elf_Addr arg_phaddr; /* program header address */ |
667 |
Elf_Addr arg_phentsize; /* Size of program header */ |
668 |
Elf_Addr arg_phnum; /* Number of program headers */ |
669 |
}; |
670 |
#endif |
671 |
|
672 |
#ifndef _LKM |
673 |
#include "opt_execfmt.h" |
674 |
#endif |
675 |
|
676 |
#ifdef EXEC_ELF32 |
677 |
int exec_elf32_makecmds __P((struct proc *, struct exec_package *)); |
678 |
int elf32_read_from __P((struct proc *, struct vnode *, u_long, |
679 |
caddr_t, int)); |
680 |
void *elf32_copyargs __P((struct exec_package *, struct ps_strings *, |
681 |
void *, void *)); |
682 |
#endif |
683 |
|
684 |
#ifdef EXEC_ELF64 |
685 |
int exec_elf64_makecmds __P((struct proc *, struct exec_package *)); |
686 |
int elf64_read_from __P((struct proc *, struct vnode *, u_long, |
687 |
caddr_t, int)); |
688 |
void *elf64_copyargs __P((struct exec_package *, struct ps_strings *, |
689 |
void *, void *)); |
690 |
#endif |
691 |
|
692 |
/* common */ |
693 |
int exec_elf_setup_stack __P((struct proc *, struct exec_package *)); |
694 |
|
695 |
#endif /* _KERNEL */ |
696 |
|
697 |
#endif /* __EXEC_ELF_H */ |
698 |
|