Framework for relocation scanning. Implement simple static TLS
[deliverable/binutils-gdb.git] / elfcpp / elfcpp_internal.h
CommitLineData
bae7f79e
ILT
1// elfcpp_internal.h -- internals for elfcpp -*- C++ -*-
2
3// This is included by elfcpp.h, the external interface, but holds
4// information which we want to keep private.
5
6#include "elfcpp_config.h"
7
8#include <byteswap.h>
9
10#ifndef ELFCPP_INTERNAL_H
11#define ELFCPP_INTERNAL_H
12
13namespace elfcpp
14{
15
16namespace internal
17{
18
92e059d8 19#ifdef WORDS_BIGENDIAN
bae7f79e
ILT
20const bool host_big_endian = true;
21#else
22const bool host_big_endian = false;
23#endif
24
25// Conversion routines between target and host.
26
27// Convert Elf_Half.
28
29template<bool same_endian>
30Elf_Half
31convert_half_host(Elf_Half v);
32
33template<>
34inline Elf_Half
35convert_half_host<true>(Elf_Half v)
36{
37 return v;
38}
39
40template<>
41inline Elf_Half
42convert_half_host<false>(Elf_Half v)
43{
44 return bswap_16(v);
45}
46
47template<bool big_endian>
48inline Elf_Half
49convert_half(Elf_Half v)
50{
51 return convert_half_host<big_endian == host_big_endian>(v);
52}
53
54// Convert Elf_Word.
55
56template<bool same_endian>
57Elf_Word
58convert_word_host(Elf_Word v);
59
60template<>
61inline Elf_Word
62convert_word_host<true>(Elf_Word v)
63{
64 return v;
65}
66
67template<>
68inline Elf_Word
69convert_word_host<false>(Elf_Word v)
70{
71 return bswap_32(v);
72}
73
74template<bool big_endian>
75inline Elf_Word
76convert_word(Elf_Word v)
77{
78 return convert_word_host<big_endian == host_big_endian>(v);
79}
80
81// Convert Elf_Xword.
82
83template<bool same_endian>
84Elf_Xword
85convert_xword_host(Elf_Xword v);
86
87template<>
88inline Elf_Xword
89convert_xword_host<true>(Elf_Xword v)
90{
91 return v;
92}
93
94template<>
95inline Elf_Xword
96convert_xword_host<false>(Elf_Xword v)
97{
98 return bswap_64(v);
99}
100
101template<bool big_endian>
102inline Elf_Xword
103convert_xword(Elf_Xword v)
104{
105 return convert_xword_host<big_endian == host_big_endian>(v);
106}
107
108// Convert Elf_addr.
109
110template<int size, bool same_endian>
111typename Elf_types<size>::Elf_Addr
112convert_addr_size(typename Elf_types<size>::Elf_Addr);
113
114template<>
115inline Elf_types<32>::Elf_Addr
116convert_addr_size<32, true>(Elf_types<32>::Elf_Addr v)
117{
118 return v;
119}
120
121template<>
122inline Elf_types<64>::Elf_Addr
123convert_addr_size<64, true>(Elf_types<64>::Elf_Addr v)
124{
125 return v;
126}
127
128template<>
129inline Elf_types<32>::Elf_Addr
130convert_addr_size<32, false>(Elf_types<32>::Elf_Addr v)
131{
132 return bswap_32(v);
133}
134
135template<>
136inline Elf_types<64>::Elf_Addr
137convert_addr_size<64, false>(Elf_types<64>::Elf_Addr v)
138{
139 return bswap_64(v);
140}
141
142template<int size, bool big_endian>
143inline typename Elf_types<size>::Elf_Addr
144convert_addr(typename Elf_types<size>::Elf_Addr v)
145{
146 return convert_addr_size<size, big_endian == host_big_endian>(v);
147}
148
149// Convert Elf_Off.
150
151template<int size, bool big_endian>
152inline typename Elf_types<size>::Elf_Off
153convert_off(typename Elf_types<size>::Elf_Off v)
154{
155 return convert_addr_size<size, big_endian == host_big_endian>(v);
156}
157
158// Convert Elf_WXword.
159
160template<int size, bool big_endian>
61ba1cf9
ILT
161inline typename Elf_types<size>::Elf_WXword
162convert_wxword(typename Elf_types<size>::Elf_WXword v)
163{
164 return convert_addr_size<size, big_endian == host_big_endian>(v);
165}
166
167// Convert ELF_Swxword.
168
169template<int size, bool big_endian>
170inline typename Elf_types<size>::Elf_Swxword
171convert_swxword(typename Elf_types<size>::Elf_Swxword v)
bae7f79e
ILT
172{
173 return convert_addr_size<size, big_endian == host_big_endian>(v);
174}
175
176// The ELF file header.
177
178template<int size>
179struct Ehdr_data
180{
181 unsigned char e_ident[EI_NIDENT];
182 Elf_Half e_type;
183 Elf_Half e_machine;
184 Elf_Word e_version;
185 typename Elf_types<size>::Elf_Addr e_entry;
186 typename Elf_types<size>::Elf_Off e_phoff;
187 typename Elf_types<size>::Elf_Off e_shoff;
188 Elf_Word e_flags;
189 Elf_Half e_ehsize;
190 Elf_Half e_phentsize;
191 Elf_Half e_phnum;
192 Elf_Half e_shentsize;
193 Elf_Half e_shnum;
194 Elf_Half e_shstrndx;
195};
196
197// An Elf section header.
198
199template<int size>
200struct Shdr_data
201{
202 Elf_Word sh_name;
203 Elf_Word sh_type;
204 typename Elf_types<size>::Elf_WXword sh_flags;
205 typename Elf_types<size>::Elf_Addr sh_addr;
206 typename Elf_types<size>::Elf_Off sh_offset;
207 typename Elf_types<size>::Elf_WXword sh_size;
208 Elf_Word sh_link;
209 Elf_Word sh_info;
210 typename Elf_types<size>::Elf_WXword sh_addralign;
211 typename Elf_types<size>::Elf_WXword sh_entsize;
212};
213
39081c14
ILT
214// An ELF segment header. We use template specialization for the
215// 32-bit and 64-bit versions because the fields are in a different
216// order.
217
218template<int size>
219struct Phdr_data;
220
221template<>
222struct Phdr_data<32>
223{
224 Elf_Word p_type;
225 Elf_types<32>::Elf_Off p_offset;
226 Elf_types<32>::Elf_Addr p_vaddr;
227 Elf_types<32>::Elf_Addr p_paddr;
228 Elf_Word p_filesz;
229 Elf_Word p_memsz;
230 Elf_Word p_flags;
231 Elf_Word p_align;
232};
233
234template<>
235struct Phdr_data<64>
236{
237 Elf_Word p_type;
238 Elf_Word p_flags;
239 Elf_types<64>::Elf_Off p_offset;
240 Elf_types<64>::Elf_Addr p_vaddr;
241 Elf_types<64>::Elf_Addr p_paddr;
242 Elf_Xword p_filesz;
243 Elf_Xword p_memsz;
244 Elf_Xword p_align;
245};
246
bae7f79e
ILT
247// An ELF symbol table entry. We use template specialization for the
248// 32-bit and 64-bit versions because the fields are in a different
249// order.
250
251template<int size>
252struct Sym_data;
253
254template<>
255struct Sym_data<32>
256{
257 Elf_Word st_name;
258 Elf_types<32>::Elf_Addr st_value;
259 Elf_Word st_size;
260 unsigned char st_info;
261 unsigned char st_other;
262 Elf_Half st_shndx;
263};
264
265template<>
266struct Sym_data<64>
267{
268 Elf_Word st_name;
269 unsigned char st_info;
270 unsigned char st_other;
271 Elf_Half st_shndx;
272 Elf_types<64>::Elf_Addr st_value;
273 Elf_Xword st_size;
274};
275
61ba1cf9
ILT
276// Elf relocation table entries.
277
278template<int size>
279struct Rel_data
280{
281 typename Elf_types<size>::Elf_Addr r_offset;
282 typename Elf_types<size>::Elf_WXword r_info;
283};
284
285template<int size>
286struct Rela_data
287{
288 typename Elf_types<size>::Elf_Addr r_offset;
289 typename Elf_types<size>::Elf_WXword r_info;
290 typename Elf_types<size>::Elf_Swxword r_addend;
291};
292
bae7f79e
ILT
293} // End namespace internal.
294
295} // End namespace elfcpp.
296
297#endif // !defined(ELFCPP_INTERNAL_H)
This page took 0.042637 seconds and 4 git commands to generate.