1 #ifndef __XEN_ELFSTRUCTS_H__
2 #define __XEN_ELFSTRUCTS_H__
3 /*
4  * Copyright (c) 1995, 1996 Erik Theisen.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 typedef uint32_t	Elf32_Addr;	/* Unsigned program address */
30 typedef uint32_t	Elf32_Off;	/* Unsigned file offset */
31 typedef uint16_t	Elf32_Half;	/* Unsigned medium integer */
32 typedef int32_t		Elf32_Sword;	/* Signed large integer */
33 typedef uint32_t	Elf32_Word;	/* Unsigned large integer */
34 
35 typedef uint64_t	Elf64_Addr;
36 typedef uint64_t	Elf64_Off;
37 typedef uint16_t	Elf64_Half;
38 typedef int32_t		Elf64_Sword;
39 typedef uint32_t	Elf64_Word;
40 typedef int64_t		Elf64_Sxword;
41 typedef uint64_t	Elf64_Xword;
42 
43 /* Unique build id string format when using --build-id. */
44 #define NT_GNU_BUILD_ID 3
45 
46 /*
47  * e_ident[] identification indexes
48  * See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html
49  */
50 #define EI_MAG0		0		/* file ID */
51 #define EI_MAG1		1		/* file ID */
52 #define EI_MAG2		2		/* file ID */
53 #define EI_MAG3		3		/* file ID */
54 #define EI_CLASS	4		/* file class */
55 #define EI_DATA		5		/* data encoding */
56 #define EI_VERSION	6		/* ELF header version */
57 #define EI_OSABI	7		/* OS/ABI ID */
58 #define EI_ABIVERSION	8		/* ABI version */
59 #define EI_PAD		9		/* start of pad bytes */
60 #define EI_NIDENT	16		/* Size of e_ident[] */
61 
62 /* e_ident[] magic number */
63 #define	ELFMAG0		0x7f		/* e_ident[EI_MAG0] */
64 #define	ELFMAG1		'E'		/* e_ident[EI_MAG1] */
65 #define	ELFMAG2		'L'		/* e_ident[EI_MAG2] */
66 #define	ELFMAG3		'F'		/* e_ident[EI_MAG3] */
67 #define	ELFMAG		"\177ELF"	/* magic */
68 #define	SELFMAG		4		/* size of magic */
69 
70 /* e_ident[] file class */
71 #define	ELFCLASSNONE	0		/* invalid */
72 #define	ELFCLASS32	1		/* 32-bit objs */
73 #define	ELFCLASS64	2		/* 64-bit objs */
74 #define	ELFCLASSNUM	3		/* number of classes */
75 
76 /* e_ident[] data encoding */
77 #define ELFDATANONE	0		/* invalid */
78 #define ELFDATA2LSB	1		/* Little-Endian */
79 #define ELFDATA2MSB	2		/* Big-Endian */
80 #define ELFDATANUM	3		/* number of data encode defines */
81 
82 /* e_ident[] Operating System/ABI */
83 #define ELFOSABI_SYSV		0	/* UNIX System V ABI */
84 #define ELFOSABI_NONE		0	/* Same as ELFOSABI_SYSV */
85 #define ELFOSABI_HPUX		1	/* HP-UX operating system */
86 #define ELFOSABI_NETBSD		2	/* NetBSD */
87 #define ELFOSABI_LINUX		3	/* GNU/Linux */
88 #define ELFOSABI_HURD		4	/* GNU/Hurd */
89 #define ELFOSABI_86OPEN		5	/* 86Open common IA32 ABI */
90 #define ELFOSABI_SOLARIS	6	/* Solaris */
91 #define ELFOSABI_MONTEREY	7	/* Monterey */
92 #define ELFOSABI_IRIX		8	/* IRIX */
93 #define ELFOSABI_FREEBSD	9	/* FreeBSD */
94 #define ELFOSABI_TRU64		10	/* TRU64 UNIX */
95 #define ELFOSABI_MODESTO	11	/* Novell Modesto */
96 #define ELFOSABI_OPENBSD	12	/* OpenBSD */
97 #define ELFOSABI_ARM		97	/* ARM */
98 #define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
99 
100 /* e_ident */
101 #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
102                       (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
103                       (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
104                       (ehdr).e_ident[EI_MAG3] == ELFMAG3)
105 
106 /* e_flags */
107 #define EF_ARM_EABI_MASK	0xff000000
108 #define EF_ARM_EABI_UNKNOWN	0x00000000
109 #define EF_ARM_EABI_VER1	0x01000000
110 #define EF_ARM_EABI_VER2	0x02000000
111 #define EF_ARM_EABI_VER3	0x03000000
112 #define EF_ARM_EABI_VER4	0x04000000
113 #define EF_ARM_EABI_VER5	0x05000000
114 
115 /* ELF Header */
116 typedef struct elfhdr {
117 	unsigned char	e_ident[EI_NIDENT]; /* ELF Identification */
118 	Elf32_Half	e_type;		/* object file type */
119 	Elf32_Half	e_machine;	/* machine */
120 	Elf32_Word	e_version;	/* object file version */
121 	Elf32_Addr	e_entry;	/* virtual entry point */
122 	Elf32_Off	e_phoff;	/* program header table offset */
123 	Elf32_Off	e_shoff;	/* section header table offset */
124 	Elf32_Word	e_flags;	/* processor-specific flags */
125 	Elf32_Half	e_ehsize;	/* ELF header size */
126 	Elf32_Half	e_phentsize;	/* program header entry size */
127 	Elf32_Half	e_phnum;	/* number of program header entries */
128 	Elf32_Half	e_shentsize;	/* section header entry size */
129 	Elf32_Half	e_shnum;	/* number of section header entries */
130 	Elf32_Half	e_shstrndx;	/* section header table's "section
131 					   header string table" entry offset */
132 } Elf32_Ehdr;
133 
134 typedef struct {
135 	unsigned char	e_ident[EI_NIDENT];	/* Id bytes */
136 	Elf64_Half	e_type;			/* file type */
137 	Elf64_Half	e_machine;		/* machine type */
138 	Elf64_Word	e_version;		/* version number */
139 	Elf64_Addr	e_entry;		/* entry point */
140 	Elf64_Off	e_phoff;		/* Program hdr offset */
141 	Elf64_Off	e_shoff;		/* Section hdr offset */
142 	Elf64_Word	e_flags;		/* Processor flags */
143 	Elf64_Half	e_ehsize;		/* sizeof ehdr */
144 	Elf64_Half	e_phentsize;		/* Program header entry size */
145 	Elf64_Half	e_phnum;		/* Number of program headers */
146 	Elf64_Half	e_shentsize;		/* Section header entry size */
147 	Elf64_Half	e_shnum;		/* Number of section headers */
148 	Elf64_Half	e_shstrndx;		/* String table index */
149 } Elf64_Ehdr;
150 
151 /* e_type */
152 #define ET_NONE		0		/* No file type */
153 #define ET_REL		1		/* relocatable file */
154 #define ET_EXEC		2		/* executable file */
155 #define ET_DYN		3		/* shared object file */
156 #define ET_CORE		4		/* core file */
157 #define ET_NUM		5		/* number of types */
158 #define ET_LOPROC	0xff00		/* reserved range for processor */
159 #define ET_HIPROC	0xffff		/*  specific e_type */
160 
161 /* e_machine */
162 #define EM_NONE		0		/* No Machine */
163 #define EM_M32		1		/* AT&T WE 32100 */
164 #define EM_SPARC	2		/* SPARC */
165 #define EM_386		3		/* Intel 80386 */
166 #define EM_68K		4		/* Motorola 68000 */
167 #define EM_88K		5		/* Motorola 88000 */
168 #define EM_486		6		/* Intel 80486 - unused? */
169 #define EM_860		7		/* Intel 80860 */
170 #define EM_MIPS		8		/* MIPS R3000 Big-Endian only */
171 /*
172  * Don't know if EM_MIPS_RS4_BE,
173  * EM_SPARC64, EM_PARISC,
174  * or EM_PPC are ABI compliant
175  */
176 #define EM_MIPS_RS4_BE	10		/* MIPS R4000 Big-Endian */
177 #define EM_SPARC64	11		/* SPARC v9 64-bit unoffical */
178 #define EM_PARISC	15		/* HPPA */
179 #define EM_SPARC32PLUS	18		/* Enhanced instruction set SPARC */
180 #define EM_PPC		20		/* PowerPC */
181 #define EM_PPC64	21		/* PowerPC 64-bit */
182 #define EM_ARM		40		/* Advanced RISC Machines ARM */
183 #define EM_ALPHA	41		/* DEC ALPHA */
184 #define EM_SPARCV9	43		/* SPARC version 9 */
185 #define EM_ALPHA_EXP	0x9026		/* DEC ALPHA */
186 #define EM_IA_64	50		/* Intel Merced */
187 #define EM_X86_64	62		/* AMD x86-64 architecture */
188 #define EM_VAX		75		/* DEC VAX */
189 #define EM_AARCH64	183		/* ARM 64-bit */
190 
191 /* Version */
192 #define EV_NONE		0		/* Invalid */
193 #define EV_CURRENT	1		/* Current */
194 #define EV_NUM		2		/* number of versions */
195 
196 /* Section Header */
197 typedef struct {
198 	Elf32_Word	sh_name;	/* name - index into section header
199 					   string table section */
200 	Elf32_Word	sh_type;	/* type */
201 	Elf32_Word	sh_flags;	/* flags */
202 	Elf32_Addr	sh_addr;	/* address */
203 	Elf32_Off	sh_offset;	/* file offset */
204 	Elf32_Word	sh_size;	/* section size */
205 	Elf32_Word	sh_link;	/* section header table index link */
206 	Elf32_Word	sh_info;	/* extra information */
207 	Elf32_Word	sh_addralign;	/* address alignment */
208 	Elf32_Word	sh_entsize;	/* section entry size */
209 } Elf32_Shdr;
210 
211 typedef struct {
212 	Elf64_Word	sh_name;	/* section name */
213 	Elf64_Word	sh_type;	/* section type */
214 	Elf64_Xword	sh_flags;	/* section flags */
215 	Elf64_Addr	sh_addr;	/* virtual address */
216 	Elf64_Off	sh_offset;	/* file offset */
217 	Elf64_Xword	sh_size;	/* section size */
218 	Elf64_Word	sh_link;	/* link to another */
219 	Elf64_Word	sh_info;	/* misc info */
220 	Elf64_Xword	sh_addralign;	/* memory alignment */
221 	Elf64_Xword	sh_entsize;	/* table entry size */
222 } Elf64_Shdr;
223 
224 /* Special Section Indexes */
225 #define SHN_UNDEF	0		/* undefined */
226 #define SHN_LORESERVE	0xff00		/* lower bounds of reserved indexes */
227 #define SHN_LOPROC	0xff00		/* reserved range for processor */
228 #define SHN_HIPROC	0xff1f		/*   specific section indexes */
229 #define SHN_ABS		0xfff1		/* absolute value */
230 #define SHN_COMMON	0xfff2		/* common symbol */
231 #define SHN_HIRESERVE	0xffff		/* upper bounds of reserved indexes */
232 
233 /* sh_type */
234 #define SHT_NULL	0		/* inactive */
235 #define SHT_PROGBITS	1		/* program defined information */
236 #define SHT_SYMTAB	2		/* symbol table section */
237 #define SHT_STRTAB	3		/* string table section */
238 #define SHT_RELA	4		/* relocation section with addends*/
239 #define SHT_HASH	5		/* symbol hash table section */
240 #define SHT_DYNAMIC	6		/* dynamic section */
241 #define SHT_NOTE	7		/* note section */
242 #define SHT_NOBITS	8		/* no space section */
243 #define SHT_REL		9		/* relation section without addends */
244 #define SHT_SHLIB	10		/* reserved - purpose unknown */
245 #define SHT_DYNSYM	11		/* dynamic symbol table section */
246 #define SHT_NUM		12		/* number of section types */
247 #define SHT_LOPROC	0x70000000	/* reserved range for processor */
248 #define SHT_HIPROC	0x7fffffff	/*  specific section header types */
249 #define SHT_LOUSER	0x80000000	/* reserved range for application */
250 #define SHT_HIUSER	0xffffffff	/*  specific indexes */
251 
252 /* Section names */
253 #define ELF_BSS         ".bss"		/* uninitialized data */
254 #define ELF_DATA        ".data"		/* initialized data */
255 #define ELF_DEBUG       ".debug"	/* debug */
256 #define ELF_DYNAMIC     ".dynamic"	/* dynamic linking information */
257 #define ELF_DYNSTR      ".dynstr"	/* dynamic string table */
258 #define ELF_DYNSYM      ".dynsym"	/* dynamic symbol table */
259 #define ELF_FINI        ".fini"		/* termination code */
260 #define ELF_GOT         ".got"		/* global offset table */
261 #define ELF_HASH        ".hash"		/* symbol hash table */
262 #define ELF_INIT        ".init"		/* initialization code */
263 #define ELF_REL_DATA    ".rel.data"	/* relocation data */
264 #define ELF_REL_FINI    ".rel.fini"	/* relocation termination code */
265 #define ELF_REL_INIT    ".rel.init"	/* relocation initialization code */
266 #define ELF_REL_DYN     ".rel.dyn"	/* relocaltion dynamic link info */
267 #define ELF_REL_RODATA  ".rel.rodata"	/* relocation read-only data */
268 #define ELF_REL_TEXT    ".rel.text"	/* relocation code */
269 #define ELF_RODATA      ".rodata"	/* read-only data */
270 #define ELF_SHSTRTAB    ".shstrtab"	/* section header string table */
271 #define ELF_STRTAB      ".strtab"	/* string table */
272 #define ELF_SYMTAB      ".symtab"	/* symbol table */
273 #define ELF_TEXT        ".text"		/* code */
274 
275 
276 /* Section Attribute Flags - sh_flags */
277 #define SHF_WRITE	0x1		/* Writable */
278 #define SHF_ALLOC	0x2		/* occupies memory */
279 #define SHF_EXECINSTR	0x4		/* executable */
280 #define SHF_MERGE	0x10            /* mergeable */
281 #define SHF_MASKPROC	0xf0000000	/* reserved bits for processor */
282 					/*  specific section attributes */
283 
284 /* Symbol Table Entry */
285 typedef struct elf32_sym {
286 	Elf32_Word	st_name;	/* name - index into string table */
287 	Elf32_Addr	st_value;	/* symbol value */
288 	Elf32_Word	st_size;	/* symbol size */
289 	unsigned char	st_info;	/* type and binding */
290 	unsigned char	st_other;	/* 0 - no defined meaning */
291 	Elf32_Half	st_shndx;	/* section header index */
292 } Elf32_Sym;
293 
294 typedef struct {
295 	Elf64_Word	st_name;	/* Symbol name index in str table */
296 	unsigned char	st_info;	/* type / binding attrs */
297 	unsigned char	st_other;	/* unused */
298 	Elf64_Half	st_shndx;	/* section index of symbol */
299 	Elf64_Addr	st_value;	/* value of symbol */
300 	Elf64_Xword	st_size;	/* size of symbol */
301 } Elf64_Sym;
302 
303 /* Symbol table index */
304 #define STN_UNDEF	0		/* undefined */
305 
306 /* Extract symbol info - st_info */
307 #define ELF32_ST_BIND(x)	((x) >> 4)
308 #define ELF32_ST_TYPE(x)	(((unsigned int) x) & 0xf)
309 #define ELF32_ST_INFO(b,t)	(((b) << 4) + ((t) & 0xf))
310 
311 #define ELF64_ST_BIND(x)	((x) >> 4)
312 #define ELF64_ST_TYPE(x)	(((unsigned int) x) & 0xf)
313 #define ELF64_ST_INFO(b,t)	(((b) << 4) + ((t) & 0xf))
314 
315 /* Symbol Binding - ELF32_ST_BIND - st_info */
316 #define STB_LOCAL	0		/* Local symbol */
317 #define STB_GLOBAL	1		/* Global symbol */
318 #define STB_WEAK	2		/* like global - lower precedence */
319 #define STB_NUM		3		/* number of symbol bindings */
320 #define STB_LOPROC	13		/* reserved range for processor */
321 #define STB_HIPROC	15		/*  specific symbol bindings */
322 
323 /* Symbol type - ELF32_ST_TYPE - st_info */
324 #define STT_NOTYPE	0		/* not specified */
325 #define STT_OBJECT	1		/* data object */
326 #define STT_FUNC	2		/* function */
327 #define STT_SECTION	3		/* section */
328 #define STT_FILE	4		/* file */
329 #define STT_NUM		5		/* number of symbol types */
330 #define STT_LOPROC	13		/* reserved range for processor */
331 #define STT_HIPROC	15		/*  specific symbol types */
332 
333 /* Relocation entry with implicit addend */
334 typedef struct {
335 	Elf32_Addr	r_offset;	/* offset of relocation */
336 	Elf32_Word	r_info;		/* symbol table index and type */
337 } Elf32_Rel;
338 
339 /* Relocation entry with explicit addend */
340 typedef struct {
341 	Elf32_Addr	r_offset;	/* offset of relocation */
342 	Elf32_Word	r_info;		/* symbol table index and type */
343 	Elf32_Sword	r_addend;
344 } Elf32_Rela;
345 
346 /* Extract relocation info - r_info */
347 #define ELF32_R_SYM(i)		((i) >> 8)
348 #define ELF32_R_TYPE(i)		((unsigned char) (i))
349 #define ELF32_R_INFO(s,t) 	(((s) << 8) + (unsigned char)(t))
350 
351 typedef struct {
352 	Elf64_Addr	r_offset;	/* where to do it */
353 	Elf64_Xword	r_info;		/* index & type of relocation */
354 } Elf64_Rel;
355 
356 typedef struct {
357 	Elf64_Addr	r_offset;	/* where to do it */
358 	Elf64_Xword	r_info;		/* index & type of relocation */
359 	Elf64_Sxword	r_addend;	/* adjustment value */
360 } Elf64_Rela;
361 
362 #define	ELF64_R_SYM(info)	((info) >> 32)
363 #define	ELF64_R_TYPE(info)	((info) & 0xFFFFFFFF)
364 #define ELF64_R_INFO(s,t) 	(((s) << 32) + (uint32_t)(t))
365 
366 /*
367  * Relocation types for x86_64 and ARM 64. We list only the ones Live Patch
368  * implements.
369  */
370 #define R_X86_64_NONE		0	/* No reloc */
371 #define R_X86_64_64	    	1	/* Direct 64 bit  */
372 #define R_X86_64_PC32		2	/* PC relative 32 bit signed */
373 #define R_X86_64_PLT32		4	/* 32 bit PLT address */
374 
375 /*
376  * ARM32 relocation types. See
377  * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf
378  * S - address of symbol.
379  * A - addend for relocation (r_addend or need to extract from insn)
380  * P - address of the dest being relocated (derieved from r_offset)
381  */
382 #define R_ARM_NONE              0
383 #define R_ARM_ABS32             2	/* Direct 32-bit. S+A */
384 #define R_ARM_REL32             3	/* PC relative. S+A */
385 #define R_ARM_CALL              28	/* SignExtend([23:0]) << 2. S+A-P */
386 #define R_ARM_JUMP24            29	/* Same as R_ARM_CALL */
387 #define R_ARM_MOVW_ABS_NC       43	/* SignExtend([19:16],[11:0])&0xFFFF, S+A */
388 #define R_ARM_MOVT_ABS          44	/* SignExtend([19:16],[11:0))&0xFFFF0000 */
389 					/*  >> 16, S+A. */
390 
391 /*
392  * NC -  No check for overflow.
393  *
394  * The defines also use _PREL for PC-relative address, and _NC is No Check.
395  */
396 #define R_AARCH64_ABS64			257 /* Direct 64 bit. S+A, NC*/
397 #define R_AARCH64_ABS32			258 /* Direct 32 bit. S+A */
398 #define R_AARCH64_ABS16			259 /* Direct 16 bit, S+A */
399 #define R_AARCH64_PREL64		260 /* S+A-P, NC */
400 #define R_AARCH64_PREL32		261 /* S+A-P */
401 #define R_AARCH64_PREL16		262 /* S+A-P */
402 
403 /* Instructions. */
404 #define R_AARCH64_MOVW_UABS_G0		263
405 #define R_AARCH64_MOVW_UABS_G0_NC	264
406 #define R_AARCH64_MOVW_UABS_G1		265
407 #define R_AARCH64_MOVW_UABS_G1_NC	266
408 #define R_AARCH64_MOVW_UABS_G2		267
409 #define R_AARCH64_MOVW_UABS_G2_NC	268
410 #define R_AARCH64_MOVW_UABS_G3		269
411 
412 #define R_AARCH64_MOVW_SABS_G0		270
413 #define R_AARCH64_MOVW_SABS_G1		271
414 #define R_AARCH64_MOVW_SABS_G2		272
415 
416 #define R_AARCH64_ADR_PREL_LO21		274 /* ADR imm, [20:0]. S+A-P */
417 #define R_AARCH64_ADR_PREL_PG_HI21	275 /* ADRP imm, [32:12]. Page(S+A) - Page(P).*/
418 #define R_AARCH64_ADR_PREL_PG_HI21_NC	276
419 #define R_AARCH64_ADD_ABS_LO12_NC	277 /* ADD imm. [11:0]. S+A, NC */
420 
421 #define R_AARCH64_TSTBR14		279
422 #define R_AARCH64_CONDBR19		280 /* Bits 20:2, S+A-P */
423 #define R_AARCH64_JUMP26		282 /* Bits 27:2, S+A-P */
424 #define R_AARCH64_CALL26		283 /* Bits 27:2, S+A-P */
425 #define R_AARCH64_LDST16_ABS_LO12_NC	284 /* LD/ST to bits 11:1, S+A, NC */
426 #define R_AARCH64_LDST32_ABS_LO12_NC	285 /* LD/ST to bits 11:2, S+A, NC */
427 #define R_AARCH64_LDST64_ABS_LO12_NC	286 /* LD/ST to bits 11:3, S+A, NC */
428 #define R_AARCH64_LDST8_ABS_LO12_NC	278 /* LD/ST to bits 11:0, S+A, NC */
429 #define R_AARCH64_LDST128_ABS_LO12_NC	299
430 
431 #define R_AARCH64_MOVW_PREL_G0		287
432 #define R_AARCH64_MOVW_PREL_G0_NC	288
433 #define R_AARCH64_MOVW_PREL_G1		289
434 #define R_AARCH64_MOVW_PREL_G1_NC	290
435 #define R_AARCH64_MOVW_PREL_G2		291
436 #define R_AARCH64_MOVW_PREL_G2_NC	292
437 #define R_AARCH64_MOVW_PREL_G3		293
438 
439 /* Program Header */
440 typedef struct {
441 	Elf32_Word	p_type;		/* segment type */
442 	Elf32_Off	p_offset;	/* segment offset */
443 	Elf32_Addr	p_vaddr;	/* virtual address of segment */
444 	Elf32_Addr	p_paddr;	/* physical address - ignored? */
445 	Elf32_Word	p_filesz;	/* number of bytes in file for seg. */
446 	Elf32_Word	p_memsz;	/* number of bytes in mem. for seg. */
447 	Elf32_Word	p_flags;	/* flags */
448 	Elf32_Word	p_align;	/* memory alignment */
449 } Elf32_Phdr;
450 
451 typedef struct {
452 	Elf64_Word	p_type;		/* entry type */
453 	Elf64_Word	p_flags;	/* flags */
454 	Elf64_Off	p_offset;	/* offset */
455 	Elf64_Addr	p_vaddr;	/* virtual address */
456 	Elf64_Addr	p_paddr;	/* physical address */
457 	Elf64_Xword	p_filesz;	/* file size */
458 	Elf64_Xword	p_memsz;	/* memory size */
459 	Elf64_Xword	p_align;	/* memory & file alignment */
460 } Elf64_Phdr;
461 
462 /* Segment types - p_type */
463 #define PT_NULL		0		/* unused */
464 #define PT_LOAD		1		/* loadable segment */
465 #define PT_DYNAMIC	2		/* dynamic linking section */
466 #define PT_INTERP	3		/* the RTLD */
467 #define PT_NOTE		4		/* auxiliary information */
468 #define PT_SHLIB	5		/* reserved - purpose undefined */
469 #define PT_PHDR		6		/* program header */
470 #define PT_NUM		7		/* Number of segment types */
471 #define PT_LOPROC	0x70000000	/* reserved range for processor */
472 #define PT_HIPROC	0x7fffffff	/*  specific segment types */
473 
474 /* Segment flags - p_flags */
475 #define PF_X		0x1		/* Executable */
476 #define PF_W		0x2		/* Writable */
477 #define PF_R		0x4		/* Readable */
478 #define PF_MASKPROC	0xf0000000	/* reserved bits for processor */
479 					/*  specific segment flags */
480 
481 /* Dynamic structure */
482 typedef struct {
483 	Elf32_Sword	d_tag;		/* controls meaning of d_val */
484 	union {
485 		Elf32_Word	d_val;	/* Multiple meanings - see d_tag */
486 		Elf32_Addr	d_ptr;	/* program virtual address */
487 	} d_un;
488 } Elf32_Dyn;
489 
490 typedef struct {
491 	Elf64_Sxword	d_tag;		/* controls meaning of d_val */
492 	union {
493 		Elf64_Xword	d_val;
494 		Elf64_Addr	d_ptr;
495 	} d_un;
496 } Elf64_Dyn;
497 
498 /* Dynamic Array Tags - d_tag */
499 #define DT_NULL		0		/* marks end of _DYNAMIC array */
500 #define DT_NEEDED	1		/* string table offset of needed lib */
501 #define DT_PLTRELSZ	2		/* size of relocation entries in PLT */
502 #define DT_PLTGOT	3		/* address PLT/GOT */
503 #define DT_HASH		4		/* address of symbol hash table */
504 #define DT_STRTAB	5		/* address of string table */
505 #define DT_SYMTAB	6		/* address of symbol table */
506 #define DT_RELA		7		/* address of relocation table */
507 #define DT_RELASZ	8		/* size of relocation table */
508 #define DT_RELAENT	9		/* size of relocation entry */
509 #define DT_STRSZ	10		/* size of string table */
510 #define DT_SYMENT	11		/* size of symbol table entry */
511 #define DT_INIT		12		/* address of initialization func. */
512 #define DT_FINI		13		/* address of termination function */
513 #define DT_SONAME	14		/* string table offset of shared obj */
514 #define DT_RPATH	15		/* string table offset of library
515 					   search path */
516 #define DT_SYMBOLIC	16		/* start sym search in shared obj. */
517 #define DT_REL		17		/* address of rel. tbl. w addends */
518 #define DT_RELSZ	18		/* size of DT_REL relocation table */
519 #define DT_RELENT	19		/* size of DT_REL relocation entry */
520 #define DT_PLTREL	20		/* PLT referenced relocation entry */
521 #define DT_DEBUG	21		/* bugger */
522 #define DT_TEXTREL	22		/* Allow rel. mod. to unwritable seg */
523 #define DT_JMPREL	23		/* add. of PLT's relocation entries */
524 #define DT_BIND_NOW	24		/* Bind now regardless of env setting */
525 #define DT_NUM		25		/* Number used. */
526 #define DT_LOPROC	0x70000000	/* reserved range for processor */
527 #define DT_HIPROC	0x7fffffff	/*  specific dynamic array tags */
528 
529 /* Standard ELF hashing function */
530 unsigned int elf_hash(const unsigned char *name);
531 
532 /*
533  * Note Definitions
534  */
535 typedef struct {
536 	Elf32_Word namesz;
537 	Elf32_Word descsz;
538 	Elf32_Word type;
539 } Elf32_Note;
540 
541 typedef struct {
542 	Elf64_Word namesz;
543 	Elf64_Word descsz;
544 	Elf64_Word type;
545 } Elf64_Note;
546 
547 
548 #if defined(ELFSIZE)
549 #define CONCAT(x,y)	__CONCAT(x,y)
550 #define ELFNAME(x)	CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
551 #define ELFNAME2(x,y)	CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
552 #define ELFNAMEEND(x)	CONCAT(x,CONCAT(_elf,ELFSIZE))
553 #define ELFDEFNNAME(x)	CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
554 #endif
555 
556 #if defined(ELFSIZE) && (ELFSIZE == 32)
557 #define PRIxElfAddr	"08x"
558 #define PRIuElfWord	"8u"
559 
560 #define Elf_Ehdr	Elf32_Ehdr
561 #define Elf_Phdr	Elf32_Phdr
562 #define Elf_Shdr	Elf32_Shdr
563 #define Elf_Sym		Elf32_Sym
564 #define Elf_Rel		Elf32_Rel
565 #define Elf_RelA	Elf32_Rela
566 #define Elf_Dyn		Elf32_Dyn
567 #define Elf_Word	Elf32_Word
568 #define Elf_Sword	Elf32_Sword
569 #define Elf_Addr	Elf32_Addr
570 #define Elf_Off		Elf32_Off
571 #define Elf_Nhdr	Elf32_Nhdr
572 #define Elf_Note	Elf32_Note
573 
574 #define ELF_R_SYM	ELF32_R_SYM
575 #define ELF_R_TYPE	ELF32_R_TYPE
576 #define ELF_R_INFO	ELF32_R_INFO
577 #define ELFCLASS	ELFCLASS32
578 
579 #define ELF_ST_BIND	ELF32_ST_BIND
580 #define ELF_ST_TYPE	ELF32_ST_TYPE
581 #define ELF_ST_INFO	ELF32_ST_INFO
582 
583 #define AuxInfo		Aux32Info
584 #elif defined(ELFSIZE) && (ELFSIZE == 64)
585 #define PRIxElfAddr	PRIx64
586 #define PRIuElfWord	PRIu64
587 
588 #define Elf_Ehdr	Elf64_Ehdr
589 #define Elf_Phdr	Elf64_Phdr
590 #define Elf_Shdr	Elf64_Shdr
591 #define Elf_Sym		Elf64_Sym
592 #define Elf_Rel		Elf64_Rel
593 #define Elf_RelA	Elf64_Rela
594 #define Elf_Dyn		Elf64_Dyn
595 #define Elf_Word	Elf64_Word
596 #define Elf_Sword	Elf64_Sword
597 #define Elf_Addr	Elf64_Addr
598 #define Elf_Off		Elf64_Off
599 #define Elf_Nhdr	Elf64_Nhdr
600 #define Elf_Note	Elf64_Note
601 
602 #define ELF_R_SYM	ELF64_R_SYM
603 #define ELF_R_TYPE	ELF64_R_TYPE
604 #define ELF_R_INFO	ELF64_R_INFO
605 #define ELFCLASS	ELFCLASS64
606 
607 #define ELF_ST_BIND	ELF64_ST_BIND
608 #define ELF_ST_TYPE	ELF64_ST_TYPE
609 #define ELF_ST_INFO	ELF64_ST_INFO
610 
611 #define AuxInfo		Aux64Info
612 #endif
613 
614 #endif /* __XEN_ELFSTRUCTS_H__ */
615