Add chdr_size, Chdr, Chdr_write and Chdr_data
[external/binutils.git] / elfcpp / elfcpp_internal.h
1 // elfcpp_internal.h -- internals for elfcpp   -*- C++ -*-
2
3 // Copyright (C) 2006-2015 Free Software Foundation, Inc.
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
32 // This is included by elfcpp.h, the external interface, but holds
33 // information which we want to keep private.
34
35 #ifndef ELFCPP_INTERNAL_H
36 #define ELFCPP_INTERNAL_H
37
38 namespace elfcpp
39 {
40
41 namespace internal
42 {
43
44 // The ELF file header.
45
46 template<int size>
47 struct 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
65 // An ELF section header.
66
67 template<int size>
68 struct 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
82 // An ELF compression header.
83
84 template<int size>
85 struct Chdr_data
86 {
87   typename Elf_types<size>::Elf_WXword ch_type;
88   typename Elf_types<size>::Elf_WXword ch_size;
89   typename Elf_types<size>::Elf_WXword ch_addralign;
90 };
91
92 // An ELF segment header.  We use template specialization for the
93 // 32-bit and 64-bit versions because the fields are in a different
94 // order.
95
96 template<int size>
97 struct Phdr_data;
98
99 template<>
100 struct Phdr_data<32>
101 {
102   Elf_Word p_type;
103   Elf_types<32>::Elf_Off p_offset;
104   Elf_types<32>::Elf_Addr p_vaddr;
105   Elf_types<32>::Elf_Addr p_paddr;
106   Elf_Word p_filesz;
107   Elf_Word p_memsz;
108   Elf_Word p_flags;
109   Elf_Word p_align;
110 };
111
112 template<>
113 struct Phdr_data<64>
114 {
115   Elf_Word p_type;
116   Elf_Word p_flags;
117   Elf_types<64>::Elf_Off p_offset;
118   Elf_types<64>::Elf_Addr p_vaddr;
119   Elf_types<64>::Elf_Addr p_paddr;
120   Elf_Xword p_filesz;
121   Elf_Xword p_memsz;
122   Elf_Xword p_align;
123 };
124
125 // An ELF symbol table entry.  We use template specialization for the
126 // 32-bit and 64-bit versions because the fields are in a different
127 // order.
128
129 template<int size>
130 struct Sym_data;
131
132 template<>
133 struct Sym_data<32>
134 {
135   Elf_Word st_name;
136   Elf_types<32>::Elf_Addr st_value;
137   Elf_Word st_size;
138   unsigned char st_info;
139   unsigned char st_other;
140   Elf_Half st_shndx;
141 };
142
143 template<>
144 struct Sym_data<64>
145 {
146   Elf_Word st_name;
147   unsigned char st_info;
148   unsigned char st_other;
149   Elf_Half st_shndx;
150   Elf_types<64>::Elf_Addr st_value;
151   Elf_Xword st_size;
152 };
153
154 // ELF relocation table entries.
155
156 template<int size>
157 struct Rel_data
158 {
159   typename Elf_types<size>::Elf_Addr r_offset;
160   typename Elf_types<size>::Elf_WXword r_info;
161 };
162
163 template<int size>
164 struct Rela_data
165 {
166   typename Elf_types<size>::Elf_Addr r_offset;
167   typename Elf_types<size>::Elf_WXword r_info;
168   typename Elf_types<size>::Elf_Swxword r_addend;
169 };
170
171 // An entry in the ELF SHT_DYNAMIC section aka PT_DYNAMIC segment.
172
173 template<int size>
174 struct Dyn_data
175 {
176   typename Elf_types<size>::Elf_Swxword d_tag;
177   typename Elf_types<size>::Elf_WXword d_val;
178 };
179
180 // An entry in a SHT_GNU_verdef section.  This structure is the same
181 // in 32-bit and 64-bit ELF files.
182
183 struct Verdef_data
184 {
185   // Version number of structure (VER_DEF_*).
186   Elf_Half vd_version;
187   // Bit flags (VER_FLG_*).
188   Elf_Half vd_flags;
189   // Version index.
190   Elf_Half vd_ndx;
191   // Number of auxiliary Verdaux entries.
192   Elf_Half vd_cnt;
193   // Hash of name.
194   Elf_Word vd_hash;
195   // Byte offset to first Verdaux entry.
196   Elf_Word vd_aux;
197   // Byte offset to next Verdef entry.
198   Elf_Word vd_next;
199 };
200
201 // An auxiliary entry in a SHT_GNU_verdef section.  This structure is
202 // the same in 32-bit and 64-bit ELF files.
203
204 struct Verdaux_data
205 {
206   // Offset in string table of version name.
207   Elf_Word vda_name;
208   // Byte offset to next Verdaux entry.
209   Elf_Word vda_next;
210 };
211
212 // An entry in a SHT_GNU_verneed section.  This structure is the same
213 // in 32-bit and 64-bit ELF files.
214
215 struct Verneed_data
216 {
217   // Version number of structure (VER_NEED_*).
218   Elf_Half vn_version;
219   // Number of auxiliary Vernaux entries.
220   Elf_Half vn_cnt;
221   // Offset in string table of library name.
222   Elf_Word vn_file;
223   // Byte offset to first Vernaux entry.
224   Elf_Word vn_aux;
225   // Byt eoffset to next Verneed entry.
226   Elf_Word vn_next;
227 };
228
229 // An auxiliary entry in a SHT_GNU_verneed section.  This structure is
230 // the same in 32-bit and 64-bit ELF files.
231
232 struct Vernaux_data
233 {
234   // Hash of dependency name.
235   Elf_Word vna_hash;
236   // Bit flags (VER_FLG_*).
237   Elf_Half vna_flags;
238   // Version index used in SHT_GNU_versym entries.
239   Elf_Half vna_other;
240   // Offset in string table of version name.
241   Elf_Word vna_name;
242   // Byte offset to next Vernaux entry.
243   Elf_Word vna_next;
244 };
245
246 } // End namespace internal.
247
248 } // End namespace elfcpp.
249
250 #endif // !defined(ELFCPP_INTERNAL_H)