Changeset 3e01316f in mainline for kernel/generic/include/lib/elf.h


Ignore:
Timestamp:
2011-08-17T18:04:50Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0cf27ee
Parents:
e898296d (diff), e6165be (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/lib/elf.h

    re898296d r3e01316f  
    3636#define KERN_ELF_H_
    3737
     38#include <typedefs.h>
     39#include <abi/elf.h>
    3840#include <arch/elf.h>
    39 #include <typedefs.h>
    40 
    41 /**
    42  * current ELF version
    43  */
    44 #define EV_CURRENT      1
    45 
    46 /**
    47  * ELF types
    48  */
    49 #define ET_NONE         0       /* No type */
    50 #define ET_REL          1       /* Relocatable file */
    51 #define ET_EXEC         2       /* Executable */
    52 #define ET_DYN          3       /* Shared object */
    53 #define ET_CORE         4       /* Core */
    54 #define ET_LOPROC       0xff00  /* Processor specific */
    55 #define ET_HIPROC       0xffff  /* Processor specific */
    56 
    57 /**
    58  * ELF machine types
    59  */
    60 #define EM_NO           0       /* No machine */
    61 #define EM_SPARC        2       /* SPARC */
    62 #define EM_386          3       /* i386 */
    63 #define EM_MIPS         8       /* MIPS RS3000 */
    64 #define EM_MIPS_RS3_LE  10      /* MIPS RS3000 LE */
    65 #define EM_PPC          20      /* PPC32 */
    66 #define EM_PPC64        21      /* PPC64 */
    67 #define EM_ARM          40      /* ARM */
    68 #define EM_SPARCV9      43      /* SPARC64 */
    69 #define EM_IA_64        50      /* IA-64 */
    70 #define EM_X86_64       62      /* AMD64/EMT64 */
    71 
    72 /**
    73  * ELF identification indexes
    74  */
    75 #define EI_MAG0         0
    76 #define EI_MAG1         1
    77 #define EI_MAG2         2
    78 #define EI_MAG3         3
    79 #define EI_CLASS        4               /* File class */
    80 #define EI_DATA         5               /* Data encoding */
    81 #define EI_VERSION      6               /* File version */
    82 #define EI_OSABI        7
    83 #define EI_ABIVERSION   8
    84 #define EI_PAD          9               /* Start of padding bytes */
    85 #define EI_NIDENT       16              /* ELF identification table size */
    86 
    87 /**
    88  * ELF magic number
    89  */
    90 #define ELFMAG0         0x7f
    91 #define ELFMAG1         'E'
    92 #define ELFMAG2         'L'
    93 #define ELFMAG3         'F'
    94 
    95 /**
    96  * ELF file classes
    97  */
    98 #define ELFCLASSNONE    0
    99 #define ELFCLASS32      1
    100 #define ELFCLASS64      2
    101 
    102 /**
    103  * ELF data encoding types
    104  */
    105 #define ELFDATANONE     0
    106 #define ELFDATA2LSB     1               /* Least significant byte first (little endian) */
    107 #define ELFDATA2MSB     2               /* Most signigicant byte first (big endian) */
    108 
    109 /**
    110  * ELF section types
    111  */
    112 #define SHT_NULL                0
    113 #define SHT_PROGBITS            1
    114 #define SHT_SYMTAB              2
    115 #define SHT_STRTAB              3
    116 #define SHT_RELA                4
    117 #define SHT_HASH                5
    118 #define SHT_DYNAMIC             6
    119 #define SHT_NOTE                7
    120 #define SHT_NOBITS              8
    121 #define SHT_REL                 9
    122 #define SHT_SHLIB               10
    123 #define SHT_DYNSYM              11
    124 #define SHT_LOOS                0x60000000
    125 #define SHT_HIOS                0x6fffffff
    126 #define SHT_LOPROC              0x70000000
    127 #define SHT_HIPROC              0x7fffffff
    128 #define SHT_LOUSER              0x80000000
    129 #define SHT_HIUSER              0xffffffff
    130 
    131 /**
    132  * ELF section flags
    133  */
    134 #define SHF_WRITE               0x1
    135 #define SHF_ALLOC               0x2
    136 #define SHF_EXECINSTR           0x4
    137 #define SHF_TLS                 0x400
    138 #define SHF_MASKPROC            0xf0000000
    139 
    140 /** Macros for decomposing elf_symbol.st_info into binging and type */
    141 #define ELF_ST_BIND(i)          ((i) >> 4)
    142 #define ELF_ST_TYPE(i)          ((i) & 0x0f)
    143 #define ELF_ST_INFO(b, t)       (((b) << 4) + ((t) & 0x0f))
    144 
    145 /**
    146  * Symbol binding
    147  */
    148 #define STB_LOCAL               0
    149 #define STB_GLOBAL              1
    150 #define STB_WEAK                2
    151 #define STB_LOPROC              13
    152 #define STB_HIPROC              15
    153 
    154 /**
    155  * Symbol types
    156  */
    157 #define STT_NOTYPE              0
    158 #define STT_OBJECT              1
    159 #define STT_FUNC                2
    160 #define STT_SECTION             3
    161 #define STT_FILE                4
    162 #define STT_LOPROC              13
    163 #define STT_HIPROC              15
    164 
    165 /**
    166  * Program segment types
    167  */
    168 #define PT_NULL                 0
    169 #define PT_LOAD                 1
    170 #define PT_DYNAMIC              2
    171 #define PT_INTERP               3
    172 #define PT_NOTE                 4
    173 #define PT_SHLIB                5
    174 #define PT_PHDR                 6
    175 #define PT_LOPROC               0x70000000
    176 #define PT_HIPROC               0x7fffffff
    177 
    178 /**
    179  * Program segment attributes.
    180  */
    181 #define PF_X    1
    182 #define PF_W    2
    183 #define PF_R    4
    184 
    185 /**
    186  * ELF data types
    187  *
    188  * These types are found to be identical in both 32-bit and 64-bit
    189  * ELF object file specifications. They are the only types used
    190  * in ELF header.
    191  */
    192 typedef uint64_t elf_xword;
    193 typedef int64_t elf_sxword;
    194 typedef uint32_t elf_word;
    195 typedef int32_t elf_sword;
    196 typedef uint16_t elf_half;
    197 
    198 /**
    199  * 32-bit ELF data types.
    200  *
    201  * These types are specific for 32-bit format.
    202  */
    203 typedef uint32_t elf32_addr;
    204 typedef uint32_t elf32_off;
    205 
    206 /**
    207  * 64-bit ELF data types.
    208  *
    209  * These types are specific for 64-bit format.
    210  */
    211 typedef uint64_t elf64_addr;
    212 typedef uint64_t elf64_off;
    213 
    214 /** ELF header */
    215 struct elf32_header {
    216         uint8_t e_ident[EI_NIDENT];
    217         elf_half e_type;
    218         elf_half e_machine;
    219         elf_word e_version;
    220         elf32_addr e_entry;
    221         elf32_off e_phoff;
    222         elf32_off e_shoff;
    223         elf_word e_flags;
    224         elf_half e_ehsize;
    225         elf_half e_phentsize;
    226         elf_half e_phnum;
    227         elf_half e_shentsize;
    228         elf_half e_shnum;
    229         elf_half e_shstrndx;
    230 };
    231 struct elf64_header {
    232         uint8_t e_ident[EI_NIDENT];
    233         elf_half e_type;
    234         elf_half e_machine;
    235         elf_word e_version;
    236         elf64_addr e_entry;
    237         elf64_off e_phoff;
    238         elf64_off e_shoff;
    239         elf_word e_flags;
    240         elf_half e_ehsize;
    241         elf_half e_phentsize;
    242         elf_half e_phnum;
    243         elf_half e_shentsize;
    244         elf_half e_shnum;
    245         elf_half e_shstrndx;
    246 };
    247 
    248 /*
    249  * ELF segment header.
    250  * Segments headers are also known as program headers.
    251  */
    252 struct elf32_segment_header {
    253         elf_word p_type;
    254         elf32_off p_offset;
    255         elf32_addr p_vaddr;
    256         elf32_addr p_paddr;
    257         elf_word p_filesz;
    258         elf_word p_memsz;
    259         elf_word p_flags;
    260         elf_word p_align;
    261 };
    262 struct elf64_segment_header {
    263         elf_word p_type;
    264         elf_word p_flags;
    265         elf64_off p_offset;
    266         elf64_addr p_vaddr;
    267         elf64_addr p_paddr;
    268         elf_xword p_filesz;
    269         elf_xword p_memsz;
    270         elf_xword p_align;
    271 };
    272 
    273 /*
    274  * ELF section header
    275  */
    276 struct elf32_section_header {
    277         elf_word sh_name;
    278         elf_word sh_type;
    279         elf_word sh_flags;
    280         elf32_addr sh_addr;
    281         elf32_off sh_offset;
    282         elf_word sh_size;
    283         elf_word sh_link;
    284         elf_word sh_info;
    285         elf_word sh_addralign;
    286         elf_word sh_entsize;
    287 };
    288 struct elf64_section_header {
    289         elf_word sh_name;
    290         elf_word sh_type;
    291         elf_xword sh_flags;
    292         elf64_addr sh_addr;
    293         elf64_off sh_offset;
    294         elf_xword sh_size;
    295         elf_word sh_link;
    296         elf_word sh_info;
    297         elf_xword sh_addralign;
    298         elf_xword sh_entsize;
    299 };
    300 
    301 /*
    302  * ELF symbol table entry
    303  */
    304 struct elf32_symbol {
    305         elf_word st_name;
    306         elf32_addr st_value;
    307         elf_word st_size;
    308         uint8_t st_info;
    309         uint8_t st_other;
    310         elf_half st_shndx;
    311 };
    312 struct elf64_symbol {
    313         elf_word st_name;
    314         uint8_t st_info;
    315         uint8_t st_other;
    316         elf_half st_shndx;
    317         elf64_addr st_value;
    318         elf_xword st_size;
    319 };
    320 
    321 /*
    322  * ELF note segment entry
    323  */
    324 struct elf32_note {
    325         elf_word namesz;
    326         elf_word descsz;
    327         elf_word type;
    328 };
    329 struct elf64_note {
    330         elf_xword namesz;
    331         elf_xword descsz;
    332         elf_xword type;
    333 };
    334 
    335 #ifdef __32_BITS__
    336 typedef struct elf32_header elf_header_t;
    337 typedef struct elf32_segment_header elf_segment_header_t;
    338 typedef struct elf32_section_header elf_section_header_t;
    339 typedef struct elf32_symbol elf_symbol_t;
    340 typedef struct elf32_note elf_note_t;
    341 #endif
    342 #ifdef __64_BITS__
    343 typedef struct elf64_header elf_header_t;
    344 typedef struct elf64_segment_header elf_segment_header_t;
    345 typedef struct elf64_section_header elf_section_header_t;
    346 typedef struct elf64_symbol elf_symbol_t;
    347 typedef struct elf64_note elf_note_t;
    348 #endif
    34941
    35042/** Interpreter string used to recognize the program loader */
Note: See TracChangeset for help on using the changeset viewer.