Home | History | Annotate | Line # | Download | only in sys
exec_elf.h revision 1.4.4.1
      1  1.4.4.1  perseant /*	$NetBSD: exec_elf.h,v 1.4.4.1 2025/08/02 05:58:23 perseant Exp $	*/
      2      1.1   tsutsui 
      3      1.1   tsutsui /*-
      4      1.1   tsutsui  * Copyright (c) 1994 The NetBSD Foundation, Inc.
      5      1.1   tsutsui  * All rights reserved.
      6      1.1   tsutsui  *
      7      1.1   tsutsui  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1   tsutsui  * by Christos Zoulas.
      9      1.1   tsutsui  *
     10      1.1   tsutsui  * Redistribution and use in source and binary forms, with or without
     11      1.1   tsutsui  * modification, are permitted provided that the following conditions
     12      1.1   tsutsui  * are met:
     13      1.1   tsutsui  * 1. Redistributions of source code must retain the above copyright
     14      1.1   tsutsui  *    notice, this list of conditions and the following disclaimer.
     15      1.1   tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1   tsutsui  *    notice, this list of conditions and the following disclaimer in the
     17      1.1   tsutsui  *    documentation and/or other materials provided with the distribution.
     18      1.1   tsutsui  *
     19      1.1   tsutsui  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1   tsutsui  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1   tsutsui  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1   tsutsui  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1   tsutsui  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1   tsutsui  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1   tsutsui  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1   tsutsui  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1   tsutsui  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1   tsutsui  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1   tsutsui  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1   tsutsui  */
     31      1.1   tsutsui 
     32      1.1   tsutsui #ifndef _SYS_EXEC_ELF_H_
     33      1.3  christos #define _SYS_EXEC_ELF_H_
     34      1.1   tsutsui 
     35      1.1   tsutsui /*
     36      1.1   tsutsui  * The current ELF ABI specification is available at:
     37      1.3  christos  *	http://www.sco.com/developers/gabi/
     38      1.1   tsutsui  *
     39      1.1   tsutsui  * Current header definitions are in:
     40      1.3  christos  *	http://www.sco.com/developers/gabi/latest/ch4.eheader.html
     41      1.1   tsutsui  */
     42      1.1   tsutsui 
     43      1.1   tsutsui #if defined(_KERNEL) || defined(_STANDALONE)
     44      1.1   tsutsui #include <sys/types.h>
     45      1.1   tsutsui #else
     46      1.1   tsutsui #include <inttypes.h>
     47      1.3  christos #include <stddef.h>
     48      1.1   tsutsui #endif /* _KERNEL || _STANDALONE */
     49      1.1   tsutsui 
     50      1.3  christos #if 0
     51      1.3  christos #if HAVE_NBTOOL_CONFIG_H
     52      1.3  christos #include <nbinclude/machine/elf_machdep.h>
     53      1.3  christos #else
     54      1.3  christos #include <machine/elf_machdep.h>
     55      1.3  christos #endif
     56      1.3  christos #endif
     57      1.1   tsutsui 
     58      1.3  christos typedef uint8_t		Elf_Byte;
     59      1.3  christos 
     60      1.3  christos typedef uint32_t	Elf32_Addr;
     61      1.3  christos #define ELF32_FSZ_ADDR	4
     62      1.3  christos typedef uint32_t	Elf32_Off;
     63      1.3  christos typedef int32_t		Elf32_SOff;
     64      1.3  christos #define ELF32_FSZ_OFF	4
     65      1.3  christos typedef int32_t		Elf32_Sword;
     66      1.3  christos #define ELF32_FSZ_SWORD 4
     67      1.3  christos typedef uint32_t	Elf32_Word;
     68      1.3  christos #define ELF32_FSZ_WORD	4
     69      1.3  christos typedef uint16_t	Elf32_Half;
     70      1.3  christos #define ELF32_FSZ_HALF	2
     71      1.3  christos typedef uint64_t	Elf32_Lword;
     72      1.3  christos #define ELF32_FSZ_LWORD 8
     73      1.3  christos 
     74      1.3  christos typedef uint64_t	Elf64_Addr;
     75      1.3  christos #define ELF64_FSZ_ADDR	8
     76      1.3  christos typedef uint64_t	Elf64_Off;
     77      1.3  christos typedef int64_t		Elf64_SOff;
     78      1.3  christos #define ELF64_FSZ_OFF	8
     79      1.3  christos 
     80      1.3  christos typedef int32_t		Elf64_Sword;
     81      1.3  christos #define ELF64_FSZ_SWORD 4
     82      1.3  christos typedef uint32_t	Elf64_Word;
     83      1.3  christos #define ELF64_FSZ_WORD	4
     84      1.3  christos 
     85      1.3  christos typedef int64_t		Elf64_Sxword;
     86      1.3  christos #define ELF64_FSZ_SXWORD 8
     87      1.3  christos typedef uint64_t	Elf64_Xword;
     88      1.3  christos #define ELF64_FSZ_XWORD 8
     89      1.3  christos typedef uint64_t	Elf64_Lword;
     90      1.3  christos #define ELF64_FSZ_LWORD 8
     91      1.3  christos typedef uint16_t	Elf64_Half;
     92      1.3  christos #define ELF64_FSZ_HALF 2
     93      1.1   tsutsui 
     94      1.1   tsutsui /*
     95      1.1   tsutsui  * ELF Header
     96      1.1   tsutsui  */
     97      1.3  christos #define ELF_NIDENT	16
     98      1.1   tsutsui 
     99      1.1   tsutsui typedef struct {
    100      1.1   tsutsui 	unsigned char	e_ident[ELF_NIDENT];	/* Id bytes */
    101      1.1   tsutsui 	Elf32_Half	e_type;			/* file type */
    102      1.1   tsutsui 	Elf32_Half	e_machine;		/* machine type */
    103      1.1   tsutsui 	Elf32_Word	e_version;		/* version number */
    104      1.1   tsutsui 	Elf32_Addr	e_entry;		/* entry point */
    105      1.1   tsutsui 	Elf32_Off	e_phoff;		/* Program hdr offset */
    106      1.1   tsutsui 	Elf32_Off	e_shoff;		/* Section hdr offset */
    107      1.1   tsutsui 	Elf32_Word	e_flags;		/* Processor flags */
    108      1.3  christos 	Elf32_Half	e_ehsize;		/* sizeof ehdr */
    109      1.3  christos 	Elf32_Half	e_phentsize;		/* Program header entry size */
    110      1.3  christos 	Elf32_Half	e_phnum;		/* Number of program headers */
    111      1.3  christos 	Elf32_Half	e_shentsize;		/* Section header entry size */
    112      1.3  christos 	Elf32_Half	e_shnum;		/* Number of section headers */
    113      1.3  christos 	Elf32_Half	e_shstrndx;		/* String table index */
    114      1.1   tsutsui } Elf32_Ehdr;
    115      1.1   tsutsui 
    116      1.1   tsutsui typedef struct {
    117      1.1   tsutsui 	unsigned char	e_ident[ELF_NIDENT];	/* Id bytes */
    118      1.1   tsutsui 	Elf64_Half	e_type;			/* file type */
    119      1.1   tsutsui 	Elf64_Half	e_machine;		/* machine type */
    120      1.1   tsutsui 	Elf64_Word	e_version;		/* version number */
    121      1.1   tsutsui 	Elf64_Addr	e_entry;		/* entry point */
    122      1.1   tsutsui 	Elf64_Off	e_phoff;		/* Program hdr offset */
    123      1.1   tsutsui 	Elf64_Off	e_shoff;		/* Section hdr offset */
    124      1.1   tsutsui 	Elf64_Word	e_flags;		/* Processor flags */
    125      1.1   tsutsui 	Elf64_Half	e_ehsize;		/* sizeof ehdr */
    126      1.1   tsutsui 	Elf64_Half	e_phentsize;		/* Program header entry size */
    127      1.1   tsutsui 	Elf64_Half	e_phnum;		/* Number of program headers */
    128      1.1   tsutsui 	Elf64_Half	e_shentsize;		/* Section header entry size */
    129      1.1   tsutsui 	Elf64_Half	e_shnum;		/* Number of section headers */
    130      1.1   tsutsui 	Elf64_Half	e_shstrndx;		/* String table index */
    131      1.1   tsutsui } Elf64_Ehdr;
    132      1.1   tsutsui 
    133      1.1   tsutsui /* e_ident offsets */
    134      1.3  christos #define EI_MAG0		0	/* '\177' */
    135      1.3  christos #define EI_MAG1		1	/* 'E'	  */
    136      1.3  christos #define EI_MAG2		2	/* 'L'	  */
    137      1.3  christos #define EI_MAG3		3	/* 'F'	  */
    138      1.3  christos #define EI_CLASS	4	/* File class */
    139      1.3  christos #define EI_DATA		5	/* Data encoding */
    140      1.3  christos #define EI_VERSION	6	/* File version */
    141      1.3  christos #define EI_OSABI	7	/* Operating system/ABI identification */
    142      1.3  christos #define EI_ABIVERSION	8	/* ABI version */
    143      1.3  christos #define EI_PAD		9	/* Start of padding bytes up to EI_NIDENT*/
    144      1.3  christos #define EI_NIDENT	16	/* First non-ident header byte */
    145      1.3  christos 
    146      1.3  christos /* e_ident[EI_MAG0,EI_MAG3] */
    147      1.3  christos #define ELFMAG0		0x7f
    148      1.3  christos #define ELFMAG1		'E'
    149      1.3  christos #define ELFMAG2		'L'
    150      1.3  christos #define ELFMAG3		'F'
    151      1.3  christos #define ELFMAG		"\177ELF"
    152      1.3  christos #define SELFMAG		4
    153      1.1   tsutsui 
    154      1.1   tsutsui /* e_ident[EI_CLASS] */
    155      1.3  christos #define ELFCLASSNONE	0	/* Invalid class */
    156      1.3  christos #define ELFCLASS32	1	/* 32-bit objects */
    157      1.3  christos #define ELFCLASS64	2	/* 64-bit objects */
    158      1.3  christos #define ELFCLASSNUM	3
    159      1.1   tsutsui 
    160      1.1   tsutsui /* e_ident[EI_DATA] */
    161      1.3  christos #define ELFDATANONE	0	/* Invalid data encoding */
    162      1.3  christos #define ELFDATA2LSB	1	/* 2's complement values, LSB first */
    163      1.3  christos #define ELFDATA2MSB	2	/* 2's complement values, MSB first */
    164      1.1   tsutsui 
    165      1.1   tsutsui /* e_ident[EI_VERSION] */
    166      1.3  christos #define EV_NONE		0	/* Invalid version */
    167      1.3  christos #define EV_CURRENT	1	/* Current version */
    168      1.3  christos #define EV_NUM		2
    169      1.1   tsutsui 
    170      1.1   tsutsui /* e_ident[EI_OSABI] */
    171      1.3  christos #define ELFOSABI_SYSV		0	/* UNIX System V ABI */
    172      1.3  christos #define ELFOSABI_HPUX		1	/* HP-UX operating system */
    173      1.1   tsutsui #define ELFOSABI_NETBSD		2	/* NetBSD */
    174      1.1   tsutsui #define ELFOSABI_LINUX		3	/* GNU/Linux */
    175      1.1   tsutsui #define ELFOSABI_HURD		4	/* GNU/Hurd */
    176      1.1   tsutsui #define ELFOSABI_86OPEN		5	/* 86Open */
    177      1.1   tsutsui #define ELFOSABI_SOLARIS	6	/* Solaris */
    178      1.1   tsutsui #define ELFOSABI_MONTEREY	7	/* Monterey */
    179      1.1   tsutsui #define ELFOSABI_IRIX		8	/* IRIX */
    180      1.1   tsutsui #define ELFOSABI_FREEBSD	9	/* FreeBSD */
    181      1.1   tsutsui #define ELFOSABI_TRU64		10	/* TRU64 UNIX */
    182      1.1   tsutsui #define ELFOSABI_MODESTO	11	/* Novell Modesto */
    183      1.1   tsutsui #define ELFOSABI_OPENBSD	12	/* OpenBSD */
    184      1.3  christos #define ELFOSABI_OPENVMS	13	/* OpenVMS */
    185      1.3  christos #define ELFOSABI_NSK		14	/* HP Non-Stop Kernel */
    186      1.3  christos #define ELFOSABI_AROS		15	/* Amiga Research OS */
    187      1.1   tsutsui /* Unofficial OSABIs follow */
    188      1.1   tsutsui #define ELFOSABI_ARM		97	/* ARM */
    189      1.3  christos #define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
    190      1.3  christos 
    191      1.3  christos #define ELFOSABI_NONE		ELFOSABI_SYSV
    192      1.3  christos #define ELFOSABI_AIX		ELFOSABI_MONTEREY
    193      1.1   tsutsui 
    194      1.1   tsutsui /* e_type */
    195      1.3  christos #define ET_NONE		0	/* No file type */
    196      1.3  christos #define ET_REL		1	/* Relocatable file */
    197      1.3  christos #define ET_EXEC		2	/* Executable file */
    198      1.3  christos #define ET_DYN		3	/* Shared object file */
    199      1.3  christos #define ET_CORE		4	/* Core file */
    200      1.3  christos #define ET_NUM		5
    201      1.3  christos 
    202      1.3  christos #define ET_LOOS		0xfe00	/* Operating system specific range */
    203      1.3  christos #define ET_HIOS		0xfeff
    204      1.3  christos #define ET_LOPROC	0xff00	/* Processor-specific range */
    205      1.3  christos #define ET_HIPROC	0xffff
    206      1.1   tsutsui 
    207      1.1   tsutsui /* e_machine */
    208      1.3  christos #define EM_NONE		0	/* No machine */
    209      1.3  christos #define EM_M32		1	/* AT&T WE 32100 */
    210      1.3  christos #define EM_SPARC	2	/* SPARC */
    211      1.3  christos #define EM_386		3	/* Intel 80386 */
    212      1.3  christos #define EM_68K		4	/* Motorola 68000 */
    213      1.3  christos #define EM_88K		5	/* Motorola 88000 */
    214      1.3  christos #define EM_486		6	/* Intel 80486 [old] */
    215      1.3  christos #define EM_IAMCU	6	/* Intel MCU. */
    216      1.3  christos #define EM_860		7	/* Intel 80860 */
    217      1.3  christos #define EM_MIPS		8	/* MIPS I Architecture */
    218      1.3  christos #define EM_S370		9	/* Amdahl UTS on System/370 */
    219      1.3  christos #define EM_MIPS_RS3_LE	10	/* MIPS RS3000 Little-endian */
    220      1.1   tsutsui 			/* 11-14 - Reserved */
    221      1.3  christos #define EM_RS6000	11	/* IBM RS/6000 XXX reserved */
    222      1.3  christos #define EM_PARISC	15	/* Hewlett-Packard PA-RISC */
    223      1.3  christos #define EM_NCUBE	16	/* NCube XXX reserved */
    224      1.3  christos #define EM_VPP500	17	/* Fujitsu VPP500 */
    225      1.3  christos #define EM_SPARC32PLUS	18	/* Enhanced instruction set SPARC */
    226      1.3  christos #define EM_960		19	/* Intel 80960 */
    227      1.3  christos #define EM_PPC		20	/* PowerPC */
    228      1.3  christos #define EM_PPC64	21	/* 64-bit PowerPC */
    229      1.1   tsutsui 			/* 22-35 - Reserved */
    230      1.3  christos #define EM_S390		22	/* System/390 XXX reserved */
    231      1.3  christos #define EM_V800		36	/* NEC V800 */
    232      1.3  christos #define EM_FR20		37	/* Fujitsu FR20 */
    233      1.3  christos #define EM_RH32		38	/* TRW RH-32 */
    234      1.3  christos #define EM_RCE		39	/* Motorola RCE */
    235      1.3  christos #define EM_ARM		40	/* Advanced RISC Machines ARM */
    236      1.3  christos #define EM_ALPHA	41	/* DIGITAL Alpha */
    237      1.3  christos #define EM_SH		42	/* Hitachi Super-H */
    238      1.3  christos #define EM_SPARCV9	43	/* SPARC Version 9 */
    239      1.3  christos #define EM_TRICORE	44	/* Siemens Tricore */
    240      1.3  christos #define EM_ARC		45	/* Argonaut RISC Core */
    241      1.3  christos #define EM_H8_300	46	/* Hitachi H8/300 */
    242      1.3  christos #define EM_H8_300H	47	/* Hitachi H8/300H */
    243      1.3  christos #define EM_H8S		48	/* Hitachi H8S */
    244      1.3  christos #define EM_H8_500	49	/* Hitachi H8/500 */
    245      1.3  christos #define EM_IA_64	50	/* Intel Merced Processor */
    246      1.3  christos #define EM_MIPS_X	51	/* Stanford MIPS-X */
    247      1.3  christos #define EM_COLDFIRE	52	/* Motorola Coldfire */
    248      1.3  christos #define EM_68HC12	53	/* Motorola MC68HC12 */
    249      1.3  christos #define EM_MMA		54	/* Fujitsu MMA Multimedia Accelerator */
    250      1.3  christos #define EM_PCP		55	/* Siemens PCP */
    251      1.3  christos #define EM_NCPU		56	/* Sony nCPU embedded RISC processor */
    252      1.3  christos #define EM_NDR1		57	/* Denso NDR1 microprocessor */
    253      1.3  christos #define EM_STARCORE	58	/* Motorola Star*Core processor */
    254      1.3  christos #define EM_ME16		59	/* Toyota ME16 processor */
    255      1.3  christos #define EM_ST100	60	/* STMicroelectronics ST100 processor */
    256      1.3  christos #define EM_TINYJ	61	/* Advanced Logic Corp. TinyJ embedded family processor */
    257      1.3  christos #define EM_X86_64	62	/* AMD x86-64 architecture */
    258      1.3  christos #define EM_PDSP		63	/* Sony DSP Processor */
    259      1.3  christos #define EM_PDP10	64	/* Digital Equipment Corp. PDP-10 */
    260      1.3  christos #define EM_PDP11	65	/* Digital Equipment Corp. PDP-11 */
    261      1.3  christos #define EM_FX66		66	/* Siemens FX66 microcontroller */
    262      1.3  christos #define EM_ST9PLUS	67	/* STMicroelectronics ST9+ 8/16 bit microcontroller */
    263      1.3  christos #define EM_ST7		68	/* STMicroelectronics ST7 8-bit microcontroller */
    264      1.3  christos #define EM_68HC16	69	/* Motorola MC68HC16 Microcontroller */
    265      1.3  christos #define EM_68HC11	70	/* Motorola MC68HC11 Microcontroller */
    266      1.3  christos #define EM_68HC08	71	/* Motorola MC68HC08 Microcontroller */
    267      1.3  christos #define EM_68HC05	72	/* Motorola MC68HC05 Microcontroller */
    268      1.3  christos #define EM_SVX		73	/* Silicon Graphics SVx */
    269      1.3  christos #define EM_ST19		74	/* STMicroelectronics ST19 8-bit CPU */
    270      1.3  christos #define EM_VAX		75	/* Digital VAX */
    271      1.3  christos #define EM_CRIS		76	/* Axis Communications 32-bit embedded processor */
    272      1.3  christos #define EM_JAVELIN	77	/* Infineon Technologies 32-bit embedded CPU */
    273      1.3  christos #define EM_FIREPATH	78	/* Element 14 64-bit DSP processor */
    274      1.3  christos #define EM_ZSP		79	/* LSI Logic's 16-bit DSP processor */
    275      1.3  christos #define EM_MMIX		80	/* Donald Knuth's educational 64-bit processor */
    276      1.3  christos #define EM_HUANY	81	/* Harvard's machine-independent format */
    277      1.3  christos #define EM_PRISM	82	/* SiTera Prism */
    278      1.3  christos #define EM_AVR		83	/* Atmel AVR 8-bit microcontroller */
    279      1.3  christos #define EM_FR30		84	/* Fujitsu FR30 */
    280      1.3  christos #define EM_D10V		85	/* Mitsubishi D10V */
    281      1.3  christos #define EM_D30V		86	/* Mitsubishi D30V */
    282      1.3  christos #define EM_V850		87	/* NEC v850 */
    283      1.3  christos #define EM_M32R		88	/* Mitsubishi M32R */
    284      1.3  christos #define EM_MN10300	89	/* Matsushita MN10300 */
    285      1.3  christos #define EM_MN10200	90	/* Matsushita MN10200 */
    286      1.3  christos #define EM_PJ		91	/* picoJava */
    287      1.3  christos #define EM_OR1K		92	/* OpenRISC 32-bit embedded processor */
    288      1.3  christos #define EM_OPENRISC	EM_OR1K
    289      1.3  christos #define EM_ARC_A5	93	/* ARC Cores Tangent-A5 */
    290      1.3  christos #define EM_XTENSA	94	/* Tensilica Xtensa Architecture */
    291      1.3  christos #define EM_VIDEOCORE	95	/* Alphamosaic VideoCore processor */
    292      1.3  christos #define EM_TMM_GPP	96	/* Thompson Multimedia General Purpose Processor */
    293      1.3  christos #define EM_NS32K	97	/* National Semiconductor 32000 series */
    294      1.3  christos #define EM_TPC		98	/* Tenor Network TPC processor */
    295      1.3  christos #define EM_SNP1K	99	/* Trebia SNP 1000 processor */
    296      1.3  christos #define EM_ST200	100	/* STMicroelectronics ST200 microcontroller */
    297      1.3  christos #define EM_IP2K		101	/* Ubicom IP2xxx microcontroller family */
    298      1.3  christos #define EM_MAX		102	/* MAX processor */
    299  1.4.4.1  perseant #define EM_CR		103	/* National Semiconductor CompactRISC microprocessor */
    300      1.3  christos #define EM_F2MC16	104	/* Fujitsu F2MC16 */
    301      1.3  christos #define EM_MSP430	105	/* Texas Instruments MSP430 */
    302      1.3  christos #define EM_BLACKFIN	106	/* Analog Devices Blackfin DSP */
    303      1.3  christos #define EM_SE_C33	107	/* Seiko Epson S1C33 family */
    304      1.3  christos #define EM_SEP		108	/* Sharp embedded microprocessor */
    305      1.3  christos #define EM_ARCA		109	/* Arca RISC microprocessor */
    306      1.3  christos #define EM_UNICORE	110	/* UNICORE from PKU-Unity Ltd. and MPRC Peking University */
    307      1.3  christos #define EM_ALTERA_NIOS2	113	/* Altera Nios II soft-core processor */
    308      1.3  christos #define EM_AARCH64	183	/* AArch64 64-bit ARM microprocessor */
    309      1.3  christos #define EM_AVR32	185	/* Atmel Corporation 32-bit microprocessor family*/
    310      1.3  christos #define EM_TILE64	187	/* Tilera TILE64 multicore architecture family */
    311      1.3  christos #define EM_TILEPRO	188	/* Tilera TILEPro multicore architecture family */
    312      1.3  christos #define EM_MICROBLAZE	189	/* Xilinx MicroBlaze 32-bit RISC soft processor core */
    313      1.3  christos #define EM_TILEGX	192	/* Tilera TILE-GX multicore architecture family */
    314      1.3  christos #define EM_Z80		220	/* Zilog Z80 */
    315      1.3  christos #define EM_RISCV	243	/* RISC-V */
    316      1.1   tsutsui 
    317      1.1   tsutsui /* Unofficial machine types follow */
    318      1.3  christos #define EM_ALPHA_EXP	36902	/* used by NetBSD/alpha; obsolete */
    319      1.3  christos #define EM_NUM		36903
    320      1.1   tsutsui 
    321      1.1   tsutsui /*
    322      1.1   tsutsui  * Program Header
    323      1.1   tsutsui  */
    324      1.1   tsutsui typedef struct {
    325      1.1   tsutsui 	Elf32_Word	p_type;		/* entry type */
    326      1.1   tsutsui 	Elf32_Off	p_offset;	/* offset */
    327      1.1   tsutsui 	Elf32_Addr	p_vaddr;	/* virtual address */
    328      1.1   tsutsui 	Elf32_Addr	p_paddr;	/* physical address */
    329      1.1   tsutsui 	Elf32_Word	p_filesz;	/* file size */
    330      1.1   tsutsui 	Elf32_Word	p_memsz;	/* memory size */
    331      1.1   tsutsui 	Elf32_Word	p_flags;	/* flags */
    332      1.1   tsutsui 	Elf32_Word	p_align;	/* memory & file alignment */
    333      1.1   tsutsui } Elf32_Phdr;
    334      1.1   tsutsui 
    335      1.1   tsutsui typedef struct {
    336      1.1   tsutsui 	Elf64_Word	p_type;		/* entry type */
    337      1.1   tsutsui 	Elf64_Word	p_flags;	/* flags */
    338      1.1   tsutsui 	Elf64_Off	p_offset;	/* offset */
    339      1.1   tsutsui 	Elf64_Addr	p_vaddr;	/* virtual address */
    340      1.1   tsutsui 	Elf64_Addr	p_paddr;	/* physical address */
    341      1.1   tsutsui 	Elf64_Xword	p_filesz;	/* file size */
    342      1.1   tsutsui 	Elf64_Xword	p_memsz;	/* memory size */
    343      1.1   tsutsui 	Elf64_Xword	p_align;	/* memory & file alignment */
    344      1.1   tsutsui } Elf64_Phdr;
    345      1.1   tsutsui 
    346      1.1   tsutsui /* p_type */
    347      1.3  christos #define PT_NULL		0		/* Program header table entry unused */
    348      1.3  christos #define PT_LOAD		1		/* Loadable program segment */
    349      1.3  christos #define PT_DYNAMIC	2		/* Dynamic linking information */
    350      1.3  christos #define PT_INTERP	3		/* Program interpreter */
    351      1.3  christos #define PT_NOTE		4		/* Auxiliary information */
    352      1.3  christos #define PT_SHLIB	5		/* Reserved, unspecified semantics */
    353      1.3  christos #define PT_PHDR		6		/* Entry for header table itself */
    354      1.3  christos #define PT_TLS		7		/* TLS initialisation image */
    355      1.3  christos #define PT_NUM		8
    356      1.3  christos 
    357      1.3  christos #define PT_LOOS		0x60000000	/* OS-specific range */
    358      1.3  christos 
    359      1.3  christos /* GNU-specific */
    360      1.3  christos #define PT_GNU_EH_FRAME 0x6474e550	/* EH frame segment */
    361      1.3  christos #define PT_GNU_STACK	0x6474e551	/* Indicate executable stack */
    362      1.3  christos #define PT_GNU_RELRO	0x6474e552	/* Make read-only after relocation */
    363      1.3  christos 
    364      1.3  christos #define PT_HIOS		0x6fffffff
    365      1.3  christos #define PT_LOPROC	0x70000000	/* Processor-specific range */
    366      1.3  christos #define PT_HIPROC	0x7fffffff
    367      1.3  christos 
    368      1.3  christos #define PT_MIPS_REGINFO 0x70000000
    369      1.3  christos #define PT_MIPS_ABIFLAGS 0x70000003
    370      1.1   tsutsui 
    371      1.1   tsutsui /* p_flags */
    372      1.3  christos #define PF_R		0x4		/* Segment is readable */
    373      1.3  christos #define PF_W		0x2		/* Segment is writable */
    374      1.3  christos #define PF_X		0x1		/* Segment is executable */
    375      1.1   tsutsui 
    376      1.3  christos #define PF_MASKOS	0x0ff00000	/* Operating system specific values */
    377      1.3  christos #define PF_MASKPROC	0xf0000000	/* Processor-specific values */
    378      1.1   tsutsui 
    379      1.3  christos /* Extended program header index. */
    380      1.3  christos #define PN_XNUM		0xffff
    381      1.1   tsutsui 
    382      1.1   tsutsui /*
    383      1.1   tsutsui  * Section Headers
    384      1.1   tsutsui  */
    385      1.1   tsutsui typedef struct {
    386      1.1   tsutsui 	Elf32_Word	sh_name;	/* section name (.shstrtab index) */
    387      1.1   tsutsui 	Elf32_Word	sh_type;	/* section type */
    388      1.1   tsutsui 	Elf32_Word	sh_flags;	/* section flags */
    389      1.1   tsutsui 	Elf32_Addr	sh_addr;	/* virtual address */
    390      1.1   tsutsui 	Elf32_Off	sh_offset;	/* file offset */
    391      1.1   tsutsui 	Elf32_Word	sh_size;	/* section size */
    392      1.1   tsutsui 	Elf32_Word	sh_link;	/* link to another */
    393      1.1   tsutsui 	Elf32_Word	sh_info;	/* misc info */
    394      1.1   tsutsui 	Elf32_Word	sh_addralign;	/* memory alignment */
    395      1.1   tsutsui 	Elf32_Word	sh_entsize;	/* table entry size */
    396      1.1   tsutsui } Elf32_Shdr;
    397      1.1   tsutsui 
    398      1.1   tsutsui typedef struct {
    399      1.1   tsutsui 	Elf64_Word	sh_name;	/* section name (.shstrtab index) */
    400      1.1   tsutsui 	Elf64_Word	sh_type;	/* section type */
    401      1.1   tsutsui 	Elf64_Xword	sh_flags;	/* section flags */
    402      1.1   tsutsui 	Elf64_Addr	sh_addr;	/* virtual address */
    403      1.1   tsutsui 	Elf64_Off	sh_offset;	/* file offset */
    404      1.1   tsutsui 	Elf64_Xword	sh_size;	/* section size */
    405      1.1   tsutsui 	Elf64_Word	sh_link;	/* link to another */
    406      1.1   tsutsui 	Elf64_Word	sh_info;	/* misc info */
    407      1.1   tsutsui 	Elf64_Xword	sh_addralign;	/* memory alignment */
    408      1.1   tsutsui 	Elf64_Xword	sh_entsize;	/* table entry size */
    409      1.1   tsutsui } Elf64_Shdr;
    410      1.1   tsutsui 
    411      1.1   tsutsui /* sh_type */
    412      1.3  christos #define SHT_NULL	      0		/* Section header table entry unused */
    413      1.3  christos #define SHT_PROGBITS	      1		/* Program information */
    414      1.3  christos #define SHT_SYMTAB	      2		/* Symbol table */
    415      1.3  christos #define SHT_STRTAB	      3		/* String table */
    416      1.3  christos #define SHT_RELA	      4		/* Relocation information w/ addend */
    417      1.3  christos #define SHT_HASH	      5		/* Symbol hash table */
    418      1.3  christos #define SHT_DYNAMIC	      6		/* Dynamic linking information */
    419      1.3  christos #define SHT_NOTE	      7		/* Auxiliary information */
    420      1.3  christos #define SHT_NOBITS	      8		/* No space allocated in file image */
    421      1.3  christos #define SHT_REL		      9		/* Relocation information w/o addend */
    422      1.3  christos #define SHT_SHLIB	     10		/* Reserved, unspecified semantics */
    423      1.3  christos #define SHT_DYNSYM	     11		/* Symbol table for dynamic linker */
    424      1.3  christos #define SHT_INIT_ARRAY	     14		/* Initialization function pointers */
    425      1.3  christos #define SHT_FINI_ARRAY	     15		/* Termination function pointers */
    426      1.3  christos #define SHT_PREINIT_ARRAY    16		/* Pre-initialization function ptrs */
    427      1.3  christos #define SHT_GROUP	     17		/* Section group */
    428      1.3  christos #define SHT_SYMTAB_SHNDX     18		/* Section indexes (see SHN_XINDEX) */
    429      1.3  christos #define SHT_NUM		     19
    430      1.3  christos 
    431      1.3  christos #define SHT_LOOS	     0x60000000 /* Operating system specific range */
    432      1.3  christos #define SHT_GNU_INCREMENTAL_INPUTS 0x6fff4700   /* GNU incremental build data */
    433      1.3  christos #define	SHT_LOSUNW	     0x6ffffff4
    434      1.3  christos #define	SHT_SUNW_dof	     0x6ffffff4
    435      1.3  christos #define	SHT_GNU_ATTRIBUTES   0x6ffffff5	/* GNU object attributes */
    436      1.3  christos #define	SHT_SUNW_cap	     0x6ffffff5
    437      1.3  christos #define	SHT_SUNW_SIGNATURE   0x6ffffff6
    438      1.3  christos #define SHT_GNU_HASH	     0x6ffffff6 /* GNU style symbol hash table */
    439      1.3  christos #define SHT_GNU_LIBLIST	     0x6ffffff7 /* GNU list of prelink dependencies */
    440      1.3  christos #define SHT_SUNW_move	     0x6ffffffa
    441      1.3  christos #define	SHT_SUNW_COMDAT	     0x6ffffffb
    442      1.3  christos #define SHT_SUNW_syminfo     0x6ffffffc
    443      1.3  christos #define SHT_SUNW_verdef	     0x6ffffffd /* Versions defined by file */
    444      1.3  christos #define SHT_GNU_verdef	     SHT_SUNW_verdef
    445      1.3  christos #define SHT_SUNW_verneed     0x6ffffffe /* Versions needed by file */
    446      1.3  christos #define SHT_GNU_verneed	     SHT_SUNW_verneed
    447      1.3  christos #define SHT_SUNW_versym	     0x6fffffff /* Symbol versions */
    448      1.3  christos #define SHT_GNU_versym	     SHT_SUNW_versym
    449      1.3  christos #define	SHT_HISUNW	     0x6fffffff
    450      1.3  christos #define SHT_HIOS	     0x6fffffff
    451      1.3  christos #define SHT_LOPROC	     0x70000000 /* Processor-specific range */
    452      1.3  christos #define SHT_AMD64_UNWIND     0x70000001 /* unwind information */
    453      1.3  christos #define SHT_ARM_EXIDX	     0x70000001	/* exception index table */
    454      1.3  christos #define SHT_ARM_PREEMPTMAP   0x70000002 /* BPABI DLL dynamic linking
    455      1.3  christos 					 * pre-emption map */
    456      1.3  christos #define SHT_ARM_ATTRIBUTES   0x70000003 /* Object file compatibility
    457      1.3  christos 					 * attributes */
    458      1.3  christos #define SHT_ARM_DEBUGOVERLAY 0x70000004 /* See DBGOVL for details */
    459      1.3  christos #define SHT_ARM_OVERLAYSECTION 0x70000005
    460      1.3  christos #define	SHT_MIPS_REGINFO     0x70000006
    461      1.3  christos #define	SHT_MIPS_OPTIONS     0x7000000d
    462      1.3  christos #define	SHT_MIPS_DWARF	     0x7000001e	/* MIPS gcc uses MIPS_DWARF */
    463      1.3  christos #define SHT_HIPROC	     0x7fffffff
    464      1.3  christos #define SHT_LOUSER	     0x80000000 /* Application-specific range */
    465      1.3  christos #define SHT_HIUSER	     0xffffffff
    466      1.1   tsutsui 
    467      1.1   tsutsui /* sh_flags */
    468      1.3  christos #define SHF_WRITE	     0x00000001 /* Contains writable data */
    469      1.3  christos #define SHF_ALLOC	     0x00000002 /* Occupies memory */
    470      1.3  christos #define SHF_EXECINSTR	     0x00000004 /* Contains executable insns */
    471      1.3  christos #define SHF_MERGE	     0x00000010 /* Might be merged */
    472      1.3  christos #define SHF_STRINGS	     0x00000020 /* Contains nul terminated strings */
    473      1.3  christos #define SHF_INFO_LINK	     0x00000040 /* "sh_info" contains SHT index */
    474      1.3  christos #define SHF_LINK_ORDER	     0x00000080 /* Preserve order after combining */
    475      1.3  christos #define SHF_OS_NONCONFORMING 0x00000100 /* OS specific handling required */
    476      1.3  christos #define SHF_GROUP	     0x00000200 /* Is member of a group */
    477      1.3  christos #define SHF_TLS		     0x00000400 /* Holds thread-local data */
    478      1.3  christos #define SHF_MASKOS	     0x0ff00000 /* Operating system specific values */
    479      1.3  christos #define SHF_MASKPROC	     0xf0000000 /* Processor-specific values */
    480      1.3  christos #define SHF_ORDERED	     0x40000000 /* Ordering requirement (Solaris) */
    481      1.3  christos #define SHF_EXCLUDE	     0x80000000 /* Excluded unless unles ref/alloc
    482      1.3  christos 					   (Solaris).*/
    483      1.1   tsutsui /*
    484      1.1   tsutsui  * Symbol Table
    485      1.1   tsutsui  */
    486      1.1   tsutsui typedef struct {
    487      1.3  christos 	Elf32_Word	st_name;	/* Symbol name (.strtab index) */
    488      1.1   tsutsui 	Elf32_Word	st_value;	/* value of symbol */
    489      1.1   tsutsui 	Elf32_Word	st_size;	/* size of symbol */
    490      1.1   tsutsui 	Elf_Byte	st_info;	/* type / binding attrs */
    491      1.1   tsutsui 	Elf_Byte	st_other;	/* unused */
    492      1.1   tsutsui 	Elf32_Half	st_shndx;	/* section index of symbol */
    493      1.1   tsutsui } Elf32_Sym;
    494      1.1   tsutsui 
    495      1.1   tsutsui typedef struct {
    496      1.3  christos 	Elf64_Word	st_name;	/* Symbol name (.strtab index) */
    497      1.1   tsutsui 	Elf_Byte	st_info;	/* type / binding attrs */
    498      1.1   tsutsui 	Elf_Byte	st_other;	/* unused */
    499      1.1   tsutsui 	Elf64_Half	st_shndx;	/* section index of symbol */
    500      1.1   tsutsui 	Elf64_Addr	st_value;	/* value of symbol */
    501      1.1   tsutsui 	Elf64_Xword	st_size;	/* size of symbol */
    502      1.1   tsutsui } Elf64_Sym;
    503      1.1   tsutsui 
    504      1.1   tsutsui /* Symbol Table index of the undefined symbol */
    505      1.3  christos #define ELF_SYM_UNDEFINED	0
    506      1.3  christos 
    507      1.3  christos #define STN_UNDEF		0	/* undefined index */
    508      1.1   tsutsui 
    509      1.1   tsutsui /* st_info: Symbol Bindings */
    510      1.3  christos #define STB_LOCAL		0	/* local symbol */
    511      1.3  christos #define STB_GLOBAL		1	/* global symbol */
    512      1.3  christos #define STB_WEAK		2	/* weakly defined global symbol */
    513      1.3  christos #define STB_NUM			3
    514      1.3  christos 
    515      1.3  christos #define STB_LOOS		10	/* Operating system specific range */
    516      1.3  christos #define STB_HIOS		12
    517      1.3  christos #define STB_LOPROC		13	/* Processor-specific range */
    518      1.3  christos #define STB_HIPROC		15
    519      1.1   tsutsui 
    520      1.1   tsutsui /* st_info: Symbol Types */
    521      1.3  christos #define STT_NOTYPE		0	/* Type not specified */
    522      1.3  christos #define STT_OBJECT		1	/* Associated with a data object */
    523      1.3  christos #define STT_FUNC		2	/* Associated with a function */
    524      1.3  christos #define STT_SECTION		3	/* Associated with a section */
    525      1.3  christos #define STT_FILE		4	/* Associated with a file name */
    526      1.3  christos #define STT_COMMON		5	/* Uninitialised common block */
    527      1.3  christos #define STT_TLS			6	/* Thread local data object */
    528      1.3  christos #define STT_NUM			7
    529      1.3  christos 
    530      1.3  christos #define STT_LOOS		10	/* Operating system specific range */
    531      1.3  christos #define STT_GNU_IFUNC		10	/* GNU extension: indirect function */
    532      1.3  christos #define STT_HIOS		12
    533      1.3  christos #define STT_LOPROC		13	/* Processor-specific range */
    534      1.3  christos #define STT_HIPROC		15
    535      1.3  christos 
    536      1.3  christos /* st_other: Visibility Types */
    537      1.3  christos #define STV_DEFAULT		0	/* use binding type */
    538      1.3  christos #define STV_INTERNAL		1	/* not referenced from outside */
    539      1.3  christos #define STV_HIDDEN		2	/* not visible, may be used via ptr */
    540      1.3  christos #define STV_PROTECTED		3	/* visible, not preemptible */
    541      1.3  christos #define STV_EXPORTED		4
    542      1.3  christos #define STV_SINGLETON		5
    543      1.3  christos #define STV_ELIMINATE		6
    544      1.3  christos 
    545      1.3  christos /* st_info/st_other utility macros */
    546      1.3  christos #define ELF_ST_BIND(info)		((uint32_t)(info) >> 4)
    547      1.3  christos #define ELF_ST_TYPE(info)		((uint32_t)(info) & 0xf)
    548      1.3  christos #define ELF_ST_INFO(bind,type)		((Elf_Byte)(((bind) << 4) | \
    549      1.3  christos 					 ((type) & 0xf)))
    550      1.3  christos #define ELF_ST_VISIBILITY(other)	((uint32_t)(other) & 3)
    551      1.1   tsutsui 
    552      1.1   tsutsui /*
    553      1.1   tsutsui  * Special section indexes
    554      1.1   tsutsui  */
    555      1.3  christos #define SHN_UNDEF	0		/* Undefined section */
    556      1.1   tsutsui 
    557      1.3  christos #define SHN_LORESERVE	0xff00		/* Reserved range */
    558      1.3  christos #define SHN_ABS		0xfff1		/*  Absolute symbols */
    559      1.3  christos #define SHN_COMMON	0xfff2		/*  Common symbols */
    560      1.3  christos #define SHN_XINDEX	0xffff		/* Escape -- index stored elsewhere */
    561      1.3  christos #define SHN_HIRESERVE	0xffff
    562      1.3  christos 
    563      1.3  christos #define SHN_LOPROC	0xff00		/* Processor-specific range */
    564      1.3  christos #define SHN_HIPROC	0xff1f
    565      1.3  christos #define SHN_LOOS	0xff20		/* Operating system specific range */
    566      1.3  christos #define SHN_HIOS	0xff3f
    567      1.3  christos 
    568      1.3  christos #define SHN_MIPS_ACOMMON 0xff00
    569      1.3  christos #define SHN_MIPS_TEXT	0xff01
    570      1.3  christos #define SHN_MIPS_DATA	0xff02
    571      1.3  christos #define SHN_MIPS_SCOMMON 0xff03
    572      1.1   tsutsui 
    573      1.1   tsutsui /*
    574      1.1   tsutsui  * Relocation Entries
    575      1.1   tsutsui  */
    576      1.1   tsutsui typedef struct {
    577      1.1   tsutsui 	Elf32_Word	r_offset;	/* where to do it */
    578      1.1   tsutsui 	Elf32_Word	r_info;		/* index & type of relocation */
    579      1.1   tsutsui } Elf32_Rel;
    580      1.1   tsutsui 
    581      1.1   tsutsui typedef struct {
    582      1.1   tsutsui 	Elf32_Word	r_offset;	/* where to do it */
    583      1.1   tsutsui 	Elf32_Word	r_info;		/* index & type of relocation */
    584      1.1   tsutsui 	Elf32_Sword	r_addend;	/* adjustment value */
    585      1.1   tsutsui } Elf32_Rela;
    586      1.1   tsutsui 
    587      1.1   tsutsui /* r_info utility macros */
    588      1.3  christos #define ELF32_R_SYM(info)	((info) >> 8)
    589      1.3  christos #define ELF32_R_TYPE(info)	((info) & 0xff)
    590      1.3  christos #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
    591      1.1   tsutsui 
    592      1.1   tsutsui typedef struct {
    593      1.1   tsutsui 	Elf64_Addr	r_offset;	/* where to do it */
    594      1.1   tsutsui 	Elf64_Xword	r_info;		/* index & type of relocation */
    595      1.1   tsutsui } Elf64_Rel;
    596      1.1   tsutsui 
    597      1.1   tsutsui typedef struct {
    598      1.1   tsutsui 	Elf64_Addr	r_offset;	/* where to do it */
    599      1.1   tsutsui 	Elf64_Xword	r_info;		/* index & type of relocation */
    600      1.1   tsutsui 	Elf64_Sxword	r_addend;	/* adjustment value */
    601      1.1   tsutsui } Elf64_Rela;
    602      1.1   tsutsui 
    603      1.1   tsutsui /* r_info utility macros */
    604      1.3  christos #define ELF64_R_SYM(info)	((info) >> 32)
    605      1.3  christos #define ELF64_R_TYPE(info)	((info) & 0xffffffff)
    606      1.3  christos #define ELF64_R_INFO(sym,type)	(((sym) << 32) + (type))
    607      1.3  christos 
    608      1.3  christos /*
    609      1.3  christos  * Move entries
    610      1.3  christos  */
    611      1.3  christos typedef struct {
    612      1.3  christos 	Elf32_Lword	m_value;	/* symbol value */
    613      1.3  christos 	Elf32_Word	m_info;		/* size + index */
    614      1.3  christos 	Elf32_Word	m_poffset;	/* symbol offset */
    615      1.3  christos 	Elf32_Half	m_repeat;	/* repeat count */
    616      1.3  christos 	Elf32_Half	m_stride;	/* stride info */
    617      1.3  christos } Elf32_Move;
    618      1.3  christos 
    619      1.3  christos #define ELF32_M_SYM(info)	((info) >> 8)
    620      1.3  christos #define ELF32_M_SIZE(info)	((info) & 0xff)
    621      1.3  christos #define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
    622      1.3  christos 
    623      1.3  christos typedef struct {
    624      1.3  christos 	Elf64_Lword	m_value;	/* symbol value */
    625      1.3  christos 	Elf64_Xword	m_info;		/* size + index */
    626      1.3  christos 	Elf64_Xword	m_poffset;	/* symbol offset */
    627      1.3  christos 	Elf64_Word	m_repeat;	/* repeat count */
    628      1.3  christos 	Elf64_Word	m_stride;	/* stride info */
    629      1.3  christos } Elf64_Move;
    630      1.3  christos 
    631      1.3  christos #define ELF64_M_SYM(info)	((info) >> 8)
    632      1.3  christos #define ELF64_M_SIZE(info)	((info) & 0xff)
    633      1.3  christos #define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
    634      1.3  christos 
    635      1.3  christos /*
    636      1.3  christos  * Hardware/software capabilities entry
    637      1.3  christos  */
    638      1.3  christos typedef struct {
    639      1.3  christos 	Elf32_Word		c_tag;	/* entry tag value */
    640      1.3  christos 	union {
    641      1.3  christos 		Elf32_Addr	c_ptr;
    642      1.3  christos 		Elf32_Word	c_val;
    643      1.3  christos 	} c_un;
    644      1.3  christos } Elf32_Cap;
    645      1.3  christos 
    646      1.3  christos typedef struct {
    647      1.3  christos 	Elf64_Xword		c_tag;	/* entry tag value */
    648      1.3  christos 	union {
    649      1.3  christos 		Elf64_Addr	c_ptr;
    650      1.3  christos 		Elf64_Xword	c_val;
    651      1.3  christos 	} c_un;
    652      1.3  christos } Elf64_Cap;
    653      1.1   tsutsui 
    654      1.1   tsutsui /*
    655      1.1   tsutsui  * Dynamic Section structure array
    656      1.1   tsutsui  */
    657      1.1   tsutsui typedef struct {
    658      1.3  christos 	Elf32_Word		d_tag;	/* entry tag value */
    659      1.1   tsutsui 	union {
    660      1.3  christos 		Elf32_Addr	d_ptr;
    661      1.3  christos 		Elf32_Word	d_val;
    662      1.1   tsutsui 	} d_un;
    663      1.1   tsutsui } Elf32_Dyn;
    664      1.1   tsutsui 
    665      1.1   tsutsui typedef struct {
    666      1.3  christos 	Elf64_Xword		d_tag;	/* entry tag value */
    667      1.1   tsutsui 	union {
    668      1.3  christos 		Elf64_Addr	d_ptr;
    669      1.3  christos 		Elf64_Xword	d_val;
    670      1.1   tsutsui 	} d_un;
    671      1.1   tsutsui } Elf64_Dyn;
    672      1.1   tsutsui 
    673      1.1   tsutsui /* d_tag */
    674      1.3  christos #define DT_NULL		0	/* Marks end of dynamic array */
    675      1.3  christos #define DT_NEEDED	1	/* Name of needed library (DT_STRTAB offset) */
    676      1.3  christos #define DT_PLTRELSZ	2	/* Size, in bytes, of relocations in PLT */
    677      1.3  christos #define DT_PLTGOT	3	/* Address of PLT and/or GOT */
    678      1.3  christos #define DT_HASH		4	/* Address of symbol hash table */
    679      1.3  christos #define DT_STRTAB	5	/* Address of string table */
    680      1.3  christos #define DT_SYMTAB	6	/* Address of symbol table */
    681      1.3  christos #define DT_RELA		7	/* Address of Rela relocation table */
    682      1.3  christos #define DT_RELASZ	8	/* Size, in bytes, of DT_RELA table */
    683      1.3  christos #define DT_RELAENT	9	/* Size, in bytes, of one DT_RELA entry */
    684      1.3  christos #define DT_STRSZ	10	/* Size, in bytes, of DT_STRTAB table */
    685      1.3  christos #define DT_SYMENT	11	/* Size, in bytes, of one DT_SYMTAB entry */
    686      1.3  christos #define DT_INIT		12	/* Address of initialization function */
    687      1.3  christos #define DT_FINI		13	/* Address of termination function */
    688      1.3  christos #define DT_SONAME	14	/* Shared object name (DT_STRTAB offset) */
    689      1.3  christos #define DT_RPATH	15	/* Library search path (DT_STRTAB offset) */
    690      1.3  christos #define DT_SYMBOLIC	16	/* Start symbol search within local object */
    691      1.3  christos #define DT_REL		17	/* Address of Rel relocation table */
    692      1.3  christos #define DT_RELSZ	18	/* Size, in bytes, of DT_REL table */
    693      1.3  christos #define DT_RELENT	19	/* Size, in bytes, of one DT_REL entry */
    694      1.3  christos #define DT_PLTREL	20	/* Type of PLT relocation entries */
    695      1.3  christos #define DT_DEBUG	21	/* Used for debugging; unspecified */
    696      1.3  christos #define DT_TEXTREL	22	/* Relocations might modify non-writable seg */
    697      1.3  christos #define DT_JMPREL	23	/* Address of relocations associated with PLT */
    698      1.3  christos #define DT_BIND_NOW	24	/* Process all relocations at load-time */
    699      1.3  christos #define DT_INIT_ARRAY	25	/* Address of initialization function array */
    700      1.3  christos #define DT_FINI_ARRAY	26	/* Size, in bytes, of DT_INIT_ARRAY array */
    701      1.3  christos #define DT_INIT_ARRAYSZ 27	/* Address of termination function array */
    702      1.3  christos #define DT_FINI_ARRAYSZ 28	/* Size, in bytes, of DT_FINI_ARRAY array*/
    703      1.3  christos #define DT_RUNPATH	29	/* overrides DT_RPATH */
    704      1.3  christos #define DT_FLAGS	30	/* Encodes ORIGIN, SYMBOLIC, TEXTREL, BIND_NOW, STATIC_TLS */
    705      1.3  christos #define DT_ENCODING	31	/* ??? */
    706      1.3  christos #define DT_PREINIT_ARRAY 32	/* Address of pre-init function array */
    707      1.3  christos #define DT_PREINIT_ARRAYSZ 33	/* Size, in bytes, of DT_PREINIT_ARRAY array */
    708      1.3  christos #define DT_NUM		34
    709      1.3  christos 
    710      1.3  christos #define DT_LOOS		0x60000000	/* Operating system specific range */
    711      1.3  christos #define DT_VERSYM	0x6ffffff0	/* Symbol versions */
    712      1.3  christos #define DT_FLAGS_1	0x6ffffffb	/* ELF dynamic flags */
    713      1.3  christos #define DT_VERDEF	0x6ffffffc	/* Versions defined by file */
    714      1.3  christos #define DT_VERDEFNUM	0x6ffffffd	/* Number of versions defined by file */
    715      1.3  christos #define DT_VERNEED	0x6ffffffe	/* Versions needed by file */
    716      1.3  christos #define DT_VERNEEDNUM	0x6fffffff	/* Number of versions needed by file */
    717      1.3  christos #define DT_HIOS		0x6fffffff
    718      1.3  christos #define DT_LOPROC	0x70000000	/* Processor-specific range */
    719      1.3  christos #define DT_HIPROC	0x7fffffff
    720      1.3  christos 
    721      1.3  christos /* Flag values for DT_FLAGS */
    722      1.3  christos #define DF_ORIGIN	0x00000001	/* uses $ORIGIN */
    723      1.3  christos #define DF_SYMBOLIC	0x00000002	/* */
    724      1.3  christos #define DF_TEXTREL	0x00000004	/* */
    725      1.3  christos #define DF_BIND_NOW	0x00000008	/* */
    726      1.3  christos #define DF_STATIC_TLS	0x00000010	/* */
    727      1.3  christos 
    728      1.3  christos /* Flag values for DT_FLAGS_1 */
    729      1.3  christos #define	DF_1_NOW	0x00000001	/* Same as DF_BIND_NOW */
    730      1.3  christos #define	DF_1_GLOBAL	0x00000002	/* Unused */
    731      1.3  christos #define	DF_1_GROUP	0x00000004	/* Is member of group */
    732      1.3  christos #define	DF_1_NODELETE	0x00000008	/* Cannot be deleted from process */
    733      1.3  christos #define	DF_1_LOADFLTR	0x00000010	/* Immediate loading of filters */
    734      1.3  christos #define	DF_1_INITFIRST	0x00000020	/* init/fini takes priority */
    735      1.3  christos #define	DF_1_NOOPEN	0x00000040	/* Do not allow loading on dlopen() */
    736      1.3  christos #define	DF_1_ORIGIN	0x00000080 	/* Require $ORIGIN processing */
    737      1.3  christos #define	DF_1_DIRECT	0x00000100	/* Enable direct bindings */
    738      1.3  christos #define	DF_1_INTERPOSE 	0x00000400	/* Is an interposer */
    739      1.3  christos #define	DF_1_NODEFLIB	0x00000800 	/* Ignore default library search path */
    740      1.3  christos #define	DF_1_NODUMP	0x00001000 	/* Cannot be dumped with dldump(3C) */
    741      1.3  christos #define	DF_1_CONFALT	0x00002000 	/* Configuration alternative */
    742      1.3  christos #define	DF_1_ENDFILTEE	0x00004000	/* Filtee ends filter's search */
    743      1.3  christos #define	DF_1_DISPRELDNE	0x00008000	/* Did displacement relocation */
    744      1.3  christos #define	DF_1_DISPRELPND 0x00010000	/* Pending displacement relocation */
    745      1.3  christos #define	DF_1_NODIRECT	0x00020000 	/* Has non-direct bindings */
    746      1.3  christos #define	DF_1_IGNMULDEF	0x00040000	/* Used internally */
    747      1.3  christos #define	DF_1_NOKSYMS	0x00080000	/* Used internally */
    748      1.3  christos #define	DF_1_NOHDR	0x00100000	/* Used internally */
    749      1.3  christos #define	DF_1_EDITED	0x00200000	/* Has been modified since build */
    750      1.3  christos #define	DF_1_NORELOC	0x00400000 	/* Used internally */
    751      1.3  christos #define	DF_1_SYMINTPOSE 0x00800000 	/* Has individual symbol interposers */
    752      1.3  christos #define	DF_1_GLOBAUDIT	0x01000000	/* Require global auditing */
    753      1.3  christos #define	DF_1_SINGLETON	0x02000000	/* Has singleton symbols */
    754      1.3  christos #define	DF_1_STUB	0x04000000	/* Stub */
    755      1.3  christos #define	DF_1_PIE	0x08000000	/* Position Independent Executable */
    756      1.1   tsutsui 
    757      1.1   tsutsui /*
    758      1.1   tsutsui  * Auxiliary Vectors
    759      1.1   tsutsui  */
    760      1.1   tsutsui typedef struct {
    761      1.1   tsutsui 	Elf32_Word	a_type;				/* 32-bit id */
    762      1.1   tsutsui 	Elf32_Word	a_v;				/* 32-bit id */
    763      1.1   tsutsui } Aux32Info;
    764      1.1   tsutsui 
    765      1.1   tsutsui typedef struct {
    766      1.3  christos 	Elf64_Word	a_type;		/* 32-bit id */
    767      1.3  christos 	Elf64_Xword	a_v;		/* 64-bit id */
    768      1.1   tsutsui } Aux64Info;
    769      1.1   tsutsui 
    770      1.1   tsutsui /* a_type */
    771      1.3  christos #define AT_NULL		0	/* Marks end of array */
    772      1.3  christos #define AT_IGNORE	1	/* No meaning, a_un is undefined */
    773      1.3  christos #define AT_EXECFD	2	/* Open file descriptor of object file */
    774      1.3  christos #define AT_PHDR		3	/* &phdr[0] */
    775      1.3  christos #define AT_PHENT	4	/* sizeof(phdr[0]) */
    776      1.3  christos #define AT_PHNUM	5	/* # phdr entries */
    777      1.3  christos #define AT_PAGESZ	6	/* PAGESIZE */
    778      1.3  christos #define AT_BASE		7	/* Interpreter base addr */
    779      1.3  christos #define AT_FLAGS	8	/* Processor flags */
    780      1.3  christos #define AT_ENTRY	9	/* Entry address of executable */
    781      1.3  christos #define AT_DCACHEBSIZE	10	/* Data cache block size */
    782      1.3  christos #define AT_ICACHEBSIZE	11	/* Instruction cache block size */
    783      1.3  christos #define AT_UCACHEBSIZE	12	/* Unified cache block size */
    784      1.3  christos #define AT_STACKBASE	13	/* Base address of the main thread */
    785      1.1   tsutsui 
    786      1.1   tsutsui 	/* Vendor specific */
    787      1.3  christos #define AT_MIPS_NOTELF	10	/* XXX a_val != 0 -> MIPS XCOFF executable */
    788      1.1   tsutsui 
    789      1.3  christos #define AT_EUID		2000	/* euid (solaris compatible numbers) */
    790      1.3  christos #define AT_RUID		2001	/* ruid (solaris compatible numbers) */
    791      1.3  christos #define AT_EGID		2002	/* egid (solaris compatible numbers) */
    792      1.3  christos #define AT_RGID		2003	/* rgid (solaris compatible numbers) */
    793      1.1   tsutsui 
    794      1.1   tsutsui 	/* Solaris kernel specific */
    795      1.3  christos #define AT_SUN_LDELF	2004	/* dynamic linker's ELF header */
    796      1.3  christos #define AT_SUN_LDSHDR	2005	/* dynamic linker's section header */
    797      1.3  christos #define AT_SUN_LDNAME	2006	/* dynamic linker's name */
    798      1.3  christos #define AT_SUN_LPGSIZE	2007	/* large pagesize */
    799      1.1   tsutsui 
    800      1.1   tsutsui 	/* Other information */
    801      1.3  christos #define AT_SUN_PLATFORM 2008	/* sysinfo(SI_PLATFORM) */
    802      1.3  christos #define AT_SUN_HWCAP	2009	/* process hardware capabilities */
    803      1.3  christos #define AT_SUN_IFLUSH	2010	/* do we need to flush the instruction cache? */
    804      1.3  christos #define AT_SUN_CPU	2011	/* CPU name */
    805      1.1   tsutsui 	/* ibcs2 emulation band aid */
    806      1.3  christos #define AT_SUN_EMUL_ENTRY 2012	/* coff entry point */
    807      1.3  christos #define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
    808      1.1   tsutsui 	/* Executable's fully resolved name */
    809      1.3  christos #define AT_SUN_EXECNAME 2014
    810      1.3  christos 
    811      1.3  christos /*
    812      1.3  christos  * The header for GNU-style hash sections.
    813      1.3  christos  */
    814      1.3  christos typedef struct {
    815      1.3  christos 	uint32_t	gh_nbuckets;	/* Number of hash buckets. */
    816      1.3  christos 	uint32_t	gh_symndx;	/* First visible symbol in .dynsym. */
    817      1.3  christos 	uint32_t	gh_maskwords;	/* #maskwords used in bloom filter. */
    818      1.3  christos 	uint32_t	gh_shift2;	/* Bloom filter shift count. */
    819      1.3  christos } Elf_GNU_Hash_Header;
    820      1.1   tsutsui 
    821      1.1   tsutsui /*
    822      1.1   tsutsui  * Note Headers
    823      1.1   tsutsui  */
    824      1.1   tsutsui typedef struct {
    825      1.1   tsutsui 	Elf32_Word n_namesz;
    826      1.1   tsutsui 	Elf32_Word n_descsz;
    827      1.1   tsutsui 	Elf32_Word n_type;
    828      1.1   tsutsui } Elf32_Nhdr;
    829      1.1   tsutsui 
    830      1.1   tsutsui typedef struct {
    831      1.1   tsutsui 	Elf64_Word n_namesz;
    832      1.1   tsutsui 	Elf64_Word n_descsz;
    833      1.1   tsutsui 	Elf64_Word n_type;
    834      1.1   tsutsui } Elf64_Nhdr;
    835      1.1   tsutsui 
    836      1.3  christos #define ELF_NOTE_GNU_NAMESZ		4
    837      1.3  christos #define ELF_NOTE_GNU_NAME		"GNU\0"
    838      1.1   tsutsui 
    839      1.3  christos /*
    840      1.3  christos  * GNU-specific note type: ABI tag
    841      1.3  christos  * name: GNU\0
    842      1.3  christos  * namesz: 4
    843      1.3  christos  * desc:
    844      1.3  christos  *	word[0]: OS tag
    845      1.3  christos  *	word[1]: major version
    846      1.3  christos  *	word[2]: minor version
    847      1.3  christos  *	word[3]: teeny version
    848      1.3  christos  * descsz: 16
    849      1.3  christos  */
    850      1.1   tsutsui /* GNU-specific note name and description sizes */
    851      1.3  christos #define ELF_NOTE_TYPE_ABI_TAG		1
    852      1.3  christos #define ELF_NOTE_ABI_NAME		ELF_NOTE_GNU_NAME
    853      1.3  christos #define ELF_NOTE_ABI_NAMESZ		ELF_NOTE_GNU_NAMESZ
    854      1.3  christos #define ELF_NOTE_ABI_DESCSZ		16
    855      1.3  christos /* GNU-specific OS/version value stuff */
    856      1.3  christos #define ELF_NOTE_ABI_OS_LINUX		0
    857      1.3  christos #define ELF_NOTE_ABI_OS_HURD		1
    858      1.3  christos #define ELF_NOTE_ABI_OS_SOLARIS		2
    859      1.3  christos #define ELF_NOTE_ABI_OS_KFREEBSD	3
    860      1.3  christos #define ELF_NOTE_ABI_OS_KNETBSD		4
    861      1.3  christos 
    862      1.3  christos /* Old gcc style, under the ABI tag */
    863      1.3  christos #define ELF_NOTE_OGCC_NAMESZ		8
    864      1.3  christos #define ELF_NOTE_OGCC_NAME		"01.01\0\0\0\0"
    865      1.3  christos #define ELF_NOTE_OGCC_DESCSZ		0
    866      1.1   tsutsui 
    867      1.3  christos /*
    868      1.3  christos  * GNU-specific note type: Hardware capabilities
    869      1.3  christos  * name: GNU\0
    870      1.3  christos  * namesz: 4
    871      1.3  christos  * desc:
    872      1.3  christos  *	word[0]: Number of entries
    873      1.3  christos  *	word[1]: Bitmask of enabled entries
    874      1.3  christos  *	Followed by a byte id, and a NUL terminated string per entry
    875      1.3  christos  * descsz: variable
    876      1.3  christos  */
    877      1.3  christos #define ELF_NOTE_TYPE_GNU_HWCAP		2
    878      1.1   tsutsui 
    879      1.3  christos /*
    880      1.3  christos  * GNU-specific note type: Build ID generated by ld
    881      1.3  christos  * name: GNU\0
    882      1.3  christos  * desc:
    883      1.3  christos  *	word[0..4] SHA1 [default]
    884      1.3  christos  * or
    885      1.3  christos  *	word[0..3] md5 or uuid
    886      1.3  christos  * descsz: 16 or 20
    887      1.3  christos  */
    888      1.3  christos #define ELF_NOTE_TYPE_GNU_BUILD_ID	3
    889      1.1   tsutsui 
    890      1.3  christos /* SuSE-specific note type: ABI
    891      1.3  christos  * name: SuSE\0
    892      1.3  christos  * namesz: 5
    893      1.3  christos  * desc:
    894      1.3  christos  *	half[0] = MMmm
    895      1.3  christos  *
    896      1.3  christos  *	M = product major version
    897      1.3  christos  *	m = product minor version
    898      1.3  christos  * descsz: 2
    899      1.3  christos  */
    900      1.3  christos #define ELF_NOTE_TYPE_SUSE_TAG	1
    901      1.3  christos /* SuSE-specific note name and description sizes */
    902      1.3  christos #define ELF_NOTE_SUSE_NAMESZ	5
    903      1.3  christos #define ELF_NOTE_SUSE_DESCSZ	2
    904      1.3  christos /* SuSE-specific note name */
    905      1.3  christos #define ELF_NOTE_SUSE_NAME		"SuSE\0"
    906      1.3  christos 
    907      1.3  christos /* SuSE-specific note type: version
    908      1.3  christos  * name: SuSE\0\0\0\0
    909      1.3  christos  * namesz: 8
    910      1.3  christos  * desc:
    911      1.3  christos  *	word[0] = VVTTMMmm
    912      1.3  christos  *
    913      1.3  christos  *	V = version of following data
    914      1.3  christos  *	T = product type: [box, sles, nld, whatever]
    915      1.3  christos  *	M = product major version
    916      1.3  christos  *	m = product minor version
    917      1.3  christos  * descsz: 8
    918      1.3  christos  */
    919      1.3  christos #define ELF_NOTE_TYPE_SUSE_VERSION_TAG	0x45537553	/* SuSE in LE */
    920      1.3  christos /* SuSE-specific note name and description sizes */
    921      1.3  christos #define ELF_NOTE_SUSE_VERSION_NAMESZ	8
    922      1.3  christos #define ELF_NOTE_SUSE_VERSION_DESCSZ	8
    923      1.3  christos /* SuSE-specific note name */
    924      1.3  christos #define ELF_NOTE_SUSE_VERSION_NAME		"SuSE\0\0\0\0"
    925      1.3  christos 
    926      1.3  christos /* Go-specific note type: buildid
    927      1.3  christos  * name: Go\0\0
    928      1.3  christos  * namesz: 4
    929      1.3  christos  * desc:
    930      1.3  christos  *	words[10]
    931      1.3  christos  * descsz: 40
    932      1.3  christos  */
    933      1.3  christos #define ELF_NOTE_TYPE_GO_BUILDID_TAG	4
    934      1.3  christos #define ELF_NOTE_GO_BUILDID_NAMESZ	4
    935      1.3  christos #define ELF_NOTE_GO_BUILDID_DESCSZ	40
    936      1.3  christos #define ELF_NOTE_GO_BUILDID_NAME	"Go\0\0"
    937      1.3  christos 
    938      1.3  christos /* NetBSD-specific note type: NetBSD ABI version.
    939      1.3  christos  * name: NetBSD\0\0
    940      1.3  christos  * namesz: 8
    941      1.3  christos  * desc:
    942      1.3  christos  *	word[0]: MMmmrrpp00
    943      1.3  christos  *
    944      1.3  christos  *	M = major version
    945      1.3  christos  *	m = minor version
    946      1.3  christos  *	r = release ["",A-Z,Z[A-Z] but numeric]
    947      1.3  christos  *	p = patchlevel
    948      1.3  christos  * descsz: 4
    949      1.3  christos  */
    950      1.3  christos #define ELF_NOTE_TYPE_NETBSD_TAG	1
    951      1.1   tsutsui /* NetBSD-specific note name and description sizes */
    952      1.3  christos #define ELF_NOTE_NETBSD_NAMESZ		7
    953      1.3  christos #define ELF_NOTE_NETBSD_DESCSZ		4
    954      1.3  christos /* NetBSD-specific note name */
    955      1.3  christos #define ELF_NOTE_NETBSD_NAME		"NetBSD\0\0"
    956      1.3  christos 
    957      1.3  christos /* NetBSD-specific note type: Emulation (obsolete; last used early 2000)
    958      1.3  christos  * name: NetBSD\0\0
    959      1.3  christos  * namesz: 8
    960      1.3  christos  * desc:
    961      1.3  christos  *	"netbsd\0"
    962      1.3  christos  *
    963      1.3  christos  * descsz: 8
    964      1.3  christos  */
    965      1.3  christos #define ELF_NOTE_TYPE_NETBSD_EMUL_TAG	2
    966      1.3  christos #define ELF_NOTE_NETBSD_EMUL_NAMESZ	7
    967      1.3  christos #define ELF_NOTE_NETBSD_EMUL_DESCSZ	7
    968      1.1   tsutsui /* NetBSD-specific note name */
    969      1.3  christos #define ELF_NOTE_NETBSD_EMUL_NAME	"NetBSD\0\0"
    970      1.3  christos 
    971      1.3  christos /*
    972      1.3  christos  * NetBSD-specific note type: PaX.
    973      1.3  christos  * There should be 1 NOTE per executable.
    974      1.3  christos  * name: PaX\0
    975      1.3  christos  * namesz: 4
    976      1.3  christos  * desc:
    977      1.3  christos  *	word[0]: capability bitmask
    978      1.3  christos  * descsz: 4
    979      1.3  christos  */
    980      1.3  christos #define ELF_NOTE_TYPE_PAX_TAG		3
    981      1.3  christos #define ELF_NOTE_PAX_MPROTECT		0x01	/* Force enable Mprotect */
    982      1.3  christos #define ELF_NOTE_PAX_NOMPROTECT		0x02	/* Force disable Mprotect */
    983      1.3  christos #define ELF_NOTE_PAX_GUARD		0x04	/* Force enable Segvguard */
    984      1.3  christos #define ELF_NOTE_PAX_NOGUARD		0x08	/* Force disable Segvguard */
    985      1.3  christos #define ELF_NOTE_PAX_ASLR		0x10	/* Force enable ASLR */
    986      1.3  christos #define ELF_NOTE_PAX_NOASLR		0x20	/* Force disable ASLR */
    987      1.3  christos #define ELF_NOTE_PAX_NAMESZ		4
    988      1.3  christos #define ELF_NOTE_PAX_NAME		"PaX\0"
    989      1.3  christos #define ELF_NOTE_PAX_DESCSZ		4
    990      1.1   tsutsui 
    991      1.1   tsutsui /*
    992      1.1   tsutsui  * NetBSD-specific core file information.
    993      1.1   tsutsui  *
    994      1.1   tsutsui  * NetBSD ELF core files use notes to provide information about
    995      1.3  christos  * the process's state.	 The note name is "NetBSD-CORE" for
    996      1.1   tsutsui  * information that is global to the process, and "NetBSD-CORE@nn",
    997      1.1   tsutsui  * where "nn" is the lwpid of the LWP that the information belongs
    998      1.1   tsutsui  * to (such as register state).
    999      1.1   tsutsui  *
   1000      1.1   tsutsui  * We use the following note identifiers:
   1001      1.1   tsutsui  *
   1002      1.1   tsutsui  *	ELF_NOTE_NETBSD_CORE_PROCINFO
   1003      1.1   tsutsui  *		Note is a "netbsd_elfcore_procinfo" structure.
   1004      1.3  christos  *	ELF_NOTE_NETBSD_CORE_AUXV
   1005      1.3  christos  *		Note is an array of AuxInfo structures.
   1006      1.1   tsutsui  *
   1007      1.1   tsutsui  * We also use ptrace(2) request numbers (the ones that exist in
   1008      1.1   tsutsui  * machine-dependent space) to identify register info notes.  The
   1009      1.1   tsutsui  * info in such notes is in the same format that ptrace(2) would
   1010      1.1   tsutsui  * export that information.
   1011      1.1   tsutsui  *
   1012      1.1   tsutsui  * Please try to keep the members of this structure nicely aligned,
   1013      1.1   tsutsui  * and if you add elements, add them to the end and bump the version.
   1014      1.1   tsutsui  */
   1015      1.1   tsutsui 
   1016      1.3  christos #define ELF_NOTE_NETBSD_CORE_NAME	"NetBSD-CORE"
   1017      1.1   tsutsui 
   1018      1.3  christos #define ELF_NOTE_NETBSD_CORE_PROCINFO	1
   1019      1.3  christos #define ELF_NOTE_NETBSD_CORE_AUXV	2
   1020      1.1   tsutsui 
   1021      1.3  christos #define NETBSD_ELFCORE_PROCINFO_VERSION 1
   1022      1.1   tsutsui 
   1023      1.1   tsutsui struct netbsd_elfcore_procinfo {
   1024      1.1   tsutsui 	/* Version 1 fields start here. */
   1025      1.3  christos 	uint32_t	cpi_version;		/* our version */
   1026      1.3  christos 	uint32_t	cpi_cpisize;		/* sizeof(this struct) */
   1027      1.3  christos 	uint32_t	cpi_signo;		/* killing signal */
   1028      1.3  christos 	uint32_t	cpi_sigcode;		/* signal code */
   1029      1.3  christos 	uint32_t	cpi_sigpend[4];		/* pending signals */
   1030      1.3  christos 	uint32_t	cpi_sigmask[4];		/* blocked signals */
   1031      1.3  christos 	uint32_t	cpi_sigignore[4];	/* ignored signals */
   1032      1.3  christos 	uint32_t	cpi_sigcatch[4];	/* caught signals */
   1033      1.3  christos 	int32_t		cpi_pid;		/* process ID */
   1034      1.3  christos 	int32_t		cpi_ppid;		/* parent process ID */
   1035      1.3  christos 	int32_t		cpi_pgrp;		/* process group ID */
   1036      1.3  christos 	int32_t		cpi_sid;		/* session ID */
   1037      1.3  christos 	uint32_t	cpi_ruid;		/* real user ID */
   1038      1.3  christos 	uint32_t	cpi_euid;		/* effective user ID */
   1039      1.3  christos 	uint32_t	cpi_svuid;		/* saved user ID */
   1040      1.3  christos 	uint32_t	cpi_rgid;		/* real group ID */
   1041      1.3  christos 	uint32_t	cpi_egid;		/* effective group ID */
   1042      1.3  christos 	uint32_t	cpi_svgid;		/* saved group ID */
   1043      1.3  christos 	uint32_t	cpi_nlwps;		/* number of LWPs */
   1044      1.3  christos 	int8_t		cpi_name[32];		/* copy of p->p_comm */
   1045      1.1   tsutsui 	/* Add version 2 fields below here. */
   1046      1.3  christos 	int32_t		cpi_siglwp;	/* LWP target of killing signal */
   1047      1.1   tsutsui };
   1048      1.1   tsutsui 
   1049      1.3  christos /*
   1050      1.3  christos  * NetBSD-specific note type: MACHINE_ARCH.
   1051      1.3  christos  * There should be 1 NOTE per executable.
   1052      1.3  christos  * name:	NetBSD\0
   1053      1.3  christos  * namesz:	7
   1054      1.3  christos  * desc:	string
   1055      1.3  christos  * descsz:	variable
   1056      1.3  christos  */
   1057      1.3  christos #define ELF_NOTE_TYPE_MARCH_TAG		5
   1058      1.3  christos /* NetBSD-specific note name and description sizes */
   1059      1.3  christos #define ELF_NOTE_MARCH_NAMESZ		ELF_NOTE_NETBSD_NAMESZ
   1060      1.3  christos /* NetBSD-specific note name */
   1061      1.3  christos #define ELF_NOTE_MARCH_NAME		ELF_NOTE_NETBSD_NAME
   1062      1.3  christos 
   1063      1.3  christos /*
   1064      1.3  christos  * NetBSD-specific note type: MCMODEL
   1065      1.3  christos  * There should be 1 NOTE per executable.
   1066      1.3  christos  * name:	NetBSD\0
   1067      1.3  christos  * namesz:	7
   1068      1.3  christos  * code model:	string
   1069      1.3  christos  */
   1070      1.3  christos 
   1071      1.3  christos #define ELF_NOTE_TYPE_MCMODEL_TAG	6
   1072      1.3  christos /* NetBSD-specific note name and description sizes */
   1073      1.3  christos #define ELF_NOTE_MCMODEL_NAMESZ		ELF_NOTE_NETBSD_NAMESZ
   1074      1.3  christos /* NetBSD-specific note name */
   1075      1.3  christos #define ELF_NOTE_MCMODEL_NAME		ELF_NOTE_NETBSD_NAME
   1076      1.3  christos 
   1077      1.3  christos 
   1078      1.3  christos #if !defined(ELFSIZE)
   1079      1.3  christos # if defined(_RUMPKERNEL) || !defined(_KERNEL)
   1080      1.3  christos #  define ELFSIZE ARCH_ELFSIZE
   1081      1.3  christos # else
   1082      1.3  christos #  define ELFSIZE KERN_ELFSIZE
   1083      1.3  christos # endif
   1084      1.3  christos #endif
   1085      1.3  christos 
   1086      1.1   tsutsui #if defined(ELFSIZE)
   1087      1.3  christos #define CONCAT(x,y)	__CONCAT(x,y)
   1088      1.3  christos #define ELFNAME(x)	CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
   1089      1.3  christos #define ELFNAME2(x,y)	CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
   1090      1.3  christos #define ELFNAMEEND(x)	CONCAT(x,CONCAT(_elf,ELFSIZE))
   1091      1.3  christos #define ELFDEFNNAME(x)	CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
   1092      1.3  christos #define	ElfW(x)		CONCAT(Elf,CONCAT(ELFSIZE,CONCAT(_,x)))
   1093      1.1   tsutsui #endif
   1094      1.1   tsutsui 
   1095      1.1   tsutsui #if defined(ELFSIZE) && (ELFSIZE == 32)
   1096      1.3  christos #define Elf_Ehdr	Elf32_Ehdr
   1097      1.3  christos #define Elf_Phdr	Elf32_Phdr
   1098      1.3  christos #define Elf_Shdr	Elf32_Shdr
   1099      1.3  christos #define Elf_Sym		Elf32_Sym
   1100      1.3  christos #define Elf_Rel		Elf32_Rel
   1101      1.3  christos #define Elf_Rela	Elf32_Rela
   1102      1.3  christos #define Elf_Dyn		Elf32_Dyn
   1103      1.3  christos #define Elf_Word	Elf32_Word
   1104      1.3  christos #define Elf_Sword	Elf32_Sword
   1105      1.3  christos #define Elf_Half	Elf32_Half
   1106      1.3  christos #define Elf_Addr	Elf32_Addr
   1107      1.3  christos #define Elf_Off		Elf32_Off
   1108      1.3  christos #define Elf_SOff	Elf32_SOff
   1109      1.3  christos #define Elf_Nhdr	Elf32_Nhdr
   1110      1.3  christos #define Elf_Verdef	Elf32_Verdef
   1111      1.3  christos #define Elf_Verdaux	Elf32_Verdaux
   1112      1.3  christos #define Elf_Verneed	Elf32_Verneed
   1113      1.3  christos #define Elf_Vernaux	Elf32_Vernaux
   1114      1.3  christos #define Elf_Versym	Elf32_Versym
   1115      1.3  christos 
   1116      1.3  christos #define ELF_R_SYM	ELF32_R_SYM
   1117      1.3  christos #define ELF_R_TYPE	ELF32_R_TYPE
   1118      1.3  christos #define ELFCLASS	ELFCLASS32
   1119      1.1   tsutsui 
   1120      1.3  christos #define AuxInfo		Aux32Info
   1121      1.1   tsutsui #elif defined(ELFSIZE) && (ELFSIZE == 64)
   1122      1.3  christos #define Elf_Ehdr	Elf64_Ehdr
   1123      1.3  christos #define Elf_Phdr	Elf64_Phdr
   1124      1.3  christos #define Elf_Shdr	Elf64_Shdr
   1125      1.3  christos #define Elf_Sym		Elf64_Sym
   1126      1.3  christos #define Elf_Rel		Elf64_Rel
   1127      1.3  christos #define Elf_Rela	Elf64_Rela
   1128      1.3  christos #define Elf_Dyn		Elf64_Dyn
   1129      1.3  christos #define Elf_Word	Elf64_Word
   1130      1.3  christos #define Elf_Sword	Elf64_Sword
   1131      1.3  christos #define Elf_Half	Elf64_Half
   1132      1.3  christos #define Elf_Addr	Elf64_Addr
   1133      1.3  christos #define Elf_Off		Elf64_Off
   1134      1.3  christos #define Elf_SOff	Elf64_SOff
   1135      1.3  christos #define Elf_Nhdr	Elf64_Nhdr
   1136      1.3  christos #define Elf_Verdef	Elf64_Verdef
   1137      1.3  christos #define Elf_Verdaux	Elf64_Verdaux
   1138      1.3  christos #define Elf_Verneed	Elf64_Verneed
   1139      1.3  christos #define Elf_Vernaux	Elf64_Vernaux
   1140      1.3  christos #define Elf_Versym	Elf64_Versym
   1141      1.3  christos 
   1142      1.3  christos #define ELF_R_SYM	ELF64_R_SYM
   1143      1.3  christos #define ELF_R_TYPE	ELF64_R_TYPE
   1144      1.3  christos #define ELFCLASS	ELFCLASS64
   1145      1.3  christos 
   1146      1.3  christos #define AuxInfo		Aux64Info
   1147      1.3  christos #endif
   1148      1.1   tsutsui 
   1149      1.3  christos #ifndef Elf_Symindx
   1150      1.3  christos #define Elf_Symindx	uint32_t
   1151      1.1   tsutsui #endif
   1152      1.1   tsutsui 
   1153      1.3  christos #define ELF32_ST_BIND(info)		ELF_ST_BIND(info)
   1154      1.3  christos #define ELF32_ST_TYPE(info)		ELF_ST_TYPE(info)
   1155      1.3  christos #define ELF32_ST_INFO(bind,type)	ELF_ST_INFO(bind,type)
   1156      1.3  christos #define ELF32_ST_VISIBILITY(other)	ELF_ST_VISIBILITY(other)
   1157      1.3  christos 
   1158      1.3  christos #define ELF64_ST_BIND(info)		ELF_ST_BIND(info)
   1159      1.3  christos #define ELF64_ST_TYPE(info)		ELF_ST_TYPE(info)
   1160      1.3  christos #define ELF64_ST_INFO(bind,type)	ELF_ST_INFO(bind,type)
   1161      1.3  christos #define ELF64_ST_VISIBILITY(other)	ELF_ST_VISIBILITY(other)
   1162      1.3  christos 
   1163      1.3  christos typedef struct {
   1164      1.3  christos 	Elf32_Half	si_boundto;	/* direct bindings - symbol bound to */
   1165      1.3  christos 	Elf32_Half	si_flags;	/* per symbol flags */
   1166      1.3  christos } Elf32_Syminfo;
   1167      1.3  christos 
   1168      1.3  christos typedef struct {
   1169      1.3  christos 	Elf64_Word	si_boundto;	/* direct bindings - symbol bound to */
   1170      1.3  christos 	Elf64_Word	si_flags;	/* per symbol flags */
   1171      1.3  christos } Elf64_Syminfo;
   1172      1.3  christos 
   1173      1.3  christos #define SYMINFO_FLG_DIRECT	0x0001	/* symbol ref has direct association
   1174      1.3  christos 					   to object containing definition */
   1175      1.3  christos #define SYMINFO_FLG_PASSTHRU	0x0002	/* ignored - see SYMINFO_FLG_FILTER */
   1176      1.3  christos #define SYMINFO_FLG_COPY	0x0004	/* symbol is a copy-reloc */
   1177      1.3  christos #define SYMINFO_FLG_LAZYLOAD	0x0008	/* object containing defn should be
   1178      1.3  christos 					   lazily-loaded */
   1179      1.3  christos #define SYMINFO_FLG_DIRECTBIND	0x0010	/* ref should be bound directly to
   1180      1.3  christos 					   object containing definition */
   1181      1.3  christos #define SYMINFO_FLG_NOEXTDIRECT 0x0020	/* don't let an external reference
   1182      1.3  christos 					   directly bind to this symbol */
   1183      1.3  christos #define SYMINFO_FLG_FILTER	0x0002	/* symbol ref is associated to a */
   1184      1.3  christos #define SYMINFO_FLG_AUXILIARY	0x0040	/*	standard or auxiliary filter */
   1185      1.3  christos 
   1186      1.3  christos #define SYMINFO_BT_SELF		0xffff	/* symbol bound to self */
   1187      1.3  christos #define SYMINFO_BT_PARENT	0xfffe	/* symbol bound to parent */
   1188      1.3  christos #define SYMINFO_BT_NONE		0xfffd	/* no special symbol binding */
   1189      1.3  christos #define SYMINFO_BT_EXTERN	0xfffc	/* symbol defined as external */
   1190      1.3  christos #define SYMINFO_BT_LOWRESERVE	0xff00	/* beginning of reserved entries */
   1191      1.3  christos 
   1192      1.3  christos #define SYMINFO_NONE		0	/* Syminfo version */
   1193      1.3  christos #define SYMINFO_CURRENT		1
   1194      1.3  christos #define SYMINFO_NUM		2
   1195      1.3  christos 
   1196      1.3  christos /*
   1197      1.3  christos  * These constants are used for Elf32_Verdef struct's version number.
   1198      1.3  christos  */
   1199      1.3  christos #define VER_DEF_NONE		0
   1200      1.3  christos #define VER_DEF_CURRENT		1
   1201      1.3  christos 
   1202      1.3  christos /*
   1203      1.3  christos  * These constants are used for Elf32_Verdef struct's vd_ndx.
   1204      1.3  christos  */
   1205      1.3  christos #define VER_DEF_IDX(x)		VER_NDX(x)
   1206      1.3  christos 
   1207      1.3  christos /*
   1208      1.3  christos  * These constants are used for Elf32_Verdef struct's vd_flags.
   1209      1.3  christos  */
   1210      1.3  christos #define VER_FLG_BASE		0x1
   1211      1.3  christos #define VER_FLG_WEAK		0x2
   1212      1.3  christos 
   1213      1.3  christos /*
   1214      1.3  christos  * These are used in an Elf32_Versym field.
   1215      1.3  christos  */
   1216      1.3  christos #define VER_NDX_LOCAL		0
   1217      1.3  christos #define VER_NDX_GLOBAL		1
   1218      1.3  christos #define VER_NDX_GIVEN		2
   1219      1.3  christos 
   1220      1.3  christos /*
   1221      1.3  christos  * These constants are used for Elf32_Verneed struct's version number.
   1222      1.3  christos  */
   1223      1.3  christos #define VER_NEED_NONE		0
   1224      1.3  christos #define VER_NEED_CURRENT	1
   1225      1.3  christos 
   1226      1.3  christos /*
   1227      1.3  christos  * These constants are used for Elf32_Vernaux struct's vna_other.
   1228      1.3  christos  */
   1229      1.3  christos #define VER_NEED_HIDDEN		VER_NDX_HIDDEN
   1230      1.3  christos #define VER_NEED_IDX(x)		VER_NDX(x)
   1231      1.3  christos 
   1232      1.3  christos /* index */
   1233      1.3  christos #define VER_NDX_HIDDEN		0x8000
   1234      1.3  christos #define VER_NDX(x)		((x) & ~VER_NDX_HIDDEN)
   1235      1.3  christos 
   1236      1.3  christos /*
   1237      1.4    andvar  * GNU Extension hiding symbol
   1238      1.3  christos  */
   1239      1.3  christos #define VERSYM_HIDDEN		0x8000
   1240      1.3  christos #define VERSYM_VERSION		0x7fff
   1241      1.3  christos 
   1242      1.3  christos #define ELF_VER_CHR		'@'
   1243      1.3  christos 
   1244      1.3  christos /*
   1245      1.3  christos  * These are current size independent.
   1246      1.3  christos  */
   1247      1.3  christos 
   1248      1.3  christos typedef struct {
   1249      1.3  christos 	Elf32_Half	vd_version;	/* version number of structure */
   1250      1.3  christos 	Elf32_Half	vd_flags;	/* flags (VER_FLG_*) */
   1251      1.3  christos 	Elf32_Half	vd_ndx;		/* version index */
   1252      1.3  christos 	Elf32_Half	vd_cnt;		/* number of verdaux entries */
   1253      1.3  christos 	Elf32_Word	vd_hash;	/* hash of name */
   1254      1.3  christos 	Elf32_Word	vd_aux;		/* offset to verdaux entries */
   1255      1.3  christos 	Elf32_Word	vd_next;	/* offset to next verdef */
   1256      1.3  christos } Elf32_Verdef;
   1257      1.3  christos typedef Elf32_Verdef	Elf64_Verdef;
   1258      1.3  christos 
   1259      1.3  christos typedef struct {
   1260      1.3  christos 	Elf32_Word	vda_name;	/* string table offset of name */
   1261      1.3  christos 	Elf32_Word	vda_next;	/* offset to verdaux */
   1262      1.3  christos } Elf32_Verdaux;
   1263      1.3  christos typedef Elf32_Verdaux	Elf64_Verdaux;
   1264      1.3  christos 
   1265      1.3  christos typedef struct {
   1266      1.3  christos 	Elf32_Half	vn_version;	/* version number of structure */
   1267      1.3  christos 	Elf32_Half	vn_cnt;		/* number of vernaux entries */
   1268      1.3  christos 	Elf32_Word	vn_file;	/* string table offset of library name*/
   1269      1.3  christos 	Elf32_Word	vn_aux;		/* offset to vernaux entries */
   1270      1.3  christos 	Elf32_Word	vn_next;	/* offset to next verneed */
   1271      1.3  christos } Elf32_Verneed;
   1272      1.3  christos typedef Elf32_Verneed	Elf64_Verneed;
   1273      1.3  christos 
   1274      1.3  christos typedef struct {
   1275      1.3  christos 	Elf32_Word	vna_hash;	/* Hash of dependency name */
   1276      1.3  christos 	Elf32_Half	vna_flags;	/* flags (VER_FLG_*) */
   1277      1.3  christos 	Elf32_Half	vna_other;	/* unused */
   1278      1.3  christos 	Elf32_Word	vna_name;	/* string table offset to version name*/
   1279      1.3  christos 	Elf32_Word	vna_next;	/* offset to next vernaux */
   1280      1.3  christos } Elf32_Vernaux;
   1281      1.3  christos typedef Elf32_Vernaux	Elf64_Vernaux;
   1282      1.3  christos 
   1283      1.3  christos typedef struct {
   1284      1.3  christos 	Elf32_Half	vs_vers;
   1285      1.3  christos } Elf32_Versym;
   1286      1.3  christos typedef Elf32_Versym	Elf64_Versym;
   1287      1.3  christos 
   1288      1.3  christos #ifdef _KERNEL
   1289      1.3  christos 
   1290      1.3  christos /*
   1291      1.3  christos  * Arbitrary limits to avoid DoS for excessive memory allocation.
   1292      1.3  christos  */
   1293      1.3  christos #define ELF_MAXPHNUM	128
   1294      1.3  christos #define ELF_MAXSHNUM	32768
   1295      1.3  christos #define ELF_MAXNOTESIZE	1024
   1296      1.3  christos 
   1297      1.3  christos #define ELF_AUX_ENTRIES 15	/* Max size of aux array passed to loader */
   1298      1.3  christos #define ELF32_NO_ADDR	(~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
   1299      1.3  christos #define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */
   1300      1.3  christos #define ELF64_NO_ADDR	(~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
   1301      1.3  christos #define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */
   1302      1.3  christos 
   1303      1.3  christos #if defined(ELFSIZE) && (ELFSIZE == 64)
   1304      1.3  christos #define ELF_NO_ADDR	ELF64_NO_ADDR
   1305      1.3  christos #define ELF_LINK_ADDR	ELF64_LINK_ADDR
   1306      1.3  christos #elif defined(ELFSIZE) && (ELFSIZE == 32)
   1307      1.3  christos #define ELF_NO_ADDR	ELF32_NO_ADDR
   1308      1.3  christos #define ELF_LINK_ADDR	ELF32_LINK_ADDR
   1309      1.3  christos #endif
   1310      1.3  christos 
   1311      1.3  christos #ifndef ELF32_EHDR_FLAGS_OK
   1312      1.3  christos #define ELF32_EHDR_FLAGS_OK(eh) 1
   1313      1.3  christos #endif
   1314      1.3  christos 
   1315      1.3  christos #ifndef ELF64_EHDR_FLAGS_OK
   1316      1.3  christos #define ELF64_EHDR_FLAGS_OK(eh) 1
   1317      1.3  christos #endif
   1318      1.3  christos 
   1319      1.3  christos #if defined(ELFSIZE) && (ELFSIZE == 64)
   1320      1.3  christos #define ELF_EHDR_FLAGS_OK(eh)	ELF64_EHDR_FLAGS_OK(eh)
   1321      1.3  christos #else
   1322      1.3  christos #define ELF_EHDR_FLAGS_OK(eh)	ELF32_EHDR_FLAGS_OK(eh)
   1323      1.3  christos #endif
   1324      1.3  christos 
   1325      1.3  christos #if defined(ELFSIZE)
   1326      1.3  christos struct elf_args {
   1327      1.3  christos 	Elf_Addr	arg_entry;	/* program entry point */
   1328      1.3  christos 	Elf_Addr	arg_interp;	/* Interpreter load address */
   1329      1.3  christos 	Elf_Addr	arg_phaddr;	/* program header address */
   1330      1.3  christos 	Elf_Addr	arg_phentsize;	/* Size of program header */
   1331      1.3  christos 	Elf_Addr	arg_phnum;	/* Number of program headers */
   1332      1.3  christos };
   1333      1.3  christos #endif
   1334      1.3  christos 
   1335      1.3  christos #ifdef _KERNEL_OPT
   1336      1.3  christos #include "opt_execfmt.h"
   1337      1.3  christos #endif
   1338      1.3  christos 
   1339      1.3  christos struct ps_strings;
   1340      1.3  christos struct coredump_iostate;
   1341      1.3  christos struct note_state;
   1342      1.3  christos struct exec_package;
   1343      1.3  christos 
   1344      1.3  christos #ifdef EXEC_ELF32
   1345      1.3  christos int	exec_elf32_makecmds(struct lwp *, struct exec_package *);
   1346      1.3  christos int	elf32_copyargs(struct lwp *, struct exec_package *,
   1347      1.3  christos     struct ps_strings *, char **, void *);
   1348      1.3  christos 
   1349      1.3  christos int	coredump_elf32(struct lwp *, struct coredump_iostate *);
   1350      1.3  christos void	coredump_savenote_elf32(struct note_state *, unsigned int,
   1351      1.3  christos 	    const char *, void *, size_t);
   1352      1.3  christos 
   1353      1.3  christos int	elf32_check_header(Elf32_Ehdr *);
   1354      1.3  christos #endif
   1355      1.3  christos 
   1356      1.3  christos #ifdef EXEC_ELF64
   1357      1.3  christos int	exec_elf64_makecmds(struct lwp *, struct exec_package *);
   1358      1.3  christos int	elf64_copyargs(struct lwp *, struct exec_package *,
   1359      1.3  christos     struct ps_strings *, char **, void *);
   1360      1.3  christos 
   1361      1.3  christos int	coredump_elf64(struct lwp *, struct coredump_iostate *);
   1362      1.3  christos void	coredump_savenote_elf64(struct note_state *, unsigned int,
   1363      1.3  christos 	    const char *, void *, size_t);
   1364      1.3  christos 
   1365      1.3  christos int	elf64_check_header(Elf64_Ehdr *);
   1366      1.3  christos #endif
   1367      1.3  christos 
   1368      1.3  christos #endif /* _KERNEL */
   1369      1.3  christos 
   1370      1.1   tsutsui #endif /* !_SYS_EXEC_ELF_H_ */
   1371