1/*-
2 * Copyright (c) 2006 Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: src/lib/libelf/elf_types.m4,v 1.2 2006/12/18 05:40:01 jkoshy Exp $
27 */
28
29/*
30 * ELF types, defined in the "enum Elf_Type" API.
31 *
32 * The members of the list form a 3-tuple: (name, C-type-suffix, OSversion).
33 * + `name' is an Elf_Type symbol without the `ELF_T_' prefix.
34 * + `C-type-suffix' is the suffix for Elf32_ and Elf64_ type names.
35 * + `version' is the OS version the symbol first appeared in.
36 *
37 */
38
39define(`ELF_TYPE_LIST',
40	``ADDR,		Addr,	600102',
41	`BYTE,		Byte,	600102',
42	`CAP,		Cap,	700025',
43	`DYN,		Dyn,	600102',
44	`EHDR,		Ehdr,	600102',
45	`HALF,		Half,	600102',
46	`LWORD,		Lword,	700025',
47	`MOVE,		Move,	700025',
48	`MOVEP,		MoveP,	700025',
49	`NOTE,		Note,	600102',
50	`OFF,		Off,	600102',
51	`PHDR,		Phdr,	600102',
52	`REL,		Rel,	600102',
53	`RELA,		Rela,	600102',
54	`SHDR,		Shdr,	600102',
55	`SWORD,		Sword,	600102',
56	`SXWORD,	Sxword,	700009',
57	`SYMINFO,	Syminfo, 700025',
58	`SYM,		Sym,	600102',
59	`VDEF,		Verdef,	700009',
60	`VNEED,		Verneed, 700009',
61	`WORD,		Word,	600102',
62	`XWORD,		Xword,	700009',
63	`NUM,		_,	_'')
64
65/*
66 * DEFINE_STRUCT(NAME,MEMBERLIST...)
67 *
68 * Map a type name to its members.
69 *
70 * Each member-list element comprises of pairs of (field name, type),
71 * in the sequence used in the file representation of `NAME'.
72 *
73 * Each member list element comprises a pair containing a field name
74 * and a basic type.  Basic types include IDENT, HALF, WORD, LWORD,
75 * ADDR{32,64}, OFF{32,64}, SWORD, XWORD, SXWORD.
76 *
77 * The last element of a member list is the null element: `_,_'.
78 */
79
80define(`DEFINE_STRUCT',`define(`$1_DEF',shift($@))dnl')
81
82DEFINE_STRUCT(`Elf32_Cap',
83	``c_tag,	WORD',
84	`c_un.c_val,	WORD',
85	`_,_'')
86
87DEFINE_STRUCT(`Elf64_Cap',
88	``c_tag,	XWORD',
89	`c_un.c_val,	XWORD',
90	`_,_'')
91
92DEFINE_STRUCT(`Elf32_Dyn',
93	``d_tag,	SWORD',
94	`d_un.d_ptr,	WORD',
95	`_,_'')
96
97DEFINE_STRUCT(`Elf64_Dyn',
98	``d_tag,	SXWORD',
99	`d_un.d_ptr,	XWORD',
100	`_,_'')
101
102DEFINE_STRUCT(`Elf32_Ehdr',
103	``e_ident,	IDENT',
104	`e_type, 	HALF',
105	`e_machine,	HALF',
106	`e_version,	WORD',
107	`e_entry,	ADDR',
108	`e_phoff,	OFF',
109	`e_shoff,	OFF',
110	`e_flags,	WORD',
111	`e_ehsize,	HALF',
112	`e_phentsize,	HALF',
113	`e_phnum,	HALF',
114	`e_shentsize,	HALF',
115	`e_shnum,	HALF',
116	`e_shstrndx,	HALF',
117	`_,_'')
118
119DEFINE_STRUCT(`Elf64_Ehdr',
120	``e_ident,	IDENT',
121	`e_type, 	HALF',
122	`e_machine,	HALF',
123	`e_version,	WORD',
124	`e_entry,	ADDR',
125	`e_phoff,	OFF',
126	`e_shoff,	OFF',
127	`e_flags,	WORD',
128	`e_ehsize,	HALF',
129	`e_phentsize,	HALF',
130	`e_phnum,	HALF',
131	`e_shentsize,	HALF',
132	`e_shnum,	HALF',
133	`e_shstrndx,	HALF',
134	`_,_'')
135
136DEFINE_STRUCT(`Elf32_Move',
137	``m_value,	LWORD',
138	`m_info,	WORD',
139	`m_poffset,	WORD',
140	`m_repeat,	HALF',
141	`m_stride,	HALF',
142	`_,_'')
143
144DEFINE_STRUCT(`Elf64_Move',
145	``m_value,	LWORD',
146	`m_info,	XWORD',
147	`m_poffset,	XWORD',
148	`m_repeat,	HALF',
149	`m_stride,	HALF',
150	`_,_'')
151
152DEFINE_STRUCT(`Elf32_Phdr',
153	``p_type,	WORD',
154	`p_offset,	OFF',
155	`p_vaddr,	ADDR',
156	`p_paddr,	ADDR',
157	`p_filesz,	WORD',
158	`p_memsz,	WORD',
159	`p_flags,	WORD',
160	`p_align,	WORD',
161	`_,_'')
162
163DEFINE_STRUCT(`Elf64_Phdr',
164	``p_type,	WORD',
165	`p_flags,	WORD',
166	`p_offset,	OFF',
167	`p_vaddr,	ADDR',
168	`p_paddr,	ADDR',
169	`p_filesz,	XWORD',
170	`p_memsz,	XWORD',
171	`p_align,	XWORD',
172	`_,_'')
173
174DEFINE_STRUCT(`Elf32_Rel',
175	``r_offset,	ADDR',
176	`r_info,	WORD',
177	`_,_'')
178
179DEFINE_STRUCT(`Elf64_Rel',
180	``r_offset,	ADDR',
181	`r_info,	XWORD',
182	`_,_'')
183
184DEFINE_STRUCT(`Elf32_Rela',
185	``r_offset,	ADDR',
186	`r_info,	WORD',
187	`r_addend,	SWORD',
188	`_,_'')
189
190DEFINE_STRUCT(`Elf64_Rela',
191	``r_offset,	ADDR',
192	`r_info,	XWORD',
193	`r_addend,	SXWORD',
194	`_,_'')
195
196DEFINE_STRUCT(`Elf32_Shdr',
197	``sh_name,	WORD',
198	`sh_type,	WORD',
199	`sh_flags,	WORD',
200	`sh_addr,	ADDR',
201	`sh_offset,	OFF',
202	`sh_size,	WORD',
203	`sh_link,	WORD',
204	`sh_info,	WORD',
205	`sh_addralign,	WORD',
206	`sh_entsize,	WORD',
207	`_,_'')
208
209DEFINE_STRUCT(`Elf64_Shdr',
210	``sh_name,	WORD',
211	`sh_type,	WORD',
212	`sh_flags,	XWORD',
213	`sh_addr,	ADDR',
214	`sh_offset,	OFF',
215	`sh_size,	XWORD',
216	`sh_link,	WORD',
217	`sh_info,	WORD',
218	`sh_addralign,	XWORD',
219	`sh_entsize,	XWORD',
220	`_,_'')
221
222DEFINE_STRUCT(`Elf32_Sym',
223	``st_name,	WORD',
224	`st_value,	ADDR',
225	`st_size,	WORD',
226	`st_info,	BYTE',
227	`st_other,	BYTE',
228	`st_shndx,	HALF',
229	`_,_'')
230
231DEFINE_STRUCT(`Elf64_Sym',
232	``st_name,	WORD',
233	`st_info,	BYTE',
234	`st_other,	BYTE',
235	`st_shndx,	HALF',
236	`st_value,	ADDR',
237	`st_size,	XWORD',
238	`_,_'')
239
240DEFINE_STRUCT(`Elf32_Syminfo',
241	``si_boundto,	HALF',
242	`si_flags,	HALF',
243	`_,_'')
244
245DEFINE_STRUCT(`Elf64_Syminfo',
246	``si_boundto,	HALF',
247	`si_flags,	HALF',
248	`_,_'')
249
250DEFINE_STRUCT(`Elf32_Verdaux',
251	``vda_name,	WORD',
252	`vda_next,	WORD',
253	`_,_'')
254
255DEFINE_STRUCT(`Elf64_Verdaux',
256	``vda_name,	WORD',
257	`vda_next,	WORD',
258	`_,_'')
259
260DEFINE_STRUCT(`Elf32_Verdef',
261	``vd_version,	HALF',
262	`vd_flags,	HALF',
263	`vd_ndx,	HALF',
264	`vd_cnt,	HALF',
265	`vd_hash,	WORD',
266	`vd_aux,	WORD',
267	`vd_next,	WORD',
268	`_,_'')
269
270DEFINE_STRUCT(`Elf64_Verdef',
271	``vd_version,	HALF',
272	`vd_flags,	HALF',
273	`vd_ndx,	HALF',
274	`vd_cnt,	HALF',
275	`vd_hash,	WORD',
276	`vd_aux,	WORD',
277	`vd_next,	WORD',
278	`_,_'')
279
280DEFINE_STRUCT(`Elf32_Verneed',
281	``vn_version,	HALF',
282	`vn_cnt,	HALF',
283	`vn_file,	WORD',
284	`vn_aux,	WORD',
285	`vn_next,	WORD',
286	`_,_'')
287
288DEFINE_STRUCT(`Elf64_Verneed',
289	``vn_version,	HALF',
290	`vn_cnt,	HALF',
291	`vn_file,	WORD',
292	`vn_aux,	WORD',
293	`vn_next,	WORD',
294	`_,_'')
295
296DEFINE_STRUCT(`Elf32_Vernaux',
297	``vna_hash,	WORD',
298	`vna_flags,	HALF',
299	`vna_other,	HALF',
300	`vna_name,	WORD',
301	`vna_next,	WORD',
302	`_,_'')
303
304DEFINE_STRUCT(`Elf64_Vernaux',
305	``vna_hash,	WORD',
306	`vna_flags,	HALF',
307	`vna_other,	HALF',
308	`vna_name,	WORD',
309	`vna_next,	WORD',
310	`_,_'')
311