~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/xc/lib/xc_elf.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

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