OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [include/] [elf/] [internal.h] - Blame information for rev 440

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

Line No. Rev Author Line
1 24 jeremybenn
/* ELF support for BFD.
2
   Copyright 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000, 2001, 2002,
3
   2003, 2006, 2007 Free Software Foundation, Inc.
4
 
5
   Written by Fred Fish @ Cygnus Support, from information published
6
   in "UNIX System V Release 4, Programmers Guide: ANSI C and
7
   Programming Support Tools".
8
 
9
This file is part of BFD, the Binary File Descriptor library.
10
 
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 2 of the License, or
14
(at your option) any later version.
15
 
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
GNU General Public License for more details.
20
 
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
24
 
25
 
26
/* This file is part of ELF support for BFD, and contains the portions
27
   that describe how ELF is represented internally in the BFD library.
28
   I.E. it describes the in-memory representation of ELF.  It requires
29
   the elf-common.h file which contains the portions that are common to
30
   both the internal and external representations. */
31
 
32
 
33
/* NOTE that these structures are not kept in the same order as they appear
34
   in the object file.  In some cases they've been reordered for more optimal
35
   packing under various circumstances.  */
36
 
37
#ifndef _ELF_INTERNAL_H
38
#define _ELF_INTERNAL_H
39
 
40
/* ELF Header */
41
 
42
#define EI_NIDENT       16              /* Size of e_ident[] */
43
 
44
typedef struct elf_internal_ehdr {
45
  unsigned char         e_ident[EI_NIDENT]; /* ELF "magic number" */
46
  bfd_vma               e_entry;        /* Entry point virtual address */
47
  bfd_size_type         e_phoff;        /* Program header table file offset */
48
  bfd_size_type         e_shoff;        /* Section header table file offset */
49
  unsigned long         e_version;      /* Identifies object file version */
50
  unsigned long         e_flags;        /* Processor-specific flags */
51
  unsigned short        e_type;         /* Identifies object file type */
52
  unsigned short        e_machine;      /* Specifies required architecture */
53
  unsigned int          e_ehsize;       /* ELF header size in bytes */
54
  unsigned int          e_phentsize;    /* Program header table entry size */
55
  unsigned int          e_phnum;        /* Program header table entry count */
56
  unsigned int          e_shentsize;    /* Section header table entry size */
57
  unsigned int          e_shnum;        /* Section header table entry count */
58
  unsigned int          e_shstrndx;     /* Section header string table index */
59
} Elf_Internal_Ehdr;
60
 
61
/* Program header */
62
 
63
struct elf_internal_phdr {
64
  unsigned long p_type;                 /* Identifies program segment type */
65
  unsigned long p_flags;                /* Segment flags */
66
  bfd_vma       p_offset;               /* Segment file offset */
67
  bfd_vma       p_vaddr;                /* Segment virtual address */
68
  bfd_vma       p_paddr;                /* Segment physical address */
69
  bfd_vma       p_filesz;               /* Segment size in file */
70
  bfd_vma       p_memsz;                /* Segment size in memory */
71
  bfd_vma       p_align;                /* Segment alignment, file & memory */
72
};
73
 
74
typedef struct elf_internal_phdr Elf_Internal_Phdr;
75
 
76
/* Section header */
77
 
78
typedef struct elf_internal_shdr {
79
  unsigned int  sh_name;                /* Section name, index in string tbl */
80
  unsigned int  sh_type;                /* Type of section */
81
  bfd_vma       sh_flags;               /* Miscellaneous section attributes */
82
  bfd_vma       sh_addr;                /* Section virtual addr at execution */
83
  bfd_size_type sh_size;                /* Size of section in bytes */
84
  bfd_size_type sh_entsize;             /* Entry size if section holds table */
85
  unsigned long sh_link;                /* Index of another section */
86
  unsigned long sh_info;                /* Additional section information */
87
  file_ptr      sh_offset;              /* Section file offset */
88
  unsigned int  sh_addralign;           /* Section alignment */
89
 
90
  /* The internal rep also has some cached info associated with it. */
91
  asection *    bfd_section;            /* Associated BFD section.  */
92
  unsigned char *contents;              /* Section contents.  */
93
} Elf_Internal_Shdr;
94
 
95
/* Symbol table entry */
96
 
97
struct elf_internal_sym {
98
  bfd_vma       st_value;               /* Value of the symbol */
99
  bfd_vma       st_size;                /* Associated symbol size */
100
  unsigned long st_name;                /* Symbol name, index in string tbl */
101
  unsigned char st_info;                /* Type and binding attributes */
102
  unsigned char st_other;               /* Visibilty, and target specific */
103
  unsigned int  st_shndx;               /* Associated section index */
104
};
105
 
106
typedef struct elf_internal_sym Elf_Internal_Sym;
107
 
108
/* Note segments */
109
 
110
typedef struct elf_internal_note {
111
  unsigned long namesz;                 /* Size of entry's owner string */
112
  unsigned long descsz;                 /* Size of the note descriptor */
113
  unsigned long type;                   /* Interpretation of the descriptor */
114
  char *        namedata;               /* Start of the name+desc data */
115
  char *        descdata;               /* Start of the desc data */
116
  bfd_vma       descpos;                /* File offset of the descdata */
117
} Elf_Internal_Note;
118
 
119
/* Relocation Entries */
120
 
121
typedef struct elf_internal_rela {
122
  bfd_vma       r_offset;       /* Location at which to apply the action */
123
  bfd_vma       r_info;         /* Index and Type of relocation */
124
  bfd_vma       r_addend;       /* Constant addend used to compute value */
125
} Elf_Internal_Rela;
126
 
127
/* dynamic section structure */
128
 
129
typedef struct elf_internal_dyn {
130
  /* This needs to support 64-bit values in elf64.  */
131
  bfd_vma d_tag;                /* entry tag value */
132
  union {
133
    /* This needs to support 64-bit values in elf64.  */
134
    bfd_vma     d_val;
135
    bfd_vma     d_ptr;
136
  } d_un;
137
} Elf_Internal_Dyn;
138
 
139
/* This structure appears in a SHT_GNU_verdef section.  */
140
 
141
typedef struct elf_internal_verdef {
142
  unsigned short vd_version;    /* Version number of structure.  */
143
  unsigned short vd_flags;      /* Flags (VER_FLG_*).  */
144
  unsigned short vd_ndx;        /* Version index.  */
145
  unsigned short vd_cnt;        /* Number of verdaux entries.  */
146
  unsigned long  vd_hash;       /* Hash of name.  */
147
  unsigned long  vd_aux;        /* Offset to verdaux entries.  */
148
  unsigned long  vd_next;       /* Offset to next verdef.  */
149
 
150
  /* These fields are set up when BFD reads in the structure.  FIXME:
151
     It would be cleaner to store these in a different structure.  */
152
  bfd                         *vd_bfd;          /* BFD.  */
153
  const char                  *vd_nodename;     /* Version name.  */
154
  struct elf_internal_verdef  *vd_nextdef;      /* vd_next as pointer.  */
155
  struct elf_internal_verdaux *vd_auxptr;       /* vd_aux as pointer.  */
156
  unsigned int                 vd_exp_refno;    /* Used by the linker.  */
157
} Elf_Internal_Verdef;
158
 
159
/* This structure appears in a SHT_GNU_verdef section.  */
160
 
161
typedef struct elf_internal_verdaux {
162
  unsigned long vda_name;       /* String table offset of name.  */
163
  unsigned long vda_next;       /* Offset to next verdaux.  */
164
 
165
  /* These fields are set up when BFD reads in the structure.  FIXME:
166
     It would be cleaner to store these in a different structure.  */
167
  const char *vda_nodename;                     /* vda_name as pointer.  */
168
  struct elf_internal_verdaux *vda_nextptr;     /* vda_next as pointer.  */
169
} Elf_Internal_Verdaux;
170
 
171
/* This structure appears in a SHT_GNU_verneed section.  */
172
 
173
typedef struct elf_internal_verneed {
174
  unsigned short vn_version;    /* Version number of structure.  */
175
  unsigned short vn_cnt;        /* Number of vernaux entries.  */
176
  unsigned long  vn_file;       /* String table offset of library name.  */
177
  unsigned long  vn_aux;        /* Offset to vernaux entries.  */
178
  unsigned long  vn_next;       /* Offset to next verneed.  */
179
 
180
  /* These fields are set up when BFD reads in the structure.  FIXME:
181
     It would be cleaner to store these in a different structure.  */
182
  bfd                         *vn_bfd;          /* BFD.  */
183
  const char                  *vn_filename;     /* vn_file as pointer.  */
184
  struct elf_internal_vernaux *vn_auxptr;       /* vn_aux as pointer.  */
185
  struct elf_internal_verneed *vn_nextref;      /* vn_nextref as pointer.  */
186
} Elf_Internal_Verneed;
187
 
188
/* This structure appears in a SHT_GNU_verneed section.  */
189
 
190
typedef struct elf_internal_vernaux {
191
  unsigned long  vna_hash;      /* Hash of dependency name.  */
192
  unsigned short vna_flags;     /* Flags (VER_FLG_*).  */
193
  unsigned short vna_other;     /* Unused.  */
194
  unsigned long  vna_name;      /* String table offset to version name.  */
195
  unsigned long  vna_next;      /* Offset to next vernaux.  */
196
 
197
  /* These fields are set up when BFD reads in the structure.  FIXME:
198
     It would be cleaner to store these in a different structure.  */
199
  const char                  *vna_nodename;    /* vna_name as pointer.  */
200
  struct elf_internal_vernaux *vna_nextptr;     /* vna_next as pointer.  */
201
} Elf_Internal_Vernaux;
202
 
203
/* This structure appears in a SHT_GNU_versym section.  This is not a
204
   standard ELF structure; ELF just uses Elf32_Half.  */
205
 
206
typedef struct elf_internal_versym {
207
  unsigned short vs_vers;
208
} Elf_Internal_Versym;
209
 
210
/* Structure for syminfo section.  */
211
typedef struct
212
{
213
  unsigned short int    si_boundto;
214
  unsigned short int    si_flags;
215
} Elf_Internal_Syminfo;
216
 
217
/* This structure appears on the stack and in NT_AUXV core file notes.  */
218
typedef struct
219
{
220
  bfd_vma a_type;
221
  bfd_vma a_val;
222
} Elf_Internal_Auxv;
223
 
224
 
225
/* This structure is used to describe how sections should be assigned
226
   to program segments.  */
227
 
228
struct elf_segment_map
229
{
230
  /* Next program segment.  */
231
  struct elf_segment_map *next;
232
  /* Program segment type.  */
233
  unsigned long p_type;
234
  /* Program segment flags.  */
235
  unsigned long p_flags;
236
  /* Program segment physical address.  */
237
  bfd_vma p_paddr;
238
  /* Program segment virtual address offset from section vma.  */
239
  bfd_vma p_vaddr_offset;
240
  /* Program segment alignment.  */
241
  bfd_vma p_align;
242
  /* Segment size in file and memory */
243
  bfd_vma p_size;
244
  /* Whether the p_flags field is valid; if not, the flags are based
245
     on the section flags.  */
246
  unsigned int p_flags_valid : 1;
247
  /* Whether the p_paddr field is valid; if not, the physical address
248
     is based on the section lma values.  */
249
  unsigned int p_paddr_valid : 1;
250
  /* Whether the p_align field is valid; if not, PT_LOAD segment
251
     alignment is based on the default maximum page size.  */
252
  unsigned int p_align_valid : 1;
253
  /* Whether the p_size field is valid; if not, the size are based
254
     on the section sizes.  */
255
  unsigned int p_size_valid : 1;
256
  /* Whether this segment includes the file header.  */
257
  unsigned int includes_filehdr : 1;
258
  /* Whether this segment includes the program headers.  */
259
  unsigned int includes_phdrs : 1;
260
  /* Number of sections (may be 0).  */
261
  unsigned int count;
262
  /* Sections.  Actual number of elements is in count field.  */
263
  asection *sections[1];
264
};
265
 
266
/* .tbss is special.  It doesn't contribute memory space to normal
267
   segments and it doesn't take file space in normal segments.  */
268
#define ELF_SECTION_SIZE(sec_hdr, segment)                      \
269
   (((sec_hdr->sh_flags & SHF_TLS) == 0                          \
270
     || sec_hdr->sh_type != SHT_NOBITS                          \
271
     || segment->p_type == PT_TLS) ? sec_hdr->sh_size : 0)
272
 
273
/* Decide if the given sec_hdr is in the given segment.  PT_TLS segment
274
   contains only SHF_TLS sections.  Only PT_LOAD, PT_GNU_RELRO and
275
   and PT_TLS segments can contain SHF_TLS sections.  */
276
#define ELF_IS_SECTION_IN_SEGMENT(sec_hdr, segment)                     \
277
  (((((sec_hdr->sh_flags & SHF_TLS) != 0)                                \
278
     && (segment->p_type == PT_TLS                                      \
279
         || segment->p_type == PT_GNU_RELRO                             \
280
         || segment->p_type == PT_LOAD))                                \
281
    || ((sec_hdr->sh_flags & SHF_TLS) == 0                               \
282
        && segment->p_type != PT_TLS))                                  \
283
   /* Any section besides one of type SHT_NOBITS must have a file       \
284
      offset within the segment.  */                                    \
285
   && (sec_hdr->sh_type == SHT_NOBITS                                   \
286
       || ((bfd_vma) sec_hdr->sh_offset >= segment->p_offset            \
287
           && (sec_hdr->sh_offset + ELF_SECTION_SIZE(sec_hdr, segment)  \
288
               <= segment->p_offset + segment->p_filesz)))              \
289
   /* SHF_ALLOC sections must have VMAs within the segment.  Be         \
290
      careful about segments right at the end of memory.  */            \
291
   && ((sec_hdr->sh_flags & SHF_ALLOC) == 0                              \
292
       || (sec_hdr->sh_addr >= segment->p_vaddr                         \
293
           && (sec_hdr->sh_addr - segment->p_vaddr                      \
294
               + ELF_SECTION_SIZE(sec_hdr, segment) <= segment->p_memsz))))
295
 
296
/* Decide if the given sec_hdr is in the given segment in file.  */
297
#define ELF_IS_SECTION_IN_SEGMENT_FILE(sec_hdr, segment)        \
298
  (sec_hdr->sh_size > 0                                          \
299
   && ELF_IS_SECTION_IN_SEGMENT (sec_hdr, segment))
300
 
301
/* Decide if the given sec_hdr is in the given segment in memory.  */
302
#define ELF_IS_SECTION_IN_SEGMENT_MEMORY(sec_hdr, segment)      \
303
  (ELF_SECTION_SIZE(sec_hdr, segment) > 0                        \
304
   && ELF_IS_SECTION_IN_SEGMENT (sec_hdr, segment))
305
 
306
#endif /* _ELF_INTERNAL_H */

powered by: WebSVN 2.1.0

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