xref: /openbmc/u-boot/include/elf.h (revision 20e00c13)
1 /*
2  * Copyright (c) 1995, 1996, 2001, 2002
3  * Erik Theisen.  All rights reserved.
4  *
5  * SPDX-License-Identifier:	BSD-3-Clause
6  */
7 
8 /*
9  * This is the ELF ABI header file
10  * formerly known as "elf_abi.h".
11  */
12 
13 #ifndef _ELF_H
14 #define _ELF_H
15 
16 #include "compiler.h"
17 
18 /*
19  *  This version doesn't work for 64-bit ABIs - Erik.
20  */
21 
22 /*
23  * These typedefs need to be handled better.
24  */
25 typedef uint32_t	Elf32_Addr;	/* Unsigned program address */
26 typedef uint32_t	Elf32_Off;	/* Unsigned file offset */
27 typedef int32_t		Elf32_Sword;	/* Signed large integer */
28 typedef uint32_t	Elf32_Word;	/* Unsigned large integer */
29 typedef uint16_t	Elf32_Half;	/* Unsigned medium integer */
30 
31 /* 64-bit ELF base types. */
32 typedef uint64_t	Elf64_Addr;
33 typedef uint16_t	Elf64_Half;
34 typedef int16_t		Elf64_SHalf;
35 typedef uint64_t	Elf64_Off;
36 typedef int32_t		Elf64_Sword;
37 typedef uint32_t	Elf64_Word;
38 typedef uint64_t	Elf64_Xword;
39 typedef int64_t		Elf64_Sxword;
40 
41 /* e_ident[] identification indexes */
42 #define EI_MAG0		0		/* file ID */
43 #define EI_MAG1		1		/* file ID */
44 #define EI_MAG2		2		/* file ID */
45 #define EI_MAG3		3		/* file ID */
46 #define EI_CLASS	4		/* file class */
47 #define EI_DATA		5		/* data encoding */
48 #define EI_VERSION	6		/* ELF header version */
49 #define EI_OSABI	7		/* OS/ABI specific ELF extensions */
50 #define EI_ABIVERSION	8		/* ABI target version */
51 #define EI_PAD		9		/* start of pad bytes */
52 #define EI_NIDENT	16		/* Size of e_ident[] */
53 
54 /* e_ident[] magic number */
55 #define	ELFMAG0		0x7f		/* e_ident[EI_MAG0] */
56 #define	ELFMAG1		'E'		/* e_ident[EI_MAG1] */
57 #define	ELFMAG2		'L'		/* e_ident[EI_MAG2] */
58 #define	ELFMAG3		'F'		/* e_ident[EI_MAG3] */
59 #define	ELFMAG		"\177ELF"	/* magic */
60 #define	SELFMAG		4		/* size of magic */
61 
62 /* e_ident[] file class */
63 #define	ELFCLASSNONE	0		/* invalid */
64 #define	ELFCLASS32	1		/* 32-bit objs */
65 #define	ELFCLASS64	2		/* 64-bit objs */
66 #define	ELFCLASSNUM	3		/* number of classes */
67 
68 /* e_ident[] data encoding */
69 #define ELFDATANONE	0		/* invalid */
70 #define ELFDATA2LSB	1		/* Little-Endian */
71 #define ELFDATA2MSB	2		/* Big-Endian */
72 #define ELFDATANUM	3		/* number of data encode defines */
73 
74 /* e_ident[] OS/ABI specific ELF extensions */
75 #define ELFOSABI_NONE		0	/* No extension specified */
76 #define ELFOSABI_HPUX		1	/* Hewlett-Packard HP-UX */
77 #define ELFOSABI_NETBSD		2	/* NetBSD */
78 #define ELFOSABI_LINUX		3	/* Linux */
79 #define ELFOSABI_SOLARIS	6	/* Sun Solaris */
80 #define ELFOSABI_AIX		7	/* AIX */
81 #define ELFOSABI_IRIX		8	/* IRIX */
82 #define ELFOSABI_FREEBSD	9	/* FreeBSD */
83 #define ELFOSABI_TRU64		10	/* Compaq TRU64 UNIX */
84 #define ELFOSABI_MODESTO	11	/* Novell Modesto */
85 #define ELFOSABI_OPENBSD	12	/* OpenBSD */
86 /* 64-255 Architecture-specific value range */
87 
88 /* e_ident[] ABI Version */
89 #define ELFABIVERSION		0
90 
91 /* e_ident */
92 #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
93 		      (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
94 		      (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
95 		      (ehdr).e_ident[EI_MAG3] == ELFMAG3)
96 
97 /* ELF Header */
98 typedef struct elfhdr{
99 	unsigned char	e_ident[EI_NIDENT]; /* ELF Identification */
100 	Elf32_Half	e_type;		/* object file type */
101 	Elf32_Half	e_machine;	/* machine */
102 	Elf32_Word	e_version;	/* object file version */
103 	Elf32_Addr	e_entry;	/* virtual entry point */
104 	Elf32_Off	e_phoff;	/* program header table offset */
105 	Elf32_Off	e_shoff;	/* section header table offset */
106 	Elf32_Word	e_flags;	/* processor-specific flags */
107 	Elf32_Half	e_ehsize;	/* ELF header size */
108 	Elf32_Half	e_phentsize;	/* program header entry size */
109 	Elf32_Half	e_phnum;	/* number of program header entries */
110 	Elf32_Half	e_shentsize;	/* section header entry size */
111 	Elf32_Half	e_shnum;	/* number of section header entries */
112 	Elf32_Half	e_shstrndx;	/* section header table's "section
113 					   header string table" entry offset */
114 } Elf32_Ehdr;
115 
116 /* e_type */
117 #define ET_NONE		0		/* No file type */
118 #define ET_REL		1		/* relocatable file */
119 #define ET_EXEC		2		/* executable file */
120 #define ET_DYN		3		/* shared object file */
121 #define ET_CORE		4		/* core file */
122 #define ET_NUM		5		/* number of types */
123 #define ET_LOOS		0xfe00		/* reserved range for operating */
124 #define ET_HIOS		0xfeff		/*  system specific e_type */
125 #define ET_LOPROC	0xff00		/* reserved range for processor */
126 #define ET_HIPROC	0xffff		/*  specific e_type */
127 
128 /* e_machine */
129 #define EM_NONE		0		/* No Machine */
130 #define EM_M32		1		/* AT&T WE 32100 */
131 #define EM_SPARC	2		/* SPARC */
132 #define EM_386		3		/* Intel 80386 */
133 #define EM_68K		4		/* Motorola 68000 */
134 #define EM_88K		5		/* Motorola 88000 */
135 #if 0
136 #define EM_486		6		/* RESERVED - was Intel 80486 */
137 #endif
138 #define EM_860		7		/* Intel 80860 */
139 #define EM_MIPS		8		/* MIPS R3000 Big-Endian only */
140 #define EM_S370		9		/* IBM System/370 Processor */
141 #define EM_MIPS_RS4_BE	10		/* MIPS R4000 Big-Endian */
142 #if 0
143 #define EM_SPARC64	11		/* RESERVED - was SPARC v9
144 					     64-bit unoffical */
145 #endif
146 /* RESERVED 11-14 for future use */
147 #define EM_PARISC	15		/* HPPA */
148 /* RESERVED 16 for future use */
149 #define EM_VPP500	17		/* Fujitsu VPP500 */
150 #define EM_SPARC32PLUS	18		/* Enhanced instruction set SPARC */
151 #define EM_960		19		/* Intel 80960 */
152 #define EM_PPC		20		/* PowerPC */
153 #define EM_PPC64	21		/* 64-bit PowerPC */
154 #define EM_S390		22		/* IBM System/390 Processor */
155 /* RESERVED 23-35 for future use */
156 #define EM_V800		36		/* NEC V800 */
157 #define EM_FR20		37		/* Fujitsu FR20 */
158 #define EM_RH32		38		/* TRW RH-32 */
159 #define EM_RCE		39		/* Motorola RCE */
160 #define EM_ARM		40		/* Advanced Risc Machines ARM */
161 #define EM_ALPHA	41		/* Digital Alpha */
162 #define EM_SH		42		/* Hitachi SH */
163 #define EM_SPARCV9	43		/* SPARC Version 9 */
164 #define EM_TRICORE	44		/* Siemens TriCore embedded processor */
165 #define EM_ARC		45		/* Argonaut RISC Core */
166 #define EM_H8_300	46		/* Hitachi H8/300 */
167 #define EM_H8_300H	47		/* Hitachi H8/300H */
168 #define EM_H8S		48		/* Hitachi H8S */
169 #define EM_H8_500	49		/* Hitachi H8/500 */
170 #define EM_IA_64	50		/* Intel Merced */
171 #define EM_MIPS_X	51		/* Stanford MIPS-X */
172 #define EM_COLDFIRE	52		/* Motorola Coldfire */
173 #define EM_68HC12	53		/* Motorola M68HC12 */
174 #define EM_MMA		54		/* Fujitsu MMA Multimedia Accelerator*/
175 #define EM_PCP		55		/* Siemens PCP */
176 #define EM_NCPU		56		/* Sony nCPU embeeded RISC */
177 #define EM_NDR1		57		/* Denso NDR1 microprocessor */
178 #define EM_STARCORE	58		/* Motorola Start*Core processor */
179 #define EM_ME16		59		/* Toyota ME16 processor */
180 #define EM_ST100	60		/* STMicroelectronic ST100 processor */
181 #define EM_TINYJ	61		/* Advanced Logic Corp. Tinyj emb.fam*/
182 #define EM_X86_64	62		/* AMD x86-64 */
183 #define EM_PDSP		63		/* Sony DSP Processor */
184 /* RESERVED 64,65 for future use */
185 #define EM_FX66		66		/* Siemens FX66 microcontroller */
186 #define EM_ST9PLUS	67		/* STMicroelectronics ST9+ 8/16 mc */
187 #define EM_ST7		68		/* STmicroelectronics ST7 8 bit mc */
188 #define EM_68HC16	69		/* Motorola MC68HC16 microcontroller */
189 #define EM_68HC11	70		/* Motorola MC68HC11 microcontroller */
190 #define EM_68HC08	71		/* Motorola MC68HC08 microcontroller */
191 #define EM_68HC05	72		/* Motorola MC68HC05 microcontroller */
192 #define EM_SVX		73		/* Silicon Graphics SVx */
193 #define EM_ST19		74		/* STMicroelectronics ST19 8 bit mc */
194 #define EM_VAX		75		/* Digital VAX */
195 #define EM_CHRIS	76		/* Axis Communications embedded proc. */
196 #define EM_JAVELIN	77		/* Infineon Technologies emb. proc. */
197 #define EM_FIREPATH	78		/* Element 14 64-bit DSP Processor */
198 #define EM_ZSP		79		/* LSI Logic 16-bit DSP Processor */
199 #define EM_MMIX		80		/* Donald Knuth's edu 64-bit proc. */
200 #define EM_HUANY	81		/* Harvard University mach-indep objs */
201 #define EM_PRISM	82		/* SiTera Prism */
202 #define EM_AVR		83		/* Atmel AVR 8-bit microcontroller */
203 #define EM_FR30		84		/* Fujitsu FR30 */
204 #define EM_D10V		85		/* Mitsubishi DV10V */
205 #define EM_D30V		86		/* Mitsubishi DV30V */
206 #define EM_V850		87		/* NEC v850 */
207 #define EM_M32R		88		/* Mitsubishi M32R */
208 #define EM_MN10300	89		/* Matsushita MN10200 */
209 #define EM_MN10200	90		/* Matsushita MN10200 */
210 #define EM_PJ		91		/* picoJava */
211 #define EM_NUM		92		/* number of machine types */
212 
213 /* Version */
214 #define EV_NONE		0		/* Invalid */
215 #define EV_CURRENT	1		/* Current */
216 #define EV_NUM		2		/* number of versions */
217 
218 /* Section Header */
219 typedef struct {
220 	Elf32_Word	sh_name;	/* name - index into section header
221 					   string table section */
222 	Elf32_Word	sh_type;	/* type */
223 	Elf32_Word	sh_flags;	/* flags */
224 	Elf32_Addr	sh_addr;	/* address */
225 	Elf32_Off	sh_offset;	/* file offset */
226 	Elf32_Word	sh_size;	/* section size */
227 	Elf32_Word	sh_link;	/* section header table index link */
228 	Elf32_Word	sh_info;	/* extra information */
229 	Elf32_Word	sh_addralign;	/* address alignment */
230 	Elf32_Word	sh_entsize;	/* section entry size */
231 } Elf32_Shdr;
232 
233 /* Special Section Indexes */
234 #define SHN_UNDEF	0		/* undefined */
235 #define SHN_LORESERVE	0xff00		/* lower bounds of reserved indexes */
236 #define SHN_LOPROC	0xff00		/* reserved range for processor */
237 #define SHN_HIPROC	0xff1f		/*   specific section indexes */
238 #define SHN_LOOS	0xff20		/* reserved range for operating */
239 #define SHN_HIOS	0xff3f		/*   specific semantics */
240 #define SHN_ABS		0xfff1		/* absolute value */
241 #define SHN_COMMON	0xfff2		/* common symbol */
242 #define SHN_XINDEX	0xffff		/* Index is an extra table */
243 #define SHN_HIRESERVE	0xffff		/* upper bounds of reserved indexes */
244 
245 /* sh_type */
246 #define SHT_NULL	0		/* inactive */
247 #define SHT_PROGBITS	1		/* program defined information */
248 #define SHT_SYMTAB	2		/* symbol table section */
249 #define SHT_STRTAB	3		/* string table section */
250 #define SHT_RELA	4		/* relocation section with addends*/
251 #define SHT_HASH	5		/* symbol hash table section */
252 #define SHT_DYNAMIC	6		/* dynamic section */
253 #define SHT_NOTE	7		/* note section */
254 #define SHT_NOBITS	8		/* no space section */
255 #define SHT_REL		9		/* relation section without addends */
256 #define SHT_SHLIB	10		/* reserved - purpose unknown */
257 #define SHT_DYNSYM	11		/* dynamic symbol table section */
258 #define SHT_INIT_ARRAY	14		/* Array of constructors */
259 #define SHT_FINI_ARRAY	15		/* Array of destructors */
260 #define SHT_PREINIT_ARRAY 16		/* Array of pre-constructors */
261 #define SHT_GROUP	17		/* Section group */
262 #define SHT_SYMTAB_SHNDX 18		/* Extended section indeces */
263 #define SHT_NUM		19		/* number of section types */
264 #define SHT_LOOS	0x60000000	/* Start OS-specific */
265 #define SHT_HIOS	0x6fffffff	/* End OS-specific */
266 #define SHT_LOPROC	0x70000000	/* reserved range for processor */
267 #define SHT_HIPROC	0x7fffffff	/*  specific section header types */
268 #define SHT_LOUSER	0x80000000	/* reserved range for application */
269 #define SHT_HIUSER	0xffffffff	/*  specific indexes */
270 
271 /* Section names */
272 #define ELF_BSS         ".bss"		/* uninitialized data */
273 #define ELF_COMMENT	".comment"	/* version control information */
274 #define ELF_DATA        ".data"		/* initialized data */
275 #define ELF_DATA1       ".data1"	/* initialized data */
276 #define ELF_DEBUG       ".debug"	/* debug */
277 #define ELF_DYNAMIC     ".dynamic"	/* dynamic linking information */
278 #define ELF_DYNSTR      ".dynstr"	/* dynamic string table */
279 #define ELF_DYNSYM      ".dynsym"	/* dynamic symbol table */
280 #define ELF_FINI        ".fini"		/* termination code */
281 #define ELF_FINI_ARRAY	".fini_array"	/* Array of destructors */
282 #define ELF_GOT         ".got"		/* global offset table */
283 #define ELF_HASH        ".hash"		/* symbol hash table */
284 #define ELF_INIT        ".init"		/* initialization code */
285 #define ELF_INIT_ARRAY	".init_array"	/* Array of constuctors */
286 #define ELF_INTERP	".interp"	/* Pathname of program interpreter */
287 #define ELF_LINE	".line"		/* Symbolic line numnber information */
288 #define ELF_NOTE	".note"		/* Contains note section */
289 #define ELF_PLT		".plt"		/* Procedure linkage table */
290 #define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
291 #define ELF_REL_DATA    ".rel.data"	/* relocation data */
292 #define ELF_REL_FINI    ".rel.fini"	/* relocation termination code */
293 #define ELF_REL_INIT    ".rel.init"	/* relocation initialization code */
294 #define ELF_REL_DYN     ".rel.dyn"	/* relocaltion dynamic link info */
295 #define ELF_REL_RODATA  ".rel.rodata"	/* relocation read-only data */
296 #define ELF_REL_TEXT    ".rel.text"	/* relocation code */
297 #define ELF_RODATA      ".rodata"	/* read-only data */
298 #define ELF_RODATA1     ".rodata1"	/* read-only data */
299 #define ELF_SHSTRTAB    ".shstrtab"	/* section header string table */
300 #define ELF_STRTAB      ".strtab"	/* string table */
301 #define ELF_SYMTAB      ".symtab"	/* symbol table */
302 #define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
303 #define ELF_TBSS	".tbss"		/* thread local uninit data */
304 #define ELF_TDATA	".tdata"	/* thread local init data */
305 #define ELF_TDATA1	".tdata1"	/* thread local init data */
306 #define ELF_TEXT        ".text"		/* code */
307 
308 /* Section Attribute Flags - sh_flags */
309 #define SHF_WRITE	0x1		/* Writable */
310 #define SHF_ALLOC	0x2		/* occupies memory */
311 #define SHF_EXECINSTR	0x4		/* executable */
312 #define SHF_MERGE	0x10		/* Might be merged */
313 #define SHF_STRINGS	0x20		/* Contains NULL terminated strings */
314 #define SHF_INFO_LINK	0x40		/* sh_info contains SHT index */
315 #define SHF_LINK_ORDER	0x80		/* Preserve order after combining*/
316 #define SHF_OS_NONCONFORMING 0x100	/* Non-standard OS specific handling */
317 #define SHF_GROUP	0x200		/* Member of section group */
318 #define SHF_TLS		0x400		/* Thread local storage */
319 #define SHF_MASKOS	0x0ff00000	/* OS specific */
320 #define SHF_MASKPROC	0xf0000000	/* reserved bits for processor */
321 					/*  specific section attributes */
322 
323 /* Section Group Flags */
324 #define GRP_COMDAT	0x1		/* COMDAT group */
325 #define GRP_MASKOS	0x0ff00000	/* Mask OS specific flags */
326 #define GRP_MASKPROC	0xf0000000	/* Mask processor specific flags */
327 
328 /* Symbol Table Entry */
329 typedef struct elf32_sym {
330 	Elf32_Word	st_name;	/* name - index into string table */
331 	Elf32_Addr	st_value;	/* symbol value */
332 	Elf32_Word	st_size;	/* symbol size */
333 	unsigned char	st_info;	/* type and binding */
334 	unsigned char	st_other;	/* 0 - no defined meaning */
335 	Elf32_Half	st_shndx;	/* section header index */
336 } Elf32_Sym;
337 
338 /* Symbol table index */
339 #define STN_UNDEF	0		/* undefined */
340 
341 /* Extract symbol info - st_info */
342 #define ELF32_ST_BIND(x)	((x) >> 4)
343 #define ELF32_ST_TYPE(x)	(((unsigned int) x) & 0xf)
344 #define ELF32_ST_INFO(b,t)	(((b) << 4) + ((t) & 0xf))
345 #define ELF32_ST_VISIBILITY(x)	((x) & 0x3)
346 
347 /* Symbol Binding - ELF32_ST_BIND - st_info */
348 #define STB_LOCAL	0		/* Local symbol */
349 #define STB_GLOBAL	1		/* Global symbol */
350 #define STB_WEAK	2		/* like global - lower precedence */
351 #define STB_NUM		3		/* number of symbol bindings */
352 #define STB_LOOS	10		/* reserved range for operating */
353 #define STB_HIOS	12		/*   system specific symbol bindings */
354 #define STB_LOPROC	13		/* reserved range for processor */
355 #define STB_HIPROC	15		/*  specific symbol bindings */
356 
357 /* Symbol type - ELF32_ST_TYPE - st_info */
358 #define STT_NOTYPE	0		/* not specified */
359 #define STT_OBJECT	1		/* data object */
360 #define STT_FUNC	2		/* function */
361 #define STT_SECTION	3		/* section */
362 #define STT_FILE	4		/* file */
363 #define STT_NUM		5		/* number of symbol types */
364 #define STT_TLS		6		/* Thread local storage symbol */
365 #define STT_LOOS	10		/* reserved range for operating */
366 #define STT_HIOS	12		/*  system specific symbol types */
367 #define STT_LOPROC	13		/* reserved range for processor */
368 #define STT_HIPROC	15		/*  specific symbol types */
369 
370 /* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
371 #define STV_DEFAULT	0		/* Normal visibility rules */
372 #define STV_INTERNAL	1		/* Processor specific hidden class */
373 #define STV_HIDDEN	2		/* Symbol unavailable in other mods */
374 #define STV_PROTECTED	3		/* Not preemptible, not exported */
375 
376 
377 /* Relocation entry with implicit addend */
378 typedef struct
379 {
380 	Elf32_Addr	r_offset;	/* offset of relocation */
381 	Elf32_Word	r_info;		/* symbol table index and type */
382 } Elf32_Rel;
383 
384 /* Relocation entry with explicit addend */
385 typedef struct
386 {
387 	Elf32_Addr	r_offset;	/* offset of relocation */
388 	Elf32_Word	r_info;		/* symbol table index and type */
389 	Elf32_Sword	r_addend;
390 } Elf32_Rela;
391 
392 typedef struct {
393 	Elf64_Addr r_offset;	/* Location at which to apply the action */
394 	Elf64_Xword r_info;	/* index and type of relocation */
395 } Elf64_Rel;
396 
397 typedef struct {
398 	Elf64_Addr r_offset;    /* Location at which to apply the action */
399 	Elf64_Xword r_info;     /* index and type of relocation */
400 	Elf64_Sxword r_addend;  /* Constant addend used to compute value */
401 } Elf64_Rela;
402 
403 /* Extract relocation info - r_info */
404 #define ELF32_R_SYM(i)		((i) >> 8)
405 #define ELF32_R_TYPE(i)		((unsigned char) (i))
406 #define ELF32_R_INFO(s,t)	(((s) << 8) + (unsigned char)(t))
407 
408 /* Program Header */
409 typedef struct {
410 	Elf32_Word	p_type;		/* segment type */
411 	Elf32_Off	p_offset;	/* segment offset */
412 	Elf32_Addr	p_vaddr;	/* virtual address of segment */
413 	Elf32_Addr	p_paddr;	/* physical address - ignored? */
414 	Elf32_Word	p_filesz;	/* number of bytes in file for seg. */
415 	Elf32_Word	p_memsz;	/* number of bytes in mem. for seg. */
416 	Elf32_Word	p_flags;	/* flags */
417 	Elf32_Word	p_align;	/* memory alignment */
418 } Elf32_Phdr;
419 
420 /* Segment types - p_type */
421 #define PT_NULL		0		/* unused */
422 #define PT_LOAD		1		/* loadable segment */
423 #define PT_DYNAMIC	2		/* dynamic linking section */
424 #define PT_INTERP	3		/* the RTLD */
425 #define PT_NOTE		4		/* auxiliary information */
426 #define PT_SHLIB	5		/* reserved - purpose undefined */
427 #define PT_PHDR		6		/* program header */
428 #define PT_TLS		7		/* Thread local storage template */
429 #define PT_NUM		8		/* Number of segment types */
430 #define PT_LOOS		0x60000000	/* reserved range for operating */
431 #define PT_HIOS		0x6fffffff	/*   system specific segment types */
432 #define PT_LOPROC	0x70000000	/* reserved range for processor */
433 #define PT_HIPROC	0x7fffffff	/*  specific segment types */
434 
435 /* Segment flags - p_flags */
436 #define PF_X		0x1		/* Executable */
437 #define PF_W		0x2		/* Writable */
438 #define PF_R		0x4		/* Readable */
439 #define PF_MASKOS	0x0ff00000	/* OS specific segment flags */
440 #define PF_MASKPROC	0xf0000000	/* reserved bits for processor */
441 					/*  specific segment flags */
442 /* Dynamic structure */
443 typedef struct
444 {
445 	Elf32_Sword	d_tag;		/* controls meaning of d_val */
446 	union
447 	{
448 		Elf32_Word	d_val;	/* Multiple meanings - see d_tag */
449 		Elf32_Addr	d_ptr;	/* program virtual address */
450 	} d_un;
451 } Elf32_Dyn;
452 
453 extern Elf32_Dyn	_DYNAMIC[];
454 
455 typedef struct {
456 	Elf64_Sxword d_tag;		/* entry tag value */
457 	union {
458 		Elf64_Xword d_val;
459 		Elf64_Addr d_ptr;
460 	} d_un;
461 } Elf64_Dyn;
462 
463 #define ELF64_R_SYM(i)			((i) >> 32)
464 #define ELF64_R_TYPE(i)			((i) & 0xffffffff)
465 
466 /* Dynamic Array Tags - d_tag */
467 #define DT_NULL		0		/* marks end of _DYNAMIC array */
468 #define DT_NEEDED	1		/* string table offset of needed lib */
469 #define DT_PLTRELSZ	2		/* size of relocation entries in PLT */
470 #define DT_PLTGOT	3		/* address PLT/GOT */
471 #define DT_HASH		4		/* address of symbol hash table */
472 #define DT_STRTAB	5		/* address of string table */
473 #define DT_SYMTAB	6		/* address of symbol table */
474 #define DT_RELA		7		/* address of relocation table */
475 #define DT_RELASZ	8		/* size of relocation table */
476 #define DT_RELAENT	9		/* size of relocation entry */
477 #define DT_STRSZ	10		/* size of string table */
478 #define DT_SYMENT	11		/* size of symbol table entry */
479 #define DT_INIT		12		/* address of initialization func. */
480 #define DT_FINI		13		/* address of termination function */
481 #define DT_SONAME	14		/* string table offset of shared obj */
482 #define DT_RPATH	15		/* string table offset of library
483 					   search path */
484 #define DT_SYMBOLIC	16		/* start sym search in shared obj. */
485 #define DT_REL		17		/* address of rel. tbl. w addends */
486 #define DT_RELSZ	18		/* size of DT_REL relocation table */
487 #define DT_RELENT	19		/* size of DT_REL relocation entry */
488 #define DT_PLTREL	20		/* PLT referenced relocation entry */
489 #define DT_DEBUG	21		/* bugger */
490 #define DT_TEXTREL	22		/* Allow rel. mod. to unwritable seg */
491 #define DT_JMPREL	23		/* add. of PLT's relocation entries */
492 #define DT_BIND_NOW	24		/* Process relocations of object */
493 #define DT_INIT_ARRAY	25		/* Array with addresses of init fct */
494 #define DT_FINI_ARRAY	26		/* Array with addresses of fini fct */
495 #define DT_INIT_ARRAYSZ	27		/* Size in bytes of DT_INIT_ARRAY */
496 #define DT_FINI_ARRAYSZ	28		/* Size in bytes of DT_FINI_ARRAY */
497 #define DT_RUNPATH	29		/* Library search path */
498 #define DT_FLAGS	30		/* Flags for the object being loaded */
499 #define DT_ENCODING	32		/* Start of encoded range */
500 #define DT_PREINIT_ARRAY 32		/* Array with addresses of preinit fct*/
501 #define DT_PREINIT_ARRAYSZ 33		/* size in bytes of DT_PREINIT_ARRAY */
502 #define DT_NUM		34		/* Number used. */
503 #define DT_LOOS		0x60000000	/* reserved range for OS */
504 #define DT_HIOS		0x6fffffff	/*   specific dynamic array tags */
505 #define DT_LOPROC	0x70000000	/* reserved range for processor */
506 #define DT_HIPROC	0x7fffffff	/*  specific dynamic array tags */
507 
508 /* Dynamic Tag Flags - d_un.d_val */
509 #define DF_ORIGIN	0x01		/* Object may use DF_ORIGIN */
510 #define DF_SYMBOLIC	0x02		/* Symbol resolutions starts here */
511 #define DF_TEXTREL	0x04		/* Object contains text relocations */
512 #define DF_BIND_NOW	0x08		/* No lazy binding for this object */
513 #define DF_STATIC_TLS	0x10		/* Static thread local storage */
514 
515 /* Standard ELF hashing function */
516 unsigned long elf_hash(const unsigned char *name);
517 
518 #define ELF_TARG_VER	1	/* The ver for which this code is intended */
519 
520 /*
521  * XXX - PowerPC defines really don't belong in here,
522  * but we'll put them in for simplicity.
523  */
524 
525 /* Values for Elf32/64_Ehdr.e_flags.  */
526 #define EF_PPC_EMB              0x80000000      /* PowerPC embedded flag */
527 
528 /* Cygnus local bits below */
529 #define EF_PPC_RELOCATABLE      0x00010000      /* PowerPC -mrelocatable flag*/
530 #define EF_PPC_RELOCATABLE_LIB  0x00008000      /* PowerPC -mrelocatable-lib
531 						   flag */
532 
533 /* PowerPC relocations defined by the ABIs */
534 #define R_PPC_NONE              0
535 #define R_PPC_ADDR32            1       /* 32bit absolute address */
536 #define R_PPC_ADDR24            2       /* 26bit address, 2 bits ignored.  */
537 #define R_PPC_ADDR16            3       /* 16bit absolute address */
538 #define R_PPC_ADDR16_LO         4       /* lower 16bit of absolute address */
539 #define R_PPC_ADDR16_HI         5       /* high 16bit of absolute address */
540 #define R_PPC_ADDR16_HA         6       /* adjusted high 16bit */
541 #define R_PPC_ADDR14            7       /* 16bit address, 2 bits ignored */
542 #define R_PPC_ADDR14_BRTAKEN    8
543 #define R_PPC_ADDR14_BRNTAKEN   9
544 #define R_PPC_REL24             10      /* PC relative 26 bit */
545 #define R_PPC_REL14             11      /* PC relative 16 bit */
546 #define R_PPC_REL14_BRTAKEN     12
547 #define R_PPC_REL14_BRNTAKEN    13
548 #define R_PPC_GOT16             14
549 #define R_PPC_GOT16_LO          15
550 #define R_PPC_GOT16_HI          16
551 #define R_PPC_GOT16_HA          17
552 #define R_PPC_PLTREL24          18
553 #define R_PPC_COPY              19
554 #define R_PPC_GLOB_DAT          20
555 #define R_PPC_JMP_SLOT          21
556 #define R_PPC_RELATIVE          22
557 #define R_PPC_LOCAL24PC         23
558 #define R_PPC_UADDR32           24
559 #define R_PPC_UADDR16           25
560 #define R_PPC_REL32             26
561 #define R_PPC_PLT32             27
562 #define R_PPC_PLTREL32          28
563 #define R_PPC_PLT16_LO          29
564 #define R_PPC_PLT16_HI          30
565 #define R_PPC_PLT16_HA          31
566 #define R_PPC_SDAREL16          32
567 #define R_PPC_SECTOFF           33
568 #define R_PPC_SECTOFF_LO        34
569 #define R_PPC_SECTOFF_HI        35
570 #define R_PPC_SECTOFF_HA        36
571 /* Keep this the last entry.  */
572 #define R_PPC_NUM               37
573 
574 /* The remaining relocs are from the Embedded ELF ABI, and are not
575    in the SVR4 ELF ABI.  */
576 #define R_PPC_EMB_NADDR32       101
577 #define R_PPC_EMB_NADDR16       102
578 #define R_PPC_EMB_NADDR16_LO    103
579 #define R_PPC_EMB_NADDR16_HI    104
580 #define R_PPC_EMB_NADDR16_HA    105
581 #define R_PPC_EMB_SDAI16        106
582 #define R_PPC_EMB_SDA2I16       107
583 #define R_PPC_EMB_SDA2REL       108
584 #define R_PPC_EMB_SDA21         109     /* 16 bit offset in SDA */
585 #define R_PPC_EMB_MRKREF        110
586 #define R_PPC_EMB_RELSEC16      111
587 #define R_PPC_EMB_RELST_LO      112
588 #define R_PPC_EMB_RELST_HI      113
589 #define R_PPC_EMB_RELST_HA      114
590 #define R_PPC_EMB_BIT_FLD       115
591 #define R_PPC_EMB_RELSDA        116     /* 16 bit relative offset in SDA */
592 
593 /* Diab tool relocations.  */
594 #define R_PPC_DIAB_SDA21_LO     180     /* like EMB_SDA21, but lower 16 bit */
595 #define R_PPC_DIAB_SDA21_HI     181     /* like EMB_SDA21, but high 16 bit */
596 #define R_PPC_DIAB_SDA21_HA     182     /* like EMB_SDA21, adjusted high 16 */
597 #define R_PPC_DIAB_RELSDA_LO    183     /* like EMB_RELSDA, but lower 16 bit */
598 #define R_PPC_DIAB_RELSDA_HI    184     /* like EMB_RELSDA, but high 16 bit */
599 #define R_PPC_DIAB_RELSDA_HA    185     /* like EMB_RELSDA, adjusted high 16 */
600 
601 /* This is a phony reloc to handle any old fashioned TOC16 references
602    that may still be in object files.  */
603 #define R_PPC_TOC16             255
604 
605 int valid_elf_image(unsigned long addr);
606 
607 #endif /* _ELF_H */
608