elf.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Sergey Bondari
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef ELF_H_
00036 #define ELF_H_
00037 
00038 #include <arch/elf.h>
00039 #include <sys/types.h>
00040 
00044 #define EV_CURRENT      1
00045 
00049 #define ET_NONE         0       /* No type */
00050 #define ET_REL          1       /* Relocatable file */
00051 #define ET_EXEC         2       /* Executable */
00052 #define ET_DYN          3       /* Shared object */
00053 #define ET_CORE         4       /* Core */
00054 #define ET_LOPROC       0xff00  /* Processor specific */
00055 #define ET_HIPROC       0xffff  /* Processor specific */
00056 
00060 #define EM_NO           0       /* No machine */
00061 #define EM_SPARC        2       /* SPARC */
00062 #define EM_386          3       /* i386 */
00063 #define EM_MIPS         8       /* MIPS RS3000 */
00064 #define EM_MIPS_RS3_LE  10      /* MIPS RS3000 LE */
00065 #define EM_PPC          20      /* PPC32 */
00066 #define EM_PPC64        21      /* PPC64 */
00067 #define EM_ARM          40      /* ARM */
00068 #define EM_SPARCV9      43      /* SPARC64 */
00069 #define EM_IA_64        50      /* IA-64 */
00070 #define EM_X86_64       62      /* AMD64/EMT64 */
00071 
00075 #define EI_MAG0         0
00076 #define EI_MAG1         1
00077 #define EI_MAG2         2
00078 #define EI_MAG3         3
00079 #define EI_CLASS        4               /* File class */
00080 #define EI_DATA         5               /* Data encoding */
00081 #define EI_VERSION      6               /* File version */
00082 #define EI_OSABI        7
00083 #define EI_ABIVERSION   8
00084 #define EI_PAD          9               /* Start of padding bytes */
00085 #define EI_NIDENT       16              /* ELF identification table size */
00086 
00090 #define ELFMAG0         0x7f
00091 #define ELFMAG1         'E'
00092 #define ELFMAG2         'L'
00093 #define ELFMAG3         'F'
00094 
00098 #define ELFCLASSNONE    0
00099 #define ELFCLASS32      1
00100 #define ELFCLASS64      2
00101 
00105 #define ELFDATANONE     0
00106 #define ELFDATA2LSB     1               /* Least significant byte first (little endian) */
00107 #define ELFDATA2MSB     2               /* Most signigicant byte first (big endian) */
00108 
00112 #define EE_OK                   0       /* No error */
00113 #define EE_INVALID              1       /* Invalid ELF image */
00114 #define EE_MEMORY               2       /* Cannot allocate address space */
00115 #define EE_INCOMPATIBLE         3       /* ELF image is not compatible with current architecture */
00116 #define EE_UNSUPPORTED          4       /* Non-supported ELF (e.g. dynamic ELFs) */
00117 #define EE_IRRECOVERABLE        5
00118 
00122 #define SHT_NULL                0
00123 #define SHT_PROGBITS            1
00124 #define SHT_SYMTAB              2
00125 #define SHT_STRTAB              3
00126 #define SHT_RELA                4
00127 #define SHT_HASH                5
00128 #define SHT_DYNAMIC             6
00129 #define SHT_NOTE                7
00130 #define SHT_NOBITS              8
00131 #define SHT_REL                 9
00132 #define SHT_SHLIB               10
00133 #define SHT_DYNSYM              11
00134 #define SHT_LOOS                0x60000000
00135 #define SHT_HIOS                0x6fffffff
00136 #define SHT_LOPROC              0x70000000
00137 #define SHT_HIPROC              0x7fffffff
00138 #define SHT_LOUSER              0x80000000
00139 #define SHT_HIUSER              0xffffffff
00140 
00144 #define SHF_WRITE               0x1 
00145 #define SHF_ALLOC               0x2
00146 #define SHF_EXECINSTR           0x4
00147 #define SHF_TLS                 0x400
00148 #define SHF_MASKPROC            0xf0000000
00149 
00151 #define ELF_ST_BIND(i)          ((i) >> 4)
00152 #define ELF_ST_TYPE(i)          ((i) & 0x0f)
00153 #define ELF_ST_INFO(b, t)       (((b) << 4) + ((t) & 0x0f))
00154 
00158 #define STB_LOCAL               0
00159 #define STB_GLOBAL              1
00160 #define STB_WEAK                2
00161 #define STB_LOPROC              13
00162 #define STB_HIPROC              15
00163 
00167 #define STT_NOTYPE              0
00168 #define STT_OBJECT              1
00169 #define STT_FUNC                2
00170 #define STT_SECTION             3
00171 #define STT_FILE                4
00172 #define STT_LOPROC              13
00173 #define STT_HIPROC              15
00174 
00178 #define PT_NULL                 0
00179 #define PT_LOAD                 1
00180 #define PT_DYNAMIC              2
00181 #define PT_INTERP               3
00182 #define PT_NOTE                 4
00183 #define PT_SHLIB                5
00184 #define PT_PHDR                 6
00185 #define PT_LOPROC               0x70000000
00186 #define PT_HIPROC               0x7fffffff
00187 
00191 #define PF_X    1
00192 #define PF_W    2
00193 #define PF_R    4
00194 
00202 typedef uint64_t elf_xword;
00203 typedef int64_t elf_sxword;
00204 typedef uint32_t elf_word;
00205 typedef int32_t elf_sword;
00206 typedef uint16_t elf_half;
00207 
00213 typedef uint32_t elf32_addr;
00214 typedef uint32_t elf32_off;
00215 
00221 typedef uint64_t elf64_addr;
00222 typedef uint64_t elf64_off;
00223 
00225 struct elf32_header {
00226         uint8_t e_ident[EI_NIDENT];
00227         elf_half e_type;
00228         elf_half e_machine;
00229         elf_word e_version;
00230         elf32_addr e_entry;
00231         elf32_off e_phoff;
00232         elf32_off e_shoff;
00233         elf_word e_flags;
00234         elf_half e_ehsize;
00235         elf_half e_phentsize;
00236         elf_half e_phnum;
00237         elf_half e_shentsize;
00238         elf_half e_shnum;
00239         elf_half e_shstrndx;
00240 };
00241 struct elf64_header {
00242         uint8_t e_ident[EI_NIDENT];
00243         elf_half e_type;
00244         elf_half e_machine;
00245         elf_word e_version;
00246         elf64_addr e_entry;
00247         elf64_off e_phoff;
00248         elf64_off e_shoff;
00249         elf_word e_flags;
00250         elf_half e_ehsize;
00251         elf_half e_phentsize;
00252         elf_half e_phnum;
00253         elf_half e_shentsize;
00254         elf_half e_shnum;
00255         elf_half e_shstrndx;
00256 };
00257 
00258 /*
00259  * ELF segment header.
00260  * Segments headers are also known as program headers.
00261  */
00262 struct elf32_segment_header {
00263         elf_word p_type;
00264         elf32_off p_offset;
00265         elf32_addr p_vaddr;
00266         elf32_addr p_paddr;
00267         elf_word p_filesz;
00268         elf_word p_memsz;
00269         elf_word p_flags;
00270         elf_word p_align;
00271 };
00272 struct elf64_segment_header {
00273         elf_word p_type;
00274         elf_word p_flags;
00275         elf64_off p_offset;
00276         elf64_addr p_vaddr;
00277         elf64_addr p_paddr;
00278         elf_xword p_filesz;
00279         elf_xword p_memsz;
00280         elf_xword p_align;
00281 };
00282 
00283 /*
00284  * ELF section header
00285  */
00286 struct elf32_section_header {
00287         elf_word sh_name;
00288         elf_word sh_type;
00289         elf_word sh_flags;
00290         elf32_addr sh_addr;
00291         elf32_off sh_offset;
00292         elf_word sh_size;
00293         elf_word sh_link;
00294         elf_word sh_info;
00295         elf_word sh_addralign;
00296         elf_word sh_entsize;
00297 };
00298 struct elf64_section_header {
00299         elf_word sh_name;
00300         elf_word sh_type;
00301         elf_xword sh_flags;
00302         elf64_addr sh_addr;
00303         elf64_off sh_offset;
00304         elf_xword sh_size;
00305         elf_word sh_link;
00306         elf_word sh_info;
00307         elf_xword sh_addralign;
00308         elf_xword sh_entsize;
00309 };
00310 
00311 /*
00312  * ELF symbol table entry
00313  */
00314 struct elf32_symbol {
00315         elf_word st_name;
00316         elf32_addr st_value;
00317         elf_word st_size;
00318         uint8_t st_info;
00319         uint8_t st_other;
00320         elf_half st_shndx;
00321 };
00322 struct elf64_symbol {
00323         elf_word st_name;
00324         uint8_t st_info;
00325         uint8_t st_other;
00326         elf_half st_shndx;
00327         elf64_addr st_value;
00328         elf_xword st_size;
00329 };
00330 
00331 #ifdef __32_BITS__ 
00332 typedef struct elf32_header elf_header_t;
00333 typedef struct elf32_segment_header elf_segment_header_t;
00334 typedef struct elf32_section_header elf_section_header_t;
00335 typedef struct elf32_symbol elf_symbol_t;
00336 #endif
00337 #ifdef __64_BITS__
00338 typedef struct elf64_header elf_header_t;
00339 typedef struct elf64_segment_header elf_segment_header_t;
00340 typedef struct elf64_section_header elf_section_header_t;
00341 typedef struct elf64_symbol elf_symbol_t;
00342 #endif
00343 
00344 extern char *elf_error(unsigned int rc);
00345 
00346 #endif
00347 

Generated on Thu Jun 2 07:45:43 2011 for HelenOS/USB by  doxygen 1.4.7