• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Abstract description of component ELF types.
2    Copyright (C) 1998, 1999, 2000, 2002, 2004, 2007, 2015 Red Hat, Inc.
3    This file is part of elfutils.
4    Written by Ulrich Drepper <drepper@redhat.com>, 1998.
5 
6    This file is free software; you can redistribute it and/or modify
7    it under the terms of either
8 
9      * the GNU Lesser General Public License as published by the Free
10        Software Foundation; either version 3 of the License, or (at
11        your option) any later version
12 
13    or
14 
15      * the GNU General Public License as published by the Free
16        Software Foundation; either version 2 of the License, or (at
17        your option) any later version
18 
19    or both in parallel, as here.
20 
21    elfutils is distributed in the hope that it will be useful, but
22    WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24    General Public License for more details.
25 
26    You should have received copies of the GNU General Public License and
27    the GNU Lesser General Public License along with this program.  If
28    not, see <http://www.gnu.org/licenses/>.  */
29 
30 /* ELF header.  */
31 #define Ehdr(Bits, Ext) \
32 START (Bits, Ehdr, Ext##Ehdr)						      \
33   TYPE_EXTRA (unsigned char e_ident[EI_NIDENT];)			      \
34   TYPE_XLATE (memmove (tdest->e_ident, tsrc->e_ident, EI_NIDENT);)	      \
35   TYPE_NAME (ElfW2(Bits, Ext##Half), e_type)				      \
36   TYPE_NAME (ElfW2(Bits, Ext##Half), e_machine)				      \
37   TYPE_NAME (ElfW2(Bits, Ext##Word), e_version)				      \
38   TYPE_NAME (ElfW2(Bits, Ext##Addr), e_entry)				      \
39   TYPE_NAME (ElfW2(Bits, Ext##Off), e_phoff)				      \
40   TYPE_NAME (ElfW2(Bits, Ext##Off), e_shoff)				      \
41   TYPE_NAME (ElfW2(Bits, Ext##Word), e_flags)				      \
42   TYPE_NAME (ElfW2(Bits, Ext##Half), e_ehsize)				      \
43   TYPE_NAME (ElfW2(Bits, Ext##Half), e_phentsize)			      \
44   TYPE_NAME (ElfW2(Bits, Ext##Half), e_phnum)				      \
45   TYPE_NAME (ElfW2(Bits, Ext##Half), e_shentsize)			      \
46   TYPE_NAME (ElfW2(Bits, Ext##Half), e_shnum)				      \
47   TYPE_NAME (ElfW2(Bits, Ext##Half), e_shstrndx)			      \
48 END (Bits, Ext##Ehdr)
49 
50 #define Ehdr32(Ext) \
51   Ehdr(32, Ext)
52 #define Ehdr64(Ext) \
53   Ehdr(64, Ext)
54 
55 
56 /* Program header.  */
57 #define Phdr32(Ext) \
58 START (32, Phdr, Ext##Phdr)						      \
59   TYPE_NAME (ElfW2(32, Ext##Word), p_type)				      \
60   TYPE_NAME (ElfW2(32, Ext##Off), p_offset)				      \
61   TYPE_NAME (ElfW2(32, Ext##Addr), p_vaddr)				      \
62   TYPE_NAME (ElfW2(32, Ext##Addr), p_paddr)				      \
63   TYPE_NAME (ElfW2(32, Ext##Word), p_filesz)				      \
64   TYPE_NAME (ElfW2(32, Ext##Word), p_memsz)				      \
65   TYPE_NAME (ElfW2(32, Ext##Word), p_flags)				      \
66   TYPE_NAME (ElfW2(32, Ext##Word), p_align)				      \
67 END (32, Ext##Phdr)
68 #define Phdr64(Ext) \
69 START (64, Phdr, Ext##Phdr)						      \
70   TYPE_NAME (ElfW2(64, Ext##Word), p_type)				      \
71   TYPE_NAME (ElfW2(64, Ext##Word), p_flags)				      \
72   TYPE_NAME (ElfW2(64, Ext##Off), p_offset)				      \
73   TYPE_NAME (ElfW2(64, Ext##Addr), p_vaddr)				      \
74   TYPE_NAME (ElfW2(64, Ext##Addr), p_paddr)				      \
75   TYPE_NAME (ElfW2(64, Ext##Xword), p_filesz)				      \
76   TYPE_NAME (ElfW2(64, Ext##Xword), p_memsz)				      \
77   TYPE_NAME (ElfW2(64, Ext##Xword), p_align)				      \
78 END (64, Ext##Phdr)
79 
80 
81 /* Section header.  */
82 #define Shdr32(Ext) \
83 START (32, Shdr, Ext##Shdr)						      \
84   TYPE_NAME (ElfW2(32, Ext##Word), sh_name)				      \
85   TYPE_NAME (ElfW2(32, Ext##Word), sh_type)				      \
86   TYPE_NAME (ElfW2(32, Ext##Word), sh_flags)				      \
87   TYPE_NAME (ElfW2(32, Ext##Addr), sh_addr)				      \
88   TYPE_NAME (ElfW2(32, Ext##Off), sh_offset)				      \
89   TYPE_NAME (ElfW2(32, Ext##Word), sh_size)				      \
90   TYPE_NAME (ElfW2(32, Ext##Word), sh_link)				      \
91   TYPE_NAME (ElfW2(32, Ext##Word), sh_info)				      \
92   TYPE_NAME (ElfW2(32, Ext##Word), sh_addralign)			      \
93   TYPE_NAME (ElfW2(32, Ext##Word), sh_entsize)				      \
94 END (32, Ext##Shdr)
95 #define Shdr64(Ext) \
96 START (64, Shdr, Ext##Shdr)						      \
97   TYPE_NAME (ElfW2(64, Ext##Word), sh_name)				      \
98   TYPE_NAME (ElfW2(64, Ext##Word), sh_type)				      \
99   TYPE_NAME (ElfW2(64, Ext##Xword), sh_flags)				      \
100   TYPE_NAME (ElfW2(64, Ext##Addr), sh_addr)				      \
101   TYPE_NAME (ElfW2(64, Ext##Off), sh_offset)				      \
102   TYPE_NAME (ElfW2(64, Ext##Xword), sh_size)				      \
103   TYPE_NAME (ElfW2(64, Ext##Word), sh_link)				      \
104   TYPE_NAME (ElfW2(64, Ext##Word), sh_info)				      \
105   TYPE_NAME (ElfW2(64, Ext##Xword), sh_addralign)			      \
106   TYPE_NAME (ElfW2(64, Ext##Xword), sh_entsize)				      \
107 END (64, Ext##Shdr)
108 
109 
110 /* Symbol table.  */
111 #define Sym32(Ext) \
112 START (32, Sym, Ext##Sym)						      \
113   TYPE_NAME (ElfW2(32, Ext##Word), st_name)				      \
114   TYPE_NAME (ElfW2(32, Ext##Addr), st_value)				      \
115   TYPE_NAME (ElfW2(32, Ext##Word), st_size)				      \
116   TYPE_EXTRA (unsigned char st_info;)					      \
117   TYPE_XLATE (tdest->st_info = tsrc->st_info;)				      \
118   TYPE_EXTRA (unsigned char st_other;)					      \
119   TYPE_XLATE (tdest->st_other = tsrc->st_other;)			      \
120   TYPE_NAME (ElfW2(32, Ext##Half), st_shndx)				      \
121 END (32, Ext##Sym)
122 #define Sym64(Ext) \
123 START (64, Sym, Ext##Sym)						      \
124   TYPE_NAME (ElfW2(64, Ext##Word), st_name)				      \
125   TYPE_EXTRA (unsigned char st_info;)					      \
126   TYPE_XLATE (tdest->st_info = tsrc->st_info;)				      \
127   TYPE_EXTRA (unsigned char st_other;)					      \
128   TYPE_XLATE (tdest->st_other = tsrc->st_other;)			      \
129   TYPE_NAME (ElfW2(64, Ext##Half), st_shndx)				      \
130   TYPE_NAME (ElfW2(64, Ext##Addr), st_value)				      \
131   TYPE_NAME (ElfW2(64, Ext##Xword), st_size)				      \
132 END (64, Ext##Sym)
133 
134 
135 /* Relocation.  */
136 #define Rel32(Ext) \
137 START (32, Rel, Ext##Rel)						      \
138   TYPE_NAME (ElfW2(32, Ext##Addr), r_offset)				      \
139   TYPE_NAME (ElfW2(32, Ext##Word), r_info)				      \
140 END (32, Ext##Rel)
141 #define Rel64(Ext) \
142 START (64, Rel, Ext##Rel)						      \
143   TYPE_NAME (ElfW2(64, Ext##Addr), r_offset)				      \
144   TYPE_NAME (ElfW2(64, Ext##Xword), r_info)				      \
145 END (64, Ext##Rel)
146 
147 #define Rela32(Ext) \
148 START (32, Rela, Ext##Rela)						      \
149   TYPE_NAME (ElfW2(32, Ext##Addr), r_offset)				      \
150   TYPE_NAME (ElfW2(32, Ext##Word), r_info)				      \
151   TYPE_NAME (ElfW2(32, Ext##Sword), r_addend)				      \
152 END (32, Ext##Rela)
153 #define Rela64(Ext) \
154 START (64, Rela, Ext##Rela)						      \
155   TYPE_NAME (ElfW2(64, Ext##Addr), r_offset)				      \
156   TYPE_NAME (ElfW2(64, Ext##Xword), r_info)				      \
157   TYPE_NAME (ElfW2(64, Ext##Sxword), r_addend)				      \
158 END (64, Ext##Rela)
159 
160 
161 /* Note entry header.  */
162 #define Note(Bits, Ext) \
163 START (Bits, Nhdr, Ext##Nhdr)						      \
164   TYPE_NAME (ElfW2(Bits, Ext##Word), n_namesz)				      \
165   TYPE_NAME (ElfW2(Bits, Ext##Word), n_descsz)				      \
166   TYPE_NAME (ElfW2(Bits, Ext##Word), n_type)				      \
167 END (Bits, Ext##Nhdr)
168 
169 #define Note32(Ext) \
170   Note (32, Ext)
171 #define Note64(Ext) \
172   Note (64, Ext)
173 
174 
175 /* Dynamic section data.  */
176 #define Dyn32(Ext) \
177 START (32, Dyn, Ext##Dyn)						      \
178   TYPE_NAME (ElfW2(32, Ext##Sword), d_tag)				      \
179   TYPE_EXTRA (union {)							      \
180   TYPE_EXTRA (ElfW2(32, Ext##Word) d_val;)				      \
181   TYPE_EXTRA (ElfW2(32, Ext##Addr) d_ptr;)				      \
182   TYPE_XLATE (Elf32_cvt_Addr1 (&tdest->d_un.d_val, &tsrc->d_un.d_val);)	      \
183   TYPE_EXTRA (ElfW2(32, Ext##Off) d_off;)				      \
184   TYPE_EXTRA (} d_un;)							      \
185 END (32, Ext##Dyn)
186 #define Dyn64(Ext) \
187 START (64, Dyn, Ext##Dyn)						      \
188   TYPE_NAME (ElfW2(64, Ext##Xword), d_tag)				      \
189   TYPE_EXTRA (union {)							      \
190   TYPE_EXTRA (ElfW2(64, Ext##Xword) d_val;)				      \
191   TYPE_EXTRA (ElfW2(64, Ext##Addr) d_ptr;)				      \
192   TYPE_XLATE (Elf64_cvt_Addr1 (&tdest->d_un.d_val, &tsrc->d_un.d_val);)	      \
193   TYPE_EXTRA (} d_un;)							      \
194 END (64, Ext##Dyn)
195 
196 
197 #ifndef GENERATE_CONVERSION
198 /* Version definitions.  */
199 # define Verdef(Bits, Ext) \
200 START (Bits, Verdef, Ext##Verdef)					      \
201   TYPE_NAME (ElfW2(Bits, Ext##Half), vd_version)			      \
202   TYPE_NAME (ElfW2(Bits, Ext##Half), vd_flags)				      \
203   TYPE_NAME (ElfW2(Bits, Ext##Half), vd_ndx)				      \
204   TYPE_NAME (ElfW2(Bits, Ext##Half), vd_cnt)				      \
205   TYPE_NAME (ElfW2(Bits, Ext##Word), vd_hash)				      \
206   TYPE_NAME (ElfW2(Bits, Ext##Word), vd_aux)				      \
207   TYPE_NAME (ElfW2(Bits, Ext##Word), vd_next)				      \
208 END (Bits, Ext##Verdef)
209 
210 # define Verdef32(Ext) \
211   Verdef (32, Ext)
212 # define Verdef64(Ext) \
213   Verdef (64, Ext)
214 
215 # define Verdaux(Bits, Ext) \
216 START (Bits, Verdaux, Ext##Verdaux)					      \
217   TYPE_NAME (ElfW2(Bits, Ext##Word), vda_name)				      \
218   TYPE_NAME (ElfW2(Bits, Ext##Word), vda_next)				      \
219 END (Bits, Ext##Verdaux)
220 
221 # define Verdaux32(Ext) \
222   Verdaux (32, Ext)
223 # define Verdaux64(Ext) \
224   Verdaux (64, Ext)
225 
226 /* Required versions.  */
227 # define Verneed(Bits, Ext) \
228 START (Bits, Verneed, Ext##Verneed)					      \
229   TYPE_NAME (ElfW2(Bits, Ext##Half), vn_version)			      \
230   TYPE_NAME (ElfW2(Bits, Ext##Half), vn_cnt)				      \
231   TYPE_NAME (ElfW2(Bits, Ext##Word), vn_file)				      \
232   TYPE_NAME (ElfW2(Bits, Ext##Word), vn_aux)				      \
233   TYPE_NAME (ElfW2(Bits, Ext##Word), vn_next)				      \
234 END (Bits, Ext##Verneed)
235 
236 # define Verneed32(Ext) \
237   Verneed (32, Ext)
238 # define Verneed64(Ext) \
239   Verneed (64, Ext)
240 
241 # define Vernaux(Bits, Ext) \
242 START (Bits, Vernaux, Ext##Vernaux)					      \
243   TYPE_NAME (ElfW2(Bits, Ext##Word), vna_hash)				      \
244   TYPE_NAME (ElfW2(Bits, Ext##Half), vna_flags)				      \
245   TYPE_NAME (ElfW2(Bits, Ext##Half), vna_other)				      \
246   TYPE_NAME (ElfW2(Bits, Ext##Word), vna_name)				      \
247   TYPE_NAME (ElfW2(Bits, Ext##Word), vna_next)				      \
248 END (Bits, Ext##Vernaux)
249 
250 # define Vernaux32(Ext) \
251   Vernaux (32, Ext)
252 # define Vernaux64(Ext) \
253   Vernaux (64, Ext)
254 #endif
255 
256 /* Symbol information.  */
257 #define Syminfo(Bits, Ext) \
258 START (Bits, Syminfo, Ext##Syminfo)					      \
259   TYPE_NAME (ElfW2(Bits, Ext##Half), si_boundto)			      \
260   TYPE_NAME (ElfW2(Bits, Ext##Half), si_flags)				      \
261 END (Bits, Ext##Syminfo)
262 
263 #define Syminfo32(Ext) \
264   Syminfo (32, Ext)
265 #define Syminfo64(Ext) \
266   Syminfo (64, Ext)
267 
268 /* Move information.  */
269 #define Move(Bits, Ext) \
270 START (Bits, Move, Ext##Move)						      \
271   TYPE_NAME (ElfW2(Bits, Ext##Xword), m_value)				      \
272   TYPE_NAME (ElfW2(Bits, Ext##Xword), m_info)				      \
273   TYPE_NAME (ElfW2(Bits, Ext##Xword), m_poffset)			      \
274   TYPE_NAME (ElfW2(Bits, Ext##Half), m_repeat)				      \
275   TYPE_NAME (ElfW2(Bits, Ext##Half), m_stride)				      \
276 END (Bits, Ext##Move)
277 
278 #define Move32(Ext) \
279   Move (32, Ext)
280 #define Move64(Ext) \
281   Move (64, Ext)
282 
283 #define Lib(Bits, Ext) \
284 START (Bits, Lib, Ext##Lib)						      \
285   TYPE_NAME (ElfW2(Bits, Ext##Word), l_name)				      \
286   TYPE_NAME (ElfW2(Bits, Ext##Word), l_time_stamp)			      \
287   TYPE_NAME (ElfW2(Bits, Ext##Word), l_checksum)			      \
288   TYPE_NAME (ElfW2(Bits, Ext##Word), l_version)				      \
289   TYPE_NAME (ElfW2(Bits, Ext##Word), l_flags)				      \
290 END (Bits, Ext##Lib)
291 
292 #define Lib32(Ext) \
293   Lib (32, Ext)
294 #define Lib64(Ext) \
295   Lib (64, Ext)
296 
297 #define auxv_t32(Ext) \
298 START (32, auxv_t, Ext##auxv_t)						      \
299   TYPE_NAME (ElfW2(32, Ext##Word), a_type)				      \
300   TYPE_EXTRA (union {)							      \
301   TYPE_EXTRA (ElfW2(32, Ext##Word) a_val;)				      \
302   TYPE_XLATE (Elf32_cvt_Addr1 (&tdest->a_un.a_val, &tsrc->a_un.a_val);)	      \
303   TYPE_EXTRA (} a_un;)							      \
304 END (32, Ext##auxv_t)
305 #define auxv_t64(Ext) \
306 START (64, auxv_t, Ext##auxv_t)						      \
307   TYPE_NAME (ElfW2(64, Ext##Xword), a_type)				      \
308   TYPE_EXTRA (union {)							      \
309   TYPE_EXTRA (ElfW2(64, Ext##Xword) a_val;)				      \
310   TYPE_XLATE (Elf64_cvt_Addr1 (&tdest->a_un.a_val, &tsrc->a_un.a_val);)	      \
311   TYPE_EXTRA (} a_un;)							      \
312 END (64, Ext##auxv_t)
313 
314 /* Note that there is actual compression data right after the Chdr.
315    So we also have a separate conversion function for the whole
316    section.  */
317 #define Chdr32(Ext) \
318 START (32, Chdr, Ext##Chdr)						\
319   TYPE_NAME (ElfW2(32, Ext##Word), ch_type)				\
320   TYPE_NAME (ElfW2(32, Ext##Word), ch_size)				\
321   TYPE_NAME (ElfW2(32, Ext##Word), ch_addralign)			\
322 END (32, Ext##Chdr)
323 
324 #define Chdr64(Ext) \
325 START (64, Chdr, Ext##Chdr)						\
326   TYPE_NAME (ElfW2(64, Ext##Word), ch_type)				\
327   TYPE_NAME (ElfW2(64, Ext##Word), ch_reserved)				\
328   TYPE_NAME (ElfW2(64, Ext##Xword), ch_size)				\
329   TYPE_NAME (ElfW2(64, Ext##Xword), ch_addralign)			\
330 END (64, Ext##Chdr)
331