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$
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
38153504Smarceltypedef uint64_t	Elf64_Addr;
39153504Smarceltypedef uint16_t	Elf64_Half;
40153504Smarceltypedef uint64_t	Elf64_Off;
41153504Smarceltypedef int32_t		Elf64_Sword;
42153504Smarceltypedef int64_t		Elf64_Sxword;
43153504Smarceltypedef uint32_t	Elf64_Word;
44163016Sjbtypedef uint64_t	Elf64_Lword;
45153504Smarceltypedef uint64_t	Elf64_Xword;
4636849Sdfr
4736849Sdfr/*
4897564Sdfr * Types of dynamic symbol hash table bucket and chain elements.
4997564Sdfr *
5097564Sdfr * This is inconsistent among 64 bit architectures, so a machine dependent
5197564Sdfr * typedef is required.
5297564Sdfr */
5397564Sdfr
54153504Smarceltypedef Elf64_Word	Elf64_Hashelt;
5597564Sdfr
56153504Smarcel/* Non-standard class-dependent datatype used for abstraction. */
57153504Smarceltypedef Elf64_Xword	Elf64_Size;
58153504Smarceltypedef Elf64_Sxword	Elf64_Ssize;
59153504Smarcel
6097564Sdfr/*
6136849Sdfr * ELF header.
6236849Sdfr */
6336849Sdfr
6436849Sdfrtypedef struct {
6536849Sdfr	unsigned char	e_ident[EI_NIDENT];	/* File identification. */
66153504Smarcel	Elf64_Half	e_type;		/* File type. */
67153504Smarcel	Elf64_Half	e_machine;	/* Machine architecture. */
68153504Smarcel	Elf64_Word	e_version;	/* ELF format version. */
6936849Sdfr	Elf64_Addr	e_entry;	/* Entry point. */
7036849Sdfr	Elf64_Off	e_phoff;	/* Program header file offset. */
7136849Sdfr	Elf64_Off	e_shoff;	/* Section header file offset. */
72153504Smarcel	Elf64_Word	e_flags;	/* Architecture-specific flags. */
73153504Smarcel	Elf64_Half	e_ehsize;	/* Size of ELF header in bytes. */
74153504Smarcel	Elf64_Half	e_phentsize;	/* Size of program header entry. */
75153504Smarcel	Elf64_Half	e_phnum;	/* Number of program header entries. */
76153504Smarcel	Elf64_Half	e_shentsize;	/* Size of section header entry. */
77153504Smarcel	Elf64_Half	e_shnum;	/* Number of section header entries. */
78153504Smarcel	Elf64_Half	e_shstrndx;	/* Section name strings section. */
7936849Sdfr} Elf64_Ehdr;
8036849Sdfr
8136849Sdfr/*
8236849Sdfr * Section header.
8336849Sdfr */
8436849Sdfr
8536849Sdfrtypedef struct {
86153504Smarcel	Elf64_Word	sh_name;	/* Section name (index into the
8736849Sdfr					   section header string table). */
88153504Smarcel	Elf64_Word	sh_type;	/* Section type. */
89153504Smarcel	Elf64_Xword	sh_flags;	/* Section flags. */
9036849Sdfr	Elf64_Addr	sh_addr;	/* Address in memory image. */
9136849Sdfr	Elf64_Off	sh_offset;	/* Offset in file. */
92153504Smarcel	Elf64_Xword	sh_size;	/* Size in bytes. */
93153504Smarcel	Elf64_Word	sh_link;	/* Index of a related section. */
94153504Smarcel	Elf64_Word	sh_info;	/* Depends on section type. */
95153504Smarcel	Elf64_Xword	sh_addralign;	/* Alignment in bytes. */
96153504Smarcel	Elf64_Xword	sh_entsize;	/* Size of each entry in section. */
9736849Sdfr} Elf64_Shdr;
9836849Sdfr
9936849Sdfr/*
10036849Sdfr * Program header.
10136849Sdfr */
10236849Sdfr
10336849Sdfrtypedef struct {
104153504Smarcel	Elf64_Word	p_type;		/* Entry type. */
105153504Smarcel	Elf64_Word	p_flags;	/* Access permission flags. */
10636849Sdfr	Elf64_Off	p_offset;	/* File offset of contents. */
10736849Sdfr	Elf64_Addr	p_vaddr;	/* Virtual address in memory image. */
10836849Sdfr	Elf64_Addr	p_paddr;	/* Physical address (not used). */
109153504Smarcel	Elf64_Xword	p_filesz;	/* Size of contents in file. */
110153504Smarcel	Elf64_Xword	p_memsz;	/* Size of contents in memory. */
111153504Smarcel	Elf64_Xword	p_align;	/* Alignment in memory and file. */
11236849Sdfr} Elf64_Phdr;
11336849Sdfr
11436849Sdfr/*
11536849Sdfr * Dynamic structure.  The ".dynamic" section contains an array of them.
11636849Sdfr */
11736849Sdfr
11836849Sdfrtypedef struct {
119153504Smarcel	Elf64_Sxword	d_tag;		/* Entry type. */
12036849Sdfr	union {
121153504Smarcel		Elf64_Xword	d_val;	/* Integer value. */
12236849Sdfr		Elf64_Addr	d_ptr;	/* Address value. */
12336849Sdfr	} d_un;
12436849Sdfr} Elf64_Dyn;
12536849Sdfr
12636849Sdfr/*
12736849Sdfr * Relocation entries.
12836849Sdfr */
12936849Sdfr
13036849Sdfr/* Relocations that don't need an addend field. */
13136849Sdfrtypedef struct {
13236849Sdfr	Elf64_Addr	r_offset;	/* Location to be relocated. */
133153504Smarcel	Elf64_Xword	r_info;		/* Relocation type and symbol index. */
13436849Sdfr} Elf64_Rel;
13536849Sdfr
13636849Sdfr/* Relocations that need an addend field. */
13736849Sdfrtypedef struct {
13836849Sdfr	Elf64_Addr	r_offset;	/* Location to be relocated. */
139153504Smarcel	Elf64_Xword	r_info;		/* Relocation type and symbol index. */
140153504Smarcel	Elf64_Sxword	r_addend;	/* Addend. */
14136849Sdfr} Elf64_Rela;
14236849Sdfr
14336849Sdfr/* Macros for accessing the fields of r_info. */
144186667Sobrien#define	ELF64_R_SYM(info)	((info) >> 32)
145186667Sobrien#define	ELF64_R_TYPE(info)	((info) & 0xffffffffL)
14636849Sdfr
14736849Sdfr/* Macro for constructing r_info from field values. */
148186667Sobrien#define	ELF64_R_INFO(sym, type)	(((sym) << 32) + ((type) & 0xffffffffL))
14936849Sdfr
150163016Sjb#define	ELF64_R_TYPE_DATA(info)	(((Elf64_Xword)(info)<<32)>>40)
151163016Sjb#define	ELF64_R_TYPE_ID(info)	(((Elf64_Xword)(info)<<56)>>56)
152163016Sjb#define	ELF64_R_TYPE_INFO(data, type)	\
153186667Sobrien				(((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))
154163016Sjb
15536849Sdfr/*
156163016Sjb *	Note entry header
157163016Sjb */
158163457Sjkoshytypedef Elf_Note Elf64_Nhdr;
159163016Sjb
160163016Sjb/*
161163016Sjb *	Move entry
162163016Sjb */
163163016Sjbtypedef struct {
164163016Sjb	Elf64_Lword	m_value;	/* symbol value */
165163016Sjb	Elf64_Xword 	m_info;		/* size + index */
166163016Sjb	Elf64_Xword	m_poffset;	/* symbol offset */
167163016Sjb	Elf64_Half	m_repeat;	/* repeat count */
168163016Sjb	Elf64_Half	m_stride;	/* stride info */
169163016Sjb} Elf64_Move;
170163016Sjb
171163016Sjb#define	ELF64_M_SYM(info)	((info)>>8)
172163016Sjb#define	ELF64_M_SIZE(info)	((unsigned char)(info))
173163016Sjb#define	ELF64_M_INFO(sym, size)	(((sym)<<8)+(unsigned char)(size))
174163016Sjb
175163016Sjb/*
176163016Sjb *	Hardware/Software capabilities entry
177163016Sjb */
178163016Sjbtypedef struct {
179163016Sjb	Elf64_Xword	c_tag;		/* how to interpret value */
180163016Sjb	union {
181163016Sjb		Elf64_Xword	c_val;
182163016Sjb		Elf64_Addr	c_ptr;
183163016Sjb	} c_un;
184163016Sjb} Elf64_Cap;
185163016Sjb
186163016Sjb/*
18736849Sdfr * Symbol table entries.
18836849Sdfr */
18936849Sdfr
19036849Sdfrtypedef struct {
191153504Smarcel	Elf64_Word	st_name;	/* String table index of name. */
19236849Sdfr	unsigned char	st_info;	/* Type and binding information. */
19336849Sdfr	unsigned char	st_other;	/* Reserved (not used). */
194153504Smarcel	Elf64_Half	st_shndx;	/* Section index of symbol. */
19536849Sdfr	Elf64_Addr	st_value;	/* Symbol value. */
196153504Smarcel	Elf64_Xword	st_size;	/* Size of associated object. */
19736849Sdfr} Elf64_Sym;
19836849Sdfr
19936849Sdfr/* Macros for accessing the fields of st_info. */
200186667Sobrien#define	ELF64_ST_BIND(info)		((info) >> 4)
201186667Sobrien#define	ELF64_ST_TYPE(info)		((info) & 0xf)
20236849Sdfr
20336849Sdfr/* Macro for constructing st_info from field values. */
204186667Sobrien#define	ELF64_ST_INFO(bind, type)	(((bind) << 4) + ((type) & 0xf))
20536849Sdfr
206153502Smarcel/* Macro for accessing the fields of st_other. */
207186667Sobrien#define	ELF64_ST_VISIBILITY(oth)	((oth) & 0x3)
208153502Smarcel
209153515Skan/* Structures used by Sun & GNU-style symbol versioning. */
210153515Skantypedef struct {
211153515Skan	Elf64_Half	vd_version;
212153515Skan	Elf64_Half	vd_flags;
213153515Skan	Elf64_Half	vd_ndx;
214153515Skan	Elf64_Half	vd_cnt;
215153515Skan	Elf64_Word	vd_hash;
216153515Skan	Elf64_Word	vd_aux;
217153515Skan	Elf64_Word	vd_next;
218153515Skan} Elf64_Verdef;
219153515Skan
220153515Skantypedef struct {
221153515Skan	Elf64_Word	vda_name;
222153515Skan	Elf64_Word	vda_next;
223153515Skan} Elf64_Verdaux;
224153515Skan
225153515Skantypedef struct {
226153515Skan	Elf64_Half	vn_version;
227153515Skan	Elf64_Half	vn_cnt;
228153515Skan	Elf64_Word	vn_file;
229153515Skan	Elf64_Word	vn_aux;
230153515Skan	Elf64_Word	vn_next;
231153515Skan} Elf64_Verneed;
232153515Skan
233153515Skantypedef struct {
234153515Skan	Elf64_Word	vna_hash;
235153515Skan	Elf64_Half	vna_flags;
236153515Skan	Elf64_Half	vna_other;
237153515Skan	Elf64_Word	vna_name;
238153515Skan	Elf64_Word	vna_next;
239153515Skan} Elf64_Vernaux;
240153515Skan
241153515Skantypedef Elf64_Half Elf64_Versym;
242153515Skan
243163016Sjbtypedef struct {
244163016Sjb	Elf64_Half	si_boundto;	/* direct bindings - symbol bound to */
245163016Sjb	Elf64_Half	si_flags;	/* per symbol flags */
246163016Sjb} Elf64_Syminfo;
247163016Sjb
24836849Sdfr#endif /* !_SYS_ELF64_H_ */
249