1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/* ELF support for BFD.
Copyright 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2001
Free Software Foundation, Inc.
Written by Fred Fish @ Cygnus Support, from information published
in "UNIX System V Release 4, Programmers Guide: ANSI C and
Programming Support Tools".
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* This file is part of ELF support for BFD, and contains the portions
that describe how ELF is represented externally by the BFD library.
I.E. it describes the in-file representation of ELF. It requires
the elf/common.h file which contains the portions that are common to
both the internal and external representations. */
/* The 64-bit stuff is kind of random. Perhaps someone will publish a
spec someday. */
#ifndef _ELF_EXTERNAL_H
#define _ELF_EXTERNAL_H
/* ELF Header (32-bit implementations) */
typedef struct {
unsigned char e_ident[16]; /* ELF "magic number" */
unsigned char e_type[2]; /* Identifies object file type */
unsigned char e_machine[2]; /* Specifies required architecture */
unsigned char e_version[4]; /* Identifies object file version */
unsigned char e_entry[4]; /* Entry point virtual address */
unsigned char e_phoff[4]; /* Program header table file offset */
unsigned char e_shoff[4]; /* Section header table file offset */
unsigned char e_flags[4]; /* Processor-specific flags */
unsigned char e_ehsize[2]; /* ELF header size in bytes */
unsigned char e_phentsize[2]; /* Program header table entry size */
unsigned char e_phnum[2]; /* Program header table entry count */
unsigned char e_shentsize[2]; /* Section header table entry size */
unsigned char e_shnum[2]; /* Section header table entry count */
unsigned char e_shstrndx[2]; /* Section header string table index */
} Elf32_External_Ehdr;
typedef struct {
unsigned char e_ident[16]; /* ELF "magic number" */
unsigned char e_type[2]; /* Identifies object file type */
unsigned char e_machine[2]; /* Specifies required architecture */
unsigned char e_version[4]; /* Identifies object file version */
unsigned char e_entry[8]; /* Entry point virtual address */
unsigned char e_phoff[8]; /* Program header table file offset */
unsigned char e_shoff[8]; /* Section header table file offset */
unsigned char e_flags[4]; /* Processor-specific flags */
unsigned char e_ehsize[2]; /* ELF header size in bytes */
unsigned char e_phentsize[2]; /* Program header table entry size */
unsigned char e_phnum[2]; /* Program header table entry count */
unsigned char e_shentsize[2]; /* Section header table entry size */
unsigned char e_shnum[2]; /* Section header table entry count */
unsigned char e_shstrndx[2]; /* Section header string table index */
} Elf64_External_Ehdr;
/* Program header */
typedef struct {
unsigned char p_type[4]; /* Identifies program segment type */
unsigned char p_offset[4]; /* Segment file offset */
unsigned char p_vaddr[4]; /* Segment virtual address */
unsigned char p_paddr[4]; /* Segment physical address */
unsigned char p_filesz[4]; /* Segment size in file */
unsigned char p_memsz[4]; /* Segment size in memory */
unsigned char p_flags[4]; /* Segment flags */
unsigned char p_align[4]; /* Segment alignment, file & memory */
} Elf32_External_Phdr;
typedef struct {
unsigned char p_type[4]; /* Identifies program segment type */
unsigned char p_flags[4]; /* Segment flags */
unsigned char p_offset[8]; /* Segment file offset */
unsigned char p_vaddr[8]; /* Segment virtual address */
unsigned char p_paddr[8]; /* Segment physical address */
unsigned char p_filesz[8]; /* Segment size in file */
unsigned char p_memsz[8]; /* Segment size in memory */
unsigned char p_align[8]; /* Segment alignment, file & memory */
} Elf64_External_Phdr;
/* Section header */
typedef struct {
unsigned char sh_name[4]; /* Section name, index in string tbl */
unsigned char sh_type[4]; /* Type of section */
unsigned char sh_flags[4]; /* Miscellaneous section attributes */
unsigned char sh_addr[4]; /* Section virtual addr at execution */
unsigned char sh_offset[4]; /* Section file offset */
unsigned char sh_size[4]; /* Size of section in bytes */
unsigned char sh_link[4]; /* Index of another section */
unsigned char sh_info[4]; /* Additional section information */
unsigned char sh_addralign[4]; /* Section alignment */
unsigned char sh_entsize[4]; /* Entry size if section holds table */
} Elf32_External_Shdr;
typedef struct {
unsigned char sh_name[4]; /* Section name, index in string tbl */
unsigned char sh_type[4]; /* Type of section */
unsigned char sh_flags[8]; /* Miscellaneous section attributes */
unsigned char sh_addr[8]; /* Section virtual addr at execution */
unsigned char sh_offset[8]; /* Section file offset */
unsigned char sh_size[8]; /* Size of section in bytes */
unsigned char sh_link[4]; /* Index of another section */
unsigned char sh_info[4]; /* Additional section information */
unsigned char sh_addralign[8]; /* Section alignment */
unsigned char sh_entsize[8]; /* Entry size if section holds table */
} Elf64_External_Shdr;
/* Symbol table entry */
typedef struct {
unsigned char st_name[4]; /* Symbol name, index in string tbl */
unsigned char st_value[4]; /* Value of the symbol */
unsigned char st_size[4]; /* Associated symbol size */
unsigned char st_info[1]; /* Type and binding attributes */
unsigned char st_other[1]; /* No defined meaning, 0 */
unsigned char st_shndx[2]; /* Associated section index */
} Elf32_External_Sym;
typedef struct {
unsigned char st_name[4]; /* Symbol name, index in string tbl */
unsigned char st_info[1]; /* Type and binding attributes */
unsigned char st_other[1]; /* No defined meaning, 0 */
unsigned char st_shndx[2]; /* Associated section index */
unsigned char st_value[8]; /* Value of the symbol */
unsigned char st_size[8]; /* Associated symbol size */
} Elf64_External_Sym;
typedef struct {
unsigned char est_shndx[4]; /* Section index */
} Elf_External_Sym_Shndx;
/* Note segments */
typedef struct {
unsigned char namesz[4]; /* Size of entry's owner string */
unsigned char descsz[4]; /* Size of the note descriptor */
unsigned char type[4]; /* Interpretation of the descriptor */
char name[1]; /* Start of the name+desc data */
} Elf_External_Note;
/* Relocation Entries */
typedef struct {
unsigned char r_offset[4]; /* Location at which to apply the action */
unsigned char r_info[4]; /* index and type of relocation */
} Elf32_External_Rel;
typedef struct {
unsigned char r_offset[4]; /* Location at which to apply the action */
unsigned char r_info[4]; /* index and type of relocation */
unsigned char r_addend[4]; /* Constant addend used to compute value */
} Elf32_External_Rela;
typedef struct {
unsigned char r_offset[8]; /* Location at which to apply the action */
unsigned char r_info[8]; /* index and type of relocation */
} Elf64_External_Rel;
typedef struct {
unsigned char r_offset[8]; /* Location at which to apply the action */
unsigned char r_info[8]; /* index and type of relocation */
unsigned char r_addend[8]; /* Constant addend used to compute value */
} Elf64_External_Rela;
/* dynamic section structure */
typedef struct {
unsigned char d_tag[4]; /* entry tag value */
union {
unsigned char d_val[4];
unsigned char d_ptr[4];
} d_un;
} Elf32_External_Dyn;
typedef struct {
unsigned char d_tag[8]; /* entry tag value */
union {
unsigned char d_val[8];
unsigned char d_ptr[8];
} d_un;
} Elf64_External_Dyn;
/* The version structures are currently size independent. They are
named without a 32 or 64. If that ever changes, these structures
will need to be renamed. */
/* This structure appears in a SHT_GNU_verdef section. */
typedef struct {
unsigned char vd_version[2];
unsigned char vd_flags[2];
unsigned char vd_ndx[2];
unsigned char vd_cnt[2];
unsigned char vd_hash[4];
unsigned char vd_aux[4];
unsigned char vd_next[4];
} Elf_External_Verdef;
/* This structure appears in a SHT_GNU_verdef section. */
typedef struct {
unsigned char vda_name[4];
unsigned char vda_next[4];
} Elf_External_Verdaux;
/* This structure appears in a SHT_GNU_verneed section. */
typedef struct {
unsigned char vn_version[2];
unsigned char vn_cnt[2];
unsigned char vn_file[4];
unsigned char vn_aux[4];
unsigned char vn_next[4];
} Elf_External_Verneed;
/* This structure appears in a SHT_GNU_verneed section. */
typedef struct {
unsigned char vna_hash[4];
unsigned char vna_flags[2];
unsigned char vna_other[2];
unsigned char vna_name[4];
unsigned char vna_next[4];
} Elf_External_Vernaux;
/* This structure appears in a SHT_GNU_versym section. This is not a
standard ELF structure; ELF just uses Elf32_Half. */
typedef struct {
unsigned char vs_vers[2];
}
#ifdef __GNUC__
__attribute__ ((packed))
#endif
Elf_External_Versym;
/* Structure for syminfo section. */
typedef struct
{
unsigned char si_boundto[2];
unsigned char si_flags[2];
} Elf_External_Syminfo;
/* This structure appears on the stack and in NT_AUXV core file notes. */
typedef struct
{
unsigned char a_type[4];
unsigned char a_val[4];
} Elf32_External_Auxv;
typedef struct
{
unsigned char a_type[8];
unsigned char a_val[8];
} Elf64_External_Auxv;
#endif /* _ELF_EXTERNAL_H */
|