1 /*
2  * sys/elfcommon.h
3  */
4 
5 #ifndef _SYS_ELFCOMMON_H
6 #define _SYS_ELFCOMMON_H
7 
8 #include <stdint.h>
9 
10 /* Segment types */
11 #define PT_NULL		0
12 #define PT_LOAD		1
13 #define PT_DYNAMIC	2
14 #define PT_INTERP	3
15 #define PT_NOTE		4
16 #define PT_SHLIB	5
17 #define PT_PHDR		6
18 #define PT_LOOS		0x60000000
19 #define PT_HIOS		0x6fffffff
20 #define PT_LOPROC	0x70000000
21 #define PT_HIPROC	0x7fffffff
22 #define PT_GNU_EH_FRAME	0x6474e550	/* Extension, eh? */
23 
24 /* ELF file types */
25 #define ET_NONE		0
26 #define ET_REL		1
27 #define ET_EXEC		2
28 #define ET_DYN		3
29 #define ET_CORE		4
30 #define ET_LOPROC	0xff00
31 #define ET_HIPROC	0xffff
32 
33 /* ELF machine types */
34 #define EM_NONE		0
35 #define EM_M32		1
36 #define EM_SPARC	2
37 #define EM_386		3
38 #define EM_68K		4
39 #define EM_88K		5
40 #define EM_486		6	/* Not used in Linux at least */
41 #define EM_860		7
42 #define EM_MIPS         8	/* R3k, bigendian(?) */
43 #define EM_MIPS_RS4_BE	10	/* R4k BE */
44 #define EM_PARISC	15
45 #define EM_SPARC32PLUS	18
46 #define EM_PPC		20
47 #define EM_PPC64	21
48 #define EM_S390         22
49 #define EM_SH		42
50 #define EM_SPARCV9	43	/* v9 = SPARC64 */
51 #define EM_H8_300H      47
52 #define EM_H8S          48
53 #define EM_IA_64        50	/* Itanic */
54 #define EM_X86_64       62
55 #define EM_CRIS         76
56 #define EM_V850         87
57 #define EM_ALPHA        0x9026	/* Interrim Alpha that stuck around */
58 #define EM_CYGNUS_V850  0x9080	/* Old v850 ID used by Cygnus */
59 #define EM_S390_OLD     0xA390	/* Obsolete interrim value for S/390 */
60 
61 /* Dynamic type values */
62 #define DT_NULL		0		/* Marks end of dynamic section */
63 #define DT_NEEDED	1		/* Name of needed library */
64 #define DT_PLTRELSZ	2		/* Size in bytes of PLT relocs */
65 #define DT_PLTGOT	3		/* Processor defined value */
66 #define DT_HASH		4		/* Address of symbol hash table */
67 #define DT_STRTAB	5		/* Address of string table */
68 #define DT_SYMTAB	6		/* Address of symbol table */
69 #define DT_RELA		7		/* Address of Rela relocs */
70 #define DT_RELASZ	8		/* Total size of Rela relocs */
71 #define DT_RELAENT	9		/* Size of one Rela reloc */
72 #define DT_STRSZ	10		/* Size of string table */
73 #define DT_SYMENT	11		/* Size of one symbol table entry */
74 #define DT_INIT		12		/* Address of init function */
75 #define DT_FINI		13		/* Address of termination function */
76 #define DT_SONAME	14		/* Name of shared object */
77 #define DT_RPATH	15		/* Library search path (deprecated) */
78 #define DT_SYMBOLIC	16		/* Start symbol search here */
79 #define DT_REL		17		/* Address of Rel relocs */
80 #define DT_RELSZ	18		/* Total size of Rel relocs */
81 #define DT_RELENT	19		/* Size of one Rel reloc */
82 #define DT_PLTREL	20		/* Type of reloc in PLT */
83 #define DT_DEBUG	21		/* For debugging; unspecified */
84 #define DT_TEXTREL	22		/* Reloc might modify .text */
85 #define DT_JMPREL	23		/* Address of PLT relocs */
86 #define	DT_BIND_NOW	24		/* Process relocations of object */
87 #define	DT_INIT_ARRAY	25		/* Array with addresses of init fct */
88 #define	DT_FINI_ARRAY	26		/* Array with addresses of fini fct */
89 #define	DT_INIT_ARRAYSZ	27		/* Size in bytes of DT_INIT_ARRAY */
90 #define	DT_FINI_ARRAYSZ	28		/* Size in bytes of DT_FINI_ARRAY */
91 #define DT_RUNPATH	29		/* Library search path */
92 #define DT_FLAGS	30		/* Flags for the object being loaded */
93 #define DT_ENCODING	32		/* Start of encoded range */
94 #define DT_PREINIT_ARRAY 32		/* Array with addresses of preinit fct*/
95 #define DT_PREINIT_ARRAYSZ 33		/* size in bytes of DT_PREINIT_ARRAY */
96 #define	DT_NUM		34		/* Number used */
97 #define DT_LOOS		0x6000000d	/* Start of OS-specific */
98 #define DT_HIOS		0x6ffff000	/* End of OS-specific */
99 #define DT_LOPROC	0x70000000	/* Start of processor-specific */
100 #define DT_HIPROC	0x7fffffff	/* End of processor-specific */
101 
102 #define DT_VALRNGLO	0x6ffffd00
103 #define DT_GNU_PRELINKED 0x6ffffdf5	/* Prelinking timestamp */
104 #define DT_GNU_CONFLICTSZ 0x6ffffdf6	/* Size of conflict section */
105 #define DT_GNU_LIBLISTSZ 0x6ffffdf7	/* Size of library list */
106 #define DT_CHECKSUM	0x6ffffdf8
107 #define DT_PLTPADSZ	0x6ffffdf9
108 #define DT_MOVEENT	0x6ffffdfa
109 #define DT_MOVESZ	0x6ffffdfb
110 #define DT_FEATURE_1	0x6ffffdfc	/* Feature selection (DTF_*).  */
111 #define DT_POSFLAG_1	0x6ffffdfd	/* Flags for DT_* entries, effecting
112 					   the following DT_* entry.  */
113 #define DT_SYMINSZ	0x6ffffdfe	/* Size of syminfo table (in bytes) */
114 #define DT_SYMINENT	0x6ffffdff	/* Entry size of syminfo */
115 #define DT_VALRNGHI	0x6ffffdff
116 #define DT_VALTAGIDX(tag)	(DT_VALRNGHI - (tag))	/* Reverse order! */
117 #define DT_VALNUM 12
118 
119 /* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the
120    Dyn.d_un.d_ptr field of the Elf*_Dyn structure.
121 
122    If any adjustment is made to the ELF object after it has been
123    built these entries will need to be adjusted.  */
124 #define DT_ADDRRNGLO	0x6ffffe00
125 #define DT_GNU_HASH	0x6ffffef5	/* GNU-style hash table.  */
126 #define DT_TLSDESC_PLT	0x6ffffef6
127 #define DT_TLSDESC_GOT	0x6ffffef7
128 #define DT_GNU_CONFLICT	0x6ffffef8	/* Start of conflict section */
129 #define DT_GNU_LIBLIST	0x6ffffef9	/* Library list */
130 #define DT_CONFIG	0x6ffffefa	/* Configuration information.  */
131 #define DT_DEPAUDIT	0x6ffffefb	/* Dependency auditing.  */
132 #define DT_AUDIT	0x6ffffefc	/* Object auditing.  */
133 #define	DT_PLTPAD	0x6ffffefd	/* PLT padding.  */
134 #define	DT_MOVETAB	0x6ffffefe	/* Move table.  */
135 #define DT_SYMINFO	0x6ffffeff	/* Syminfo table.  */
136 #define DT_ADDRRNGHI	0x6ffffeff
137 #define DT_ADDRTAGIDX(tag)	(DT_ADDRRNGHI - (tag))	/* Reverse order! */
138 #define DT_ADDRNUM 11
139 
140 /* The versioning entry types.  The next are defined as part of the
141    GNU extension.  */
142 #define DT_VERSYM	0x6ffffff0
143 
144 #define DT_RELACOUNT	0x6ffffff9
145 #define DT_RELCOUNT	0x6ffffffa
146 
147 /* These were chosen by Sun.  */
148 #define DT_FLAGS_1	0x6ffffffb	/* State flags, see DF_1_* below.  */
149 #define	DT_VERDEF	0x6ffffffc	/* Address of version definition
150 					   table */
151 #define	DT_VERDEFNUM	0x6ffffffd	/* Number of version definitions */
152 #define	DT_VERNEED	0x6ffffffe	/* Address of table with needed
153 					   versions */
154 #define	DT_VERNEEDNUM	0x6fffffff	/* Number of needed versions */
155 #define DT_VERSIONTAGIDX(tag)	(DT_VERNEEDNUM - (tag))	/* Reverse order! */
156 #define DT_VERSIONTAGNUM 16
157 
158 /* Sun added these machine-independent extensions in the "processor-specific"
159    range.  Be compatible.  */
160 #define DT_AUXILIARY    0x7ffffffd      /* Shared object to load before self */
161 #define DT_FILTER       0x7fffffff      /* Shared object to get values from */
162 #define DT_EXTRATAGIDX(tag)	((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
163 #define DT_EXTRANUM	3
164 
165 /* Auxilliary table entries */
166 #define AT_NULL		0	/* end of vector */
167 #define AT_IGNORE	1	/* entry should be ignored */
168 #define AT_EXECFD	2	/* file descriptor of program */
169 #define AT_PHDR		3	/* program headers for program */
170 #define AT_PHENT	4	/* size of program header entry */
171 #define AT_PHNUM	5	/* number of program headers */
172 #define AT_PAGESZ	6	/* system page size */
173 #define AT_BASE		7	/* base address of interpreter */
174 #define AT_FLAGS	8	/* flags */
175 #define AT_ENTRY	9	/* entry point of program */
176 #define AT_NOTELF	10	/* program is not ELF */
177 #define AT_UID		11	/* real uid */
178 #define AT_EUID		12	/* effective uid */
179 #define AT_GID		13	/* real gid */
180 #define AT_EGID		14	/* effective gid */
181 #define AT_PLATFORM	15	/* string identifying CPU for optimizations */
182 #define AT_HWCAP	16	/* arch dependent hints at CPU capabilities */
183 #define AT_CLKTCK	17	/* frequency at which times() increments */
184 /* 18..22 = ? */
185 #define AT_SECURE	23	/* secure mode boolean */
186 
187 /* Program header permission flags */
188 #define PF_X            0x1
189 #define PF_W            0x2
190 #define PF_R            0x4
191 
192 /* Section header types */
193 #define SHT_NULL        0
194 #define SHT_PROGBITS    1
195 #define SHT_SYMTAB      2
196 #define SHT_STRTAB      3
197 #define SHT_RELA        4
198 #define SHT_HASH        5
199 #define SHT_DYNAMIC     6
200 #define SHT_NOTE        7
201 #define SHT_NOBITS      8
202 #define SHT_REL         9
203 #define SHT_SHLIB       10
204 #define SHT_DYNSYM      11
205 #define SHT_NUM         12
206 #define SHT_LOPROC      0x70000000
207 #define SHT_HIPROC      0x7fffffff
208 #define SHT_LOUSER      0x80000000
209 #define SHT_HIUSER      0xffffffff
210 
211 /* Section header flags */
212 #define SHF_WRITE       0x1
213 #define SHF_ALLOC       0x2
214 #define SHF_EXECINSTR   0x4
215 #define SHF_MASKPROC    0xf0000000
216 
217 /* Special section numbers */
218 #define SHN_UNDEF       0
219 #define SHN_LORESERVE   0xff00
220 #define SHN_LOPROC      0xff00
221 #define SHN_HIPROC      0xff1f
222 #define SHN_ABS         0xfff1
223 #define SHN_COMMON      0xfff2
224 #define SHN_HIRESERVE   0xffff
225 
226 /* Symbol table definitions */
227 
228 /* How to extract and insert information held in the st_info field.  */
229 
230 #define ELF32_ST_BIND(val)		(((unsigned char) (val)) >> 4)
231 #define ELF32_ST_TYPE(val)		((val) & 0xf)
232 #define ELF32_ST_INFO(bind, type)	(((bind) << 4) + ((type) & 0xf))
233 
234 /* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field.  */
235 #define ELF64_ST_BIND(val)		ELF32_ST_BIND (val)
236 #define ELF64_ST_TYPE(val)		ELF32_ST_TYPE (val)
237 #define ELF64_ST_INFO(bind, type)	ELF32_ST_INFO ((bind), (type))
238 
239 /* Legal values for ST_BIND subfield of st_info (symbol binding).  */
240 
241 #define STB_LOCAL	0		/* Local symbol */
242 #define STB_GLOBAL	1		/* Global symbol */
243 #define STB_WEAK	2		/* Weak symbol */
244 #define	STB_NUM		3		/* Number of defined types.  */
245 #define STB_LOOS	10		/* Start of OS-specific */
246 #define STB_HIOS	12		/* End of OS-specific */
247 #define STB_LOPROC	13		/* Start of processor-specific */
248 #define STB_HIPROC	15		/* End of processor-specific */
249 
250 /* Legal values for ST_TYPE subfield of st_info (symbol type).  */
251 
252 #define STT_NOTYPE	0		/* Symbol type is unspecified */
253 #define STT_OBJECT	1		/* Symbol is a data object */
254 #define STT_FUNC	2		/* Symbol is a code object */
255 #define STT_SECTION	3		/* Symbol associated with a section */
256 #define STT_FILE	4		/* Symbol's name is file name */
257 #define STT_COMMON	5		/* Symbol is a common data object */
258 #define STT_TLS		6		/* Symbol is thread-local data object*/
259 #define	STT_NUM		7		/* Number of defined types.  */
260 #define STT_LOOS	10		/* Start of OS-specific */
261 #define STT_HIOS	12		/* End of OS-specific */
262 #define STT_LOPROC	13		/* Start of processor-specific */
263 #define STT_HIPROC	15		/* End of processor-specific */
264 
265 
266 /* Symbol table indices are found in the hash buckets and chain table
267    of a symbol hash table section.  This special index value indicates
268    the end of a chain, meaning no further symbols are found in that bucket.  */
269 
270 #define STN_UNDEF	0		/* End of a chain.  */
271 
272 /* Lenght of magic at the start of a file */
273 #define EI_NIDENT	16
274 
275 /* Magic number constants... */
276 #define EI_MAG0         0	/* e_ident[] indexes */
277 #define EI_MAG1         1
278 #define EI_MAG2         2
279 #define EI_MAG3         3
280 #define EI_CLASS        4
281 #define EI_DATA         5
282 #define EI_VERSION      6
283 #define EI_OSABI        7
284 #define EI_PAD          8
285 
286 #define ELFMAG0         0x7f	/* EI_MAG */
287 #define ELFMAG1         'E'
288 #define ELFMAG2         'L'
289 #define ELFMAG3         'F'
290 #define ELFMAG          "\177ELF"
291 #define SELFMAG         4
292 
293 #define ELFCLASSNONE    0	/* EI_CLASS */
294 #define ELFCLASS32      1
295 #define ELFCLASS64      2
296 #define ELFCLASSNUM     3
297 
298 #define ELFDATANONE     0	/* e_ident[EI_DATA] */
299 #define ELFDATA2LSB     1
300 #define ELFDATA2MSB     2
301 
302 #define EV_NONE         0	/* e_version, EI_VERSION */
303 #define EV_CURRENT      1
304 #define EV_NUM          2
305 
306 #define ELFOSABI_NONE   0
307 #define ELFOSABI_LINUX  3
308 
309 /* Intel 80386 specific definitions.  */
310 
311 /* i386 relocs.  */
312 
313 #define R_386_NONE	   0		/* No reloc */
314 #define R_386_32	   1		/* Direct 32 bit  */
315 #define R_386_PC32	   2		/* PC relative 32 bit */
316 #define R_386_GOT32	   3		/* 32 bit GOT entry */
317 #define R_386_PLT32	   4		/* 32 bit PLT address */
318 #define R_386_COPY	   5		/* Copy symbol at runtime */
319 #define R_386_GLOB_DAT	   6		/* Create GOT entry */
320 #define R_386_JMP_SLOT	   7		/* Create PLT entry */
321 #define R_386_RELATIVE	   8		/* Adjust by program base */
322 #define R_386_GOTOFF	   9		/* 32 bit offset to GOT */
323 #define R_386_GOTPC	   10		/* 32 bit PC relative offset to GOT */
324 #define R_386_32PLT	   11
325 #define R_386_TLS_TPOFF	   14		/* Offset in static TLS block */
326 #define R_386_TLS_IE	   15		/* Address of GOT entry for static TLS
327 					   block offset */
328 #define R_386_TLS_GOTIE	   16		/* GOT entry for static TLS block
329 					   offset */
330 #define R_386_TLS_LE	   17		/* Offset relative to static TLS
331 					   block */
332 #define R_386_TLS_GD	   18		/* Direct 32 bit for GNU version of
333 					   general dynamic thread local data */
334 #define R_386_TLS_LDM	   19		/* Direct 32 bit for GNU version of
335 					   local dynamic thread local data
336 					   in LE code */
337 #define R_386_16	   20
338 #define R_386_PC16	   21
339 #define R_386_8		   22
340 #define R_386_PC8	   23
341 #define R_386_TLS_GD_32	   24		/* Direct 32 bit for general dynamic
342 					   thread local data */
343 #define R_386_TLS_GD_PUSH  25		/* Tag for pushl in GD TLS code */
344 #define R_386_TLS_GD_CALL  26		/* Relocation for call to
345 					   __tls_get_addr() */
346 #define R_386_TLS_GD_POP   27		/* Tag for popl in GD TLS code */
347 #define R_386_TLS_LDM_32   28		/* Direct 32 bit for local dynamic
348 					   thread local data in LE code */
349 #define R_386_TLS_LDM_PUSH 29		/* Tag for pushl in LDM TLS code */
350 #define R_386_TLS_LDM_CALL 30		/* Relocation for call to
351 					   __tls_get_addr() in LDM code */
352 #define R_386_TLS_LDM_POP  31		/* Tag for popl in LDM TLS code */
353 #define R_386_TLS_LDO_32   32		/* Offset relative to TLS block */
354 #define R_386_TLS_IE_32	   33		/* GOT entry for negated static TLS
355 					   block offset */
356 #define R_386_TLS_LE_32	   34		/* Negated offset relative to static
357 					   TLS block */
358 #define R_386_TLS_DTPMOD32 35		/* ID of module containing symbol */
359 #define R_386_TLS_DTPOFF32 36		/* Offset in TLS block */
360 #define R_386_TLS_TPOFF32  37		/* Negated offset in static TLS block */
361 /* Keep this the last entry.  */
362 #define R_386_NUM	   38
363 
364 /* AMD x86-64 relocations.  */
365 #define R_X86_64_NONE		0	/* No reloc */
366 #define R_X86_64_64		1	/* Direct 64 bit  */
367 #define R_X86_64_PC32		2	/* PC relative 32 bit signed */
368 #define R_X86_64_GOT32		3	/* 32 bit GOT entry */
369 #define R_X86_64_PLT32		4	/* 32 bit PLT address */
370 #define R_X86_64_COPY		5	/* Copy symbol at runtime */
371 #define R_X86_64_GLOB_DAT	6	/* Create GOT entry */
372 #define R_X86_64_JUMP_SLOT	7	/* Create PLT entry */
373 #define R_X86_64_RELATIVE	8	/* Adjust by program base */
374 #define R_X86_64_GOTPCREL	9	/* 32 bit signed PC relative
375 					   offset to GOT */
376 #define R_X86_64_32		10	/* Direct 32 bit zero extended */
377 #define R_X86_64_32S		11	/* Direct 32 bit sign extended */
378 #define R_X86_64_16		12	/* Direct 16 bit zero extended */
379 #define R_X86_64_PC16		13	/* 16 bit sign extended pc relative */
380 #define R_X86_64_8		14	/* Direct 8 bit sign extended  */
381 #define R_X86_64_PC8		15	/* 8 bit sign extended pc relative */
382 #define R_X86_64_DTPMOD64	16	/* ID of module containing symbol */
383 #define R_X86_64_DTPOFF64	17	/* Offset in module's TLS block */
384 #define R_X86_64_TPOFF64	18	/* Offset in initial TLS block */
385 #define R_X86_64_TLSGD		19	/* 32 bit signed PC relative offset
386 					   to two GOT entries for GD symbol */
387 #define R_X86_64_TLSLD		20	/* 32 bit signed PC relative offset
388 					   to two GOT entries for LD symbol */
389 #define R_X86_64_DTPOFF32	21	/* Offset in TLS block */
390 #define R_X86_64_GOTTPOFF	22	/* 32 bit signed PC relative offset
391 					   to GOT entry for IE symbol */
392 #define R_X86_64_TPOFF32	23	/* Offset in initial TLS block */
393 #define R_X86_64_PC64		24	/* PC relative 64 bit */
394 #define R_X86_64_GOTOFF64	25	/* 64 bit offset to GOT */
395 #define R_X86_64_GOTPC32	26	/* 32 bit signed pc relative
396 					   offset to GOT */
397 #define R_X86_64_GOT64		27	/* 64-bit GOT entry offset */
398 #define R_X86_64_GOTPCREL64	28	/* 64-bit PC relative offset
399 					   to GOT entry */
400 #define R_X86_64_GOTPC64	29	/* 64-bit PC relative offset to GOT */
401 #define R_X86_64_GOTPLT64	30 	/* like GOT64, says PLT entry needed */
402 #define R_X86_64_PLTOFF64	31	/* 64-bit GOT relative offset
403 					   to PLT entry */
404 #define R_X86_64_SIZE32		32	/* Size of symbol plus 32-bit addend */
405 #define R_X86_64_SIZE64		33	/* Size of symbol plus 64-bit addend */
406 #define R_X86_64_GOTPC32_TLSDESC 34	/* GOT offset for TLS descriptor.  */
407 #define R_X86_64_TLSDESC_CALL   35	/* Marker for call through TLS
408 					   descriptor.  */
409 #define R_X86_64_TLSDESC        36	/* TLS descriptor.  */
410 #define R_X86_64_IRELATIVE	37	/* Adjust indirectly by program base */
411 
412 #define R_X86_64_NUM		38
413 
414 #endif				/* _SYS_ELFCOMMON_H */
415