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