2 * Copyright (c) 2006,2008 Joseph Koshy
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
33 /* WARNING: GENERATED FROM __file__. */
36 * Create an array of file sizes from the elf_type definitions
40 include(SRCDIR`/elf_types.m4')
43 * Translations from structure definitions to the size of their file
48 define(`BYTE_SIZE', 1)
49 define(`IDENT_SIZE', `EI_NIDENT')
51 /* Types that have variable length. */
52 define(`GNUHASH_SIZE', 1)
53 define(`NOTE_SIZE', 1)
55 /* Currently unimplemented types. */
56 define(`MOVEP_SIZE', 0)
58 /* Overrides for 32 bit types that do not exist. */
59 define(`XWORD_SIZE32', 0)
60 define(`SXWORD_SIZE32', 0)
63 * FSZ{32,64} define the sizes of 32 and 64 bit file structures respectively.
66 define(`FSZ32',`_FSZ32($1_DEF)')
69 `_BSZ32($1)+_FSZ32(shift($@))')')
70 define(`_BSZ32',`$2_SIZE32')
72 define(`FSZ64',`_FSZ64($1_DEF)')
75 `_BSZ64($1)+_FSZ64(shift($@))')')
76 define(`_BSZ64',`$2_SIZE64')
79 * DEFINE_ELF_FSIZES(TYPE,NAME)
81 * Shorthand for defining for 32 and 64 versions
84 * If TYPE`'_SIZE is defined, use its value for both 32 bit and 64 bit
87 * Otherwise, look for a explicit 32/64 bit size definition for TYPE,
88 * TYPE`'_SIZE32 or TYPE`'_SIZE64. If this definition is present, there
89 * is nothing further to do.
91 * Otherwise, if an Elf{32,64}_`'NAME structure definition is known,
92 * compute an expression that adds up the sizes of the structure's
95 * If such a structure definition is not known, treat TYPE as a primitive
96 * (i.e., integral) type and use sizeof(Elf{32,64}_`'NAME) to get its
97 * file representation size.
100 define(`DEFINE_ELF_FSIZE',
102 `define($1_SIZE32,$1_SIZE)
103 define($1_SIZE64,$1_SIZE)',
104 `ifdef($1`_SIZE32',`',
105 `ifdef(`Elf32_'$2`_DEF',
106 `define($1_SIZE32,FSZ32(Elf32_$2))',
107 `define($1_SIZE32,`sizeof(Elf32_'$2`)')')')
108 ifdef($1`_SIZE64',`',
109 `ifdef(`Elf64_'$2`_DEF',
110 `define($1_SIZE64,FSZ64(Elf64_$2))',
111 `define($1_SIZE64,`sizeof(Elf64_'$2`)')')')')')
113 define(`DEFINE_ELF_FSIZES',
115 `DEFINE_ELF_FSIZE($1)
116 DEFINE_ELF_FSIZES(shift($@))')')
118 DEFINE_ELF_FSIZES(ELF_TYPE_LIST)
119 DEFINE_ELF_FSIZE(`IDENT',`') # `IDENT' is a pseudo type
122 `[ELF_T_$1] = { .fsz32 = $1_SIZE32, .fsz64 = $1_SIZE64 },
127 FSIZES(shift($@))')')
136 static struct fsize fsize[ELF_T_NUM] = {
137 FSIZES(ELF_TYPE_LIST)
141 _libelf_fsize(Elf_Type t, int ec, unsigned int v, size_t c)
147 LIBELF_SET_ERROR(VERSION, 0);
148 else if ((int) t < ELF_T_FIRST || t > ELF_T_LAST)
149 LIBELF_SET_ERROR(ARGUMENT, 0);
151 sz = ec == ELFCLASS64 ? fsize[t].fsz64 : fsize[t].fsz32;
153 LIBELF_SET_ERROR(UNIMPL, 0);