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_ELF64_H_ 30*199767f8SToomas Soome #define _SYS_ELF64_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 64-bit architectures. 36*199767f8SToomas Soome */ 37*199767f8SToomas Soome 38*199767f8SToomas Soome typedef uint64_t Elf64_Addr; 39*199767f8SToomas Soome typedef uint16_t Elf64_Half; 40*199767f8SToomas Soome typedef uint64_t Elf64_Off; 41*199767f8SToomas Soome typedef int32_t Elf64_Sword; 42*199767f8SToomas Soome typedef int64_t Elf64_Sxword; 43*199767f8SToomas Soome typedef uint32_t Elf64_Word; 44*199767f8SToomas Soome typedef uint64_t Elf64_Lword; 45*199767f8SToomas Soome typedef uint64_t Elf64_Xword; 46*199767f8SToomas Soome 47*199767f8SToomas Soome /* 48*199767f8SToomas Soome * Types of dynamic symbol hash table bucket and chain elements. 49*199767f8SToomas Soome * 50*199767f8SToomas Soome * This is inconsistent among 64 bit architectures, so a machine dependent 51*199767f8SToomas Soome * typedef is required. 52*199767f8SToomas Soome */ 53*199767f8SToomas Soome 54*199767f8SToomas Soome typedef Elf64_Word Elf64_Hashelt; 55*199767f8SToomas Soome 56*199767f8SToomas Soome /* Non-standard class-dependent datatype used for abstraction. */ 57*199767f8SToomas Soome typedef Elf64_Xword Elf64_Size; 58*199767f8SToomas Soome typedef Elf64_Sxword Elf64_Ssize; 59*199767f8SToomas Soome 60*199767f8SToomas Soome /* 61*199767f8SToomas Soome * ELF header. 62*199767f8SToomas Soome */ 63*199767f8SToomas Soome 64*199767f8SToomas Soome typedef struct { 65*199767f8SToomas Soome unsigned char e_ident[EI_NIDENT]; /* File identification. */ 66*199767f8SToomas Soome Elf64_Half e_type; /* File type. */ 67*199767f8SToomas Soome Elf64_Half e_machine; /* Machine architecture. */ 68*199767f8SToomas Soome Elf64_Word e_version; /* ELF format version. */ 69*199767f8SToomas Soome Elf64_Addr e_entry; /* Entry point. */ 70*199767f8SToomas Soome Elf64_Off e_phoff; /* Program header file offset. */ 71*199767f8SToomas Soome Elf64_Off e_shoff; /* Section header file offset. */ 72*199767f8SToomas Soome Elf64_Word e_flags; /* Architecture-specific flags. */ 73*199767f8SToomas Soome Elf64_Half e_ehsize; /* Size of ELF header in bytes. */ 74*199767f8SToomas Soome Elf64_Half e_phentsize; /* Size of program header entry. */ 75*199767f8SToomas Soome Elf64_Half e_phnum; /* Number of program header entries. */ 76*199767f8SToomas Soome Elf64_Half e_shentsize; /* Size of section header entry. */ 77*199767f8SToomas Soome Elf64_Half e_shnum; /* Number of section header entries. */ 78*199767f8SToomas Soome Elf64_Half e_shstrndx; /* Section name strings section. */ 79*199767f8SToomas Soome } Elf64_Ehdr; 80*199767f8SToomas Soome 81*199767f8SToomas Soome /* 82*199767f8SToomas Soome * Shared object information, found in SHT_MIPS_LIBLIST. 83*199767f8SToomas Soome */ 84*199767f8SToomas Soome 85*199767f8SToomas Soome typedef struct { 86*199767f8SToomas Soome Elf64_Word l_name; /* The name of a shared object. */ 87*199767f8SToomas Soome Elf64_Word l_time_stamp; /* 64-bit timestamp. */ 88*199767f8SToomas Soome Elf64_Word l_checksum; /* Checksum of visible symbols, sizes. */ 89*199767f8SToomas Soome Elf64_Word l_version; /* Interface version string index. */ 90*199767f8SToomas Soome Elf64_Word l_flags; /* Flags (LL_*). */ 91*199767f8SToomas Soome } Elf64_Lib; 92*199767f8SToomas Soome 93*199767f8SToomas Soome /* 94*199767f8SToomas Soome * Section header. 95*199767f8SToomas Soome */ 96*199767f8SToomas Soome 97*199767f8SToomas Soome typedef struct { 98*199767f8SToomas Soome Elf64_Word sh_name; /* Section name (index into the 99*199767f8SToomas Soome section header string table). */ 100*199767f8SToomas Soome Elf64_Word sh_type; /* Section type. */ 101*199767f8SToomas Soome Elf64_Xword sh_flags; /* Section flags. */ 102*199767f8SToomas Soome Elf64_Addr sh_addr; /* Address in memory image. */ 103*199767f8SToomas Soome Elf64_Off sh_offset; /* Offset in file. */ 104*199767f8SToomas Soome Elf64_Xword sh_size; /* Size in bytes. */ 105*199767f8SToomas Soome Elf64_Word sh_link; /* Index of a related section. */ 106*199767f8SToomas Soome Elf64_Word sh_info; /* Depends on section type. */ 107*199767f8SToomas Soome Elf64_Xword sh_addralign; /* Alignment in bytes. */ 108*199767f8SToomas Soome Elf64_Xword sh_entsize; /* Size of each entry in section. */ 109*199767f8SToomas Soome } Elf64_Shdr; 110*199767f8SToomas Soome 111*199767f8SToomas Soome /* 112*199767f8SToomas Soome * Program header. 113*199767f8SToomas Soome */ 114*199767f8SToomas Soome 115*199767f8SToomas Soome typedef struct { 116*199767f8SToomas Soome Elf64_Word p_type; /* Entry type. */ 117*199767f8SToomas Soome Elf64_Word p_flags; /* Access permission flags. */ 118*199767f8SToomas Soome Elf64_Off p_offset; /* File offset of contents. */ 119*199767f8SToomas Soome Elf64_Addr p_vaddr; /* Virtual address in memory image. */ 120*199767f8SToomas Soome Elf64_Addr p_paddr; /* Physical address (not used). */ 121*199767f8SToomas Soome Elf64_Xword p_filesz; /* Size of contents in file. */ 122*199767f8SToomas Soome Elf64_Xword p_memsz; /* Size of contents in memory. */ 123*199767f8SToomas Soome Elf64_Xword p_align; /* Alignment in memory and file. */ 124*199767f8SToomas Soome } Elf64_Phdr; 125*199767f8SToomas Soome 126*199767f8SToomas Soome /* 127*199767f8SToomas Soome * Dynamic structure. The ".dynamic" section contains an array of them. 128*199767f8SToomas Soome */ 129*199767f8SToomas Soome 130*199767f8SToomas Soome typedef struct { 131*199767f8SToomas Soome Elf64_Sxword d_tag; /* Entry type. */ 132*199767f8SToomas Soome union { 133*199767f8SToomas Soome Elf64_Xword d_val; /* Integer value. */ 134*199767f8SToomas Soome Elf64_Addr d_ptr; /* Address value. */ 135*199767f8SToomas Soome } d_un; 136*199767f8SToomas Soome } Elf64_Dyn; 137*199767f8SToomas Soome 138*199767f8SToomas Soome /* 139*199767f8SToomas Soome * Relocation entries. 140*199767f8SToomas Soome */ 141*199767f8SToomas Soome 142*199767f8SToomas Soome /* Relocations that don't need an addend field. */ 143*199767f8SToomas Soome typedef struct { 144*199767f8SToomas Soome Elf64_Addr r_offset; /* Location to be relocated. */ 145*199767f8SToomas Soome Elf64_Xword r_info; /* Relocation type and symbol index. */ 146*199767f8SToomas Soome } Elf64_Rel; 147*199767f8SToomas Soome 148*199767f8SToomas Soome /* Relocations that need an addend field. */ 149*199767f8SToomas Soome typedef struct { 150*199767f8SToomas Soome Elf64_Addr r_offset; /* Location to be relocated. */ 151*199767f8SToomas Soome Elf64_Xword r_info; /* Relocation type and symbol index. */ 152*199767f8SToomas Soome Elf64_Sxword r_addend; /* Addend. */ 153*199767f8SToomas Soome } Elf64_Rela; 154*199767f8SToomas Soome 155*199767f8SToomas Soome /* Macros for accessing the fields of r_info. */ 156*199767f8SToomas Soome #define ELF64_R_SYM(info) ((info) >> 32) 157*199767f8SToomas Soome #define ELF64_R_TYPE(info) ((info) & 0xffffffffL) 158*199767f8SToomas Soome 159*199767f8SToomas Soome /* Macro for constructing r_info from field values. */ 160*199767f8SToomas Soome #define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL)) 161*199767f8SToomas Soome 162*199767f8SToomas Soome #define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40) 163*199767f8SToomas Soome #define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info)<<56)>>56) 164*199767f8SToomas Soome #define ELF64_R_TYPE_INFO(data, type) \ 165*199767f8SToomas Soome (((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type)) 166*199767f8SToomas Soome 167*199767f8SToomas Soome /* 168*199767f8SToomas Soome * Note entry header 169*199767f8SToomas Soome */ 170*199767f8SToomas Soome typedef Elf_Note Elf64_Nhdr; 171*199767f8SToomas Soome 172*199767f8SToomas Soome /* 173*199767f8SToomas Soome * Move entry 174*199767f8SToomas Soome */ 175*199767f8SToomas Soome typedef struct { 176*199767f8SToomas Soome Elf64_Lword m_value; /* symbol value */ 177*199767f8SToomas Soome Elf64_Xword m_info; /* size + index */ 178*199767f8SToomas Soome Elf64_Xword m_poffset; /* symbol offset */ 179*199767f8SToomas Soome Elf64_Half m_repeat; /* repeat count */ 180*199767f8SToomas Soome Elf64_Half m_stride; /* stride info */ 181*199767f8SToomas Soome } Elf64_Move; 182*199767f8SToomas Soome 183*199767f8SToomas Soome #define ELF64_M_SYM(info) ((info)>>8) 184*199767f8SToomas Soome #define ELF64_M_SIZE(info) ((unsigned char)(info)) 185*199767f8SToomas Soome #define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size)) 186*199767f8SToomas Soome 187*199767f8SToomas Soome /* 188*199767f8SToomas Soome * Hardware/Software capabilities entry 189*199767f8SToomas Soome */ 190*199767f8SToomas Soome typedef struct { 191*199767f8SToomas Soome Elf64_Xword c_tag; /* how to interpret value */ 192*199767f8SToomas Soome union { 193*199767f8SToomas Soome Elf64_Xword c_val; 194*199767f8SToomas Soome Elf64_Addr c_ptr; 195*199767f8SToomas Soome } c_un; 196*199767f8SToomas Soome } Elf64_Cap; 197*199767f8SToomas Soome 198*199767f8SToomas Soome /* 199*199767f8SToomas Soome * Symbol table entries. 200*199767f8SToomas Soome */ 201*199767f8SToomas Soome 202*199767f8SToomas Soome typedef struct { 203*199767f8SToomas Soome Elf64_Word st_name; /* String table index of name. */ 204*199767f8SToomas Soome unsigned char st_info; /* Type and binding information. */ 205*199767f8SToomas Soome unsigned char st_other; /* Reserved (not used). */ 206*199767f8SToomas Soome Elf64_Half st_shndx; /* Section index of symbol. */ 207*199767f8SToomas Soome Elf64_Addr st_value; /* Symbol value. */ 208*199767f8SToomas Soome Elf64_Xword st_size; /* Size of associated object. */ 209*199767f8SToomas Soome } Elf64_Sym; 210*199767f8SToomas Soome 211*199767f8SToomas Soome /* Macros for accessing the fields of st_info. */ 212*199767f8SToomas Soome #define ELF64_ST_BIND(info) ((info) >> 4) 213*199767f8SToomas Soome #define ELF64_ST_TYPE(info) ((info) & 0xf) 214*199767f8SToomas Soome 215*199767f8SToomas Soome /* Macro for constructing st_info from field values. */ 216*199767f8SToomas Soome #define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 217*199767f8SToomas Soome 218*199767f8SToomas Soome /* Macro for accessing the fields of st_other. */ 219*199767f8SToomas Soome #define ELF64_ST_VISIBILITY(oth) ((oth) & 0x3) 220*199767f8SToomas Soome 221*199767f8SToomas Soome /* Structures used by Sun & GNU-style symbol versioning. */ 222*199767f8SToomas Soome typedef struct { 223*199767f8SToomas Soome Elf64_Half vd_version; 224*199767f8SToomas Soome Elf64_Half vd_flags; 225*199767f8SToomas Soome Elf64_Half vd_ndx; 226*199767f8SToomas Soome Elf64_Half vd_cnt; 227*199767f8SToomas Soome Elf64_Word vd_hash; 228*199767f8SToomas Soome Elf64_Word vd_aux; 229*199767f8SToomas Soome Elf64_Word vd_next; 230*199767f8SToomas Soome } Elf64_Verdef; 231*199767f8SToomas Soome 232*199767f8SToomas Soome typedef struct { 233*199767f8SToomas Soome Elf64_Word vda_name; 234*199767f8SToomas Soome Elf64_Word vda_next; 235*199767f8SToomas Soome } Elf64_Verdaux; 236*199767f8SToomas Soome 237*199767f8SToomas Soome typedef struct { 238*199767f8SToomas Soome Elf64_Half vn_version; 239*199767f8SToomas Soome Elf64_Half vn_cnt; 240*199767f8SToomas Soome Elf64_Word vn_file; 241*199767f8SToomas Soome Elf64_Word vn_aux; 242*199767f8SToomas Soome Elf64_Word vn_next; 243*199767f8SToomas Soome } Elf64_Verneed; 244*199767f8SToomas Soome 245*199767f8SToomas Soome typedef struct { 246*199767f8SToomas Soome Elf64_Word vna_hash; 247*199767f8SToomas Soome Elf64_Half vna_flags; 248*199767f8SToomas Soome Elf64_Half vna_other; 249*199767f8SToomas Soome Elf64_Word vna_name; 250*199767f8SToomas Soome Elf64_Word vna_next; 251*199767f8SToomas Soome } Elf64_Vernaux; 252*199767f8SToomas Soome 253*199767f8SToomas Soome typedef Elf64_Half Elf64_Versym; 254*199767f8SToomas Soome 255*199767f8SToomas Soome typedef struct { 256*199767f8SToomas Soome Elf64_Half si_boundto; /* direct bindings - symbol bound to */ 257*199767f8SToomas Soome Elf64_Half si_flags; /* per symbol flags */ 258*199767f8SToomas Soome } Elf64_Syminfo; 259*199767f8SToomas Soome 260*199767f8SToomas Soome #endif /* !_SYS_ELF64_H_ */ 261