elf.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1994 The NetBSD Foundation, Inc.
00003  * All rights reserved.
00004  *
00005  * This code is derived from software contributed to The NetBSD Foundation
00006  * by Christos Zoulas.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. All advertising materials mentioning features or use of this software
00017  *    must display the following acknowledgement:
00018  *      This product includes software developed by the NetBSD
00019  *      Foundation, Inc. and its contributors.
00020  * 4. Neither the name of The NetBSD Foundation nor the names of its
00021  *    contributors may be used to endorse or promote products derived
00022  *    from this software without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
00025  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00027  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
00028  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  * POSSIBILITY OF SUCH DAMAGE.
00035  */
00036 
00037 #ifndef _SYS_EXEC_ELF_H_
00038 #define _SYS_EXEC_ELF_H_
00039 
00040 /*
00041  * The current ELF ABI specification is available at:
00042  *      http://www.sco.com/developer/gabi/
00043  *
00044  * Current header definitions are in:
00045  *      http://www.sco.com/developer/gabi/latest/ch4.eheader.html
00046  */
00047 #include <sysinterf/types.h>
00048 #include <machdep/elf_machdep.h>
00049 
00050 typedef u_int8_t        Elf_Byte;
00051 
00052 typedef u_int32_t       Elf32_Addr;
00053 #define ELF32_FSZ_ADDR  4
00054 typedef u_int32_t       Elf32_Off;
00055 #define ELF32_FSZ_OFF   4
00056 typedef int32_t         Elf32_Sword;
00057 #define ELF32_FSZ_SWORD 4
00058 typedef u_int32_t       Elf32_Word;
00059 #define ELF32_FSZ_WORD  4
00060 typedef u_int16_t       Elf32_Half;
00061 #define ELF32_FSZ_HALF  2
00062 
00063 typedef u_int64_t       Elf64_Addr;
00064 #define ELF64_FSZ_ADDR  8
00065 typedef u_int64_t       Elf64_Off;
00066 #define ELF64_FSZ_OFF   8
00067 typedef int32_t         Elf64_Shalf;
00068 #define ELF64_FSZ_SHALF 4
00069 
00070 #ifndef ELF64_FSZ_SWORD
00071 typedef int32_t         Elf64_Sword;
00072 #define ELF64_FSZ_SWORD 4
00073 #endif /* ELF64_FSZ_SWORD */
00074 #ifndef ELF64_FSZ_WORD
00075 typedef u_int32_t       Elf64_Word;
00076 #define ELF64_FSZ_WORD  4
00077 #endif /* ELF64_FSZ_WORD */
00078 
00079 typedef int64_t         Elf64_Sxword;
00080 #define ELF64_FSZ_XWORD 8
00081 typedef u_int64_t       Elf64_Xword;
00082 #define ELF64_FSZ_XWORD 8
00083 typedef u_int32_t       Elf64_Half;
00084 #define ELF64_FSZ_HALF  4
00085 typedef u_int16_t       Elf64_Quarter;
00086 #define ELF64_FSZ_QUARTER 2
00087 
00088 /*
00089  * ELF Header
00090  */
00091 #define ELF_NIDENT      16
00092 
00093 typedef struct {
00094         unsigned char   e_ident[ELF_NIDENT];    /* Id bytes */
00095         Elf32_Half      e_type;                 /* file type */
00096         Elf32_Half      e_machine;              /* machine type */
00097         Elf32_Word      e_version;              /* version number */
00098         Elf32_Addr      e_entry;                /* entry point */
00099         Elf32_Off       e_phoff;                /* Program hdr offset */
00100         Elf32_Off       e_shoff;                /* Section hdr offset */
00101         Elf32_Word      e_flags;                /* Processor flags */
00102         Elf32_Half      e_ehsize;               /* sizeof ehdr */
00103         Elf32_Half      e_phentsize;            /* Program header entry size */
00104         Elf32_Half      e_phnum;                /* Number of program headers */
00105         Elf32_Half      e_shentsize;            /* Section header entry size */
00106         Elf32_Half      e_shnum;                /* Number of section headers */
00107         Elf32_Half      e_shstrndx;             /* String table index */
00108 } Elf32_Ehdr;
00109 
00110 typedef struct {
00111         unsigned char   e_ident[ELF_NIDENT];    /* Id bytes */
00112         Elf64_Quarter   e_type;                 /* file type */
00113         Elf64_Quarter   e_machine;              /* machine type */
00114         Elf64_Half      e_version;              /* version number */
00115         Elf64_Addr      e_entry;                /* entry point */
00116         Elf64_Off       e_phoff;                /* Program hdr offset */
00117         Elf64_Off       e_shoff;                /* Section hdr offset */
00118         Elf64_Half      e_flags;                /* Processor flags */
00119         Elf64_Quarter   e_ehsize;               /* sizeof ehdr */
00120         Elf64_Quarter   e_phentsize;            /* Program header entry size */
00121         Elf64_Quarter   e_phnum;                /* Number of program headers */
00122         Elf64_Quarter   e_shentsize;            /* Section header entry size */
00123         Elf64_Quarter   e_shnum;                /* Number of section headers */
00124         Elf64_Quarter   e_shstrndx;             /* String table index */
00125 } Elf64_Ehdr;
00126 
00127 /* e_ident offsets */
00128 #define EI_MAG0         0       /* '\177' */
00129 #define EI_MAG1         1       /* 'E'    */
00130 #define EI_MAG2         2       /* 'L'    */
00131 #define EI_MAG3         3       /* 'F'    */
00132 #define EI_CLASS        4       /* File class */
00133 #define EI_DATA         5       /* Data encoding */
00134 #define EI_VERSION      6       /* File version */
00135 #define EI_OSABI        7       /* Operating system/ABI identification */
00136 #define EI_ABIVERSION   8       /* ABI version */
00137 #define EI_PAD          9       /* Start of padding bytes up to EI_NIDENT*/
00138 
00139 /* e_ident[ELFMAG0,ELFMAG3] */
00140 #define ELFMAG0         0x7f
00141 #define ELFMAG1         'E'
00142 #define ELFMAG2         'L'
00143 #define ELFMAG3         'F'
00144 #define ELFMAG          "\177ELF"
00145 #define SELFMAG         4
00146 
00147 /* e_ident[EI_CLASS] */
00148 #define ELFCLASSNONE    0       /* Invalid class */
00149 #define ELFCLASS32      1       /* 32-bit objects */
00150 #define ELFCLASS64      2       /* 64-bit objects */
00151 #define ELFCLASSNUM     3
00152 
00153 /* e_ident[EI_DATA] */
00154 #define ELFDATANONE     0       /* Invalid data encoding */
00155 #define ELFDATA2LSB     1       /* 2's complement values, LSB first */
00156 #define ELFDATA2MSB     2       /* 2's complement values, MSB first */
00157 
00158 /* e_ident[EI_VERSION] */
00159 #define EV_NONE         0       /* Invalid version */
00160 #define EV_CURRENT      1       /* Current version */
00161 #define EV_NUM          2
00162 
00163 /* e_ident[EI_OSABI] */
00164 #define ELFOSABI_SYSV           0       /* UNIX System V ABI */
00165 #define ELFOSABI_HPUX           1       /* HP-UX operating system */
00166 #define ELFOSABI_NETBSD         2       /* NetBSD */
00167 #define ELFOSABI_LINUX          3       /* GNU/Linux */
00168 #define ELFOSABI_HURD           4       /* GNU/Hurd */
00169 #define ELFOSABI_86OPEN         5       /* 86Open */
00170 #define ELFOSABI_SOLARIS        6       /* Solaris */
00171 #define ELFOSABI_MONTEREY       7       /* Monterey */
00172 #define ELFOSABI_IRIX           8       /* IRIX */
00173 #define ELFOSABI_FREEBSD        9       /* FreeBSD */
00174 #define ELFOSABI_TRU64          10      /* TRU64 UNIX */
00175 #define ELFOSABI_MODESTO        11      /* Novell Modesto */
00176 #define ELFOSABI_OPENBSD        12      /* OpenBSD */
00177 /* Unofficial OSABIs follow */
00178 #define ELFOSABI_ARM            97      /* ARM */
00179 #define ELFOSABI_STANDALONE     255     /* Standalone (embedded) application */
00180 
00181 /* e_type */
00182 #define ET_NONE         0       /* No file type */
00183 #define ET_REL          1       /* Relocatable file */
00184 #define ET_EXEC         2       /* Executable file */
00185 #define ET_DYN          3       /* Shared object file */
00186 #define ET_CORE         4       /* Core file */
00187 #define ET_NUM          5
00188 
00189 #define ET_LOOS         0xfe00  /* Operating system specific range */
00190 #define ET_HIOS         0xfeff
00191 #define ET_LOPROC       0xff00  /* Processor-specific range */
00192 #define ET_HIPROC       0xffff
00193 
00194 /* e_machine */
00195 #define EM_NONE         0       /* No machine */
00196 #define EM_M32          1       /* AT&T WE 32100 */
00197 #define EM_SPARC        2       /* SPARC */
00198 #define EM_386          3       /* Intel 80386 */
00199 #define EM_68K          4       /* Motorola 68000 */
00200 #define EM_88K          5       /* Motorola 88000 */
00201 #define EM_486          6       /* Intel 80486 */
00202 #define EM_860          7       /* Intel 80860 */
00203 #define EM_MIPS         8       /* MIPS I Architecture */
00204 #define EM_S370         9       /* Amdahl UTS on System/370 */
00205 #define EM_MIPS_RS3_LE  10      /* MIPS RS3000 Little-endian */
00206                         /* 11-14 - Reserved */
00207 #define EM_RS6000       11      /* IBM RS/6000 XXX reserved */
00208 #define EM_PARISC       15      /* Hewlett-Packard PA-RISC */
00209 #define EM_NCUBE        16      /* NCube XXX reserved */
00210 #define EM_VPP500       17      /* Fujitsu VPP500 */
00211 #define EM_SPARC32PLUS  18      /* Enhanced instruction set SPARC */
00212 #define EM_960          19      /* Intel 80960 */
00213 #define EM_PPC          20      /* PowerPC */
00214 #define EM_PPC64        21      /* 64-bit PowerPC */
00215                         /* 22-35 - Reserved */
00216 #define EM_V800         36      /* NEC V800 */
00217 #define EM_FR20         37      /* Fujitsu FR20 */
00218 #define EM_RH32         38      /* TRW RH-32 */
00219 #define EM_RCE          39      /* Motorola RCE */
00220 #define EM_ARM          40      /* Advanced RISC Machines ARM */
00221 #define EM_ALPHA        41      /* DIGITAL Alpha */
00222 #define EM_SH           42      /* Hitachi Super-H */
00223 #define EM_SPARCV9      43      /* SPARC Version 9 */
00224 #define EM_TRICORE      44      /* Siemens Tricore */
00225 #define EM_ARC          45      /* Argonaut RISC Core */
00226 #define EM_H8_300       46      /* Hitachi H8/300 */
00227 #define EM_H8_300H      47      /* Hitachi H8/300H */
00228 #define EM_H8S          48      /* Hitachi H8S */
00229 #define EM_H8_500       49      /* Hitachi H8/500 */
00230 #define EM_IA_64        50      /* Intel Merced Processor */
00231 #define EM_MIPS_X       51      /* Stanford MIPS-X */
00232 #define EM_COLDFIRE     52      /* Motorola Coldfire */
00233 #define EM_68HC12       53      /* Motorola MC68HC12 */
00234 #define EM_MMA          54      /* Fujitsu MMA Multimedia Accelerator */
00235 #define EM_PCP          55      /* Siemens PCP */
00236 #define EM_NCPU         56      /* Sony nCPU embedded RISC processor */
00237 #define EM_NDR1         57      /* Denso NDR1 microprocessor */
00238 #define EM_STARCORE     58      /* Motorola Star*Core processor */
00239 #define EM_ME16         59      /* Toyota ME16 processor */
00240 #define EM_ST100        60      /* STMicroelectronics ST100 processor */
00241 #define EM_TINYJ        61      /* Advanced Logic Corp. TinyJ embedded family processor */
00242 #define EM_X86_64       62      /* AMD x86-64 architecture */
00243 #define EM_PDSP         63      /* Sony DSP Processor */
00244                         /* 64-65 - Reserved */
00245 #define EM_FX66         66      /* Siemens FX66 microcontroller */
00246 #define EM_ST9PLUS      67      /* STMicroelectronics ST9+ 8/16 bit microcontroller */
00247 #define EM_ST7          68      /* STMicroelectronics ST7 8-bit microcontroller */
00248 #define EM_68HC16       69      /* Motorola MC68HC16 Microcontroller */
00249 #define EM_68HC11       70      /* Motorola MC68HC11 Microcontroller */
00250 #define EM_68HC08       71      /* Motorola MC68HC08 Microcontroller */
00251 #define EM_68HC05       72      /* Motorola MC68HC05 Microcontroller */
00252 #define EM_SVX          73      /* Silicon Graphics SVx */
00253 #define EM_ST19         74      /* STMicroelectronics ST19 8-bit cpu */
00254 #define EM_VAX          75      /* Digital VAX */
00255 #define EM_CRIS         76      /* Axis Communications 32-bit embedded processor */
00256 #define EM_JAVELIN      77      /* Infineon Technologies 32-bit embedded cpu */
00257 #define EM_FIREPATH     78      /* Element 14 64-bit DSP processor */
00258 #define EM_ZSP          79      /* LSI Logic's 16-bit DSP processor */
00259 #define EM_MMIX         80      /* Donald Knuth's educational 64-bit processor */
00260 #define EM_HUANY        81      /* Harvard's machine-independent format */
00261 #define EM_PRISM        82      /* SiTera Prism */
00262 #define EM_AVR          83      /* Atmel AVR 8-bit microcontroller */
00263 #define EM_FR30         84      /* Fujitsu FR30 */
00264 #define EM_D10V         85      /* Mitsubishi D10V */
00265 #define EM_D30V         86      /* Mitsubishi D30V */
00266 #define EM_V850         87      /* NEC v850 */
00267 #define EM_M32R         88      /* Mitsubishi M32R */
00268 #define EM_MN10300      89      /* Matsushita MN10300 */
00269 #define EM_MN10200      90      /* Matsushita MN10200 */
00270 #define EM_PJ           91      /* picoJava */
00271 #define EM_OPENRISC     92      /* OpenRISC 32-bit embedded processor */
00272 #define EM_ARC_A5       93      /* ARC Cores Tangent-A5 */
00273 #define EM_XTENSA       94      /* Tensilica Xtensa Architecture */
00274 #define EM_NS32K        97      /* National Semiconductor 32000 series */
00275 
00276 /* Unofficial machine types follow */
00277 #define EM_ALPHA_EXP    36902   /* used by NetBSD/alpha; obsolete */
00278 #define EM_NUM          36903
00279 
00280 /*
00281  * Program Header
00282  */
00283 typedef struct {
00284         Elf32_Word      p_type;         /* entry type */
00285         Elf32_Off       p_offset;       /* offset */
00286         Elf32_Addr      p_vaddr;        /* virtual address */
00287         Elf32_Addr      p_paddr;        /* physical address */
00288         Elf32_Word      p_filesz;       /* file size */
00289         Elf32_Word      p_memsz;        /* memory size */
00290         Elf32_Word      p_flags;        /* flags */
00291         Elf32_Word      p_align;        /* memory & file alignment */
00292 } Elf32_Phdr;
00293 
00294 typedef struct {
00295         Elf64_Half      p_type;         /* entry type */
00296         Elf64_Half      p_flags;        /* flags */
00297         Elf64_Off       p_offset;       /* offset */
00298         Elf64_Addr      p_vaddr;        /* virtual address */
00299         Elf64_Addr      p_paddr;        /* physical address */
00300         Elf64_Xword     p_filesz;       /* file size */
00301         Elf64_Xword     p_memsz;        /* memory size */
00302         Elf64_Xword     p_align;        /* memory & file alignment */
00303 } Elf64_Phdr;
00304 
00305 /* p_type */
00306 #define PT_NULL         0               /* Program header table entry unused */
00307 #define PT_LOAD         1               /* Loadable program segment */
00308 #define PT_DYNAMIC      2               /* Dynamic linking information */
00309 #define PT_INTERP       3               /* Program interpreter */
00310 #define PT_NOTE         4               /* Auxiliary information */
00311 #define PT_SHLIB        5               /* Reserved, unspecified semantics */
00312 #define PT_PHDR         6               /* Entry for header table itself */
00313 #define PT_NUM          7
00314 
00315 /* p_flags */
00316 #define PF_R            0x4     /* Segment is readable */
00317 #define PF_W            0x2     /* Segment is writable */
00318 #define PF_X            0x1     /* Segment is executable */
00319 
00320 #define PF_MASKOS       0x0ff00000      /* Opersting system specific values */
00321 #define PF_MASKPROC     0xf0000000      /* Processor-specific values */
00322 
00323 #define PT_LOPROC       0x70000000      /* Processor-specific range */
00324 #define PT_HIPROC       0x7fffffff
00325 
00326 #define PT_MIPS_REGINFO 0x70000000
00327 
00328 /*
00329  * Section Headers
00330  */
00331 typedef struct {
00332         Elf32_Word      sh_name;        /* section name (.shstrtab index) */
00333         Elf32_Word      sh_type;        /* section type */
00334         Elf32_Word      sh_flags;       /* section flags */
00335         Elf32_Addr      sh_addr;        /* virtual address */
00336         Elf32_Off       sh_offset;      /* file offset */
00337         Elf32_Word      sh_size;        /* section size */
00338         Elf32_Word      sh_link;        /* link to another */
00339         Elf32_Word      sh_info;        /* misc info */
00340         Elf32_Word      sh_addralign;   /* memory alignment */
00341         Elf32_Word      sh_entsize;     /* table entry size */
00342 } Elf32_Shdr;
00343 
00344 typedef struct {
00345         Elf64_Half      sh_name;        /* section name (.shstrtab index) */
00346         Elf64_Half      sh_type;        /* section type */
00347         Elf64_Xword     sh_flags;       /* section flags */
00348         Elf64_Addr      sh_addr;        /* virtual address */
00349         Elf64_Off       sh_offset;      /* file offset */
00350         Elf64_Xword     sh_size;        /* section size */
00351         Elf64_Half      sh_link;        /* link to another */
00352         Elf64_Half      sh_info;        /* misc info */
00353         Elf64_Xword     sh_addralign;   /* memory alignment */
00354         Elf64_Xword     sh_entsize;     /* table entry size */
00355 } Elf64_Shdr;
00356 
00357 /* sh_type */
00358 #define SHT_NULL        0               /* Section header table entry unused */
00359 #define SHT_PROGBITS    1               /* Program information */
00360 #define SHT_SYMTAB      2               /* Symbol table */
00361 #define SHT_STRTAB      3               /* String table */
00362 #define SHT_RELA        4               /* Relocation information w/ addend */
00363 #define SHT_HASH        5               /* Symbol hash table */
00364 #define SHT_DYNAMIC     6               /* Dynamic linking information */
00365 #define SHT_NOTE        7               /* Auxiliary information */
00366 #define SHT_NOBITS      8               /* No space allocated in file image */
00367 #define SHT_REL         9               /* Relocation information w/o addend */
00368 #define SHT_SHLIB       10              /* Reserved, unspecified semantics */
00369 #define SHT_DYNSYM      11              /* Symbol table for dynamic linker */
00370 #define SHT_NUM         12
00371 
00372 #define SHT_LOOS        0x60000000      /* Operating system specific range */
00373 #define SHT_HIOS        0x6fffffff
00374 #define SHT_LOPROC      0x70000000      /* Processor-specific range */
00375 #define SHT_HIPROC      0x7fffffff
00376 #define SHT_LOUSER      0x80000000      /* Application-specific range */
00377 #define SHT_HIUSER      0xffffffff
00378 
00379 /* sh_flags */
00380 #define SHF_WRITE       0x1             /* Section contains writable data */
00381 #define SHF_ALLOC       0x2             /* Section occupies memory */
00382 #define SHF_EXECINSTR   0x4             /* Section contains executable insns */
00383 
00384 #define SHF_MASKOS      0x0f000000      /* Operating system specific values */
00385 #define SHF_MASKPROC    0xf0000000      /* Processor-specific values */
00386 
00387 /*
00388  * Symbol Table
00389  */
00390 typedef struct {
00391         Elf32_Word      st_name;        /* Symbol name (.symtab index) */
00392         Elf32_Word      st_value;       /* value of symbol */
00393         Elf32_Word      st_size;        /* size of symbol */
00394         Elf_Byte        st_info;        /* type / binding attrs */
00395         Elf_Byte        st_other;       /* unused */
00396         Elf32_Half      st_shndx;       /* section index of symbol */
00397 } Elf32_Sym;
00398 
00399 typedef struct {
00400         Elf64_Half      st_name;        /* Symbol name (.symtab index) */
00401         Elf_Byte        st_info;        /* type / binding attrs */
00402         Elf_Byte        st_other;       /* unused */
00403         Elf64_Quarter   st_shndx;       /* section index of symbol */
00404         Elf64_Addr      st_value;       /* value of symbol */
00405         Elf64_Xword     st_size;        /* size of symbol */
00406 } Elf64_Sym;
00407 
00408 /* Symbol Table index of the undefined symbol */
00409 #define ELF_SYM_UNDEFINED       0
00410 
00411 /* st_info: Symbol Bindings */
00412 #define STB_LOCAL               0       /* local symbol */
00413 #define STB_GLOBAL              1       /* global symbol */
00414 #define STB_WEAK                2       /* weakly defined global symbol */
00415 #define STB_NUM                 3
00416 
00417 #define STB_LOOS                10      /* Operating system specific range */
00418 #define STB_HIOS                12
00419 #define STB_LOPROC              13      /* Processor-specific range */
00420 #define STB_HIPROC              15
00421 
00422 /* st_info: Symbol Types */
00423 #define STT_NOTYPE              0       /* Type not specified */
00424 #define STT_OBJECT              1       /* Associated with a data object */
00425 #define STT_FUNC                2       /* Associated with a function */
00426 #define STT_SECTION             3       /* Associated with a section */
00427 #define STT_FILE                4       /* Associated with a file name */
00428 #define STT_NUM                 5
00429 
00430 #define STT_LOOS                10      /* Operating system specific range */
00431 #define STT_HIOS                12
00432 #define STT_LOPROC              13      /* Processor-specific range */
00433 #define STT_HIPROC              15
00434 
00435 /* st_info utility macros */
00436 #define ELF32_ST_BIND(info)             ((Elf32_Word)(info) >> 4)
00437 #define ELF32_ST_TYPE(info)             ((Elf32_Word)(info) & 0xf)
00438 #define ELF32_ST_INFO(bind,type)        ((Elf_Byte)(((bind) << 4) | ((type) & 0xf)))
00439 
00440 #define ELF64_ST_BIND(info)             ((Elf64_Xword)(info) >> 4)
00441 #define ELF64_ST_TYPE(info)             ((Elf64_Xword)(info) & 0xf)
00442 #define ELF64_ST_INFO(bind,type)        ((Elf_Byte)(((bind) << 4) | ((type) & 0xf)))
00443 
00444 /*
00445  * Special section indexes
00446  */
00447 #define SHN_UNDEF       0               /* Undefined section */
00448 
00449 #define SHN_LORESERVE   0xff00          /* Reserved range */
00450 #define SHN_ABS         0xfff1          /*  Absolute symbols */
00451 #define SHN_COMMON      0xfff2          /*  Common symbols */
00452 #define SHN_HIRESERVE   0xffff
00453 
00454 #define SHN_LOPROC      0xff00          /* Processor-specific range */
00455 #define SHN_HIPROC      0xff1f
00456 #define SHN_LOOS        0xff20          /* Operating system specific range */
00457 #define SHN_HIOS        0xff3f
00458 
00459 #define SHN_MIPS_ACOMMON 0xff00
00460 #define SHN_MIPS_TEXT   0xff01
00461 #define SHN_MIPS_DATA   0xff02
00462 #define SHN_MIPS_SCOMMON 0xff03
00463 
00464 /*
00465  * Relocation Entries
00466  */
00467 typedef struct {
00468         Elf32_Word      r_offset;       /* where to do it */
00469         Elf32_Word      r_info;         /* index & type of relocation */
00470 } Elf32_Rel;
00471 
00472 typedef struct {
00473         Elf32_Word      r_offset;       /* where to do it */
00474         Elf32_Word      r_info;         /* index & type of relocation */
00475         Elf32_Sword     r_addend;       /* adjustment value */
00476 } Elf32_Rela;
00477 
00478 /* r_info utility macros */
00479 #define ELF32_R_SYM(info)       ((info) >> 8)
00480 #define ELF32_R_TYPE(info)      ((info) & 0xff)
00481 #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
00482 
00483 typedef struct {
00484         Elf64_Addr      r_offset;       /* where to do it */
00485         Elf64_Xword     r_info;         /* index & type of relocation */
00486 } Elf64_Rel;
00487 
00488 typedef struct {
00489         Elf64_Addr      r_offset;       /* where to do it */
00490         Elf64_Xword     r_info;         /* index & type of relocation */
00491         Elf64_Sxword    r_addend;       /* adjustment value */
00492 } Elf64_Rela;
00493 
00494 /* r_info utility macros */
00495 #define ELF64_R_SYM(info)       ((info) >> 32)
00496 #define ELF64_R_TYPE(info)      ((info) & 0xffffffff)
00497 #define ELF64_R_INFO(sym,type)  (((sym) << 32) + (type))
00498 
00499 /*
00500  * Dynamic Section structure array
00501  */
00502 typedef struct {
00503         Elf32_Word      d_tag;          /* entry tag value */
00504         union {
00505             Elf32_Addr  d_ptr;
00506             Elf32_Word  d_val;
00507         } d_un;
00508 } Elf32_Dyn;
00509 
00510 typedef struct {
00511         Elf64_Xword     d_tag;          /* entry tag value */
00512         union {
00513             Elf64_Addr  d_ptr;
00514             Elf64_Xword d_val;
00515         } d_un;
00516 } Elf64_Dyn;
00517 
00518 /* d_tag */
00519 #define DT_NULL         0       /* Marks end of dynamic array */
00520 #define DT_NEEDED       1       /* Name of needed library (DT_STRTAB offset) */
00521 #define DT_PLTRELSZ     2       /* Size, in bytes, of relocations in PLT */
00522 #define DT_PLTGOT       3       /* Address of PLT and/or GOT */
00523 #define DT_HASH         4       /* Address of symbol hash table */
00524 #define DT_STRTAB       5       /* Address of string table */
00525 #define DT_SYMTAB       6       /* Address of symbol table */
00526 #define DT_RELA         7       /* Address of Rela relocation table */
00527 #define DT_RELASZ       8       /* Size, in bytes, of DT_RELA table */
00528 #define DT_RELAENT      9       /* Size, in bytes, of one DT_RELA entry */
00529 #define DT_STRSZ        10      /* Size, in bytes, of DT_STRTAB table */
00530 #define DT_SYMENT       11      /* Size, in bytes, of one DT_SYMTAB entry */
00531 #define DT_INIT         12      /* Address of initialization function */
00532 #define DT_FINI         13      /* Address of termination function */
00533 #define DT_SONAME       14      /* Shared object name (DT_STRTAB offset) */
00534 #define DT_RPATH        15      /* Library search path (DT_STRTAB offset) */
00535 #define DT_SYMBOLIC     16      /* Start symbol search within local object */
00536 #define DT_REL          17      /* Address of Rel relocation table */
00537 #define DT_RELSZ        18      /* Size, in bytes, of DT_REL table */
00538 #define DT_RELENT       19      /* Size, in bytes, of one DT_REL entry */
00539 #define DT_PLTREL       20      /* Type of PLT relocation entries */
00540 #define DT_DEBUG        21      /* Used for debugging; unspecified */
00541 #define DT_TEXTREL      22      /* Relocations might modify non-writable seg */
00542 #define DT_JMPREL       23      /* Address of relocations associated with PLT */
00543 #define DT_BIND_NOW     24      /* Process all relocations at load-time */
00544 #define DT_INIT_ARRAY   25      /* Address of initialization function array */
00545 #define DT_FINI_ARRAY   26      /* Size, in bytes, of DT_INIT_ARRAY array */
00546 #define DT_INIT_ARRAYSZ 27      /* Address of termination function array */
00547 #define DT_FINI_ARRAYSZ 28      /* Size, in bytes, of DT_FINI_ARRAY array*/
00548 #define DT_NUM          29
00549 
00550 #define DT_LOOS         0x60000000      /* Operating system specific range */
00551 #define DT_HIOS         0x6fffffff
00552 #define DT_LOPROC       0x70000000      /* Processor-specific range */
00553 #define DT_HIPROC       0x7fffffff
00554 
00555 /*
00556  * Auxiliary Vectors
00557  */
00558 typedef struct {
00559         Elf32_Word      a_type;                         /* 32-bit id */
00560         Elf32_Word      a_v;                            /* 32-bit id */
00561 } Aux32Info;
00562 
00563 typedef struct {
00564         Elf64_Half      a_type;                         /* 32-bit id */
00565         Elf64_Xword     a_v;                            /* 64-bit id */
00566 } Aux64Info;
00567 
00568 /* a_type */
00569 #define AT_NULL         0       /* Marks end of array */
00570 #define AT_IGNORE       1       /* No meaning, a_un is undefined */
00571 #define AT_EXECFD       2       /* Open file descriptor of object file */
00572 #define AT_PHDR         3       /* &phdr[0] */
00573 #define AT_PHENT        4       /* sizeof(phdr[0]) */
00574 #define AT_PHNUM        5       /* # phdr entries */
00575 #define AT_PAGESZ       6       /* PAGESIZE */
00576 #define AT_BASE         7       /* Interpreter base addr */
00577 #define AT_FLAGS        8       /* Processor flags */
00578 #define AT_ENTRY        9       /* Entry address of executable */
00579 #define AT_DCACHEBSIZE  10      /* Data cache block size */
00580 #define AT_ICACHEBSIZE  11      /* Instruction cache block size */
00581 #define AT_UCACHEBSIZE  12      /* Unified cache block size */
00582 
00583         /* Vendor specific */
00584 #define AT_MIPS_NOTELF  10      /* XXX a_val != 0 -> MIPS XCOFF executable */
00585 
00586 #define AT_SUN_UID      2000    /* euid */
00587 #define AT_SUN_RUID     2001    /* ruid */
00588 #define AT_SUN_GID      2002    /* egid */
00589 #define AT_SUN_RGID     2003    /* rgid */
00590 
00591         /* Solaris kernel specific */
00592 #define AT_SUN_LDELF    2004    /* dynamic linker's ELF header */
00593 #define AT_SUN_LDSHDR   2005    /* dynamic linker's section header */
00594 #define AT_SUN_LDNAME   2006    /* dynamic linker's name */
00595 #define AT_SUN_LPGSIZE  2007    /* large pagesize */
00596 
00597         /* Other information */
00598 #define AT_SUN_PLATFORM 2008    /* sysinfo(SI_PLATFORM) */
00599 #define AT_SUN_HWCAP    2009    /* process hardware capabilities */
00600 #define AT_SUN_IFLUSH   2010    /* do we need to flush the instruction cache? */
00601 #define AT_SUN_CPU      2011    /* cpu name */
00602         /* ibcs2 emulation band aid */
00603 #define AT_SUN_EMUL_ENTRY 2012  /* coff entry point */
00604 #define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
00605         /* Executable's fully resolved name */
00606 #define AT_SUN_EXECNAME 2014
00607 
00608 /*
00609  * Note Headers
00610  */
00611 typedef struct {
00612         Elf32_Word n_namesz;
00613         Elf32_Word n_descsz;
00614         Elf32_Word n_type;
00615 } Elf32_Nhdr;
00616 
00617 typedef struct {
00618         Elf64_Half n_namesz;
00619         Elf64_Half n_descsz;
00620         Elf64_Half n_type;
00621 } Elf64_Nhdr;
00622 
00623 #define ELF_NOTE_TYPE_ABI_TAG           1
00624 
00625 /* GNU-specific note name and description sizes */
00626 #define ELF_NOTE_ABI_NAMESZ             4
00627 #define ELF_NOTE_ABI_DESCSZ             16
00628 /* GNU-specific note name */
00629 #define ELF_NOTE_ABI_NAME               "GNU\0"
00630 
00631 /* GNU-specific OS/version value stuff */
00632 #define ELF_NOTE_ABI_OS_LINUX           0
00633 #define ELF_NOTE_ABI_OS_HURD            1
00634 #define ELF_NOTE_ABI_OS_SOLARIS         2
00635 
00636 /* NetBSD-specific note type: Emulation name.  desc is emul name string. */
00637 #define ELF_NOTE_TYPE_NETBSD_TAG        1
00638 
00639 /* NetBSD-specific note name and description sizes */
00640 #define ELF_NOTE_NETBSD_NAMESZ          7
00641 #define ELF_NOTE_NETBSD_DESCSZ          4
00642 /* NetBSD-specific note name */
00643 #define ELF_NOTE_NETBSD_NAME            "NetBSD\0\0"
00644 
00645 /*
00646  * NetBSD-specific core file information.
00647  *
00648  * NetBSD ELF core files use notes to provide information about
00649  * the process's state.  The note name is "NetBSD-CORE" for
00650  * information that is global to the process, and "NetBSD-CORE@nn",
00651  * where "nn" is the lwpid of the LWP that the information belongs
00652  * to (such as register state).
00653  *
00654  * We use the following note identifiers:
00655  *
00656  *      ELF_NOTE_NETBSD_CORE_PROCINFO
00657  *              Note is a "netbsd_elfcore_procinfo" structure.
00658  *
00659  * We also use ptrace(2) request numbers (the ones that exist in
00660  * machine-dependent space) to identify register info notes.  The
00661  * info in such notes is in the same format that ptrace(2) would
00662  * export that information.
00663  *
00664  * Please try to keep the members of this structure nicely aligned,
00665  * and if you add elements, add them to the end and bump the version.
00666  */
00667 
00668 #define ELF_NOTE_NETBSD_CORE_NAME       "NetBSD-CORE"
00669 
00670 #define ELF_NOTE_NETBSD_CORE_PROCINFO   1
00671 
00672 #define NETBSD_ELFCORE_PROCINFO_VERSION 1
00673 
00674 struct netbsd_elfcore_procinfo {
00675         /* Version 1 fields start here. */
00676         u_int32_t       cpi_version;    /* netbsd_elfcore_procinfo version */
00677         u_int32_t       cpi_cpisize;    /* sizeof(netbsd_elfcore_procinfo) */
00678         u_int32_t       cpi_signo;      /* killing signal */
00679         u_int32_t       cpi_sigcode;    /* signal code */
00680         u_int32_t       cpi_sigpend[4]; /* pending signals */
00681         u_int32_t       cpi_sigmask[4]; /* blocked signals */
00682         u_int32_t       cpi_sigignore[4];/* blocked signals */
00683         u_int32_t       cpi_sigcatch[4];/* blocked signals */
00684         int32_t         cpi_pid;        /* process ID */
00685         int32_t         cpi_ppid;       /* parent process ID */
00686         int32_t         cpi_pgrp;       /* process group ID */
00687         int32_t         cpi_sid;        /* session ID */
00688         u_int32_t       cpi_ruid;       /* real user ID */
00689         u_int32_t       cpi_euid;       /* effective user ID */
00690         u_int32_t       cpi_svuid;      /* saved user ID */
00691         u_int32_t       cpi_rgid;       /* real group ID */
00692         u_int32_t       cpi_egid;       /* effective group ID */
00693         u_int32_t       cpi_svgid;      /* saved group ID */
00694         u_int32_t       cpi_nlwps;      /* number of LWPs */
00695         int8_t          cpi_name[32];   /* copy of p->p_comm */
00696         /* Add version 2 fields below here. */
00697 };
00698 
00699 #if defined(ELFSIZE)
00700 #define CONCAT(x,y)     __CONCAT(x,y) 
00701 #define ELFNAME(x)      CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
00702 #define ELFNAME2(x,y)   CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
00703 #define ELFNAMEEND(x)   CONCAT(x,CONCAT(_elf,ELFSIZE))
00704 #define ELFDEFNNAME(x)  CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
00705 #endif
00706 
00707 #if defined(ELFSIZE) && (ELFSIZE == 32)
00708 #define Elf_Ehdr        Elf32_Ehdr
00709 #define Elf_Phdr        Elf32_Phdr
00710 #define Elf_Shdr        Elf32_Shdr
00711 #define Elf_Sym         Elf32_Sym
00712 #define Elf_Rel         Elf32_Rel
00713 #define Elf_Rela        Elf32_Rela
00714 #define Elf_Dyn         Elf32_Dyn
00715 #define Elf_Word        Elf32_Word
00716 #define Elf_Sword       Elf32_Sword
00717 #define Elf_Addr        Elf32_Addr
00718 #define Elf_Off         Elf32_Off
00719 #define Elf_Nhdr        Elf32_Nhdr
00720 
00721 #define ELF_R_SYM       ELF32_R_SYM
00722 #define ELF_R_TYPE      ELF32_R_TYPE
00723 #define ELFCLASS        ELFCLASS32
00724 
00725 #define ELF_ST_BIND     ELF32_ST_BIND
00726 #define ELF_ST_TYPE     ELF32_ST_TYPE
00727 #define ELF_ST_INFO     ELF32_ST_INFO
00728 
00729 #define AuxInfo         Aux32Info
00730 #elif defined(ELFSIZE) && (ELFSIZE == 64)
00731 #define Elf_Ehdr        Elf64_Ehdr
00732 #define Elf_Phdr        Elf64_Phdr
00733 #define Elf_Shdr        Elf64_Shdr
00734 #define Elf_Sym         Elf64_Sym
00735 #define Elf_Rel         Elf64_Rel
00736 #define Elf_Rela        Elf64_Rela
00737 #define Elf_Dyn         Elf64_Dyn
00738 #define Elf_Word        Elf64_Word
00739 #define Elf_Sword       Elf64_Sword
00740 #define Elf_Addr        Elf64_Addr
00741 #define Elf_Off         Elf64_Off
00742 #define Elf_Nhdr        Elf64_Nhdr
00743 
00744 #define ELF_R_SYM       ELF64_R_SYM
00745 #define ELF_R_TYPE      ELF64_R_TYPE
00746 #define ELFCLASS        ELFCLASS64
00747 
00748 #define ELF_ST_BIND     ELF64_ST_BIND
00749 #define ELF_ST_TYPE     ELF64_ST_TYPE
00750 #define ELF_ST_INFO     ELF64_ST_INFO
00751 
00752 #define AuxInfo         Aux64Info
00753 #endif
00754 
00755 #endif /* !_SYS_EXEC_ELF_H_ */

Generated on Wed May 24 23:04:18 2006 for LSE/OS by  doxygen 1.4.6