elf64.h revision 38873
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 *
2638873Sjb *      $Id: elf64.h,v 1.4 1998/08/16 03:03:38 jdp Exp $
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/*
4736849Sdfr * ELF header.
4836849Sdfr */
4936849Sdfr
5036849Sdfrtypedef struct {
5136849Sdfr	unsigned char	e_ident[EI_NIDENT];	/* File identification. */
5238873Sjb	Elf64_Quarter	e_type;		/* File type. */
5338873Sjb	Elf64_Quarter	e_machine;	/* Machine architecture. */
5438873Sjb	Elf64_Half	e_version;	/* ELF format version. */
5536849Sdfr	Elf64_Addr	e_entry;	/* Entry point. */
5636849Sdfr	Elf64_Off	e_phoff;	/* Program header file offset. */
5736849Sdfr	Elf64_Off	e_shoff;	/* Section header file offset. */
5838873Sjb	Elf64_Half	e_flags;	/* Architecture-specific flags. */
5938873Sjb	Elf64_Quarter	e_ehsize;	/* Size of ELF header in bytes. */
6038873Sjb	Elf64_Quarter	e_phentsize;	/* Size of program header entry. */
6138873Sjb	Elf64_Quarter	e_phnum;	/* Number of program header entries. */
6238873Sjb	Elf64_Quarter	e_shentsize;	/* Size of section header entry. */
6338873Sjb	Elf64_Quarter	e_shnum;	/* Number of section header entries. */
6438873Sjb	Elf64_Quarter	e_shstrndx;	/* Section name strings section. */
6536849Sdfr} Elf64_Ehdr;
6636849Sdfr
6736849Sdfr/*
6836849Sdfr * Section header.
6936849Sdfr */
7036849Sdfr
7136849Sdfrtypedef struct {
7238873Sjb	Elf64_Half	sh_name;	/* Section name (index into the
7336849Sdfr					   section header string table). */
7438873Sjb	Elf64_Half	sh_type;	/* Section type. */
7536849Sdfr	Elf64_Size	sh_flags;	/* Section flags. */
7636849Sdfr	Elf64_Addr	sh_addr;	/* Address in memory image. */
7736849Sdfr	Elf64_Off	sh_offset;	/* Offset in file. */
7836970Sdfr	Elf64_Size	sh_size;	/* Size in bytes. */
7938873Sjb	Elf64_Half	sh_link;	/* Index of a related section. */
8038873Sjb	Elf64_Half	sh_info;	/* Depends on section type. */
8136849Sdfr	Elf64_Size	sh_addralign;	/* Alignment in bytes. */
8236849Sdfr	Elf64_Size	sh_entsize;	/* Size of each entry in section. */
8336849Sdfr} Elf64_Shdr;
8436849Sdfr
8536849Sdfr/*
8636849Sdfr * Program header.
8736849Sdfr */
8836849Sdfr
8936849Sdfrtypedef struct {
9038873Sjb	Elf64_Half	p_type;		/* Entry type. */
9138873Sjb	Elf64_Half	p_flags;	/* Access permission flags. */
9236849Sdfr	Elf64_Off	p_offset;	/* File offset of contents. */
9336849Sdfr	Elf64_Addr	p_vaddr;	/* Virtual address in memory image. */
9436849Sdfr	Elf64_Addr	p_paddr;	/* Physical address (not used). */
9536849Sdfr	Elf64_Size	p_filesz;	/* Size of contents in file. */
9636849Sdfr	Elf64_Size	p_memsz;	/* Size of contents in memory. */
9736849Sdfr	Elf64_Size	p_align;	/* Alignment in memory and file. */
9836849Sdfr} Elf64_Phdr;
9936849Sdfr
10036849Sdfr/*
10136849Sdfr * Dynamic structure.  The ".dynamic" section contains an array of them.
10236849Sdfr */
10336849Sdfr
10436849Sdfrtypedef struct {
10536849Sdfr	Elf64_Size	d_tag;		/* Entry type. */
10636849Sdfr	union {
10736849Sdfr		Elf64_Size	d_val;	/* Integer value. */
10836849Sdfr		Elf64_Addr	d_ptr;	/* Address value. */
10936849Sdfr	} d_un;
11036849Sdfr} Elf64_Dyn;
11136849Sdfr
11236849Sdfr/*
11336849Sdfr * Relocation entries.
11436849Sdfr */
11536849Sdfr
11636849Sdfr/* Relocations that don't need an addend field. */
11736849Sdfrtypedef struct {
11836849Sdfr	Elf64_Addr	r_offset;	/* Location to be relocated. */
11936849Sdfr	Elf64_Size	r_info;		/* Relocation type and symbol index. */
12036849Sdfr} Elf64_Rel;
12136849Sdfr
12236849Sdfr/* Relocations that need an addend field. */
12336849Sdfrtypedef struct {
12436849Sdfr	Elf64_Addr	r_offset;	/* Location to be relocated. */
12536849Sdfr	Elf64_Size	r_info;		/* Relocation type and symbol index. */
12636849Sdfr	Elf64_Off	r_addend;	/* Addend. */
12736849Sdfr} Elf64_Rela;
12836849Sdfr
12936849Sdfr/* Macros for accessing the fields of r_info. */
13038873Sjb#define ELF64_R_SYM(info)	((info) >> 32)
13136849Sdfr#define ELF64_R_TYPE(info)	((unsigned char)(info))
13236849Sdfr
13336849Sdfr/* Macro for constructing r_info from field values. */
13436849Sdfr#define ELF64_R_INFO(sym, type)	(((sym) << 8) + (unsigned char)(type))
13536849Sdfr
13636849Sdfr/*
13736849Sdfr * Symbol table entries.
13836849Sdfr */
13936849Sdfr
14036849Sdfrtypedef struct {
14138873Sjb	Elf64_Half	st_name;	/* String table index of name. */
14236849Sdfr	unsigned char	st_info;	/* Type and binding information. */
14336849Sdfr	unsigned char	st_other;	/* Reserved (not used). */
14438873Sjb	Elf64_Quarter	st_shndx;	/* Section index of symbol. */
14536849Sdfr	Elf64_Addr	st_value;	/* Symbol value. */
14636849Sdfr	Elf64_Size	st_size;	/* Size of associated object. */
14736849Sdfr} Elf64_Sym;
14836849Sdfr
14936849Sdfr/* Macros for accessing the fields of st_info. */
15036849Sdfr#define ELF64_ST_BIND(info)		((info) >> 4)
15136849Sdfr#define ELF64_ST_TYPE(info)		((info) & 0xf)
15236849Sdfr
15336849Sdfr/* Macro for constructing st_info from field values. */
15436849Sdfr#define ELF64_ST_INFO(bind, type)	(((bind) << 4) + ((type) & 0xf))
15536849Sdfr
15636849Sdfr#endif /* !_SYS_ELF64_H_ */
157