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