[BACK]Return to readelf.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / file

Annotation of src/usr.bin/file/readelf.h, Revision 1.4

1.2       ian         1: /*     $NetBSD: readelf.h,v 1.9 2002/05/18 07:00:47 pooka Exp $        */
1.1       millert     2:
                      3: /*
                      4:  * readelf.h
1.2       ian         5:  * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp
1.1       millert     6:  *
                      7:  * Provide elf data structures for non-elf machines, allowing file
                      8:  * non-elf hosts to determine if an elf binary is stripped.
                      9:  * Note: cobbled from the linux header file, with modifications
1.3       ian        10:  *
                     11:  * Copyright (c) Ian F. Darwin 1986-1995.
                     12:  * Software written by Ian F. Darwin and others;
                     13:  * maintained 1995-present by Christos Zoulas and others.
                     14:  *
                     15:  * Redistribution and use in source and binary forms, with or without
                     16:  * modification, are permitted provided that the following conditions
                     17:  * are met:
                     18:  * 1. Redistributions of source code must retain the above copyright
                     19:  *    notice immediately at the beginning of the file, without modification,
                     20:  *    this list of conditions, and the following disclaimer.
                     21:  * 2. Redistributions in binary form must reproduce the above copyright
                     22:  *    notice, this list of conditions and the following disclaimer in the
                     23:  *    documentation and/or other materials provided with the distribution.
                     24:  *
                     25:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     28:  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
                     29:  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     35:  * SUCH DAMAGE.
1.1       millert    36:  */
1.3       ian        37:
1.1       millert    38: #ifndef __fake_elf_h__
                     39: #define __fake_elf_h__
                     40:
1.2       ian        41: #if HAVE_STDINT_H
                     42: #include <stdint.h>
                     43: #endif
                     44:
                     45: typedef uint32_t       Elf32_Addr;
                     46: typedef uint32_t       Elf32_Off;
                     47: typedef uint16_t       Elf32_Half;
                     48: typedef uint32_t       Elf32_Word;
                     49: typedef uint8_t                Elf32_Char;
                     50:
                     51: #if SIZEOF_UINT64_T != 8
                     52: #define USE_ARRAY_FOR_64BIT_TYPES
                     53: typedef        uint32_t        Elf64_Addr[2];
                     54: typedef        uint32_t        Elf64_Off[2];
                     55: typedef uint32_t       Elf64_Xword[2];
                     56: #else
                     57: typedef        uint64_t        Elf64_Addr;
                     58: typedef        uint64_t        Elf64_Off;
                     59: typedef uint64_t       Elf64_Xword;
                     60: #endif
                     61: typedef uint16_t       Elf64_Half;
                     62: typedef uint32_t       Elf64_Word;
                     63: typedef uint8_t                Elf64_Char;
1.1       millert    64:
                     65: #define EI_NIDENT      16
                     66:
                     67: typedef struct {
                     68:     Elf32_Char e_ident[EI_NIDENT];
                     69:     Elf32_Half e_type;
                     70:     Elf32_Half e_machine;
                     71:     Elf32_Word e_version;
                     72:     Elf32_Addr e_entry;  /* Entry point */
                     73:     Elf32_Off  e_phoff;
                     74:     Elf32_Off  e_shoff;
                     75:     Elf32_Word e_flags;
                     76:     Elf32_Half e_ehsize;
                     77:     Elf32_Half e_phentsize;
                     78:     Elf32_Half e_phnum;
                     79:     Elf32_Half e_shentsize;
                     80:     Elf32_Half e_shnum;
                     81:     Elf32_Half e_shstrndx;
                     82: } Elf32_Ehdr;
                     83:
                     84: typedef struct {
                     85:     Elf64_Char e_ident[EI_NIDENT];
                     86:     Elf64_Half e_type;
                     87:     Elf64_Half e_machine;
                     88:     Elf64_Word e_version;
                     89:     Elf64_Addr e_entry;  /* Entry point */
                     90:     Elf64_Off  e_phoff;
                     91:     Elf64_Off  e_shoff;
                     92:     Elf64_Word e_flags;
                     93:     Elf64_Half e_ehsize;
                     94:     Elf64_Half e_phentsize;
                     95:     Elf64_Half e_phnum;
                     96:     Elf64_Half e_shentsize;
                     97:     Elf64_Half e_shnum;
                     98:     Elf64_Half e_shstrndx;
                     99: } Elf64_Ehdr;
                    100:
                    101: /* e_type */
                    102: #define ET_EXEC                2
                    103: #define ET_CORE                4
                    104:
                    105: /* sh_type */
                    106: #define SHT_SYMTAB     2
                    107: #define SHT_NOTE       7
1.2       ian       108: #define SHT_DYNSYM     11
1.1       millert   109:
                    110: /* elf type */
                    111: #define ELFDATANONE    0               /* e_ident[EI_DATA] */
                    112: #define ELFDATA2LSB    1
                    113: #define ELFDATA2MSB    2
                    114:
                    115: /* elf class */
                    116: #define ELFCLASSNONE   0
                    117: #define ELFCLASS32     1
                    118: #define ELFCLASS64     2
                    119:
                    120: /* magic number */
                    121: #define        EI_MAG0         0               /* e_ident[] indexes */
                    122: #define        EI_MAG1         1
                    123: #define        EI_MAG2         2
                    124: #define        EI_MAG3         3
                    125: #define        EI_CLASS        4
                    126: #define        EI_DATA         5
                    127: #define        EI_VERSION      6
                    128: #define        EI_PAD          7
                    129:
                    130: #define        ELFMAG0         0x7f            /* EI_MAG */
                    131: #define        ELFMAG1         'E'
                    132: #define        ELFMAG2         'L'
                    133: #define        ELFMAG3         'F'
                    134: #define        ELFMAG          "\177ELF"
                    135:
1.2       ian       136: #define        OLFMAG1         'O'
                    137: #define        OLFMAG          "\177OLF"
                    138:
1.1       millert   139: typedef struct {
                    140:     Elf32_Word p_type;
                    141:     Elf32_Off  p_offset;
                    142:     Elf32_Addr p_vaddr;
                    143:     Elf32_Addr p_paddr;
                    144:     Elf32_Word p_filesz;
                    145:     Elf32_Word p_memsz;
                    146:     Elf32_Word p_flags;
                    147:     Elf32_Word p_align;
                    148: } Elf32_Phdr;
                    149:
1.2       ian       150: typedef struct {
                    151:     Elf64_Word p_type;
                    152:     Elf64_Word p_flags;
                    153:     Elf64_Off  p_offset;
                    154:     Elf64_Addr p_vaddr;
                    155:     Elf64_Addr p_paddr;
                    156:     Elf64_Xword        p_filesz;
                    157:     Elf64_Xword        p_memsz;
                    158:     Elf64_Xword        p_align;
                    159: } Elf64_Phdr;
                    160:
1.1       millert   161: #define        PT_NULL         0               /* p_type */
                    162: #define        PT_LOAD         1
                    163: #define        PT_DYNAMIC      2
                    164: #define        PT_INTERP       3
                    165: #define        PT_NOTE         4
                    166: #define        PT_SHLIB        5
                    167: #define        PT_PHDR         6
                    168: #define        PT_NUM          7
                    169:
                    170: typedef struct {
                    171:     Elf32_Word sh_name;
                    172:     Elf32_Word sh_type;
                    173:     Elf32_Word sh_flags;
                    174:     Elf32_Addr sh_addr;
                    175:     Elf32_Off  sh_offset;
                    176:     Elf32_Word sh_size;
                    177:     Elf32_Word sh_link;
                    178:     Elf32_Word sh_info;
                    179:     Elf32_Word sh_addralign;
                    180:     Elf32_Word sh_entsize;
                    181: } Elf32_Shdr;
                    182:
                    183: typedef struct {
                    184:     Elf64_Word sh_name;
                    185:     Elf64_Word sh_type;
                    186:     Elf64_Off  sh_flags;
                    187:     Elf64_Addr sh_addr;
                    188:     Elf64_Off  sh_offset;
                    189:     Elf64_Off  sh_size;
                    190:     Elf64_Word sh_link;
                    191:     Elf64_Word sh_info;
                    192:     Elf64_Off  sh_addralign;
                    193:     Elf64_Off  sh_entsize;
                    194: } Elf64_Shdr;
                    195:
                    196: /* Notes used in ET_CORE */
                    197: #define NT_PRSTATUS    1
                    198: #define NT_PRFPREG     2
                    199: #define NT_PRPSINFO    3
                    200: #define NT_TASKSTRUCT  4
                    201:
1.2       ian       202: #define        NT_NETBSD_CORE_PROCINFO         1
                    203:
1.1       millert   204: /* Note header in a PT_NOTE section */
                    205: typedef struct elf_note {
1.2       ian       206:     Elf32_Word n_namesz;       /* Name size */
                    207:     Elf32_Word n_descsz;       /* Content size */
                    208:     Elf32_Word n_type;         /* Content type */
1.1       millert   209: } Elf32_Nhdr;
                    210:
                    211: typedef struct {
                    212:     Elf64_Word n_namesz;
                    213:     Elf64_Word n_descsz;
                    214:     Elf64_Word n_type;
                    215: } Elf64_Nhdr;
                    216:
                    217: #define        NT_PRSTATUS     1
                    218: #define        NT_PRFPREG      2
                    219: #define        NT_PRPSINFO     3
                    220: #define        NT_PRXREG       4
                    221: #define        NT_PLATFORM     5
                    222: #define        NT_AUXV         6
1.2       ian       223:
                    224: /* Note types used in executables */
                    225: /* NetBSD executables (name = "NetBSD") */
                    226: #define NT_NETBSD_VERSION      1
                    227: #define NT_NETBSD_EMULATION    2
                    228: #define NT_FREEBSD_VERSION     1
                    229: #define NT_OPENBSD_VERSION     1
                    230: /* GNU executables (name = "GNU") */
                    231: #define NT_GNU_VERSION         1
                    232:
                    233: /* GNU OS tags */
                    234: #define GNU_OS_LINUX   0
                    235: #define GNU_OS_HURD    1
                    236: #define GNU_OS_SOLARIS 2
1.1       millert   237:
                    238: #endif