* gdb.texinfo (Source Path): Add documentation for new
[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
19#ifdef WORDS_BIG_ENDIAN
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>
161inline typename Elf_types<size>::Elf_Off
162convert_wxword(typename Elf_types<size>::Elf_Off v)
163{
164 return convert_addr_size<size, big_endian == host_big_endian>(v);
165}
166
167// The ELF file header.
168
169template<int size>
170struct Ehdr_data
171{
172 unsigned char e_ident[EI_NIDENT];
173 Elf_Half e_type;
174 Elf_Half e_machine;
175 Elf_Word e_version;
176 typename Elf_types<size>::Elf_Addr e_entry;
177 typename Elf_types<size>::Elf_Off e_phoff;
178 typename Elf_types<size>::Elf_Off e_shoff;
179 Elf_Word e_flags;
180 Elf_Half e_ehsize;
181 Elf_Half e_phentsize;
182 Elf_Half e_phnum;
183 Elf_Half e_shentsize;
184 Elf_Half e_shnum;
185 Elf_Half e_shstrndx;
186};
187
188// An Elf section header.
189
190template<int size>
191struct Shdr_data
192{
193 Elf_Word sh_name;
194 Elf_Word sh_type;
195 typename Elf_types<size>::Elf_WXword sh_flags;
196 typename Elf_types<size>::Elf_Addr sh_addr;
197 typename Elf_types<size>::Elf_Off sh_offset;
198 typename Elf_types<size>::Elf_WXword sh_size;
199 Elf_Word sh_link;
200 Elf_Word sh_info;
201 typename Elf_types<size>::Elf_WXword sh_addralign;
202 typename Elf_types<size>::Elf_WXword sh_entsize;
203};
204
205// An ELF symbol table entry. We use template specialization for the
206// 32-bit and 64-bit versions because the fields are in a different
207// order.
208
209template<int size>
210struct Sym_data;
211
212template<>
213struct Sym_data<32>
214{
215 Elf_Word st_name;
216 Elf_types<32>::Elf_Addr st_value;
217 Elf_Word st_size;
218 unsigned char st_info;
219 unsigned char st_other;
220 Elf_Half st_shndx;
221};
222
223template<>
224struct Sym_data<64>
225{
226 Elf_Word st_name;
227 unsigned char st_info;
228 unsigned char st_other;
229 Elf_Half st_shndx;
230 Elf_types<64>::Elf_Addr st_value;
231 Elf_Xword st_size;
232};
233
234} // End namespace internal.
235
236} // End namespace elfcpp.
237
238#endif // !defined(ELFCPP_INTERNAL_H)
This page took 0.039997 seconds and 4 git commands to generate.