125984Sjdp/*- 238357Sjdp * Copyright (c) 1996-1998 John D. Polstra. 325984Sjdp * All rights reserved. 425984Sjdp * 525984Sjdp * Redistribution and use in source and binary forms, with or without 625984Sjdp * modification, are permitted provided that the following conditions 725984Sjdp * are met: 825984Sjdp * 1. Redistributions of source code must retain the above copyright 925984Sjdp * notice, this list of conditions and the following disclaimer. 1025984Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1125984Sjdp * notice, this list of conditions and the following disclaimer in the 1225984Sjdp * documentation and/or other materials provided with the distribution. 1325984Sjdp * 1425984Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1525984Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1625984Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1725984Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1825984Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1925984Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2025984Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2125984Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2225984Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2325984Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2425984Sjdp * SUCH DAMAGE. 2525984Sjdp * 2650477Speter * $FreeBSD$ 2725984Sjdp */ 2825984Sjdp 2925984Sjdp#ifndef _SYS_ELF32_H_ 3025984Sjdp#define _SYS_ELF32_H_ 1 3125984Sjdp 3238357Sjdp#include <sys/elf_common.h> 3338357Sjdp 3425984Sjdp/* 3525984Sjdp * ELF definitions common to all 32-bit architectures. 3625984Sjdp */ 3725984Sjdp 38153504Smarceltypedef uint32_t Elf32_Addr; 39153504Smarceltypedef uint16_t Elf32_Half; 40153504Smarceltypedef uint32_t Elf32_Off; 4125984Sjdptypedef int32_t Elf32_Sword; 42153504Smarceltypedef uint32_t Elf32_Word; 43163016Sjbtypedef uint64_t Elf32_Lword; 4425984Sjdp 45153504Smarceltypedef Elf32_Word Elf32_Hashelt; 46153504Smarcel 47153504Smarcel/* Non-standard class-dependent datatype used for abstraction. */ 48153504Smarceltypedef Elf32_Word Elf32_Size; 49153504Smarceltypedef Elf32_Sword Elf32_Ssize; 50153504Smarcel 5125984Sjdp/* 5225984Sjdp * ELF header. 5325984Sjdp */ 5425984Sjdp 5525984Sjdptypedef struct { 5625984Sjdp unsigned char e_ident[EI_NIDENT]; /* File identification. */ 5725984Sjdp Elf32_Half e_type; /* File type. */ 5825984Sjdp Elf32_Half e_machine; /* Machine architecture. */ 5925984Sjdp Elf32_Word e_version; /* ELF format version. */ 6025984Sjdp Elf32_Addr e_entry; /* Entry point. */ 6125984Sjdp Elf32_Off e_phoff; /* Program header file offset. */ 6225984Sjdp Elf32_Off e_shoff; /* Section header file offset. */ 6325984Sjdp Elf32_Word e_flags; /* Architecture-specific flags. */ 6425984Sjdp Elf32_Half e_ehsize; /* Size of ELF header in bytes. */ 6525984Sjdp Elf32_Half e_phentsize; /* Size of program header entry. */ 6625984Sjdp Elf32_Half e_phnum; /* Number of program header entries. */ 6725984Sjdp Elf32_Half e_shentsize; /* Size of section header entry. */ 6825984Sjdp Elf32_Half e_shnum; /* Number of section header entries. */ 6925984Sjdp Elf32_Half e_shstrndx; /* Section name strings section. */ 7025984Sjdp} Elf32_Ehdr; 7125984Sjdp 7225984Sjdp/* 7325984Sjdp * Section header. 7425984Sjdp */ 7525984Sjdp 7625984Sjdptypedef struct { 7725984Sjdp Elf32_Word sh_name; /* Section name (index into the 7825984Sjdp section header string table). */ 7925984Sjdp Elf32_Word sh_type; /* Section type. */ 8025984Sjdp Elf32_Word sh_flags; /* Section flags. */ 8125984Sjdp Elf32_Addr sh_addr; /* Address in memory image. */ 8225984Sjdp Elf32_Off sh_offset; /* Offset in file. */ 83153504Smarcel Elf32_Word sh_size; /* Size in bytes. */ 8425984Sjdp Elf32_Word sh_link; /* Index of a related section. */ 8525984Sjdp Elf32_Word sh_info; /* Depends on section type. */ 86153504Smarcel Elf32_Word sh_addralign; /* Alignment in bytes. */ 87153504Smarcel Elf32_Word sh_entsize; /* Size of each entry in section. */ 8825984Sjdp} Elf32_Shdr; 8925984Sjdp 9025984Sjdp/* 9125984Sjdp * Program header. 9225984Sjdp */ 9325984Sjdp 9425984Sjdptypedef struct { 9525984Sjdp Elf32_Word p_type; /* Entry type. */ 9625984Sjdp Elf32_Off p_offset; /* File offset of contents. */ 9725984Sjdp Elf32_Addr p_vaddr; /* Virtual address in memory image. */ 9825984Sjdp Elf32_Addr p_paddr; /* Physical address (not used). */ 99153504Smarcel Elf32_Word p_filesz; /* Size of contents in file. */ 100153504Smarcel Elf32_Word p_memsz; /* Size of contents in memory. */ 10125984Sjdp Elf32_Word p_flags; /* Access permission flags. */ 102153504Smarcel Elf32_Word p_align; /* Alignment in memory and file. */ 10325984Sjdp} Elf32_Phdr; 10425984Sjdp 10525984Sjdp/* 10625984Sjdp * Dynamic structure. The ".dynamic" section contains an array of them. 10725984Sjdp */ 10825984Sjdp 10925984Sjdptypedef struct { 11025984Sjdp Elf32_Sword d_tag; /* Entry type. */ 11125984Sjdp union { 112153504Smarcel Elf32_Word d_val; /* Integer value. */ 11325984Sjdp Elf32_Addr d_ptr; /* Address value. */ 11425984Sjdp } d_un; 11525984Sjdp} Elf32_Dyn; 11625984Sjdp 11725984Sjdp/* 11825984Sjdp * Relocation entries. 11925984Sjdp */ 12025984Sjdp 12125984Sjdp/* Relocations that don't need an addend field. */ 12225984Sjdptypedef struct { 12325984Sjdp Elf32_Addr r_offset; /* Location to be relocated. */ 12425984Sjdp Elf32_Word r_info; /* Relocation type and symbol index. */ 12525984Sjdp} Elf32_Rel; 12625984Sjdp 12725984Sjdp/* Relocations that need an addend field. */ 12825984Sjdptypedef struct { 12925984Sjdp Elf32_Addr r_offset; /* Location to be relocated. */ 13025984Sjdp Elf32_Word r_info; /* Relocation type and symbol index. */ 13125984Sjdp Elf32_Sword r_addend; /* Addend. */ 13225984Sjdp} Elf32_Rela; 13325984Sjdp 13425984Sjdp/* Macros for accessing the fields of r_info. */ 13525984Sjdp#define ELF32_R_SYM(info) ((info) >> 8) 13625984Sjdp#define ELF32_R_TYPE(info) ((unsigned char)(info)) 13725984Sjdp 13825984Sjdp/* Macro for constructing r_info from field values. */ 13925984Sjdp#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) 14025984Sjdp 14125984Sjdp/* 142163016Sjb * Note entry header 143163016Sjb */ 144163457Sjkoshytypedef Elf_Note Elf32_Nhdr; 145163016Sjb 146163016Sjb/* 147163016Sjb * Move entry 148163016Sjb */ 149163016Sjbtypedef struct { 150163016Sjb Elf32_Lword m_value; /* symbol value */ 151163016Sjb Elf32_Word m_info; /* size + index */ 152163016Sjb Elf32_Word m_poffset; /* symbol offset */ 153163016Sjb Elf32_Half m_repeat; /* repeat count */ 154163016Sjb Elf32_Half m_stride; /* stride info */ 155163016Sjb} Elf32_Move; 156163016Sjb 157163016Sjb/* 158163016Sjb * The macros compose and decompose values for Move.r_info 159163016Sjb * 160163016Sjb * sym = ELF32_M_SYM(M.m_info) 161163016Sjb * size = ELF32_M_SIZE(M.m_info) 162163016Sjb * M.m_info = ELF32_M_INFO(sym, size) 163163016Sjb */ 164163016Sjb#define ELF32_M_SYM(info) ((info)>>8) 165163016Sjb#define ELF32_M_SIZE(info) ((unsigned char)(info)) 166163016Sjb#define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size)) 167163016Sjb 168163016Sjb/* 169163016Sjb * Hardware/Software capabilities entry 170163016Sjb */ 171163016Sjbtypedef struct { 172163016Sjb Elf32_Word c_tag; /* how to interpret value */ 173163016Sjb union { 174163016Sjb Elf32_Word c_val; 175163016Sjb Elf32_Addr c_ptr; 176163016Sjb } c_un; 177163016Sjb} Elf32_Cap; 178163016Sjb 179163016Sjb/* 18025984Sjdp * Symbol table entries. 18125984Sjdp */ 18225984Sjdp 18325984Sjdptypedef struct { 18425984Sjdp Elf32_Word st_name; /* String table index of name. */ 18525984Sjdp Elf32_Addr st_value; /* Symbol value. */ 186153504Smarcel Elf32_Word st_size; /* Size of associated object. */ 18725984Sjdp unsigned char st_info; /* Type and binding information. */ 18825984Sjdp unsigned char st_other; /* Reserved (not used). */ 18925984Sjdp Elf32_Half st_shndx; /* Section index of symbol. */ 19025984Sjdp} Elf32_Sym; 19125984Sjdp 19225984Sjdp/* Macros for accessing the fields of st_info. */ 19325984Sjdp#define ELF32_ST_BIND(info) ((info) >> 4) 19425984Sjdp#define ELF32_ST_TYPE(info) ((info) & 0xf) 19525984Sjdp 19625984Sjdp/* Macro for constructing st_info from field values. */ 19725984Sjdp#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 19825984Sjdp 199153502Smarcel/* Macro for accessing the fields of st_other. */ 200153502Smarcel#define ELF32_ST_VISIBILITY(oth) ((oth) & 0x3) 201153502Smarcel 202153515Skan/* Structures used by Sun & GNU symbol versioning. */ 203153515Skantypedef struct 204153515Skan{ 205153515Skan Elf32_Half vd_version; 206153515Skan Elf32_Half vd_flags; 207153515Skan Elf32_Half vd_ndx; 208153515Skan Elf32_Half vd_cnt; 209153515Skan Elf32_Word vd_hash; 210153515Skan Elf32_Word vd_aux; 211153515Skan Elf32_Word vd_next; 212153515Skan} Elf32_Verdef; 213153515Skan 214153515Skantypedef struct 215153515Skan{ 216153515Skan Elf32_Word vda_name; 217153515Skan Elf32_Word vda_next; 218153515Skan} Elf32_Verdaux; 219153515Skan 220153515Skantypedef struct 221153515Skan{ 222153515Skan Elf32_Half vn_version; 223153515Skan Elf32_Half vn_cnt; 224153515Skan Elf32_Word vn_file; 225153515Skan Elf32_Word vn_aux; 226153515Skan Elf32_Word vn_next; 227153515Skan} Elf32_Verneed; 228153515Skan 229153515Skantypedef struct 230153515Skan{ 231153515Skan Elf32_Word vna_hash; 232153515Skan Elf32_Half vna_flags; 233153515Skan Elf32_Half vna_other; 234153515Skan Elf32_Word vna_name; 235153515Skan Elf32_Word vna_next; 236153515Skan} Elf32_Vernaux; 237153515Skan 238153515Skantypedef Elf32_Half Elf32_Versym; 239153515Skan 240163016Sjbtypedef struct { 241163016Sjb Elf32_Half si_boundto; /* direct bindings - symbol bound to */ 242163016Sjb Elf32_Half si_flags; /* per symbol flags */ 243163016Sjb} Elf32_Syminfo; 244163016Sjb 24525984Sjdp#endif /* !_SYS_ELF32_H_ */ 246