elf64.h revision 38357
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 * 2638357Sjdp * $Id: elf64.h,v 1.3 1998/07/07 23:32:57 jdp Exp $ 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 3836849Sdfrtypedef u_int64_t Elf64_Addr; 3936849Sdfrtypedef u_int16_t Elf64_Half; 4036849Sdfrtypedef u_int64_t Elf64_Off; 4136849Sdfrtypedef int32_t Elf64_Sword; 4236849Sdfrtypedef u_int32_t Elf64_Word; 4336849Sdfrtypedef u_int64_t Elf64_Size; 4436849Sdfr 4536849Sdfr/* 4636849Sdfr * ELF header. 4736849Sdfr */ 4836849Sdfr 4936849Sdfrtypedef struct { 5036849Sdfr unsigned char e_ident[EI_NIDENT]; /* File identification. */ 5136849Sdfr Elf64_Half e_type; /* File type. */ 5236849Sdfr Elf64_Half e_machine; /* Machine architecture. */ 5336849Sdfr Elf64_Word e_version; /* ELF format version. */ 5436849Sdfr Elf64_Addr e_entry; /* Entry point. */ 5536849Sdfr Elf64_Off e_phoff; /* Program header file offset. */ 5636849Sdfr Elf64_Off e_shoff; /* Section header file offset. */ 5736849Sdfr Elf64_Word e_flags; /* Architecture-specific flags. */ 5836849Sdfr Elf64_Half e_ehsize; /* Size of ELF header in bytes. */ 5936849Sdfr Elf64_Half e_phentsize; /* Size of program header entry. */ 6036849Sdfr Elf64_Half e_phnum; /* Number of program header entries. */ 6136849Sdfr Elf64_Half e_shentsize; /* Size of section header entry. */ 6236849Sdfr Elf64_Half e_shnum; /* Number of section header entries. */ 6336849Sdfr Elf64_Half e_shstrndx; /* Section name strings section. */ 6436849Sdfr} Elf64_Ehdr; 6536849Sdfr 6636849Sdfr/* 6736849Sdfr * Section header. 6836849Sdfr */ 6936849Sdfr 7036849Sdfrtypedef struct { 7136849Sdfr Elf64_Word sh_name; /* Section name (index into the 7236849Sdfr section header string table). */ 7336849Sdfr Elf64_Word sh_type; /* Section type. */ 7436849Sdfr Elf64_Size sh_flags; /* Section flags. */ 7536849Sdfr Elf64_Addr sh_addr; /* Address in memory image. */ 7636849Sdfr Elf64_Off sh_offset; /* Offset in file. */ 7736970Sdfr Elf64_Size sh_size; /* Size in bytes. */ 7836849Sdfr Elf64_Word sh_link; /* Index of a related section. */ 7936849Sdfr Elf64_Word sh_info; /* Depends on section type. */ 8036849Sdfr Elf64_Size sh_addralign; /* Alignment in bytes. */ 8136849Sdfr Elf64_Size sh_entsize; /* Size of each entry in section. */ 8236849Sdfr} Elf64_Shdr; 8336849Sdfr 8436849Sdfr/* 8536849Sdfr * Program header. 8636849Sdfr */ 8736849Sdfr 8836849Sdfrtypedef struct { 8936849Sdfr Elf64_Word p_type; /* Entry type. */ 9036849Sdfr Elf64_Word p_flags; /* Access permission flags. */ 9136849Sdfr Elf64_Off p_offset; /* File offset of contents. */ 9236849Sdfr Elf64_Addr p_vaddr; /* Virtual address in memory image. */ 9336849Sdfr Elf64_Addr p_paddr; /* Physical address (not used). */ 9436849Sdfr Elf64_Size p_filesz; /* Size of contents in file. */ 9536849Sdfr Elf64_Size p_memsz; /* Size of contents in memory. */ 9636849Sdfr Elf64_Size p_align; /* Alignment in memory and file. */ 9736849Sdfr} Elf64_Phdr; 9836849Sdfr 9936849Sdfr/* 10036849Sdfr * Dynamic structure. The ".dynamic" section contains an array of them. 10136849Sdfr */ 10236849Sdfr 10336849Sdfrtypedef struct { 10436849Sdfr Elf64_Size d_tag; /* Entry type. */ 10536849Sdfr union { 10636849Sdfr Elf64_Size d_val; /* Integer value. */ 10736849Sdfr Elf64_Addr d_ptr; /* Address value. */ 10836849Sdfr } d_un; 10936849Sdfr} Elf64_Dyn; 11036849Sdfr 11136849Sdfr/* 11236849Sdfr * Relocation entries. 11336849Sdfr */ 11436849Sdfr 11536849Sdfr/* Relocations that don't need an addend field. */ 11636849Sdfrtypedef struct { 11736849Sdfr Elf64_Addr r_offset; /* Location to be relocated. */ 11836849Sdfr Elf64_Size r_info; /* Relocation type and symbol index. */ 11936849Sdfr} Elf64_Rel; 12036849Sdfr 12136849Sdfr/* Relocations that need an addend field. */ 12236849Sdfrtypedef struct { 12336849Sdfr Elf64_Addr r_offset; /* Location to be relocated. */ 12436849Sdfr Elf64_Size r_info; /* Relocation type and symbol index. */ 12536849Sdfr Elf64_Off r_addend; /* Addend. */ 12636849Sdfr} Elf64_Rela; 12736849Sdfr 12836849Sdfr/* Macros for accessing the fields of r_info. */ 12936849Sdfr#define ELF64_R_SYM(info) ((info) >> 8) 13036849Sdfr#define ELF64_R_TYPE(info) ((unsigned char)(info)) 13136849Sdfr 13236849Sdfr/* Macro for constructing r_info from field values. */ 13336849Sdfr#define ELF64_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) 13436849Sdfr 13536849Sdfr/* 13636849Sdfr * Symbol table entries. 13736849Sdfr */ 13836849Sdfr 13936849Sdfrtypedef struct { 14036849Sdfr Elf64_Word st_name; /* String table index of name. */ 14136849Sdfr unsigned char st_info; /* Type and binding information. */ 14236849Sdfr unsigned char st_other; /* Reserved (not used). */ 14336849Sdfr Elf64_Half st_shndx; /* Section index of symbol. */ 14436849Sdfr Elf64_Addr st_value; /* Symbol value. */ 14536849Sdfr Elf64_Size st_size; /* Size of associated object. */ 14636849Sdfr} Elf64_Sym; 14736849Sdfr 14836849Sdfr/* Macros for accessing the fields of st_info. */ 14936849Sdfr#define ELF64_ST_BIND(info) ((info) >> 4) 15036849Sdfr#define ELF64_ST_TYPE(info) ((info) & 0xf) 15136849Sdfr 15236849Sdfr/* Macro for constructing st_info from field values. */ 15336849Sdfr#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 15436849Sdfr 15536849Sdfr#endif /* !_SYS_ELF64_H_ */ 156