Annotation of prex-old/include/sys/elf.h, Revision 1.1.1.1
1.1 nbrk 1: /*-
2: * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved.
3: *
4: * Redistribution and use in source and binary forms, with or without
5: * modification, are permitted provided that the following conditions
6: * are met:
7: * 1. Redistributions of source code must retain the above copyright
8: * notice, this list of conditions and the following disclaimer.
9: * 2. Redistributions in binary form must reproduce the above copyright
10: * notice, this list of conditions and the following disclaimer in the
11: * documentation and/or other materials provided with the distribution.
12: * 3. The name of the author may not be used to endorse or promote products
13: * derived from this software without specific prior written permission
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
27: /*
28: * This is the ELF ABI header file
29: * formerly known as "elf_abi.h".
30: */
31:
32: #ifndef _SYS_ELF_H
33: #define _SYS_ELF_H
34:
35: #include <machine/types.h>
36:
37: #include <machine/elf.h>
38:
39: typedef uint8_t Elf_Byte;
40:
41: typedef uint32_t Elf32_Addr; /* Unsigned program address */
42: typedef uint32_t Elf32_Off; /* Unsigned file offset */
43: typedef int32_t Elf32_Sword; /* Signed large integer */
44: typedef uint32_t Elf32_Word; /* Unsigned large integer */
45: typedef uint16_t Elf32_Half; /* Unsigned medium integer */
46:
47: /* e_ident[] identification indexes */
48: #define EI_MAG0 0 /* file ID */
49: #define EI_MAG1 1 /* file ID */
50: #define EI_MAG2 2 /* file ID */
51: #define EI_MAG3 3 /* file ID */
52: #define EI_CLASS 4 /* file class */
53: #define EI_DATA 5 /* data encoding */
54: #define EI_VERSION 6 /* ELF header version */
55: #define EI_OSABI 7 /* Operating system / ABI identification */
56: #define EI_ABIVERSION 8 /* ABI version */
57: #define OLD_EI_BRAND 8 /* Start of architecture identification. */
58: #define EI_PAD 9 /* Start of padding (per SVR4 ABI). */
59: #define EI_NIDENT 16 /* Size of e_ident[] */
60:
61: /* e_ident[] magic number */
62: #define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
63: #define ELFMAG1 'E' /* e_ident[EI_MAG1] */
64: #define ELFMAG2 'L' /* e_ident[EI_MAG2] */
65: #define ELFMAG3 'F' /* e_ident[EI_MAG3] */
66: #define ELFMAG "\177ELF" /* magic */
67: #define SELFMAG 4 /* size of magic */
68:
69: /* e_ident[] file class */
70: #define ELFCLASSNONE 0 /* invalid */
71: #define ELFCLASS32 1 /* 32-bit objs */
72: #define ELFCLASS64 2 /* 64-bit objs */
73: #define ELFCLASSNUM 3 /* number of classes */
74:
75: /* e_ident[] data encoding */
76: #define ELFDATANONE 0 /* invalid */
77: #define ELFDATA2LSB 1 /* Little-Endian */
78: #define ELFDATA2MSB 2 /* Big-Endian */
79: #define ELFDATANUM 3 /* number of data encode defines */
80:
81: /* e_ident[] OS ABI */
82: #define ELFOSABI_SYSV 0 /* UNIX System V ABI */
83: #define ELFOSABI_NONE ELFOSABI_SYSV /* symbol used in old spec */
84: #define ELFOSABI_HPUX 1 /* HP-UX operating system */
85: #define ELFOSABI_NETBSD 2 /* NetBSD */
86: #define ELFOSABI_LINUX 3 /* GNU/Linux */
87: #define ELFOSABI_HURD 4 /* GNU/Hurd */
88: #define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */
89: #define ELFOSABI_SOLARIS 6 /* Solaris */
90: #define ELFOSABI_MONTEREY 7 /* Monterey */
91: #define ELFOSABI_IRIX 8 /* IRIX */
92: #define ELFOSABI_FREEBSD 9 /* FreeBSD */
93: #define ELFOSABI_TRU64 10 /* TRU64 UNIX */
94: #define ELFOSABI_MODESTO 11 /* Novell Modesto */
95: #define ELFOSABI_OPENBSD 12 /* OpenBSD */
96: #define ELFOSABI_ARM 97 /* ARM */
97: #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
98:
99: /* e_ident */
100: #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
101: (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
102: (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
103: (ehdr).e_ident[EI_MAG3] == ELFMAG3)
104:
105: /* ELF Header */
106: typedef struct elfhdr{
107: unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
108: Elf32_Half e_type; /* object file type */
109: Elf32_Half e_machine; /* machine */
110: Elf32_Word e_version; /* object file version */
111: Elf32_Addr e_entry; /* virtual entry point */
112: Elf32_Off e_phoff; /* program header table offset */
113: Elf32_Off e_shoff; /* section header table offset */
114: Elf32_Word e_flags; /* processor-specific flags */
115: Elf32_Half e_ehsize; /* ELF header size */
116: Elf32_Half e_phentsize; /* program header entry size */
117: Elf32_Half e_phnum; /* number of program header entries */
118: Elf32_Half e_shentsize; /* section header entry size */
119: Elf32_Half e_shnum; /* number of section header entries */
120: Elf32_Half e_shstrndx; /* section header table's "section
121: header string table" entry offset */
122: } Elf32_Ehdr;
123:
124: /* e_type */
125: #define ET_NONE 0 /* No file type */
126: #define ET_REL 1 /* relocatable file */
127: #define ET_EXEC 2 /* executable file */
128: #define ET_DYN 3 /* shared object file */
129: #define ET_CORE 4 /* core file */
130: #define ET_NUM 5 /* number of types */
131: #define ET_LOPROC 0xff00 /* reserved range for processor */
132: #define ET_HIPROC 0xffff /* specific e_type */
133:
134: /* e_machine */
135: #define EM_NONE 0 /* No Machine */
136: #define EM_M32 1 /* AT&T WE 32100 */
137: #define EM_SPARC 2 /* SPARC */
138: #define EM_386 3 /* Intel 80386 */
139: #define EM_68K 4 /* Motorola 68000 */
140: #define EM_88K 5 /* Motorola 88000 */
141: #define EM_486 6 /* Intel 80486 - unused? */
142: #define EM_860 7 /* Intel 80860 */
143: #define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
144: /*
145: * Don't know if EM_MIPS_RS4_BE,
146: * EM_SPARC64, EM_PARISC,
147: * or EM_PPC are ABI compliant
148: */
149: #define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
150: #define EM_SPARC64 11 /* SPARC v9 64-bit unoffical */
151: #define EM_PARISC 15 /* HPPA */
152: #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
153: #define EM_PPC 20 /* PowerPC */
154: #define EM_ARM 40
155: #define EM_ALPHA 41 /* DEC ALPHA */
156: #define EM_SPARCV9 43 /* SPARC version 9 */
157: #define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */
158: #define EM_VAX 75 /* DEC VAX */
159: #define EM_NUM 15 /* number of machine types */
160:
161: /* Version */
162: #define EV_NONE 0 /* Invalid */
163: #define EV_CURRENT 1 /* Current */
164: #define EV_NUM 2 /* number of versions */
165:
166: /* Section Header */
167: typedef struct {
168: Elf32_Word sh_name; /* name - index into section header
169: string table section */
170: Elf32_Word sh_type; /* type */
171: Elf32_Word sh_flags; /* flags */
172: Elf32_Addr sh_addr; /* address */
173: Elf32_Off sh_offset; /* file offset */
174: Elf32_Word sh_size; /* section size */
175: Elf32_Word sh_link; /* section header table index link */
176: Elf32_Word sh_info; /* extra information */
177: Elf32_Word sh_addralign; /* address alignment */
178: Elf32_Word sh_entsize; /* section entry size */
179: } Elf32_Shdr;
180:
181: /* Special Section Indexes */
182: #define SHN_UNDEF 0 /* undefined */
183: #define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
184: #define SHN_LOPROC 0xff00 /* reserved range for processor */
185: #define SHN_HIPROC 0xff1f /* specific section indexes */
186: #define SHN_ABS 0xfff1 /* absolute value */
187: #define SHN_COMMON 0xfff2 /* common symbol */
188: #define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
189:
190: /* sh_type */
191: #define SHT_NULL 0 /* inactive */
192: #define SHT_PROGBITS 1 /* program defined information */
193: #define SHT_SYMTAB 2 /* symbol table section */
194: #define SHT_STRTAB 3 /* string table section */
195: #define SHT_RELA 4 /* relocation section with addends*/
196: #define SHT_HASH 5 /* symbol hash table section */
197: #define SHT_DYNAMIC 6 /* dynamic section */
198: #define SHT_NOTE 7 /* note section */
199: #define SHT_NOBITS 8 /* no space section */
200: #define SHT_REL 9 /* relation section without addends */
201: #define SHT_SHLIB 10 /* reserved - purpose unknown */
202: #define SHT_DYNSYM 11 /* dynamic symbol table section */
203: #define SHT_NUM 12 /* number of section types */
204: #define SHT_LOPROC 0x70000000 /* reserved range for processor */
205: #define SHT_HIPROC 0x7fffffff /* specific section header types */
206: #define SHT_LOUSER 0x80000000 /* reserved range for application */
207: #define SHT_HIUSER 0xffffffff /* specific indexes */
208:
209: /* Section names */
210: #define ELF_BSS ".bss" /* uninitialized data */
211: #define ELF_DATA ".data" /* initialized data */
212: #define ELF_DEBUG ".debug" /* debug */
213: #define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
214: #define ELF_DYNSTR ".dynstr" /* dynamic string table */
215: #define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
216: #define ELF_FINI ".fini" /* termination code */
217: #define ELF_GOT ".got" /* global offset table */
218: #define ELF_HASH ".hash" /* symbol hash table */
219: #define ELF_INIT ".init" /* initialization code */
220: #define ELF_REL_DATA ".rel.data" /* relocation data */
221: #define ELF_REL_FINI ".rel.fini" /* relocation termination code */
222: #define ELF_REL_INIT ".rel.init" /* relocation initialization code */
223: #define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
224: #define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
225: #define ELF_REL_TEXT ".rel.text" /* relocation code */
226: #define ELF_RODATA ".rodata" /* read-only data */
227: #define ELF_SHSTRTAB ".shstrtab" /* section header string table */
228: #define ELF_STRTAB ".strtab" /* string table */
229: #define ELF_SYMTAB ".symtab" /* symbol table */
230: #define ELF_TEXT ".text" /* code */
231:
232:
233: /* Section Attribute Flags - sh_flags */
234: #define SHF_WRITE 0x1 /* Writable */
235: #define SHF_ALLOC 0x2 /* occupies memory */
236: #define SHF_EXECINSTR 0x4 /* executable */
237: #define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
238: /* specific section attributes */
239:
240: /* Symbol Table Entry */
241: typedef struct elf32_sym {
242: Elf32_Word st_name; /* name - index into string table */
243: Elf32_Addr st_value; /* symbol value */
244: Elf32_Word st_size; /* symbol size */
245: unsigned char st_info; /* type and binding */
246: unsigned char st_other; /* 0 - no defined meaning */
247: Elf32_Half st_shndx; /* section header index */
248: } Elf32_Sym;
249:
250: /* Symbol table index */
251: #define STN_UNDEF 0 /* undefined */
252:
253: /* Extract symbol info - st_info */
254: #define ELF32_ST_BIND(x) ((x) >> 4)
255: #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
256: #define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
257:
258: /* Symbol Binding - ELF32_ST_BIND - st_info */
259: #define STB_LOCAL 0 /* Local symbol */
260: #define STB_GLOBAL 1 /* Global symbol */
261: #define STB_WEAK 2 /* like global - lower precedence */
262: #define STB_NUM 3 /* number of symbol bindings */
263: #define STB_LOPROC 13 /* reserved range for processor */
264: #define STB_HIPROC 15 /* specific symbol bindings */
265:
266: /* Symbol type - ELF32_ST_TYPE - st_info */
267: #define STT_NOTYPE 0 /* not specified */
268: #define STT_OBJECT 1 /* data object */
269: #define STT_FUNC 2 /* function */
270: #define STT_SECTION 3 /* section */
271: #define STT_FILE 4 /* file */
272: #define STT_NUM 5 /* number of symbol types */
273: #define STT_LOPROC 13 /* reserved range for processor */
274: #define STT_HIPROC 15 /* specific symbol types */
275:
276: /* Relocation entry with implicit addend */
277: typedef struct
278: {
279: Elf32_Addr r_offset; /* offset of relocation */
280: Elf32_Word r_info; /* symbol table index and type */
281: } Elf32_Rel;
282:
283: /* Relocation entry with explicit addend */
284: typedef struct
285: {
286: Elf32_Addr r_offset; /* offset of relocation */
287: Elf32_Word r_info; /* symbol table index and type */
288: Elf32_Sword r_addend;
289: } Elf32_Rela;
290:
291: /* Extract relocation info - r_info */
292: #define ELF32_R_SYM(i) ((i) >> 8)
293: #define ELF32_R_TYPE(i) ((unsigned char) (i))
294: #define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
295:
296: /* Program Header */
297: typedef struct {
298: Elf32_Word p_type; /* segment type */
299: Elf32_Off p_offset; /* segment offset */
300: Elf32_Addr p_vaddr; /* virtual address of segment */
301: Elf32_Addr p_paddr; /* physical address - ignored? */
302: Elf32_Word p_filesz; /* number of bytes in file for seg. */
303: Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
304: Elf32_Word p_flags; /* flags */
305: Elf32_Word p_align; /* memory alignment */
306: } Elf32_Phdr;
307:
308: /* Segment types - p_type */
309: #define PT_NULL 0 /* unused */
310: #define PT_LOAD 1 /* loadable segment */
311: #define PT_DYNAMIC 2 /* dynamic linking section */
312: #define PT_INTERP 3 /* the RTLD */
313: #define PT_NOTE 4 /* auxiliary information */
314: #define PT_SHLIB 5 /* reserved - purpose undefined */
315: #define PT_PHDR 6 /* program header */
316: #define PT_NUM 7 /* Number of segment types */
317: #define PT_LOPROC 0x70000000 /* reserved range for processor */
318: #define PT_HIPROC 0x7fffffff /* specific segment types */
319:
320: /* Segment flags - p_flags */
321: #define PF_X 0x1 /* Executable */
322: #define PF_W 0x2 /* Writable */
323: #define PF_R 0x4 /* Readable */
324: #define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
325: /* specific segment flags */
326:
327: /* Dynamic structure */
328: typedef struct {
329: Elf32_Sword d_tag; /* controls meaning of d_val */
330: union {
331: Elf32_Word d_val; /* Multiple meanings - see d_tag */
332: Elf32_Addr d_ptr; /* program virtual address */
333: } d_un;
334: } Elf32_Dyn;
335:
336: /* Dynamic Array Tags - d_tag */
337: #define DT_NULL 0 /* marks end of _DYNAMIC array */
338: #define DT_NEEDED 1 /* string table offset of needed lib */
339: #define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
340: #define DT_PLTGOT 3 /* address PLT/GOT */
341: #define DT_HASH 4 /* address of symbol hash table */
342: #define DT_STRTAB 5 /* address of string table */
343: #define DT_SYMTAB 6 /* address of symbol table */
344: #define DT_RELA 7 /* address of relocation table */
345: #define DT_RELASZ 8 /* size of relocation table */
346: #define DT_RELAENT 9 /* size of relocation entry */
347: #define DT_STRSZ 10 /* size of string table */
348: #define DT_SYMENT 11 /* size of symbol table entry */
349: #define DT_INIT 12 /* address of initialization func. */
350: #define DT_FINI 13 /* address of termination function */
351: #define DT_SONAME 14 /* string table offset of shared obj */
352: #define DT_RPATH 15 /* string table offset of library
353: search path */
354: #define DT_SYMBOLIC 16 /* start sym search in shared obj. */
355: #define DT_REL 17 /* address of rel. tbl. w addends */
356: #define DT_RELSZ 18 /* size of DT_REL relocation table */
357: #define DT_RELENT 19 /* size of DT_REL relocation entry */
358: #define DT_PLTREL 20 /* PLT referenced relocation entry */
359: #define DT_DEBUG 21 /* bugger */
360: #define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
361: #define DT_JMPREL 23 /* add. of PLT's relocation entries */
362: #define DT_BIND_NOW 24 /* Bind now regardless of env setting */
363: #define DT_NUM 25 /* Number used. */
364: #define DT_LOPROC 0x70000000 /* reserved range for processor */
365: #define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
366:
367: /* Standard ELF hashing function */
368: unsigned int elf_hash(const unsigned char *name);
369:
370: /*
371: * Note Definitions
372: */
373: typedef struct {
374: Elf32_Word namesz;
375: Elf32_Word descsz;
376: Elf32_Word type;
377: } Elf32_Note;
378:
379: /*
380: * XXX - these _KERNEL items aren't part of the ABI!
381: */
382: #if defined(_KERNEL) || defined(_DYN_LOADER)
383:
384: #define ELF32_NO_ADDR ((u_long) ~0) /* Indicates addr. not yet filled in */
385: #define ELF_AUX_ENTRIES 8 /* Size of aux array passed to loader */
386:
387: typedef struct {
388: Elf32_Sword au_id; /* 32-bit id */
389: Elf32_Word au_v; /* 32-bit value */
390: } Aux32Info;
391:
392: enum AuxID {
393: AUX_null = 0,
394: AUX_ignore = 1,
395: AUX_execfd = 2,
396: AUX_phdr = 3, /* &phdr[0] */
397: AUX_phent = 4, /* sizeof(phdr[0]) */
398: AUX_phnum = 5, /* # phdr entries */
399: AUX_pagesz = 6, /* PAGESIZE */
400: AUX_base = 7, /* ld.so base addr */
401: AUX_flags = 8, /* processor flags */
402: AUX_entry = 9, /* a.out entry */
403: AUX_sun_uid = 2000, /* euid */
404: AUX_sun_ruid = 2001, /* ruid */
405: AUX_sun_gid = 2002, /* egid */
406: AUX_sun_rgid = 2003 /* rgid */
407: };
408:
409: struct elf_args {
410: u_long arg_entry; /* program entry point */
411: u_long arg_interp; /* Interpreter load address */
412: u_long arg_phaddr; /* program header address */
413: u_long arg_phentsize; /* Size of program header */
414: u_long arg_phnum; /* Number of program headers */
415: u_long arg_os; /* OS tag */
416: };
417:
418: #endif
419:
420: #if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
421: #define ELFSIZE ARCH_ELFSIZE
422: #endif
423:
424: #if defined(ELFSIZE)
425: #define CONCAT(x,y) __CONCAT(x,y)
426: #define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
427: #define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
428: #define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE))
429: #define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
430: #endif
431:
432: #define Elf_Ehdr Elf32_Ehdr
433: #define Elf_Phdr Elf32_Phdr
434: #define Elf_Shdr Elf32_Shdr
435: #define Elf_Sym Elf32_Sym
436: #define Elf_Rel Elf32_Rel
437: #define Elf_RelA Elf32_Rela
438: #define Elf_Dyn Elf32_Dyn
439: #define Elf_Word Elf32_Word
440: #define Elf_Sword Elf32_Sword
441: #define Elf_Addr Elf32_Addr
442: #define Elf_Off Elf32_Off
443: #define Elf_Nhdr Elf32_Nhdr
444: #define Elf_Note Elf32_Note
445:
446: #define ELF_R_SYM ELF32_R_SYM
447: #define ELF_R_TYPE ELF32_R_TYPE
448: #define ELF_R_INFO ELF32_R_INFO
449: #define ELFCLASS ELFCLASS32
450:
451: #define ELF_ST_BIND ELF32_ST_BIND
452: #define ELF_ST_TYPE ELF32_ST_TYPE
453: #define ELF_ST_INFO ELF32_ST_INFO
454:
455: #define AuxInfo Aux32Info
456:
457: #define ELF_TARG_VER 1 /* The ver for which this code is intended */
458:
459: #endif /* _SYS_ELF_H */
CVSweb