1*199767f8SToomas Soome /*- 2*199767f8SToomas Soome * Copyright (c) 1996-1998 John D. Polstra. 3*199767f8SToomas Soome * All rights reserved. 4*199767f8SToomas Soome * 5*199767f8SToomas Soome * Redistribution and use in source and binary forms, with or without 6*199767f8SToomas Soome * modification, are permitted provided that the following conditions 7*199767f8SToomas Soome * are met: 8*199767f8SToomas Soome * 1. Redistributions of source code must retain the above copyright 9*199767f8SToomas Soome * notice, this list of conditions and the following disclaimer. 10*199767f8SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 11*199767f8SToomas Soome * notice, this list of conditions and the following disclaimer in the 12*199767f8SToomas Soome * documentation and/or other materials provided with the distribution. 13*199767f8SToomas Soome * 14*199767f8SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*199767f8SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*199767f8SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*199767f8SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*199767f8SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*199767f8SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*199767f8SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*199767f8SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*199767f8SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*199767f8SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*199767f8SToomas Soome * SUCH DAMAGE. 25*199767f8SToomas Soome * 26*199767f8SToomas Soome * $FreeBSD$ 27*199767f8SToomas Soome */ 28*199767f8SToomas Soome 29*199767f8SToomas Soome #ifndef _SYS_ELF32_H_ 30*199767f8SToomas Soome #define _SYS_ELF32_H_ 1 31*199767f8SToomas Soome 32*199767f8SToomas Soome #include <sys/elf_common.h> 33*199767f8SToomas Soome 34*199767f8SToomas Soome /* 35*199767f8SToomas Soome * ELF definitions common to all 32-bit architectures. 36*199767f8SToomas Soome */ 37*199767f8SToomas Soome 38*199767f8SToomas Soome typedef uint32_t Elf32_Addr; 39*199767f8SToomas Soome typedef uint16_t Elf32_Half; 40*199767f8SToomas Soome typedef uint32_t Elf32_Off; 41*199767f8SToomas Soome typedef int32_t Elf32_Sword; 42*199767f8SToomas Soome typedef uint32_t Elf32_Word; 43*199767f8SToomas Soome typedef uint64_t Elf32_Lword; 44*199767f8SToomas Soome 45*199767f8SToomas Soome typedef Elf32_Word Elf32_Hashelt; 46*199767f8SToomas Soome 47*199767f8SToomas Soome /* Non-standard class-dependent datatype used for abstraction. */ 48*199767f8SToomas Soome typedef Elf32_Word Elf32_Size; 49*199767f8SToomas Soome typedef Elf32_Sword Elf32_Ssize; 50*199767f8SToomas Soome 51*199767f8SToomas Soome /* 52*199767f8SToomas Soome * ELF header. 53*199767f8SToomas Soome */ 54*199767f8SToomas Soome 55*199767f8SToomas Soome typedef struct { 56*199767f8SToomas Soome unsigned char e_ident[EI_NIDENT]; /* File identification. */ 57*199767f8SToomas Soome Elf32_Half e_type; /* File type. */ 58*199767f8SToomas Soome Elf32_Half e_machine; /* Machine architecture. */ 59*199767f8SToomas Soome Elf32_Word e_version; /* ELF format version. */ 60*199767f8SToomas Soome Elf32_Addr e_entry; /* Entry point. */ 61*199767f8SToomas Soome Elf32_Off e_phoff; /* Program header file offset. */ 62*199767f8SToomas Soome Elf32_Off e_shoff; /* Section header file offset. */ 63*199767f8SToomas Soome Elf32_Word e_flags; /* Architecture-specific flags. */ 64*199767f8SToomas Soome Elf32_Half e_ehsize; /* Size of ELF header in bytes. */ 65*199767f8SToomas Soome Elf32_Half e_phentsize; /* Size of program header entry. */ 66*199767f8SToomas Soome Elf32_Half e_phnum; /* Number of program header entries. */ 67*199767f8SToomas Soome Elf32_Half e_shentsize; /* Size of section header entry. */ 68*199767f8SToomas Soome Elf32_Half e_shnum; /* Number of section header entries. */ 69*199767f8SToomas Soome Elf32_Half e_shstrndx; /* Section name strings section. */ 70*199767f8SToomas Soome } Elf32_Ehdr; 71*199767f8SToomas Soome 72*199767f8SToomas Soome /* 73*199767f8SToomas Soome * Shared object information, found in SHT_MIPS_LIBLIST. 74*199767f8SToomas Soome */ 75*199767f8SToomas Soome 76*199767f8SToomas Soome typedef struct { 77*199767f8SToomas Soome Elf32_Word l_name; /* The name of a shared object. */ 78*199767f8SToomas Soome Elf32_Word l_time_stamp; /* 32-bit timestamp. */ 79*199767f8SToomas Soome Elf32_Word l_checksum; /* Checksum of visible symbols, sizes. */ 80*199767f8SToomas Soome Elf32_Word l_version; /* Interface version string index. */ 81*199767f8SToomas Soome Elf32_Word l_flags; /* Flags (LL_*). */ 82*199767f8SToomas Soome } Elf32_Lib; 83*199767f8SToomas Soome 84*199767f8SToomas Soome /* 85*199767f8SToomas Soome * Section header. 86*199767f8SToomas Soome */ 87*199767f8SToomas Soome 88*199767f8SToomas Soome typedef struct { 89*199767f8SToomas Soome Elf32_Word sh_name; /* Section name (index into the 90*199767f8SToomas Soome section header string table). */ 91*199767f8SToomas Soome Elf32_Word sh_type; /* Section type. */ 92*199767f8SToomas Soome Elf32_Word sh_flags; /* Section flags. */ 93*199767f8SToomas Soome Elf32_Addr sh_addr; /* Address in memory image. */ 94*199767f8SToomas Soome Elf32_Off sh_offset; /* Offset in file. */ 95*199767f8SToomas Soome Elf32_Word sh_size; /* Size in bytes. */ 96*199767f8SToomas Soome Elf32_Word sh_link; /* Index of a related section. */ 97*199767f8SToomas Soome Elf32_Word sh_info; /* Depends on section type. */ 98*199767f8SToomas Soome Elf32_Word sh_addralign; /* Alignment in bytes. */ 99*199767f8SToomas Soome Elf32_Word sh_entsize; /* Size of each entry in section. */ 100*199767f8SToomas Soome } Elf32_Shdr; 101*199767f8SToomas Soome 102*199767f8SToomas Soome /* 103*199767f8SToomas Soome * Program header. 104*199767f8SToomas Soome */ 105*199767f8SToomas Soome 106*199767f8SToomas Soome typedef struct { 107*199767f8SToomas Soome Elf32_Word p_type; /* Entry type. */ 108*199767f8SToomas Soome Elf32_Off p_offset; /* File offset of contents. */ 109*199767f8SToomas Soome Elf32_Addr p_vaddr; /* Virtual address in memory image. */ 110*199767f8SToomas Soome Elf32_Addr p_paddr; /* Physical address (not used). */ 111*199767f8SToomas Soome Elf32_Word p_filesz; /* Size of contents in file. */ 112*199767f8SToomas Soome Elf32_Word p_memsz; /* Size of contents in memory. */ 113*199767f8SToomas Soome Elf32_Word p_flags; /* Access permission flags. */ 114*199767f8SToomas Soome Elf32_Word p_align; /* Alignment in memory and file. */ 115*199767f8SToomas Soome } Elf32_Phdr; 116*199767f8SToomas Soome 117*199767f8SToomas Soome /* 118*199767f8SToomas Soome * Dynamic structure. The ".dynamic" section contains an array of them. 119*199767f8SToomas Soome */ 120*199767f8SToomas Soome 121*199767f8SToomas Soome typedef struct { 122*199767f8SToomas Soome Elf32_Sword d_tag; /* Entry type. */ 123*199767f8SToomas Soome union { 124*199767f8SToomas Soome Elf32_Word d_val; /* Integer value. */ 125*199767f8SToomas Soome Elf32_Addr d_ptr; /* Address value. */ 126*199767f8SToomas Soome } d_un; 127*199767f8SToomas Soome } Elf32_Dyn; 128*199767f8SToomas Soome 129*199767f8SToomas Soome /* 130*199767f8SToomas Soome * Relocation entries. 131*199767f8SToomas Soome */ 132*199767f8SToomas Soome 133*199767f8SToomas Soome /* Relocations that don't need an addend field. */ 134*199767f8SToomas Soome typedef struct { 135*199767f8SToomas Soome Elf32_Addr r_offset; /* Location to be relocated. */ 136*199767f8SToomas Soome Elf32_Word r_info; /* Relocation type and symbol index. */ 137*199767f8SToomas Soome } Elf32_Rel; 138*199767f8SToomas Soome 139*199767f8SToomas Soome /* Relocations that need an addend field. */ 140*199767f8SToomas Soome typedef struct { 141*199767f8SToomas Soome Elf32_Addr r_offset; /* Location to be relocated. */ 142*199767f8SToomas Soome Elf32_Word r_info; /* Relocation type and symbol index. */ 143*199767f8SToomas Soome Elf32_Sword r_addend; /* Addend. */ 144*199767f8SToomas Soome } Elf32_Rela; 145*199767f8SToomas Soome 146*199767f8SToomas Soome /* Macros for accessing the fields of r_info. */ 147*199767f8SToomas Soome #define ELF32_R_SYM(info) ((info) >> 8) 148*199767f8SToomas Soome #define ELF32_R_TYPE(info) ((unsigned char)(info)) 149*199767f8SToomas Soome 150*199767f8SToomas Soome /* Macro for constructing r_info from field values. */ 151*199767f8SToomas Soome #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) 152*199767f8SToomas Soome 153*199767f8SToomas Soome /* 154*199767f8SToomas Soome * Note entry header 155*199767f8SToomas Soome */ 156*199767f8SToomas Soome typedef Elf_Note Elf32_Nhdr; 157*199767f8SToomas Soome 158*199767f8SToomas Soome /* 159*199767f8SToomas Soome * Move entry 160*199767f8SToomas Soome */ 161*199767f8SToomas Soome typedef struct { 162*199767f8SToomas Soome Elf32_Lword m_value; /* symbol value */ 163*199767f8SToomas Soome Elf32_Word m_info; /* size + index */ 164*199767f8SToomas Soome Elf32_Word m_poffset; /* symbol offset */ 165*199767f8SToomas Soome Elf32_Half m_repeat; /* repeat count */ 166*199767f8SToomas Soome Elf32_Half m_stride; /* stride info */ 167*199767f8SToomas Soome } Elf32_Move; 168*199767f8SToomas Soome 169*199767f8SToomas Soome /* 170*199767f8SToomas Soome * The macros compose and decompose values for Move.r_info 171*199767f8SToomas Soome * 172*199767f8SToomas Soome * sym = ELF32_M_SYM(M.m_info) 173*199767f8SToomas Soome * size = ELF32_M_SIZE(M.m_info) 174*199767f8SToomas Soome * M.m_info = ELF32_M_INFO(sym, size) 175*199767f8SToomas Soome */ 176*199767f8SToomas Soome #define ELF32_M_SYM(info) ((info)>>8) 177*199767f8SToomas Soome #define ELF32_M_SIZE(info) ((unsigned char)(info)) 178*199767f8SToomas Soome #define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size)) 179*199767f8SToomas Soome 180*199767f8SToomas Soome /* 181*199767f8SToomas Soome * Hardware/Software capabilities entry 182*199767f8SToomas Soome */ 183*199767f8SToomas Soome typedef struct { 184*199767f8SToomas Soome Elf32_Word c_tag; /* how to interpret value */ 185*199767f8SToomas Soome union { 186*199767f8SToomas Soome Elf32_Word c_val; 187*199767f8SToomas Soome Elf32_Addr c_ptr; 188*199767f8SToomas Soome } c_un; 189*199767f8SToomas Soome } Elf32_Cap; 190*199767f8SToomas Soome 191*199767f8SToomas Soome /* 192*199767f8SToomas Soome * Symbol table entries. 193*199767f8SToomas Soome */ 194*199767f8SToomas Soome 195*199767f8SToomas Soome typedef struct { 196*199767f8SToomas Soome Elf32_Word st_name; /* String table index of name. */ 197*199767f8SToomas Soome Elf32_Addr st_value; /* Symbol value. */ 198*199767f8SToomas Soome Elf32_Word st_size; /* Size of associated object. */ 199*199767f8SToomas Soome unsigned char st_info; /* Type and binding information. */ 200*199767f8SToomas Soome unsigned char st_other; /* Reserved (not used). */ 201*199767f8SToomas Soome Elf32_Half st_shndx; /* Section index of symbol. */ 202*199767f8SToomas Soome } Elf32_Sym; 203*199767f8SToomas Soome 204*199767f8SToomas Soome /* Macros for accessing the fields of st_info. */ 205*199767f8SToomas Soome #define ELF32_ST_BIND(info) ((info) >> 4) 206*199767f8SToomas Soome #define ELF32_ST_TYPE(info) ((info) & 0xf) 207*199767f8SToomas Soome 208*199767f8SToomas Soome /* Macro for constructing st_info from field values. */ 209*199767f8SToomas Soome #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 210*199767f8SToomas Soome 211*199767f8SToomas Soome /* Macro for accessing the fields of st_other. */ 212*199767f8SToomas Soome #define ELF32_ST_VISIBILITY(oth) ((oth) & 0x3) 213*199767f8SToomas Soome 214*199767f8SToomas Soome /* Structures used by Sun & GNU symbol versioning. */ 215*199767f8SToomas Soome typedef struct 216*199767f8SToomas Soome { 217*199767f8SToomas Soome Elf32_Half vd_version; 218*199767f8SToomas Soome Elf32_Half vd_flags; 219*199767f8SToomas Soome Elf32_Half vd_ndx; 220*199767f8SToomas Soome Elf32_Half vd_cnt; 221*199767f8SToomas Soome Elf32_Word vd_hash; 222*199767f8SToomas Soome Elf32_Word vd_aux; 223*199767f8SToomas Soome Elf32_Word vd_next; 224*199767f8SToomas Soome } Elf32_Verdef; 225*199767f8SToomas Soome 226*199767f8SToomas Soome typedef struct 227*199767f8SToomas Soome { 228*199767f8SToomas Soome Elf32_Word vda_name; 229*199767f8SToomas Soome Elf32_Word vda_next; 230*199767f8SToomas Soome } Elf32_Verdaux; 231*199767f8SToomas Soome 232*199767f8SToomas Soome typedef struct 233*199767f8SToomas Soome { 234*199767f8SToomas Soome Elf32_Half vn_version; 235*199767f8SToomas Soome Elf32_Half vn_cnt; 236*199767f8SToomas Soome Elf32_Word vn_file; 237*199767f8SToomas Soome Elf32_Word vn_aux; 238*199767f8SToomas Soome Elf32_Word vn_next; 239*199767f8SToomas Soome } Elf32_Verneed; 240*199767f8SToomas Soome 241*199767f8SToomas Soome typedef struct 242*199767f8SToomas Soome { 243*199767f8SToomas Soome Elf32_Word vna_hash; 244*199767f8SToomas Soome Elf32_Half vna_flags; 245*199767f8SToomas Soome Elf32_Half vna_other; 246*199767f8SToomas Soome Elf32_Word vna_name; 247*199767f8SToomas Soome Elf32_Word vna_next; 248*199767f8SToomas Soome } Elf32_Vernaux; 249*199767f8SToomas Soome 250*199767f8SToomas Soome typedef Elf32_Half Elf32_Versym; 251*199767f8SToomas Soome 252*199767f8SToomas Soome typedef struct { 253*199767f8SToomas Soome Elf32_Half si_boundto; /* direct bindings - symbol bound to */ 254*199767f8SToomas Soome Elf32_Half si_flags; /* per symbol flags */ 255*199767f8SToomas Soome } Elf32_Syminfo; 256*199767f8SToomas Soome 257*199767f8SToomas Soome #endif /* !_SYS_ELF32_H_ */ 258