OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [loader/] [v2_0/] [include/] [elf.h] - Blame information for rev 307

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#ifndef CYGONCE_LOADER_ELF_H
2
#define CYGONCE_LOADER_ELF_H
3
 
4
//==========================================================================
5
//
6
//      elf.h
7
//
8
//      ELF file format definitions
9
//
10
//==========================================================================
11
//####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License along
26
// with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28
//
29
// As a special exception, if other files instantiate templates or use macros
30
// or inline functions from this file, or you compile this file and link it
31
// with other works to produce a work based on this file, this file does not
32
// by itself cause the resulting work to be covered by the GNU General Public
33
// License. However the source code for this file must still be made available
34
// in accordance with section (3) of the GNU General Public License.
35
//
36
// This exception does not invalidate any other reasons why a work based on
37
// this file might be covered by the GNU General Public License.
38
//
39
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40
// at http://sources.redhat.com/ecos/ecos-license/
41
// -------------------------------------------
42
//####ECOSGPLCOPYRIGHTEND####
43
//==========================================================================
44
//#####DESCRIPTIONBEGIN####
45
//
46
// Author(s):           nickg
47
// Contributors:        nickg
48
// Date:                2000-11-15
49
// Purpose:             Define ELF file format
50
// Description:         The types defined here describe the ELF file format.
51
//              
52
// Usage:       #include <cyg/loader/elf.h>
53
//
54
//####DESCRIPTIONEND####
55
//
56
//==========================================================================
57
//
58
// Quite a lot of this file was taken from the BSD exec_elf.h header file.
59
// Hence we should show you this...
60
//
61
/*      $OpenBSD: exec_elf.h,v 1.20 1999/09/19 16:16:49 kstailey Exp $  */
62
/*
63
 * Copyright (c) 1995, 1996 Erik Theisen.  All rights reserved.
64
 *
65
 * Redistribution and use in source and binary forms, with or without
66
 * modification, are permitted provided that the following conditions
67
 * are met:
68
 * 1. Redistributions of source code must retain the above copyright
69
 *    notice, this list of conditions and the following disclaimer.
70
 * 2. Redistributions in binary form must reproduce the above copyright
71
 *    notice, this list of conditions and the following disclaimer in the
72
 *    documentation and/or other materials provided with the distribution.
73
 * 3. The name of the author may not be used to endorse or promote products
74
 *    derived from this software without specific prior written permission
75
 *
76
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
77
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
78
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
79
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
80
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
81
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
83
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
85
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86
 */
87
//==========================================================================
88
 
89
#include <cyg/infra/cyg_type.h>
90
 
91
// -------------------------------------------------------------------------
92
// Basic types:
93
 
94
typedef cyg_uint32 Elf32_Addr;
95
typedef cyg_uint32 Elf32_Off;
96
typedef cyg_uint16 Elf32_Half;
97
typedef cyg_uint32 Elf32_Word;
98
typedef cyg_int32  Elf32_Sword;
99
 
100
typedef cyg_uint64 Elf64_Addr;
101
typedef cyg_uint64 Elf64_Off;
102
typedef cyg_uint16 Elf64_Half;
103
typedef cyg_uint32 Elf64_Word;
104
typedef cyg_int32  Elf64_Sword;
105
typedef cyg_uint64 Elf64_Xword;
106
typedef cyg_int64  Elf64_Sxword;
107
 
108
// -------------------------------------------------------------------------
109
// ELF header
110
 
111
#define EI_NIDENT 16
112
 
113
typedef struct {
114
    unsigned char   e_ident[EI_NIDENT];
115
    Elf32_Half      e_type;
116
    Elf32_Half      e_machine;
117
    Elf32_Word      e_version;
118
    Elf32_Addr      e_entry;
119
    Elf32_Off       e_phoff;
120
    Elf32_Off       e_shoff;
121
    Elf32_Word      e_flags;
122
    Elf32_Half      e_ehsize;
123
    Elf32_Half      e_phentsize;
124
    Elf32_Half      e_phnum;
125
    Elf32_Half      e_shentsize;
126
    Elf32_Half      e_shnum;
127
    Elf32_Half      e_shtrndx;
128
} Elf32_Ehdr;
129
 
130
typedef struct {
131
    unsigned char   e_ident[EI_NIDENT];
132
    Elf64_Half      e_type;
133
    Elf64_Half      e_machine;
134
    Elf64_Word      e_version;
135
    Elf64_Addr      e_entry;
136
    Elf64_Off       e_phoff;
137
    Elf64_Off       e_shoff;
138
    Elf64_Word      e_flags;
139
    Elf64_Half      e_ehsize;
140
    Elf64_Half      e_phentsize;
141
    Elf64_Half      e_phnum;
142
    Elf64_Half      e_shentsize;
143
    Elf64_Half      e_shnum;
144
    Elf64_Half      e_shtrndx;
145
} Elf64_Ehdr;
146
 
147
// -------------------------------------------------------------------------
148
/* e_ident[] identification indexes */
149
 
150
#define EI_MAG0         0               /* file ID */
151
#define EI_MAG1         1               /* file ID */
152
#define EI_MAG2         2               /* file ID */
153
#define EI_MAG3         3               /* file ID */
154
#define EI_CLASS        4               /* file class */
155
#define EI_DATA         5               /* data encoding */
156
#define EI_VERSION      6               /* ELF header version */
157
#define EI_OSABI        7               /* Operating system/ABI identification */
158
#define EI_ABIVERSION   8               /* ABI version */
159
#define EI_PAD          9               /* start of pad bytes */
160
 
161
// -------------------------------------------------------------------------
162
/* e_ident[] magic number */
163
 
164
#define ELFMAG0         0x7f            /* e_ident[EI_MAG0] */
165
#define ELFMAG1         'E'             /* e_ident[EI_MAG1] */
166
#define ELFMAG2         'L'             /* e_ident[EI_MAG2] */
167
#define ELFMAG3         'F'             /* e_ident[EI_MAG3] */
168
#define ELFMAG          "\177ELF"       /* magic */
169
#define SELFMAG         4               /* size of magic */
170
 
171
// -------------------------------------------------------------------------
172
/* e_ident[] file class */
173
 
174
#define ELFCLASSNONE    0               /* invalid */
175
#define ELFCLASS32      1               /* 32-bit objs */
176
#define ELFCLASS64      2               /* 64-bit objs */
177
#define ELFCLASSNUM     3               /* number of classes */
178
 
179
// -------------------------------------------------------------------------
180
/* e_ident[] data encoding */
181
 
182
#define ELFDATANONE     0               /* invalid */
183
#define ELFDATA2LSB     1               /* Little-Endian */
184
#define ELFDATA2MSB     2               /* Big-Endian */
185
#define ELFDATANUM      3               /* number of data encode defines */
186
 
187
// -------------------------------------------------------------------------
188
/* e_ident */
189
 
190
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
191
                      (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
192
                      (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
193
                      (ehdr).e_ident[EI_MAG3] == ELFMAG3)
194
 
195
// -------------------------------------------------------------------------
196
/* e_type */
197
 
198
#define ET_NONE         0               /* No file type */
199
#define ET_REL          1               /* relocatable file */
200
#define ET_EXEC         2               /* executable file */
201
#define ET_DYN          3               /* shared object file */
202
#define ET_CORE         4               /* core file */
203
#define ET_NUM          5               /* number of types */
204
#define ET_LOOS         0xfe00          /* Operating system-specific */
205
#define ET_HIOS         0xfeff          /* Operating system-specific */
206
#define ET_LOPROC       0xff00          /* reserved range for processor */
207
#define ET_HIPROC       0xffff          /*  specific e_type */
208
 
209
// -------------------------------------------------------------------------
210
/* e_machine */
211
// The following values taken from 22 June 2000 SysV ABI spec, updated with
212
// extra values from binutils elf/common.h.
213
 
214
#define EM_NONE                 0       // No machine
215
#define EM_M32                  1       // AT&T WE 32100
216
#define EM_SPARC                2       // SPARC
217
#define EM_386                  3       // Intel 80386
218
#define EM_68K                  4       // Motorola 68000
219
#define EM_88K                  5       // Motorola 88000
220
#define EM_860                  7       // Intel 80860
221
#define EM_MIPS                 8       // MIPS I Architecture
222
#define EM_S370                 9       // IBM System/370 Processor
223
#define EM_MIPS_RS3_LE          10      // MIPS RS3000 Little-endian
224
#define EM_PARISC               15      // Hewlett-Packard PA-RISC
225
#define EM_VPP500               17      // Fujitsu VPP500
226
#define EM_SPARC32PLUS          18      // Enhanced instruction set SPARC
227
#define EM_960                  19      // Intel 80960
228
#define EM_PPC                  20      // PowerPC
229
#define EM_PPC64                21      // 64-bit PowerPC
230
#define EM_V800                 36      // NEC V800
231
#define EM_FR20                 37      // Fujitsu FR20
232
#define EM_RH32                 38      // TRW RH-32
233
#define EM_RCE                  39      // Motorola RCE
234
#define EM_ARM                  40      // Advanced RISC Machines ARM
235
#define EM_ALPHA                41      // Digital Alpha
236
#define EM_SH                   42      // Hitachi SH
237
#define EM_SPARCV9              43      // SPARC Version 9
238
#define EM_TRICORE              44      // Siemens Tricore embedded processor
239
#define EM_ARC                  45      // Argonaut RISC Core, Argonaut Technologies Inc.
240
#define EM_H8_300               46      // Hitachi H8/300
241
#define EM_H8_300H              47      // Hitachi H8/300H
242
#define EM_H8S                  48      // Hitachi H8S
243
#define EM_H8_500               49      // Hitachi H8/500
244
#define EM_IA_64                50      // Intel IA-64 processor architecture
245
#define EM_MIPS_X               51      // Stanford MIPS-X
246
#define EM_COLDFIRE             52      // Motorola ColdFire
247
#define EM_68HC12               53      // Motorola M68HC12
248
#define EM_MMA                  54      // Fujitsu MMA Multimedia Accelerator
249
#define EM_PCP                  55      // Siemens PCP
250
#define EM_NCPU                 56      // Sony nCPU embedded RISC processor
251
#define EM_NDR1                 57      // Denso NDR1 microprocessor
252
#define EM_STARCORE             58      // Motorola Star*Core processor
253
#define EM_ME16                 59      // Toyota ME16 processor
254
#define EM_ST100                60      // STMicroelectronics ST100 processor
255
#define EM_TINYJ                61      // Advanced Logic Corp. TinyJ embedded processor family
256
#define EM_FX66                 66      // Siemens FX66 microcontroller
257
#define EM_ST9PLUS              67      // STMicroelectronics ST9+ 8/16 bit microcontroller
258
#define EM_ST7                  68      // STMicroelectronics ST7 8-bit microcontroller
259
#define EM_68HC16               69      // Motorola MC68HC16 Microcontroller
260
#define EM_68HC11               70      // Motorola MC68HC11 Microcontroller
261
#define EM_68HC08               71      // Motorola MC68HC08 Microcontroller
262
#define EM_68HC05               72      // Motorola MC68HC05 Microcontroller
263
#define EM_SVX                  73      // Silicon Graphics SVx
264
#define EM_ST19                 74      // STMicroelectronics ST19 8-bit microcontroller
265
#define EM_VAX                  75      // Digital VAX
266
#define EM_CRIS                 76      // Axis Communications 32-bit embedded processor
267
#define EM_JAVELIN              77      // Infineon Technologies 32-bit embedded processor
268
#define EM_FIREPATH             78      // Element 14 64-bit DSP Processor
269
#define EM_ZSP                  79      // LSI Logic 16-bit DSP Processor
270
#define EM_MMIX                 80      // Donald Knuth's educational 64-bit processor
271
#define EM_HUANY                81      // Harvard University machine-independent object files
272
#define EM_PRISM                82      // SiTera Prism
273
 
274
/* Cygnus PowerPC ELF backend.  Written in the absence of an ABI.  */
275
#define EM_CYGNUS_POWERPC 0x9025
276
 
277
/* Old version of Sparc v9, from before the ABI; this should be
278
   removed shortly.  */
279
#define EM_OLD_SPARCV9  11
280
 
281
/* Old version of PowerPC, this should be removed shortly. */
282
#define EM_PPC_OLD      17
283
 
284
/* Cygnus ARC ELF backend.  Written in the absence of an ABI.  */
285
#define EM_CYGNUS_ARC 0x9040
286
 
287
/* Cygnus M32R ELF backend.  Written in the absence of an ABI.  */
288
#define EM_CYGNUS_M32R 0x9041
289
 
290
/* Alpha backend magic number.  Written in the absence of an ABI.  */
291
//#define EM_ALPHA        0x9026
292
 
293
/* D10V backend magic number.  Written in the absence of an ABI.  */
294
#define EM_CYGNUS_D10V  0x7650
295
 
296
/* D30V backend magic number.  Written in the absence of an ABI.  */
297
#define EM_CYGNUS_D30V  0x7676
298
 
299
/* V850 backend magic number.  Written in the absense of an ABI.  */
300
#define EM_CYGNUS_V850  0x9080
301
 
302
/* mn10200 and mn10300 backend magic numbers.
303
   Written in the absense of an ABI.  */
304
#define EM_CYGNUS_MN10200       0xdead
305
#define EM_CYGNUS_MN10300       0xbeef
306
 
307
/* FR30 magic number - no EABI available.  */
308
#define EM_CYGNUS_FR30          0x3330
309
 
310
/* AVR magic number
311
   Written in the absense of an ABI.  */
312
#define EM_AVR                  0x1057
313
 
314
// -------------------------------------------------------------------------
315
/* Version */
316
 
317
#define EV_NONE         0               /* Invalid */
318
#define EV_CURRENT      1               /* Current */
319
#define EV_NUM          2               /* number of versions */
320
 
321
// -------------------------------------------------------------------------
322
/* Section Header */
323
 
324
typedef struct {
325
    Elf32_Word  sh_name;        /* name - index into section header
326
                                   string table section */
327
    Elf32_Word  sh_type;        /* type */
328
    Elf32_Word  sh_flags;       /* flags */
329
    Elf32_Addr  sh_addr;        /* address */
330
    Elf32_Off   sh_offset;      /* file offset */
331
    Elf32_Word  sh_size;        /* section size */
332
    Elf32_Word  sh_link;        /* section header table index link */
333
    Elf32_Word  sh_info;        /* extra information */
334
    Elf32_Word  sh_addralign;   /* address alignment */
335
    Elf32_Word  sh_entsize;     /* section entry size */
336
} Elf32_Shdr;
337
 
338
typedef struct {
339
    Elf64_Word  sh_name;        /* section name */
340
    Elf64_Word  sh_type;        /* section type */
341
    Elf64_Xword sh_flags;       /* section flags */
342
    Elf64_Addr  sh_addr;        /* virtual address */
343
    Elf64_Off   sh_offset;      /* file offset */
344
    Elf64_Xword sh_size;        /* section size */
345
    Elf64_Word  sh_link;        /* link to another */
346
    Elf64_Word  sh_info;        /* misc info */
347
    Elf64_Xword sh_addralign;   /* memory alignment */
348
    Elf64_Xword sh_entsize;     /* table entry size */
349
} Elf64_Shdr;
350
 
351
// -------------------------------------------------------------------------
352
/* Special Section Indexes */
353
 
354
#define SHN_UNDEF       0               /* undefined */
355
#define SHN_LORESERVE   0xff00          /* lower bounds of reserved indexes */
356
#define SHN_LOPROC      0xff00          /* reserved range for processor */
357
#define SHN_HIPROC      0xff1f          /*   specific section indexes */
358
#define SHN_LOOS        0xff20          /* reserved range for operating */
359
#define SHN_HIOS        0xff3f          /*   system specific section indexes */
360
#define SHN_ABS         0xfff1          /* absolute value */
361
#define SHN_COMMON      0xfff2          /* common symbol */
362
#define SHN_XINDEX      0xffff          /* escape value for oversize index */
363
#define SHN_HIRESERVE   0xffff          /* upper bounds of reserved indexes */
364
 
365
// -------------------------------------------------------------------------
366
/* sh_type */
367
 
368
#define SHT_NULL        0               /* inactive */
369
#define SHT_PROGBITS    1               /* program defined information */
370
#define SHT_SYMTAB      2               /* symbol table section */
371
#define SHT_STRTAB      3               /* string table section */
372
#define SHT_RELA        4               /* relocation section with addends*/
373
#define SHT_HASH        5               /* symbol hash table section */
374
#define SHT_DYNAMIC     6               /* dynamic section */
375
#define SHT_NOTE        7               /* note section */
376
#define SHT_NOBITS      8               /* no space section */
377
#define SHT_REL         9               /* relation section without addends */
378
#define SHT_SHLIB       10              /* reserved - purpose unknown */
379
#define SHT_DYNSYM      11              /* dynamic symbol table section */
380
#define SHT_INIT_ARRAY  14              /* init procedure array */
381
#define SHT_FINI_ARRAY  15              /* fini procedure array */
382
#define SHT_PREINIT_ARRAY 16            /* preinit procedure array */
383
#define SHT_GROUP       17              /* section group */
384
#define SHT_SYMTAB_SHNDX 18             /* oversize index table */
385
#define SHT_NUM         19              /* number of section types */
386
#define SHT_LOOS        0x60000000      /* reserved range for O/S */
387
#define SHT_HIOS        0x6fffffff      /*  specific section header types */
388
#define SHT_LOPROC      0x70000000      /* reserved range for processor */
389
#define SHT_HIPROC      0x7fffffff      /*  specific section header types */
390
#define SHT_LOUSER      0x80000000      /* reserved range for application */
391
#define SHT_HIUSER      0xffffffff      /*  specific indexes */
392
 
393
// -------------------------------------------------------------------------
394
/* Section names */
395
 
396
#define ELF_BSS         ".bss"          /* uninitialized data */
397
#define ELF_DATA        ".data"         /* initialized data */
398
#define ELF_DEBUG       ".debug"        /* debug */
399
#define ELF_DYNAMIC     ".dynamic"      /* dynamic linking information */
400
#define ELF_DYNSTR      ".dynstr"       /* dynamic string table */
401
#define ELF_DYNSYM      ".dynsym"       /* dynamic symbol table */
402
#define ELF_FINI        ".fini"         /* termination code */
403
#define ELF_GOT         ".got"          /* global offset table */
404
#define ELF_HASH        ".hash"         /* symbol hash table */
405
#define ELF_INIT        ".init"         /* initialization code */
406
#define ELF_REL_DATA    ".rel.data"     /* relocation data */
407
#define ELF_REL_FINI    ".rel.fini"     /* relocation termination code */
408
#define ELF_REL_INIT    ".rel.init"     /* relocation initialization code */
409
#define ELF_REL_DYN     ".rel.dyn"      /* relocaltion dynamic link info */
410
#define ELF_REL_RODATA  ".rel.rodata"   /* relocation read-only data */
411
#define ELF_REL_TEXT    ".rel.text"     /* relocation code */
412
#define ELF_RODATA      ".rodata"       /* read-only data */
413
#define ELF_SHSTRTAB    ".shstrtab"     /* section header string table */
414
#define ELF_STRTAB      ".strtab"       /* string table */
415
#define ELF_SYMTAB      ".symtab"       /* symbol table */
416
#define ELF_TEXT        ".text"         /* code */
417
 
418
// -------------------------------------------------------------------------
419
/* Section Attribute Flags - sh_flags */
420
 
421
#define SHF_WRITE               0x001           /* Writable */
422
#define SHF_ALLOC               0x002           /* occupies memory */
423
#define SHF_EXECINSTR           0x004           /* executable */
424
#define SHF_MERGE               0x010           /* merge data */
425
#define SHF_STRINGS             0x020           /* contains strings */
426
#define SHF_INFO_LINK           0x040           /* link in sh_info field */
427
#define SHF_LINK_ORDER          0x080           /* preserve link order */
428
#define SHF_OS_NONCONFORMING    0x100           /* special OS-specific */
429
                                                /*  processing needed */
430
#define SHF_GROUP               0x200           /* member of group */
431
#define SHF_MASKOS              0x0ff00000      /* reserved bits for OS */
432
                                                /*  specific section attributes */
433
#define SHF_MASKPROC            0xf0000000      /* reserved bits for processor */
434
                                                /*  specific section attributes */
435
 
436
// -------------------------------------------------------------------------
437
/* Symbol Table Entry */
438
 
439
typedef struct {
440
    Elf32_Word          st_name;        /* name - index into string table */
441
    Elf32_Addr          st_value;       /* symbol value */
442
    Elf32_Word          st_size;        /* symbol size */
443
    unsigned char       st_info;        /* type and binding */
444
    unsigned char       st_other;       /* visibility */
445
    Elf32_Half          st_shndx;       /* section header index */
446
} Elf32_Sym;
447
 
448
typedef struct {
449
    Elf64_Word          st_name;        /* Symbol name index in str table */
450
    unsigned char       st_info;        /* type / binding attrs */
451
    unsigned char       st_other;       /* visibility */
452
    Elf64_Half          st_shndx;       /* section index of symbol */
453
    Elf64_Addr          st_value;       /* value of symbol */
454
    Elf64_Xword          st_size;        /* size of symbol */
455
} Elf64_Sym;
456
 
457
// -------------------------------------------------------------------------
458
/* Symbol table index */
459
 
460
#define STN_UNDEF       0               /* undefined */
461
 
462
/* Extract symbol info - st_info */
463
#define ELF32_ST_BIND(x)        ((x) >> 4)
464
#define ELF32_ST_TYPE(x)        (((unsigned int) x) & 0xf)
465
#define ELF32_ST_INFO(b,t)      (((b) << 4) + ((t) & 0xf))
466
 
467
#define ELF64_ST_BIND(x)        ((x) >> 4)
468
#define ELF64_ST_TYPE(x)        (((unsigned int) x) & 0xf)
469
#define ELF64_ST_INFO(b,t)      (((b) << 4) + ((t) & 0xf))
470
 
471
#define ELF32_ST_VISIBILITY(o)  ((o)&0x3)
472
#define ELF64_ST_VISIBILITY(o)  ((o)&0x3)
473
 
474
// -------------------------------------------------------------------------
475
/* Symbol Binding - ELF32_ST_BIND - st_info */
476
 
477
#define STB_LOCAL       0               /* Local symbol */
478
#define STB_GLOBAL      1               /* Global symbol */
479
#define STB_WEAK        2               /* like global - lower precedence */
480
#define STB_NUM         3               /* number of symbol bindings */
481
#define STB_LOOS        10              /* reserved range for OS */
482
#define STB_HIOS        12              /*  specific symbol bindings */
483
#define STB_LOPROC      13              /* reserved range for processor */
484
#define STB_HIPROC      15              /*  specific symbol bindings */
485
 
486
// -------------------------------------------------------------------------
487
/* Symbol type - ELF32_ST_TYPE - st_info */
488
 
489
#define STT_NOTYPE      0               /* not specified */
490
#define STT_OBJECT      1               /* data object */
491
#define STT_FUNC        2               /* function */
492
#define STT_SECTION     3               /* section */
493
#define STT_FILE        4               /* file */
494
#define STT_COMMON      5               /* common block */
495
#define STT_NUM         6               /* number of symbol types */
496
#define STT_LOOS        10              /* reserved range for OS */
497
#define STT_HIOS        12              /*  specific symbol types */
498
#define STT_LOPROC      13              /* reserved range for processor */
499
#define STT_HIPROC      15              /*  specific symbol types */
500
 
501
// -------------------------------------------------------------------------
502
// symbol visibility in st_other
503
 
504
#define STV_DEFAULT     0               /* default to binding type */
505
#define STV_INTERNAL    1               /* processor specific */
506
#define STV_HIDDEN      2               /* invisible */
507
#define STV_PROTECTED   3               /* non-premptable */
508
 
509
// -------------------------------------------------------------------------
510
// 32 bit relocation records
511
 
512
/* Relocation entry with implicit addend */
513
typedef struct
514
{
515
        Elf32_Addr      r_offset;       /* offset of relocation */
516
        Elf32_Word      r_info;         /* symbol table index and type */
517
} Elf32_Rel;
518
 
519
/* Relocation entry with explicit addend */
520
typedef struct
521
{
522
        Elf32_Addr      r_offset;       /* offset of relocation */
523
        Elf32_Word      r_info;         /* symbol table index and type */
524
        Elf32_Sword     r_addend;
525
} Elf32_Rela;
526
 
527
/* Extract relocation info - r_info */
528
#define ELF32_R_SYM(i)          ((i) >> 8)
529
#define ELF32_R_TYPE(i)         ((unsigned char) (i))
530
#define ELF32_R_INFO(s,t)       (((s) << 8) + (unsigned char)(t))
531
 
532
// -------------------------------------------------------------------------
533
// 64 bit equivalents of above structures and macros.
534
 
535
typedef struct {
536
        Elf64_Addr      r_offset;       /* where to do it */
537
        Elf64_Xword     r_info;         /* index & type of relocation */
538
} Elf64_Rel;
539
 
540
typedef struct {
541
        Elf64_Addr      r_offset;       /* where to do it */
542
        Elf64_Xword     r_info;         /* index & type of relocation */
543
        Elf64_Sxword    r_addend;       /* adjustment value */
544
} Elf64_RelA;
545
 
546
#define ELF64_R_SYM(info)       ((info) >> 32)
547
#define ELF64_R_TYPE(info)      ((info) & 0xFFFFFFFF)
548
#define ELF64_R_INFO(s,t)       (((s) << 32) + (u_int32_t)(t))
549
 
550
// -------------------------------------------------------------------------
551
/* Program Header */
552
 
553
typedef struct {
554
    Elf32_Word  p_type;         /* segment type */
555
    Elf32_Off   p_offset;       /* segment offset */
556
    Elf32_Addr  p_vaddr;        /* virtual address of segment */
557
    Elf32_Addr  p_paddr;        /* physical address - ignored? */
558
    Elf32_Word  p_filesz;       /* number of bytes in file for seg. */
559
    Elf32_Word  p_memsz;        /* number of bytes in mem. for seg. */
560
    Elf32_Word  p_flags;        /* flags */
561
    Elf32_Word  p_align;        /* memory alignment */
562
} Elf32_Phdr;
563
 
564
typedef struct {
565
    Elf64_Word  p_type;         /* entry type */
566
    Elf64_Word  p_flags;        /* flags */
567
    Elf64_Off   p_offset;       /* offset */
568
    Elf64_Addr  p_vaddr;        /* virtual address */
569
    Elf64_Addr  p_paddr;        /* physical address */
570
    Elf64_Xword p_filesz;       /* file size */
571
    Elf64_Xword p_memsz;        /* memory size */
572
    Elf64_Xword p_align;        /* memory & file alignment */
573
} Elf64_Phdr;
574
 
575
// -------------------------------------------------------------------------
576
/* Segment types - p_type */
577
 
578
#define PT_NULL         0               /* unused */
579
#define PT_LOAD         1               /* loadable segment */
580
#define PT_DYNAMIC      2               /* dynamic linking section */
581
#define PT_INTERP       3               /* the RTLD */
582
#define PT_NOTE         4               /* auxiliary information */
583
#define PT_SHLIB        5               /* reserved - purpose undefined */
584
#define PT_PHDR         6               /* program header */
585
#define PT_NUM          7               /* Number of segment types */
586
#define PT_LOOS         0x60000000      /* reserved range for OS */
587
#define PT_HIOS         0x6fffffff      /*  specific segment types */
588
#define PT_LOPROC       0x70000000      /* reserved range for processor */
589
#define PT_HIPROC       0x7fffffff      /*  specific segment types */
590
 
591
// -------------------------------------------------------------------------
592
/* Segment flags - p_flags */
593
 
594
#define PF_X            0x1             /* Executable */
595
#define PF_W            0x2             /* Writable */
596
#define PF_R            0x4             /* Readable */
597
#define PF_MASKOS       0x0ff00000      /* reserved bits for OS */
598
                                        /*  specific segment flags */
599
#define PF_MASKPROC     0xf0000000      /* reserved bits for processor */
600
                                        /*  specific segment flags */
601
 
602
// -------------------------------------------------------------------------
603
/* Dynamic structure */
604
 
605
typedef struct {
606
    Elf32_Sword         d_tag;  /* controls meaning of d_val */
607
    union {
608
        Elf32_Word      d_val;  /* Multiple meanings - see d_tag */
609
        Elf32_Addr      d_ptr;  /* program virtual address */
610
    } d_un;
611
} Elf32_Dyn;
612
 
613
extern Elf32_Dyn        _DYNAMIC[];     /* XXX not 64-bit clean */
614
 
615
typedef struct {
616
    Elf64_Sxword        d_tag;  /* controls meaning of d_val */
617
    union {
618
        Elf64_Xword     d_val;
619
        Elf64_Addr      d_ptr;
620
    } d_un;
621
} Elf64_Dyn;
622
 
623
// -------------------------------------------------------------------------
624
/* Dynamic Array Tags - d_tag */
625
 
626
#define DT_NULL         0               /* marks end of _DYNAMIC array */
627
#define DT_NEEDED       1               /* string table offset of needed lib */
628
#define DT_PLTRELSZ     2               /* size of relocation entries in PLT */
629
#define DT_PLTGOT       3               /* address PLT/GOT */
630
#define DT_HASH         4               /* address of symbol hash table */
631
#define DT_STRTAB       5               /* address of string table */
632
#define DT_SYMTAB       6               /* address of symbol table */
633
#define DT_RELA         7               /* address of relocation table */
634
#define DT_RELASZ       8               /* size of relocation table */
635
#define DT_RELAENT      9               /* size of relocation entry */
636
#define DT_STRSZ        10              /* size of string table */
637
#define DT_SYMENT       11              /* size of symbol table entry */
638
#define DT_INIT         12              /* address of initialization func. */
639
#define DT_FINI         13              /* address of termination function */
640
#define DT_SONAME       14              /* string table offset of shared obj */
641
#define DT_RPATH        15              /* string table offset of library
642
                                           search path */
643
#define DT_SYMBOLIC     16              /* start sym search in shared obj. */
644
#define DT_REL          17              /* address of rel. tbl. w addends */
645
#define DT_RELSZ        18              /* size of DT_REL relocation table */
646
#define DT_RELENT       19              /* size of DT_REL relocation entry */
647
#define DT_PLTREL       20              /* PLT referenced relocation entry */
648
#define DT_DEBUG        21              /* bugger */
649
#define DT_TEXTREL      22              /* Allow rel. mod. to unwritable seg */
650
#define DT_JMPREL       23              /* add. of PLT's relocation entries */
651
#define DT_BIND_NOW     24              /* Bind now regardless of env setting */
652
#define DT_INIT_ARRAY   25              /* init array address */
653
#define DT_FINI_ARRAY   26              /* fini array address */
654
#define DT_INIT_ARRAYSZ 27              /* init array size */
655
#define DT_FINI_ARRAYSZ 28              /* fini array size */
656
#define DT_RUNPATH      29              /* library search path */
657
#define DT_FLAGS        30              /* flags */
658
#define DT_ENCODING     32              /* encoding rules start here */
659
#define DT_PREINIT_ARRAY 32             /* preinit array address */
660
#define DT_PREINIT_ARRAYSZ 33           /* preinit array size */
661
#define DT_NUM          26              /* Number used. */
662
#define DT_LOOS         0x60000000      /* reserved range for OS */
663
#define DT_HIOS         0x6fffffff      /*  specific dynamic array tags */
664
#define DT_LOPROC       0x70000000      /* reserved range for processor */
665
#define DT_HIPROC       0x7fffffff      /*  specific dynamic array tags */
666
 
667
// -------------------------------------------------------------------------
668
// Values for DT_FLAGS entry
669
 
670
#define DF_ORIGIN       0x1             /* Uses $ORIGIN substitution string */
671
#define DF_SYMBOLIC     0x2             /* search for symbols here first */
672
#define DF_TEXTREL      0x4             /* text may be relocatable */
673
#define DF_BIND_NOW     0x8             /* bind references now, dammit */
674
 
675
// -------------------------------------------------------------------------
676
/* Note Definitions */
677
 
678
typedef struct {
679
    Elf32_Word namesz;
680
    Elf32_Word descsz;
681
    Elf32_Word type;
682
} Elf32_Note;
683
 
684
typedef struct {
685
    Elf64_Word namesz;
686
    Elf64_Word descsz;
687
    Elf64_Word type;
688
} Elf64_Note;
689
 
690
// -------------------------------------------------------------------------
691
// Hash table structure
692
// The same structure is used by both 32 and 64 bit formats
693
 
694
typedef struct {
695
    Elf32_Word          nbucket;        /* number of buckets */
696
    Elf32_Word          nchain;         /* number of chains */
697
 
698
    /* The buckets follow this structure in memory and the chains
699
       follow those. */
700
} Elf_Hash;
701
 
702
// -------------------------------------------------------------------------
703
#endif // ifndef CYGONCE_LOADER_ELF_H
704
// EOF elf.h

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.