elf64.h revision 97564
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: head/sys/sys/elf64.h 97564 2002-05-30 08:32:18Z dfr $ 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; 3938873Sjbtypedef u_int32_t Elf64_Half; 4036849Sdfrtypedef u_int64_t Elf64_Off; 4138873Sjbtypedef int64_t Elf64_Sword; 4238873Sjbtypedef u_int64_t Elf64_Word; 4336849Sdfrtypedef u_int64_t Elf64_Size; 4438873Sjbtypedef u_int16_t Elf64_Quarter; 4536849Sdfr 4636849Sdfr/* 4797564Sdfr * Types of dynamic symbol hash table bucket and chain elements. 4897564Sdfr * 4997564Sdfr * This is inconsistent among 64 bit architectures, so a machine dependent 5097564Sdfr * typedef is required. 5197564Sdfr */ 5297564Sdfr 5397564Sdfr#ifdef __alpha__ 5497564Sdfrtypedef Elf64_Off Elf64_Hashelt; 5597564Sdfr#else 5697564Sdfrtypedef Elf64_Half Elf64_Hashelt; 5797564Sdfr#endif 5897564Sdfr 5997564Sdfr/* 6036849Sdfr * ELF header. 6136849Sdfr */ 6236849Sdfr 6336849Sdfrtypedef struct { 6436849Sdfr unsigned char e_ident[EI_NIDENT]; /* File identification. */ 6538873Sjb Elf64_Quarter e_type; /* File type. */ 6638873Sjb Elf64_Quarter e_machine; /* Machine architecture. */ 6738873Sjb Elf64_Half e_version; /* ELF format version. */ 6836849Sdfr Elf64_Addr e_entry; /* Entry point. */ 6936849Sdfr Elf64_Off e_phoff; /* Program header file offset. */ 7036849Sdfr Elf64_Off e_shoff; /* Section header file offset. */ 7138873Sjb Elf64_Half e_flags; /* Architecture-specific flags. */ 7238873Sjb Elf64_Quarter e_ehsize; /* Size of ELF header in bytes. */ 7338873Sjb Elf64_Quarter e_phentsize; /* Size of program header entry. */ 7438873Sjb Elf64_Quarter e_phnum; /* Number of program header entries. */ 7538873Sjb Elf64_Quarter e_shentsize; /* Size of section header entry. */ 7638873Sjb Elf64_Quarter e_shnum; /* Number of section header entries. */ 7738873Sjb Elf64_Quarter e_shstrndx; /* Section name strings section. */ 7836849Sdfr} Elf64_Ehdr; 7936849Sdfr 8036849Sdfr/* 8136849Sdfr * Section header. 8236849Sdfr */ 8336849Sdfr 8436849Sdfrtypedef struct { 8538873Sjb Elf64_Half sh_name; /* Section name (index into the 8636849Sdfr section header string table). */ 8738873Sjb Elf64_Half sh_type; /* Section type. */ 8836849Sdfr Elf64_Size sh_flags; /* Section flags. */ 8936849Sdfr Elf64_Addr sh_addr; /* Address in memory image. */ 9036849Sdfr Elf64_Off sh_offset; /* Offset in file. */ 9136970Sdfr Elf64_Size sh_size; /* Size in bytes. */ 9238873Sjb Elf64_Half sh_link; /* Index of a related section. */ 9338873Sjb Elf64_Half sh_info; /* Depends on section type. */ 9436849Sdfr Elf64_Size sh_addralign; /* Alignment in bytes. */ 9536849Sdfr Elf64_Size sh_entsize; /* Size of each entry in section. */ 9636849Sdfr} Elf64_Shdr; 9736849Sdfr 9836849Sdfr/* 9936849Sdfr * Program header. 10036849Sdfr */ 10136849Sdfr 10236849Sdfrtypedef struct { 10338873Sjb Elf64_Half p_type; /* Entry type. */ 10438873Sjb Elf64_Half p_flags; /* Access permission flags. */ 10536849Sdfr Elf64_Off p_offset; /* File offset of contents. */ 10636849Sdfr Elf64_Addr p_vaddr; /* Virtual address in memory image. */ 10736849Sdfr Elf64_Addr p_paddr; /* Physical address (not used). */ 10836849Sdfr Elf64_Size p_filesz; /* Size of contents in file. */ 10936849Sdfr Elf64_Size p_memsz; /* Size of contents in memory. */ 11036849Sdfr Elf64_Size p_align; /* Alignment in memory and file. */ 11136849Sdfr} Elf64_Phdr; 11236849Sdfr 11336849Sdfr/* 11436849Sdfr * Dynamic structure. The ".dynamic" section contains an array of them. 11536849Sdfr */ 11636849Sdfr 11736849Sdfrtypedef struct { 11836849Sdfr Elf64_Size d_tag; /* Entry type. */ 11936849Sdfr union { 12036849Sdfr Elf64_Size d_val; /* Integer value. */ 12136849Sdfr Elf64_Addr d_ptr; /* Address value. */ 12236849Sdfr } d_un; 12336849Sdfr} Elf64_Dyn; 12436849Sdfr 12536849Sdfr/* 12636849Sdfr * Relocation entries. 12736849Sdfr */ 12836849Sdfr 12936849Sdfr/* Relocations that don't need an addend field. */ 13036849Sdfrtypedef struct { 13136849Sdfr Elf64_Addr r_offset; /* Location to be relocated. */ 13236849Sdfr Elf64_Size r_info; /* Relocation type and symbol index. */ 13336849Sdfr} Elf64_Rel; 13436849Sdfr 13536849Sdfr/* Relocations that need an addend field. */ 13636849Sdfrtypedef struct { 13736849Sdfr Elf64_Addr r_offset; /* Location to be relocated. */ 13836849Sdfr Elf64_Size r_info; /* Relocation type and symbol index. */ 13936849Sdfr Elf64_Off r_addend; /* Addend. */ 14036849Sdfr} Elf64_Rela; 14136849Sdfr 14236849Sdfr/* Macros for accessing the fields of r_info. */ 14338873Sjb#define ELF64_R_SYM(info) ((info) >> 32) 14436849Sdfr#define ELF64_R_TYPE(info) ((unsigned char)(info)) 14536849Sdfr 14636849Sdfr/* Macro for constructing r_info from field values. */ 14739095Sdfr#define ELF64_R_INFO(sym, type) (((sym) << 32) + (unsigned char)(type)) 14836849Sdfr 14936849Sdfr/* 15036849Sdfr * Symbol table entries. 15136849Sdfr */ 15236849Sdfr 15336849Sdfrtypedef struct { 15438873Sjb Elf64_Half st_name; /* String table index of name. */ 15536849Sdfr unsigned char st_info; /* Type and binding information. */ 15636849Sdfr unsigned char st_other; /* Reserved (not used). */ 15738873Sjb Elf64_Quarter st_shndx; /* Section index of symbol. */ 15836849Sdfr Elf64_Addr st_value; /* Symbol value. */ 15936849Sdfr Elf64_Size st_size; /* Size of associated object. */ 16036849Sdfr} Elf64_Sym; 16136849Sdfr 16236849Sdfr/* Macros for accessing the fields of st_info. */ 16336849Sdfr#define ELF64_ST_BIND(info) ((info) >> 4) 16436849Sdfr#define ELF64_ST_TYPE(info) ((info) & 0xf) 16536849Sdfr 16636849Sdfr/* Macro for constructing st_info from field values. */ 16736849Sdfr#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 16836849Sdfr 16936849Sdfr#endif /* !_SYS_ELF64_H_ */ 170