/*-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_ELF64_H_31#define _SYS_ELF64_H_ 13233#include "elf_common.h"3435/*36* ELF definitions common to all 64-bit architectures.37*/3839typedef uint64_t Elf64_Addr;40typedef uint16_t Elf64_Half;41typedef uint64_t Elf64_Off;42typedef int32_t Elf64_Sword;43typedef int64_t Elf64_Sxword;44typedef uint32_t Elf64_Word;45typedef uint64_t Elf64_Lword;46typedef uint64_t Elf64_Xword;4748/*49* Types of dynamic symbol hash table bucket and chain elements.50*51* This is inconsistent among 64 bit architectures, so a machine dependent52* typedef is required.53*/5455typedef Elf64_Word Elf64_Hashelt;5657/* Non-standard class-dependent datatype used for abstraction. */58typedef Elf64_Xword Elf64_Size;59typedef Elf64_Sxword Elf64_Ssize;6061/*62* ELF header.63*/6465typedef struct {66unsigned char e_ident[EI_NIDENT]; /* File identification. */67Elf64_Half e_type; /* File type. */68Elf64_Half e_machine; /* Machine architecture. */69Elf64_Word e_version; /* ELF format version. */70Elf64_Addr e_entry; /* Entry point. */71Elf64_Off e_phoff; /* Program header file offset. */72Elf64_Off e_shoff; /* Section header file offset. */73Elf64_Word e_flags; /* Architecture-specific flags. */74Elf64_Half e_ehsize; /* Size of ELF header in bytes. */75Elf64_Half e_phentsize; /* Size of program header entry. */76Elf64_Half e_phnum; /* Number of program header entries. */77Elf64_Half e_shentsize; /* Size of section header entry. */78Elf64_Half e_shnum; /* Number of section header entries. */79Elf64_Half e_shstrndx; /* Section name strings section. */80} Elf64_Ehdr;8182/*83* Shared object information, found in SHT_MIPS_LIBLIST.84*/8586typedef struct {87Elf64_Word l_name; /* The name of a shared object. */88Elf64_Word l_time_stamp; /* 64-bit timestamp. */89Elf64_Word l_checksum; /* Checksum of visible symbols, sizes. */90Elf64_Word l_version; /* Interface version string index. */91Elf64_Word l_flags; /* Flags (LL_*). */92} Elf64_Lib;9394/*95* Section header.96*/9798typedef struct {99Elf64_Word sh_name; /* Section name (index into the100section header string table). */101Elf64_Word sh_type; /* Section type. */102Elf64_Xword sh_flags; /* Section flags. */103Elf64_Addr sh_addr; /* Address in memory image. */104Elf64_Off sh_offset; /* Offset in file. */105Elf64_Xword sh_size; /* Size in bytes. */106Elf64_Word sh_link; /* Index of a related section. */107Elf64_Word sh_info; /* Depends on section type. */108Elf64_Xword sh_addralign; /* Alignment in bytes. */109Elf64_Xword sh_entsize; /* Size of each entry in section. */110} Elf64_Shdr;111112/*113* Program header.114*/115116typedef struct {117Elf64_Word p_type; /* Entry type. */118Elf64_Word p_flags; /* Access permission flags. */119Elf64_Off p_offset; /* File offset of contents. */120Elf64_Addr p_vaddr; /* Virtual address in memory image. */121Elf64_Addr p_paddr; /* Physical address (not used). */122Elf64_Xword p_filesz; /* Size of contents in file. */123Elf64_Xword p_memsz; /* Size of contents in memory. */124Elf64_Xword p_align; /* Alignment in memory and file. */125} Elf64_Phdr;126127/*128* Dynamic structure. The ".dynamic" section contains an array of them.129*/130131typedef struct {132Elf64_Sxword d_tag; /* Entry type. */133union {134Elf64_Xword d_val; /* Integer value. */135Elf64_Addr d_ptr; /* Address value. */136} d_un;137} Elf64_Dyn;138139/*140* Relocation entries.141*/142143/* Relocations that don't need an addend field. */144typedef struct {145Elf64_Addr r_offset; /* Location to be relocated. */146Elf64_Xword r_info; /* Relocation type and symbol index. */147} Elf64_Rel;148149/* Relocations that need an addend field. */150typedef struct {151Elf64_Addr r_offset; /* Location to be relocated. */152Elf64_Xword r_info; /* Relocation type and symbol index. */153Elf64_Sxword r_addend; /* Addend. */154} Elf64_Rela;155156/* Macros for accessing the fields of r_info. */157#define ELF64_R_SYM(info) ((info) >> 32)158#define ELF64_R_TYPE(info) ((info) & 0xffffffffL)159160/* Macro for constructing r_info from field values. */161#define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL))162163#define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40)164#define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info)<<56)>>56)165#define ELF64_R_TYPE_INFO(data, type) \166(((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))167168/*169* Note entry header170*/171typedef Elf_Note Elf64_Nhdr;172173/*174* Move entry175*/176typedef struct {177Elf64_Lword m_value; /* symbol value */178Elf64_Xword m_info; /* size + index */179Elf64_Xword m_poffset; /* symbol offset */180Elf64_Half m_repeat; /* repeat count */181Elf64_Half m_stride; /* stride info */182} Elf64_Move;183184#define ELF64_M_SYM(info) ((info)>>8)185#define ELF64_M_SIZE(info) ((unsigned char)(info))186#define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))187188/*189* Hardware/Software capabilities entry190*/191typedef struct {192Elf64_Xword c_tag; /* how to interpret value */193union {194Elf64_Xword c_val;195Elf64_Addr c_ptr;196} c_un;197} Elf64_Cap;198199/*200* Symbol table entries.201*/202203typedef struct {204Elf64_Word st_name; /* String table index of name. */205unsigned char st_info; /* Type and binding information. */206unsigned char st_other; /* Reserved (not used). */207Elf64_Half st_shndx; /* Section index of symbol. */208Elf64_Addr st_value; /* Symbol value. */209Elf64_Xword st_size; /* Size of associated object. */210} Elf64_Sym;211212/* Macros for accessing the fields of st_info. */213#define ELF64_ST_BIND(info) ((info) >> 4)214#define ELF64_ST_TYPE(info) ((info) & 0xf)215216/* Macro for constructing st_info from field values. */217#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))218219/* Macro for accessing the fields of st_other. */220#define ELF64_ST_VISIBILITY(oth) ((oth) & 0x3)221222/* Structures used by Sun & GNU-style symbol versioning. */223typedef struct {224Elf64_Half vd_version;225Elf64_Half vd_flags;226Elf64_Half vd_ndx;227Elf64_Half vd_cnt;228Elf64_Word vd_hash;229Elf64_Word vd_aux;230Elf64_Word vd_next;231} Elf64_Verdef;232233typedef struct {234Elf64_Word vda_name;235Elf64_Word vda_next;236} Elf64_Verdaux;237238typedef struct {239Elf64_Half vn_version;240Elf64_Half vn_cnt;241Elf64_Word vn_file;242Elf64_Word vn_aux;243Elf64_Word vn_next;244} Elf64_Verneed;245246typedef struct {247Elf64_Word vna_hash;248Elf64_Half vna_flags;249Elf64_Half vna_other;250Elf64_Word vna_name;251Elf64_Word vna_next;252} Elf64_Vernaux;253254typedef Elf64_Half Elf64_Versym;255256typedef struct {257Elf64_Half si_boundto; /* direct bindings - symbol bound to */258Elf64_Half si_flags; /* per symbol flags */259} Elf64_Syminfo;260261typedef struct {262Elf64_Word ch_type;263Elf64_Word ch_reserved;264Elf64_Xword ch_size;265Elf64_Xword ch_addralign;266} Elf64_Chdr;267268#endif /* !_SYS_ELF64_H_ */269270271