Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4680 right-hear 1
/*
2
elf_repl.h - public header file for systems that lack it.
3
Copyright (C) 1995 - 1998 Michael Riepe 
4
 
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
9
 
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
Library General Public License for more details.
14
 
15
You should have received a copy of the GNU Library General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
*/
19
 
20
/* @(#) $Id: elf_repl.h,v 1.4 1998/06/04 17:14:01 michael Exp $ */
21
 
22
/*
23
 * NEVER INCLUDE THIS FILE DIRECTLY - USE  INSTEAD!
24
 */
25
 
26
#ifndef _ELF_REPL_H
27
#define _ELF_REPL_H
28
 
29
#ifdef	__cplusplus
30
extern "C" {
31
#endif /* __cplusplus */
32
 
33
/*
34
 * Scalar data types
35
 */
36
typedef __libelf_u32_t		Elf32_Addr;
37
typedef __libelf_u16_t		Elf32_Half;
38
typedef __libelf_u32_t		Elf32_Off;
39
typedef __libelf_i32_t		Elf32_Sword;
40
typedef __libelf_u32_t		Elf32_Word;
41
 
42
#define ELF32_FSZ_ADDR		4
43
#define ELF32_FSZ_HALF		2
44
#define ELF32_FSZ_OFF		4
45
#define ELF32_FSZ_SWORD		4
46
#define ELF32_FSZ_WORD		4
47
 
48
#if __LIBELF64
49
typedef __libelf_u64_t		Elf64_Addr;
50
typedef __libelf_u16_t		Elf64_Half;
51
typedef __libelf_u64_t		Elf64_Off;
52
typedef __libelf_i32_t		Elf64_Sword;
53
typedef __libelf_i64_t		Elf64_Sxword;
54
typedef __libelf_u32_t		Elf64_Word;
55
typedef __libelf_u64_t		Elf64_Xword;
56
 
57
#define ELF64_FSZ_ADDR		8
58
#define ELF64_FSZ_HALF		2
59
#define ELF64_FSZ_OFF		8
60
#define ELF64_FSZ_SWORD		4
61
#define ELF64_FSZ_SXWORD	8
62
#define ELF64_FSZ_WORD		4
63
#define ELF64_FSZ_XWORD		8
64
#endif /* __LIBELF64 */
65
 
66
/*
67
 * ELF header
68
 */
69
#define EI_NIDENT	16
70
 
71
typedef struct {
72
    unsigned char	e_ident[EI_NIDENT];
73
    Elf32_Half		e_type;
74
    Elf32_Half		e_machine;
75
    Elf32_Word		e_version;
76
    Elf32_Addr		e_entry;
77
    Elf32_Off		e_phoff;
78
    Elf32_Off		e_shoff;
79
    Elf32_Word		e_flags;
80
    Elf32_Half		e_ehsize;
81
    Elf32_Half		e_phentsize;
82
    Elf32_Half		e_phnum;
83
    Elf32_Half		e_shentsize;
84
    Elf32_Half		e_shnum;
85
    Elf32_Half		e_shstrndx;
86
} Elf32_Ehdr;
87
 
88
#if __LIBELF64
89
typedef struct {
90
    unsigned char	e_ident[EI_NIDENT];
91
    Elf64_Half		e_type;
92
    Elf64_Half		e_machine;
93
    Elf64_Word		e_version;
94
    Elf64_Addr		e_entry;
95
    Elf64_Off		e_phoff;
96
    Elf64_Off		e_shoff;
97
    Elf64_Word		e_flags;
98
    Elf64_Half		e_ehsize;
99
    Elf64_Half		e_phentsize;
100
    Elf64_Half		e_phnum;
101
    Elf64_Half		e_shentsize;
102
    Elf64_Half		e_shnum;
103
    Elf64_Half		e_shstrndx;
104
} Elf64_Ehdr;
105
#endif /* __LIBELF64 */
106
 
107
/*
108
 * e-ident
109
 */
110
#define EI_MAG0		0
111
#define EI_MAG1		1
112
#define EI_MAG2		2
113
#define EI_MAG3		3
114
#define EI_CLASS	4
115
#define EI_DATA		5
116
#define EI_VERSION	6
117
#define EI_PAD		7
118
 
119
#define ELFMAG0		0x7f
120
#define ELFMAG1		'E'
121
#define ELFMAG2		'L'
122
#define ELFMAG3		'F'
123
#define ELFMAG		"\177ELF"
124
#define SELFMAG		4
125
 
126
#define ELFCLASSNONE	0
127
#define ELFCLASS32	1
128
#define ELFCLASS64	2
129
#define ELFCLASSNUM	3
130
 
131
#define ELFDATANONE	0
132
#define ELFDATA2LSB	1
133
#define ELFDATA2MSB	2
134
#define ELFDATANUM	3
135
 
136
/*
137
 * e_type
138
 */
139
#define ET_NONE		0
140
#define ET_REL		1
141
#define ET_EXEC		2
142
#define ET_DYN		3
143
#define ET_CORE		4
144
#define ET_NUM		5
145
#define ET_LOPROC	0xff00
146
#define ET_HIPROC	0xffff
147
 
148
/*
149
 * e_machine
150
 */
151
#define EM_NONE		0
152
#define EM_M32		1		/* AT&T WE 32100 */
153
#define EM_SPARC	2		/* SPARC */
154
#define EM_386		3		/* Intel i386 */
155
#define EM_68K		4		/* Motorola 68000 */
156
#define EM_88K		5		/* Motorola 88000 */
157
#define EM_486		6		/* Intel i486 (do not use this one) */
158
#define EM_860		7		/* Intel i860 */
159
#define EM_MIPS		8		/* MIPS R3000 */
160
#define EM_NUM		9
161
 
162
/*
163
 * e_ident[EI_VERSION], e_version
164
 */
165
#define EV_NONE		0
166
#define EV_CURRENT	1
167
#define EV_NUM		2
168
 
169
/*
170
 * Section header
171
 */
172
typedef struct {
173
    Elf32_Word		sh_name;
174
    Elf32_Word		sh_type;
175
    Elf32_Word		sh_flags;
176
    Elf32_Addr		sh_addr;
177
    Elf32_Off		sh_offset;
178
    Elf32_Word		sh_size;
179
    Elf32_Word		sh_link;
180
    Elf32_Word		sh_info;
181
    Elf32_Word		sh_addralign;
182
    Elf32_Word		sh_entsize;
183
} Elf32_Shdr;
184
 
185
#if __LIBELF64
186
typedef struct {
187
    Elf64_Word		sh_name;
188
    Elf64_Word		sh_type;
189
    Elf64_Xword		sh_flags;
190
    Elf64_Addr		sh_addr;
191
    Elf64_Off		sh_offset;
192
    Elf64_Xword		sh_size;
193
    Elf64_Word		sh_link;
194
    Elf64_Word		sh_info;
195
    Elf64_Xword		sh_addralign;
196
    Elf64_Xword		sh_entsize;
197
} Elf64_Shdr;
198
#endif /* __LIBELF64 */
199
 
200
/*
201
 * Special section indices
202
 */
203
#define SHN_UNDEF	0
204
#define SHN_LORESERVE	0xff00
205
#define SHN_LOPROC	0xff00
206
#define SHN_HIPROC	0xff1f
207
#define SHN_ABS		0xfff1
208
#define SHN_COMMON	0xfff2
209
#define SHN_HIRESERVE	0xffff
210
 
211
/*
212
 * sh_type
213
 */
214
#define SHT_NULL	0
215
#define SHT_PROGBITS	1
216
#define SHT_SYMTAB	2
217
#define SHT_STRTAB	3
218
#define SHT_RELA	4
219
#define SHT_HASH	5
220
#define SHT_DYNAMIC	6
221
#define SHT_NOTE	7
222
#define SHT_NOBITS	8
223
#define SHT_REL		9
224
#define SHT_SHLIB	10
225
#define SHT_DYNSYM	11
226
#define SHT_NUM		12
227
#define SHT_LOPROC	0x70000000
228
#define SHT_HIPROC	0x7fffffff
229
#define SHT_LOUSER	0x80000000
230
#define SHT_HIUSER	0xffffffff
231
 
232
/*
233
 * sh_flags
234
 */
235
#define SHF_WRITE	0x1
236
#define SHF_ALLOC	0x2
237
#define SHF_EXECINSTR	0x4
238
#define SHF_MASKPROC	0xf0000000
239
 
240
/*
241
 * Symbol table
242
 */
243
typedef struct {
244
    Elf32_Word		st_name;
245
    Elf32_Addr		st_value;
246
    Elf32_Word		st_size;
247
    unsigned char	st_info;
248
    unsigned char	st_other;
249
    Elf32_Half		st_shndx;
250
} Elf32_Sym;
251
 
252
#if __LIBELF64
253
typedef struct {
254
    Elf64_Word		st_name;
255
    unsigned char	st_info;
256
    unsigned char	st_other;
257
    Elf64_Half		st_shndx;
258
    Elf64_Addr		st_value;
259
    Elf64_Xword		st_size;
260
} Elf64_Sym;
261
#endif /* __LIBELF64 */
262
 
263
/*
264
 * Special symbol indices
265
 */
266
#define STN_UNDEF	0
267
 
268
/*
269
 * Macros for manipulating st_info
270
 */
271
#define ELF32_ST_BIND(i)	((i)>>4)
272
#define ELF32_ST_TYPE(i)	((i)&0xf)
273
#define ELF32_ST_INFO(b,t)	(((b)<<4)+((t)&0xf))
274
 
275
/*
276
 * Symbol binding
277
 */
278
#define STB_LOCAL	0
279
#define STB_GLOBAL	1
280
#define STB_WEAK	2
281
#define STB_NUM		3
282
#define STB_LOPROC	13
283
#define STB_HIPROC	15
284
 
285
/*
286
 * Symbol types
287
 */
288
#define STT_NOTYPE	0
289
#define STT_OBJECT	1
290
#define STT_FUNC	2
291
#define STT_SECTION	3
292
#define STT_FILE	4
293
#define STT_NUM		5
294
#define STT_LOPROC	13
295
#define STT_HIPROC	15
296
 
297
/*
298
 * Relocation
299
 */
300
typedef struct {
301
    Elf32_Addr		r_offset;
302
    Elf32_Word		r_info;
303
} Elf32_Rel;
304
 
305
typedef struct {
306
    Elf32_Addr		r_offset;
307
    Elf32_Word		r_info;
308
    Elf32_Sword		r_addend;
309
} Elf32_Rela;
310
 
311
#if __LIBELF64
312
typedef struct {
313
    Elf64_Addr		r_offset;
314
    Elf64_Xword		r_info;
315
} Elf64_Rel;
316
 
317
typedef struct {
318
    Elf64_Addr		r_offset;
319
    Elf64_Xword		r_info;
320
    Elf64_Sxword	r_addend;
321
} Elf64_Rela;
322
#endif /* __LIBELF64 */
323
 
324
/*
325
 * Macros for manipulating r_info
326
 */
327
#define ELF32_R_SYM(i)		((i)>>8)
328
#define ELF32_R_TYPE(i)		((unsigned char)(i))
329
#define ELF32_R_INFO(s,t)	(((s)<<8)+(unsigned char)(t))
330
 
331
/*
332
 * Note entry header
333
 */
334
typedef struct {
335
    Elf32_Word		n_namesz;	/* name size */
336
    Elf32_Word		n_descsz;	/* descriptor size */
337
    Elf32_Word		n_type;		/* descriptor type */
338
} Elf32_Nhdr;
339
 
340
#if __LIBELF64 && 0	/* I don't know if this is correct */
341
typedef struct {
342
    Elf64_Word		n_namesz;	/* name size */
343
    Elf64_Word		n_descsz;	/* descriptor size */
344
    Elf64_Word		n_type;		/* descriptor type */
345
} Elf64_Nhdr;
346
#endif /* __LIBELF64 */
347
 
348
/*
349
 * Well-known descriptor types for ET_CORE files
350
 */
351
#define NT_PRSTATUS	1
352
#define NT_PRFPREG	2
353
#define NT_PRPSINFO	3
354
 
355
/*
356
 * Program header
357
 */
358
typedef struct {
359
    Elf32_Word		p_type;
360
    Elf32_Off		p_offset;
361
    Elf32_Addr		p_vaddr;
362
    Elf32_Addr		p_paddr;
363
    Elf32_Word		p_filesz;
364
    Elf32_Word		p_memsz;
365
    Elf32_Word		p_flags;
366
    Elf32_Word		p_align;
367
} Elf32_Phdr;
368
 
369
#if __LIBELF64
370
typedef struct {
371
    Elf64_Word		p_type;
372
    Elf64_Word		p_flags;
373
    Elf64_Off		p_offset;
374
    Elf64_Addr		p_vaddr;
375
    Elf64_Addr		p_paddr;
376
    Elf64_Xword		p_filesz;
377
    Elf64_Xword		p_memsz;
378
    Elf64_Xword		p_align;
379
} Elf64_Phdr;
380
#endif /* __LIBELF64 */
381
 
382
/*
383
 * p_type
384
 */
385
#define PT_NULL		0
386
#define PT_LOAD		1
387
#define PT_DYNAMIC	2
388
#define PT_INTERP	3
389
#define PT_NOTE		4
390
#define PT_SHLIB	5
391
#define PT_PHDR		6
392
#define PT_NUM		7
393
#define PT_LOPROC	0x70000000
394
#define PT_HIPROC	0x7fffffff
395
 
396
/*
397
 * p_flags
398
 */
399
#define PF_R		0x4
400
#define PF_W		0x2
401
#define PF_X		0x1
402
#define PF_MASKPROC	0xf0000000
403
 
404
/*
405
 * Dynamic structure
406
 */
407
typedef struct {
408
    Elf32_Sword		d_tag;
409
    union {
410
	Elf32_Word	d_val;
411
	Elf32_Addr	d_ptr;
412
    } d_un;
413
} Elf32_Dyn;
414
 
415
#if __LIBELF64
416
typedef struct {
417
    Elf64_Sxword	d_tag;
418
    union {
419
	Elf64_Xword	d_val;
420
	Elf64_Addr	d_ptr;
421
    } d_un;
422
} Elf64_Dyn;
423
#endif /* __LIBELF64 */
424
 
425
/*
426
 * Dynamic array tags
427
 */
428
#define DT_NULL		0
429
#define DT_NEEDED	1
430
#define DT_PLTRELSZ	2
431
#define DT_PLTGOT	3
432
#define DT_HASH		4
433
#define DT_STRTAB	5
434
#define DT_SYMTAB	6
435
#define DT_RELA		7
436
#define DT_RELASZ	8
437
#define DT_RELAENT	9
438
#define DT_STRSZ	10
439
#define DT_SYMENT	11
440
#define DT_INIT		12
441
#define DT_FINI		13
442
#define DT_SONAME	14
443
#define DT_RPATH	15
444
#define DT_SYMBOLIC	16
445
#define DT_REL		17
446
#define DT_RELSZ	18
447
#define DT_RELENT	19
448
#define DT_PLTREL	20
449
#define DT_DEBUG	21
450
#define DT_TEXTREL	22
451
#define DT_JMPREL	23
452
#define DT_NUM		24
453
#define DT_LOPROC	0x70000000
454
#define DT_HIPROC	0x7fffffff
455
 
456
#ifdef	__cplusplus
457
}
458
#endif /* __cplusplus */
459
 
460
#endif /* _ELF_REPL_H */