1 /* Conversion functions for versioning information.
2 Copyright (C) 1998, 1999, 2000, 2002, 2003 Red Hat, Inc.
3 This file is part of Red Hat elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 1998.
6 Red Hat elfutils is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by the
8 Free Software Foundation; version 2 of the License.
10 Red Hat elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with Red Hat elfutils; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
19 In addition, as a special exception, Red Hat, Inc. gives You the
20 additional right to link the code of Red Hat elfutils with code licensed
21 under any Open Source Initiative certified open source license
22 (http://www.opensource.org/licenses/index.php) which requires the
23 distribution of source code with any binary distribution and to
24 distribute linked combinations of the two. Non-GPL Code permitted under
25 this exception must only link to the code of Red Hat elfutils through
26 those well defined interfaces identified in the file named EXCEPTION
27 found in the source code files (the "Approved Interfaces"). The files
28 of Non-GPL Code may instantiate templates or use macros or inline
29 functions from the Approved Interfaces without causing the resulting
30 work to be covered by the GNU General Public License. Only Red Hat,
31 Inc. may make changes or additions to the list of Approved Interfaces.
32 Red Hat's grant of this exception is conditioned upon your not adding
33 any new exceptions. If you wish to add a new Approved Interface or
34 exception, please contact Red Hat. You must obey the GNU General Public
35 License in all respects for all of the Red Hat elfutils code and other
36 code used in conjunction with Red Hat elfutils except the Non-GPL Code
37 covered by this exception. If you modify this file, you may extend this
38 exception to your version of the file, but you are not obligated to do
39 so. If you do not wish to provide this exception without modification,
40 you must delete this exception statement from your version and license
41 this file solely under the GPL without exception.
43 Red Hat elfutils is an included package of the Open Invention Network.
44 An included package of the Open Invention Network is a package for which
45 Open Invention Network licensees cross-license their patents. No patent
46 license is granted, either expressly or impliedly, by designation as an
47 included package. Should you wish to participate in the Open Invention
48 Network licensing program, please visit www.openinventionnetwork.com
49 <http://www.openinventionnetwork.com>. */
58 elf_cvt_Verdef (void *dest, const void *src, size_t len, int encode)
60 /* We have two different record types: ElfXX_Verndef and ElfXX_Verdaux.
61 To recognize them we have to walk the data structure and convert
62 them one after the other. The ENCODE parameter specifies whether
63 we are encoding or decoding. When we are encoding we can immediately
64 use the data in the buffer; if not, we have to decode the data before
66 size_t def_offset = 0;
70 /* We rely on the types being all the same size. */
71 assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
72 assert (sizeof (GElf_Verdaux) == sizeof (Elf32_Verdaux));
73 assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
74 assert (sizeof (GElf_Verdaux) == sizeof (Elf64_Verdaux));
84 /* Test for correct offset. */
85 if (def_offset + sizeof (GElf_Verdef) > len)
88 /* Work the tree from the first record. */
89 ddest = (GElf_Verdef *) ((char *) dest + def_offset);
90 dsrc = (GElf_Verdef *) ((char *) src + def_offset);
92 /* Decode first if necessary. */
95 ddest->vd_version = bswap_16 (dsrc->vd_version);
96 ddest->vd_flags = bswap_16 (dsrc->vd_flags);
97 ddest->vd_ndx = bswap_16 (dsrc->vd_ndx);
98 ddest->vd_cnt = bswap_16 (dsrc->vd_cnt);
99 ddest->vd_hash = bswap_32 (dsrc->vd_hash);
100 ddest->vd_aux = bswap_32 (dsrc->vd_aux);
101 ddest->vd_next = bswap_32 (dsrc->vd_next);
103 aux_offset = def_offset + ddest->vd_aux;
106 aux_offset = def_offset + dsrc->vd_aux;
108 /* Handle all the auxiliary records belonging to this definition. */
113 /* Test for correct offset. */
114 if (aux_offset + sizeof (GElf_Verdaux) > len)
117 adest = (GElf_Verdaux *) ((char *) dest + aux_offset);
118 asrc = (GElf_Verdaux *) ((char *) src + aux_offset);
121 aux_offset += asrc->vda_next;
123 adest->vda_name = bswap_32 (asrc->vda_name);
124 adest->vda_next = bswap_32 (asrc->vda_next);
127 aux_offset += adest->vda_next;
129 while (asrc->vda_next != 0);
131 /* Encode now if necessary. */
134 def_offset += dsrc->vd_next;
136 ddest->vd_version = bswap_16 (dsrc->vd_version);
137 ddest->vd_flags = bswap_16 (dsrc->vd_flags);
138 ddest->vd_ndx = bswap_16 (dsrc->vd_ndx);
139 ddest->vd_cnt = bswap_16 (dsrc->vd_cnt);
140 ddest->vd_hash = bswap_32 (dsrc->vd_hash);
141 ddest->vd_aux = bswap_32 (dsrc->vd_aux);
142 ddest->vd_next = bswap_32 (dsrc->vd_next);
145 def_offset += ddest->vd_next;
147 while (dsrc->vd_next != 0);
152 elf_cvt_Verneed (void *dest, const void *src, size_t len, int encode)
154 /* We have two different record types: ElfXX_Verndef and ElfXX_Verdaux.
155 To recognize them we have to walk the data structure and convert
156 them one after the other. The ENCODE parameter specifies whether
157 we are encoding or decoding. When we are encoding we can immediately
158 use the data in the buffer; if not, we have to decode the data before
160 size_t need_offset = 0;
164 /* We rely on the types being all the same size. */
165 assert (sizeof (GElf_Verneed) == sizeof (Elf32_Verneed));
166 assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
167 assert (sizeof (GElf_Verneed) == sizeof (Elf64_Verneed));
168 assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
178 /* Test for correct offset. */
179 if (need_offset + sizeof (GElf_Verneed) > len)
182 /* Work the tree from the first record. */
183 ndest = (GElf_Verneed *) ((char *) dest + need_offset);
184 nsrc = (GElf_Verneed *) ((char *) src + need_offset);
186 /* Decode first if necessary. */
189 ndest->vn_version = bswap_16 (nsrc->vn_version);
190 ndest->vn_cnt = bswap_16 (nsrc->vn_cnt);
191 ndest->vn_file = bswap_32 (nsrc->vn_file);
192 ndest->vn_aux = bswap_32 (nsrc->vn_aux);
193 ndest->vn_next = bswap_32 (nsrc->vn_next);
195 aux_offset = need_offset + ndest->vn_aux;
198 aux_offset = need_offset + nsrc->vn_aux;
200 /* Handle all the auxiliary records belonging to this requirement. */
205 /* Test for correct offset. */
206 if (aux_offset + sizeof (GElf_Vernaux) > len)
209 adest = (GElf_Vernaux *) ((char *) dest + aux_offset);
210 asrc = (GElf_Vernaux *) ((char *) src + aux_offset);
213 aux_offset += asrc->vna_next;
215 adest->vna_hash = bswap_32 (asrc->vna_hash);
216 adest->vna_flags = bswap_16 (asrc->vna_flags);
217 adest->vna_other = bswap_16 (asrc->vna_other);
218 adest->vna_name = bswap_32 (asrc->vna_name);
219 adest->vna_next = bswap_32 (asrc->vna_next);
222 aux_offset += adest->vna_next;
224 while (asrc->vna_next != 0);
226 /* Encode now if necessary. */
229 need_offset += nsrc->vn_next;
231 ndest->vn_version = bswap_16 (nsrc->vn_version);
232 ndest->vn_cnt = bswap_16 (nsrc->vn_cnt);
233 ndest->vn_file = bswap_32 (nsrc->vn_file);
234 ndest->vn_aux = bswap_32 (nsrc->vn_aux);
235 ndest->vn_next = bswap_32 (nsrc->vn_next);
238 need_offset += ndest->vn_next;
240 while (nsrc->vn_next != 0);