Home | History | Annotate | Download | only in libelf
      1 /* Conversion functions for versioning information.
      2    Copyright (C) 2006, 2007 Red Hat, Inc.
      3    This file is part of Red Hat elfutils.
      4    Written by Ulrich Drepper <drepper (at) redhat.com>, 2006.
      5 
      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.
      9 
     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.
     14 
     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.
     18 
     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.
     42 
     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>.  */
     50 
     51 #include <assert.h>
     52 #include <gelf.h>
     53 
     54 #include "libelfP.h"
     55 
     56 
     57 static void
     58 elf_cvt_gnuhash (void *dest, const void *src, size_t len, int encode)
     59 {
     60   /* The GNU hash table format on 64 bit machines mixes 32 bit and 64 bit
     61      words.  We must detangle them here.   */
     62   Elf32_Word *dest32 = dest;
     63   const Elf32_Word *src32 = src;
     64 
     65   /* First four control words, 32 bits.  */
     66   for (unsigned int cnt = 0; cnt < 4; ++cnt)
     67     {
     68       if (len < 4)
     69 	return;
     70       dest32[cnt] = bswap_32 (src32[cnt]);
     71       len -= 4;
     72     }
     73 
     74   Elf32_Word bitmask_words = encode ? src32[2] : dest32[2];
     75 
     76   /* Now the 64 bit words.  */
     77   Elf64_Xword *dest64 = (Elf64_Xword *) &dest32[4];
     78   const Elf64_Xword *src64 = (const Elf64_Xword *) &src32[4];
     79   for (unsigned int cnt = 0; cnt < bitmask_words; ++cnt)
     80     {
     81       if (len < 8)
     82 	return;
     83       dest64[cnt] = bswap_64 (src64[cnt]);
     84       len -= 8;
     85     }
     86 
     87   /* The rest are 32 bit words again.  */
     88   src32 = (const Elf32_Word *) &src64[bitmask_words];
     89   dest32 = (Elf32_Word *) &dest64[bitmask_words];
     90   while (len >= 4)
     91     {
     92       *dest32++ = bswap_32 (*src32++);
     93       len -= 4;
     94     }
     95 }
     96