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