]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - elfcpp/elfcpp_internal.h
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / elfcpp / elfcpp_internal.h
CommitLineData
bae7f79e
ILT
1// elfcpp_internal.h -- internals for elfcpp -*- C++ -*-
2
fd67aa11 3// Copyright (C) 2006-2024 Free Software Foundation, Inc.
6cb15b7f
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of elfcpp.
7
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public License
10// as published by the Free Software Foundation; either version 2, or
11// (at your option) any later version.
12
13// In addition to the permissions in the GNU Library General Public
14// License, the Free Software Foundation gives you unlimited
15// permission to link the compiled version of this file into
16// combinations with other programs, and to distribute those
17// combinations without any restriction coming from the use of this
18// file. (The Library Public License restrictions do apply in other
19// respects; for example, they cover modification of the file, and
20/// distribution when not linked into a combined executable.)
21
22// This program is distributed in the hope that it will be useful, but
23// WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25// Library General Public License for more details.
26
27// You should have received a copy of the GNU Library General Public
28// License along with this program; if not, write to the Free Software
29// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
30// 02110-1301, USA.
31
bae7f79e
ILT
32// This is included by elfcpp.h, the external interface, but holds
33// information which we want to keep private.
34
bae7f79e
ILT
35#ifndef ELFCPP_INTERNAL_H
36#define ELFCPP_INTERNAL_H
37
38namespace elfcpp
39{
40
41namespace internal
42{
43
bae7f79e
ILT
44// The ELF file header.
45
46template<int size>
47struct Ehdr_data
48{
49 unsigned char e_ident[EI_NIDENT];
50 Elf_Half e_type;
51 Elf_Half e_machine;
52 Elf_Word e_version;
53 typename Elf_types<size>::Elf_Addr e_entry;
54 typename Elf_types<size>::Elf_Off e_phoff;
55 typename Elf_types<size>::Elf_Off e_shoff;
56 Elf_Word e_flags;
57 Elf_Half e_ehsize;
58 Elf_Half e_phentsize;
59 Elf_Half e_phnum;
60 Elf_Half e_shentsize;
61 Elf_Half e_shnum;
62 Elf_Half e_shstrndx;
63};
64
dbe717ef 65// An ELF section header.
bae7f79e
ILT
66
67template<int size>
68struct Shdr_data
69{
70 Elf_Word sh_name;
71 Elf_Word sh_type;
72 typename Elf_types<size>::Elf_WXword sh_flags;
73 typename Elf_types<size>::Elf_Addr sh_addr;
74 typename Elf_types<size>::Elf_Off sh_offset;
75 typename Elf_types<size>::Elf_WXword sh_size;
76 Elf_Word sh_link;
77 Elf_Word sh_info;
78 typename Elf_types<size>::Elf_WXword sh_addralign;
79 typename Elf_types<size>::Elf_WXword sh_entsize;
80};
81
febdfe65
L
82// An ELF compression header.
83
84template<int size>
9706b5e6
L
85struct Chdr_data;
86
87template<>
88struct Chdr_data<32>
89{
90 Elf_Word ch_type;
91 Elf_Word ch_size;
92 Elf_Word ch_addralign;
93};
94
95template<>
96struct Chdr_data<64>
febdfe65 97{
9706b5e6
L
98 Elf_Word ch_type;
99 Elf_Word ch_reserved;
100 Elf_Xword ch_size;
101 Elf_Xword ch_addralign;
febdfe65
L
102};
103
39081c14
ILT
104// An ELF segment header. We use template specialization for the
105// 32-bit and 64-bit versions because the fields are in a different
106// order.
107
108template<int size>
109struct Phdr_data;
110
111template<>
112struct Phdr_data<32>
113{
114 Elf_Word p_type;
115 Elf_types<32>::Elf_Off p_offset;
116 Elf_types<32>::Elf_Addr p_vaddr;
117 Elf_types<32>::Elf_Addr p_paddr;
118 Elf_Word p_filesz;
119 Elf_Word p_memsz;
120 Elf_Word p_flags;
121 Elf_Word p_align;
122};
123
124template<>
125struct Phdr_data<64>
126{
127 Elf_Word p_type;
128 Elf_Word p_flags;
129 Elf_types<64>::Elf_Off p_offset;
130 Elf_types<64>::Elf_Addr p_vaddr;
131 Elf_types<64>::Elf_Addr p_paddr;
132 Elf_Xword p_filesz;
133 Elf_Xword p_memsz;
134 Elf_Xword p_align;
135};
136
bae7f79e
ILT
137// An ELF symbol table entry. We use template specialization for the
138// 32-bit and 64-bit versions because the fields are in a different
139// order.
140
141template<int size>
142struct Sym_data;
143
144template<>
145struct Sym_data<32>
146{
147 Elf_Word st_name;
148 Elf_types<32>::Elf_Addr st_value;
149 Elf_Word st_size;
150 unsigned char st_info;
151 unsigned char st_other;
152 Elf_Half st_shndx;
153};
154
155template<>
156struct Sym_data<64>
157{
158 Elf_Word st_name;
159 unsigned char st_info;
160 unsigned char st_other;
161 Elf_Half st_shndx;
162 Elf_types<64>::Elf_Addr st_value;
163 Elf_Xword st_size;
164};
165
dbe717ef 166// ELF relocation table entries.
61ba1cf9
ILT
167
168template<int size>
169struct Rel_data
170{
171 typename Elf_types<size>::Elf_Addr r_offset;
172 typename Elf_types<size>::Elf_WXword r_info;
173};
174
175template<int size>
176struct Rela_data
177{
178 typename Elf_types<size>::Elf_Addr r_offset;
179 typename Elf_types<size>::Elf_WXword r_info;
180 typename Elf_types<size>::Elf_Swxword r_addend;
181};
182
4d625b70
CC
183// MIPS-64 has a non-standard layout for relocations.
184
185struct Mips64_rel_data
186{
d1193add 187 Elf_types<64>::Elf_Addr r_offset;
4d625b70
CC
188 Elf_Word r_sym;
189 unsigned char r_ssym;
190 unsigned char r_type3;
191 unsigned char r_type2;
192 unsigned char r_type;
193};
194
195struct Mips64_rela_data
196{
d1193add 197 Elf_types<64>::Elf_Addr r_offset;
4d625b70
CC
198 Elf_Word r_sym;
199 unsigned char r_ssym;
200 unsigned char r_type3;
201 unsigned char r_type2;
202 unsigned char r_type;
f9498162 203 Elf_types<64>::Elf_Swxword r_addend;
4d625b70
CC
204};
205
dbe717ef
ILT
206// An entry in the ELF SHT_DYNAMIC section aka PT_DYNAMIC segment.
207
208template<int size>
209struct Dyn_data
210{
211 typename Elf_types<size>::Elf_Swxword d_tag;
212 typename Elf_types<size>::Elf_WXword d_val;
213};
214
215// An entry in a SHT_GNU_verdef section. This structure is the same
216// in 32-bit and 64-bit ELF files.
217
218struct Verdef_data
219{
220 // Version number of structure (VER_DEF_*).
221 Elf_Half vd_version;
222 // Bit flags (VER_FLG_*).
223 Elf_Half vd_flags;
224 // Version index.
225 Elf_Half vd_ndx;
226 // Number of auxiliary Verdaux entries.
227 Elf_Half vd_cnt;
228 // Hash of name.
229 Elf_Word vd_hash;
230 // Byte offset to first Verdaux entry.
231 Elf_Word vd_aux;
232 // Byte offset to next Verdef entry.
233 Elf_Word vd_next;
234};
235
236// An auxiliary entry in a SHT_GNU_verdef section. This structure is
237// the same in 32-bit and 64-bit ELF files.
238
239struct Verdaux_data
240{
241 // Offset in string table of version name.
242 Elf_Word vda_name;
243 // Byte offset to next Verdaux entry.
244 Elf_Word vda_next;
245};
246
247// An entry in a SHT_GNU_verneed section. This structure is the same
248// in 32-bit and 64-bit ELF files.
249
250struct Verneed_data
251{
252 // Version number of structure (VER_NEED_*).
253 Elf_Half vn_version;
254 // Number of auxiliary Vernaux entries.
255 Elf_Half vn_cnt;
256 // Offset in string table of library name.
257 Elf_Word vn_file;
258 // Byte offset to first Vernaux entry.
259 Elf_Word vn_aux;
260 // Byt eoffset to next Verneed entry.
261 Elf_Word vn_next;
262};
263
264// An auxiliary entry in a SHT_GNU_verneed section. This structure is
265// the same in 32-bit and 64-bit ELF files.
266
267struct Vernaux_data
268{
269 // Hash of dependency name.
270 Elf_Word vna_hash;
271 // Bit flags (VER_FLG_*).
272 Elf_Half vna_flags;
273 // Version index used in SHT_GNU_versym entries.
274 Elf_Half vna_other;
275 // Offset in string table of version name.
276 Elf_Word vna_name;
277 // Byte offset to next Vernaux entry.
278 Elf_Word vna_next;
279};
280
bae7f79e
ILT
281} // End namespace internal.
282
283} // End namespace elfcpp.
284
285#endif // !defined(ELFCPP_INTERNAL_H)