136849Sdfr/*- 238357Sjdp * Copyright (c) 1996-1998 John D. Polstra. 336849Sdfr * All rights reserved. 436849Sdfr * 536849Sdfr * Redistribution and use in source and binary forms, with or without 636849Sdfr * modification, are permitted provided that the following conditions 736849Sdfr * are met: 836849Sdfr * 1. Redistributions of source code must retain the above copyright 936849Sdfr * notice, this list of conditions and the following disclaimer. 1036849Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1136849Sdfr * notice, this list of conditions and the following disclaimer in the 1236849Sdfr * documentation and/or other materials provided with the distribution. 1336849Sdfr * 1436849Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1536849Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1636849Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1736849Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1836849Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1936849Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2036849Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2136849Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2236849Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2336849Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2436849Sdfr * SUCH DAMAGE. 2536849Sdfr * 2650477Speter * $FreeBSD: stable/11/sys/sys/elf64.h 318972 2017-05-27 01:35:59Z emaste $ 2736849Sdfr */ 2836849Sdfr 2936849Sdfr#ifndef _SYS_ELF64_H_ 3036849Sdfr#define _SYS_ELF64_H_ 1 3136849Sdfr 3238357Sjdp#include <sys/elf_common.h> 3338357Sjdp 3436849Sdfr/* 3536849Sdfr * ELF definitions common to all 64-bit architectures. 3636849Sdfr */ 3736849Sdfr 38153504Smarceltypedef uint64_t Elf64_Addr; 39153504Smarceltypedef uint16_t Elf64_Half; 40153504Smarceltypedef uint64_t Elf64_Off; 41153504Smarceltypedef int32_t Elf64_Sword; 42153504Smarceltypedef int64_t Elf64_Sxword; 43153504Smarceltypedef uint32_t Elf64_Word; 44163016Sjbtypedef uint64_t Elf64_Lword; 45153504Smarceltypedef uint64_t Elf64_Xword; 4636849Sdfr 4736849Sdfr/* 4897564Sdfr * Types of dynamic symbol hash table bucket and chain elements. 4997564Sdfr * 5097564Sdfr * This is inconsistent among 64 bit architectures, so a machine dependent 5197564Sdfr * typedef is required. 5297564Sdfr */ 5397564Sdfr 54153504Smarceltypedef Elf64_Word Elf64_Hashelt; 5597564Sdfr 56153504Smarcel/* Non-standard class-dependent datatype used for abstraction. */ 57153504Smarceltypedef Elf64_Xword Elf64_Size; 58153504Smarceltypedef Elf64_Sxword Elf64_Ssize; 59153504Smarcel 6097564Sdfr/* 6136849Sdfr * ELF header. 6236849Sdfr */ 6336849Sdfr 6436849Sdfrtypedef struct { 6536849Sdfr unsigned char e_ident[EI_NIDENT]; /* File identification. */ 66153504Smarcel Elf64_Half e_type; /* File type. */ 67153504Smarcel Elf64_Half e_machine; /* Machine architecture. */ 68153504Smarcel Elf64_Word e_version; /* ELF format version. */ 6936849Sdfr Elf64_Addr e_entry; /* Entry point. */ 7036849Sdfr Elf64_Off e_phoff; /* Program header file offset. */ 7136849Sdfr Elf64_Off e_shoff; /* Section header file offset. */ 72153504Smarcel Elf64_Word e_flags; /* Architecture-specific flags. */ 73153504Smarcel Elf64_Half e_ehsize; /* Size of ELF header in bytes. */ 74153504Smarcel Elf64_Half e_phentsize; /* Size of program header entry. */ 75153504Smarcel Elf64_Half e_phnum; /* Number of program header entries. */ 76153504Smarcel Elf64_Half e_shentsize; /* Size of section header entry. */ 77153504Smarcel Elf64_Half e_shnum; /* Number of section header entries. */ 78153504Smarcel Elf64_Half e_shstrndx; /* Section name strings section. */ 7936849Sdfr} Elf64_Ehdr; 8036849Sdfr 8136849Sdfr/* 82276539Semaste * Shared object information, found in SHT_MIPS_LIBLIST. 83276539Semaste */ 84276539Semaste 85276539Semastetypedef struct { 86276539Semaste Elf64_Word l_name; /* The name of a shared object. */ 87276539Semaste Elf64_Word l_time_stamp; /* 64-bit timestamp. */ 88276539Semaste Elf64_Word l_checksum; /* Checksum of visible symbols, sizes. */ 89276539Semaste Elf64_Word l_version; /* Interface version string index. */ 90276539Semaste Elf64_Word l_flags; /* Flags (LL_*). */ 91276539Semaste} Elf64_Lib; 92276539Semaste 93276539Semaste/* 9436849Sdfr * Section header. 9536849Sdfr */ 9636849Sdfr 9736849Sdfrtypedef struct { 98153504Smarcel Elf64_Word sh_name; /* Section name (index into the 9936849Sdfr section header string table). */ 100153504Smarcel Elf64_Word sh_type; /* Section type. */ 101153504Smarcel Elf64_Xword sh_flags; /* Section flags. */ 10236849Sdfr Elf64_Addr sh_addr; /* Address in memory image. */ 10336849Sdfr Elf64_Off sh_offset; /* Offset in file. */ 104153504Smarcel Elf64_Xword sh_size; /* Size in bytes. */ 105153504Smarcel Elf64_Word sh_link; /* Index of a related section. */ 106153504Smarcel Elf64_Word sh_info; /* Depends on section type. */ 107153504Smarcel Elf64_Xword sh_addralign; /* Alignment in bytes. */ 108153504Smarcel Elf64_Xword sh_entsize; /* Size of each entry in section. */ 10936849Sdfr} Elf64_Shdr; 11036849Sdfr 11136849Sdfr/* 11236849Sdfr * Program header. 11336849Sdfr */ 11436849Sdfr 11536849Sdfrtypedef struct { 116153504Smarcel Elf64_Word p_type; /* Entry type. */ 117153504Smarcel Elf64_Word p_flags; /* Access permission flags. */ 11836849Sdfr Elf64_Off p_offset; /* File offset of contents. */ 11936849Sdfr Elf64_Addr p_vaddr; /* Virtual address in memory image. */ 12036849Sdfr Elf64_Addr p_paddr; /* Physical address (not used). */ 121153504Smarcel Elf64_Xword p_filesz; /* Size of contents in file. */ 122153504Smarcel Elf64_Xword p_memsz; /* Size of contents in memory. */ 123153504Smarcel Elf64_Xword p_align; /* Alignment in memory and file. */ 12436849Sdfr} Elf64_Phdr; 12536849Sdfr 12636849Sdfr/* 12736849Sdfr * Dynamic structure. The ".dynamic" section contains an array of them. 12836849Sdfr */ 12936849Sdfr 13036849Sdfrtypedef struct { 131153504Smarcel Elf64_Sxword d_tag; /* Entry type. */ 13236849Sdfr union { 133153504Smarcel Elf64_Xword d_val; /* Integer value. */ 13436849Sdfr Elf64_Addr d_ptr; /* Address value. */ 13536849Sdfr } d_un; 13636849Sdfr} Elf64_Dyn; 13736849Sdfr 13836849Sdfr/* 13936849Sdfr * Relocation entries. 14036849Sdfr */ 14136849Sdfr 14236849Sdfr/* Relocations that don't need an addend field. */ 14336849Sdfrtypedef struct { 14436849Sdfr Elf64_Addr r_offset; /* Location to be relocated. */ 145153504Smarcel Elf64_Xword r_info; /* Relocation type and symbol index. */ 14636849Sdfr} Elf64_Rel; 14736849Sdfr 14836849Sdfr/* Relocations that need an addend field. */ 14936849Sdfrtypedef struct { 15036849Sdfr Elf64_Addr r_offset; /* Location to be relocated. */ 151153504Smarcel Elf64_Xword r_info; /* Relocation type and symbol index. */ 152153504Smarcel Elf64_Sxword r_addend; /* Addend. */ 15336849Sdfr} Elf64_Rela; 15436849Sdfr 15536849Sdfr/* Macros for accessing the fields of r_info. */ 156186667Sobrien#define ELF64_R_SYM(info) ((info) >> 32) 157186667Sobrien#define ELF64_R_TYPE(info) ((info) & 0xffffffffL) 15836849Sdfr 15936849Sdfr/* Macro for constructing r_info from field values. */ 160186667Sobrien#define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL)) 16136849Sdfr 162163016Sjb#define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40) 163163016Sjb#define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info)<<56)>>56) 164163016Sjb#define ELF64_R_TYPE_INFO(data, type) \ 165186667Sobrien (((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type)) 166163016Sjb 16736849Sdfr/* 168163016Sjb * Note entry header 169163016Sjb */ 170163457Sjkoshytypedef Elf_Note Elf64_Nhdr; 171163016Sjb 172163016Sjb/* 173163016Sjb * Move entry 174163016Sjb */ 175163016Sjbtypedef struct { 176163016Sjb Elf64_Lword m_value; /* symbol value */ 177163016Sjb Elf64_Xword m_info; /* size + index */ 178163016Sjb Elf64_Xword m_poffset; /* symbol offset */ 179163016Sjb Elf64_Half m_repeat; /* repeat count */ 180163016Sjb Elf64_Half m_stride; /* stride info */ 181163016Sjb} Elf64_Move; 182163016Sjb 183163016Sjb#define ELF64_M_SYM(info) ((info)>>8) 184163016Sjb#define ELF64_M_SIZE(info) ((unsigned char)(info)) 185163016Sjb#define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size)) 186163016Sjb 187163016Sjb/* 188163016Sjb * Hardware/Software capabilities entry 189163016Sjb */ 190163016Sjbtypedef struct { 191163016Sjb Elf64_Xword c_tag; /* how to interpret value */ 192163016Sjb union { 193163016Sjb Elf64_Xword c_val; 194163016Sjb Elf64_Addr c_ptr; 195163016Sjb } c_un; 196163016Sjb} Elf64_Cap; 197163016Sjb 198163016Sjb/* 19936849Sdfr * Symbol table entries. 20036849Sdfr */ 20136849Sdfr 20236849Sdfrtypedef struct { 203153504Smarcel Elf64_Word st_name; /* String table index of name. */ 20436849Sdfr unsigned char st_info; /* Type and binding information. */ 20536849Sdfr unsigned char st_other; /* Reserved (not used). */ 206153504Smarcel Elf64_Half st_shndx; /* Section index of symbol. */ 20736849Sdfr Elf64_Addr st_value; /* Symbol value. */ 208153504Smarcel Elf64_Xword st_size; /* Size of associated object. */ 20936849Sdfr} Elf64_Sym; 21036849Sdfr 21136849Sdfr/* Macros for accessing the fields of st_info. */ 212186667Sobrien#define ELF64_ST_BIND(info) ((info) >> 4) 213186667Sobrien#define ELF64_ST_TYPE(info) ((info) & 0xf) 21436849Sdfr 21536849Sdfr/* Macro for constructing st_info from field values. */ 216186667Sobrien#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 21736849Sdfr 218153502Smarcel/* Macro for accessing the fields of st_other. */ 219186667Sobrien#define ELF64_ST_VISIBILITY(oth) ((oth) & 0x3) 220153502Smarcel 221153515Skan/* Structures used by Sun & GNU-style symbol versioning. */ 222153515Skantypedef struct { 223153515Skan Elf64_Half vd_version; 224153515Skan Elf64_Half vd_flags; 225153515Skan Elf64_Half vd_ndx; 226153515Skan Elf64_Half vd_cnt; 227153515Skan Elf64_Word vd_hash; 228153515Skan Elf64_Word vd_aux; 229153515Skan Elf64_Word vd_next; 230153515Skan} Elf64_Verdef; 231153515Skan 232153515Skantypedef struct { 233153515Skan Elf64_Word vda_name; 234153515Skan Elf64_Word vda_next; 235153515Skan} Elf64_Verdaux; 236153515Skan 237153515Skantypedef struct { 238153515Skan Elf64_Half vn_version; 239153515Skan Elf64_Half vn_cnt; 240153515Skan Elf64_Word vn_file; 241153515Skan Elf64_Word vn_aux; 242153515Skan Elf64_Word vn_next; 243153515Skan} Elf64_Verneed; 244153515Skan 245153515Skantypedef struct { 246153515Skan Elf64_Word vna_hash; 247153515Skan Elf64_Half vna_flags; 248153515Skan Elf64_Half vna_other; 249153515Skan Elf64_Word vna_name; 250153515Skan Elf64_Word vna_next; 251153515Skan} Elf64_Vernaux; 252153515Skan 253153515Skantypedef Elf64_Half Elf64_Versym; 254153515Skan 255163016Sjbtypedef struct { 256163016Sjb Elf64_Half si_boundto; /* direct bindings - symbol bound to */ 257163016Sjb Elf64_Half si_flags; /* per symbol flags */ 258163016Sjb} Elf64_Syminfo; 259163016Sjb 260318972Semastetypedef struct { 261318972Semaste Elf64_Word ch_type; 262318972Semaste Elf64_Word ch_reserved; 263318972Semaste Elf64_Xword ch_size; 264318972Semaste Elf64_Xword ch_addralign; 265318972Semaste} Elf64_Chdr; 266318972Semaste 26736849Sdfr#endif /* !_SYS_ELF64_H_ */ 268