/*-1* SPDX-License-Identifier: BSD-2-Clause-FreeBSD2*3* Copyright (c) 1996-1998 John D. Polstra.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*27* $FreeBSD$28*/2930#ifndef _SYS_ELF32_H_31#define _SYS_ELF32_H_ 13233#include "elf_common.h"3435/*36* ELF definitions common to all 32-bit architectures.37*/3839typedef uint32_t Elf32_Addr;40typedef uint16_t Elf32_Half;41typedef uint32_t Elf32_Off;42typedef int32_t Elf32_Sword;43typedef uint32_t Elf32_Word;44typedef uint64_t Elf32_Lword;4546typedef Elf32_Word Elf32_Hashelt;4748/* Non-standard class-dependent datatype used for abstraction. */49typedef Elf32_Word Elf32_Size;50typedef Elf32_Sword Elf32_Ssize;5152/*53* ELF header.54*/5556typedef struct {57unsigned char e_ident[EI_NIDENT]; /* File identification. */58Elf32_Half e_type; /* File type. */59Elf32_Half e_machine; /* Machine architecture. */60Elf32_Word e_version; /* ELF format version. */61Elf32_Addr e_entry; /* Entry point. */62Elf32_Off e_phoff; /* Program header file offset. */63Elf32_Off e_shoff; /* Section header file offset. */64Elf32_Word e_flags; /* Architecture-specific flags. */65Elf32_Half e_ehsize; /* Size of ELF header in bytes. */66Elf32_Half e_phentsize; /* Size of program header entry. */67Elf32_Half e_phnum; /* Number of program header entries. */68Elf32_Half e_shentsize; /* Size of section header entry. */69Elf32_Half e_shnum; /* Number of section header entries. */70Elf32_Half e_shstrndx; /* Section name strings section. */71} Elf32_Ehdr;7273/*74* Shared object information, found in SHT_MIPS_LIBLIST.75*/7677typedef struct {78Elf32_Word l_name; /* The name of a shared object. */79Elf32_Word l_time_stamp; /* 32-bit timestamp. */80Elf32_Word l_checksum; /* Checksum of visible symbols, sizes. */81Elf32_Word l_version; /* Interface version string index. */82Elf32_Word l_flags; /* Flags (LL_*). */83} Elf32_Lib;8485/*86* Section header.87*/8889typedef struct {90Elf32_Word sh_name; /* Section name (index into the91section header string table). */92Elf32_Word sh_type; /* Section type. */93Elf32_Word sh_flags; /* Section flags. */94Elf32_Addr sh_addr; /* Address in memory image. */95Elf32_Off sh_offset; /* Offset in file. */96Elf32_Word sh_size; /* Size in bytes. */97Elf32_Word sh_link; /* Index of a related section. */98Elf32_Word sh_info; /* Depends on section type. */99Elf32_Word sh_addralign; /* Alignment in bytes. */100Elf32_Word sh_entsize; /* Size of each entry in section. */101} Elf32_Shdr;102103/*104* Program header.105*/106107typedef struct {108Elf32_Word p_type; /* Entry type. */109Elf32_Off p_offset; /* File offset of contents. */110Elf32_Addr p_vaddr; /* Virtual address in memory image. */111Elf32_Addr p_paddr; /* Physical address (not used). */112Elf32_Word p_filesz; /* Size of contents in file. */113Elf32_Word p_memsz; /* Size of contents in memory. */114Elf32_Word p_flags; /* Access permission flags. */115Elf32_Word p_align; /* Alignment in memory and file. */116} Elf32_Phdr;117118/*119* Dynamic structure. The ".dynamic" section contains an array of them.120*/121122typedef struct {123Elf32_Sword d_tag; /* Entry type. */124union {125Elf32_Word d_val; /* Integer value. */126Elf32_Addr d_ptr; /* Address value. */127} d_un;128} Elf32_Dyn;129130/*131* Relocation entries.132*/133134/* Relocations that don't need an addend field. */135typedef struct {136Elf32_Addr r_offset; /* Location to be relocated. */137Elf32_Word r_info; /* Relocation type and symbol index. */138} Elf32_Rel;139140/* Relocations that need an addend field. */141typedef struct {142Elf32_Addr r_offset; /* Location to be relocated. */143Elf32_Word r_info; /* Relocation type and symbol index. */144Elf32_Sword r_addend; /* Addend. */145} Elf32_Rela;146147/* Macros for accessing the fields of r_info. */148#define ELF32_R_SYM(info) ((info) >> 8)149#define ELF32_R_TYPE(info) ((unsigned char)(info))150151/* Macro for constructing r_info from field values. */152#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))153154/*155* Note entry header156*/157typedef Elf_Note Elf32_Nhdr;158159/*160* Move entry161*/162typedef struct {163Elf32_Lword m_value; /* symbol value */164Elf32_Word m_info; /* size + index */165Elf32_Word m_poffset; /* symbol offset */166Elf32_Half m_repeat; /* repeat count */167Elf32_Half m_stride; /* stride info */168} Elf32_Move;169170/*171* The macros compose and decompose values for Move.r_info172*173* sym = ELF32_M_SYM(M.m_info)174* size = ELF32_M_SIZE(M.m_info)175* M.m_info = ELF32_M_INFO(sym, size)176*/177#define ELF32_M_SYM(info) ((info)>>8)178#define ELF32_M_SIZE(info) ((unsigned char)(info))179#define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))180181/*182* Hardware/Software capabilities entry183*/184typedef struct {185Elf32_Word c_tag; /* how to interpret value */186union {187Elf32_Word c_val;188Elf32_Addr c_ptr;189} c_un;190} Elf32_Cap;191192/*193* Symbol table entries.194*/195196typedef struct {197Elf32_Word st_name; /* String table index of name. */198Elf32_Addr st_value; /* Symbol value. */199Elf32_Word st_size; /* Size of associated object. */200unsigned char st_info; /* Type and binding information. */201unsigned char st_other; /* Reserved (not used). */202Elf32_Half st_shndx; /* Section index of symbol. */203} Elf32_Sym;204205/* Macros for accessing the fields of st_info. */206#define ELF32_ST_BIND(info) ((info) >> 4)207#define ELF32_ST_TYPE(info) ((info) & 0xf)208209/* Macro for constructing st_info from field values. */210#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))211212/* Macro for accessing the fields of st_other. */213#define ELF32_ST_VISIBILITY(oth) ((oth) & 0x3)214215/* Structures used by Sun & GNU symbol versioning. */216typedef struct217{218Elf32_Half vd_version;219Elf32_Half vd_flags;220Elf32_Half vd_ndx;221Elf32_Half vd_cnt;222Elf32_Word vd_hash;223Elf32_Word vd_aux;224Elf32_Word vd_next;225} Elf32_Verdef;226227typedef struct228{229Elf32_Word vda_name;230Elf32_Word vda_next;231} Elf32_Verdaux;232233typedef struct234{235Elf32_Half vn_version;236Elf32_Half vn_cnt;237Elf32_Word vn_file;238Elf32_Word vn_aux;239Elf32_Word vn_next;240} Elf32_Verneed;241242typedef struct243{244Elf32_Word vna_hash;245Elf32_Half vna_flags;246Elf32_Half vna_other;247Elf32_Word vna_name;248Elf32_Word vna_next;249} Elf32_Vernaux;250251typedef Elf32_Half Elf32_Versym;252253typedef struct {254Elf32_Half si_boundto; /* direct bindings - symbol bound to */255Elf32_Half si_flags; /* per symbol flags */256} Elf32_Syminfo;257258typedef struct {259Elf32_Word ch_type;260Elf32_Word ch_size;261Elf32_Word ch_addralign;262} Elf32_Chdr;263264#endif /* !_SYS_ELF32_H_ */265266267