Subversion Repositories Kolibri OS

Rev

Rev 5191 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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