Line data Source code
1 : /* Conversion functions for versioning information.
2 : Copyright (C) 2006, 2007 Red Hat, Inc.
3 : This file is part of elfutils.
4 : Written by Ulrich Drepper <drepper@redhat.com>, 2006.
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 : #include <assert.h>
31 : #include <gelf.h>
32 :
33 : #include "libelfP.h"
34 :
35 :
36 : static void
37 41 : elf_cvt_gnuhash (void *dest, const void *src, size_t len, int encode)
38 : {
39 : /* The GNU hash table format on 64 bit machines mixes 32 bit and 64 bit
40 : words. We must detangle them here. */
41 41 : Elf32_Word *dest32 = dest;
42 41 : const Elf32_Word *src32 = src;
43 :
44 : /* First four control words, 32 bits. */
45 205 : for (unsigned int cnt = 0; cnt < 4; ++cnt)
46 : {
47 164 : if (len < 4)
48 : return;
49 164 : dest32[cnt] = bswap_32 (src32[cnt]);
50 164 : len -= 4;
51 : }
52 :
53 41 : Elf32_Word bitmask_words = encode ? src32[2] : dest32[2];
54 :
55 : /* Now the 64 bit words. */
56 41 : Elf64_Xword *dest64 = (Elf64_Xword *) &dest32[4];
57 41 : const Elf64_Xword *src64 = (const Elf64_Xword *) &src32[4];
58 82 : for (unsigned int cnt = 0; cnt < bitmask_words; ++cnt)
59 : {
60 41 : if (len < 8)
61 : return;
62 41 : dest64[cnt] = bswap_64 (src64[cnt]);
63 41 : len -= 8;
64 : }
65 :
66 : /* The rest are 32 bit words again. */
67 41 : src32 = (const Elf32_Word *) &src64[bitmask_words];
68 41 : dest32 = (Elf32_Word *) &dest64[bitmask_words];
69 93 : while (len >= 4)
70 : {
71 52 : *dest32++ = bswap_32 (*src32++);
72 52 : len -= 4;
73 : }
74 : }
|