LCOV - code coverage report
Current view: top level - elfutils/libelf - gelf_fsize.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 5 9 55.6 %
Date: 2012-10-31 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* Return the size of an object file type.
       2                 :            :    Copyright (C) 1998-2010 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 1998.
       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                 :            : #ifdef HAVE_CONFIG_H
      31                 :            : # include <config.h>
      32                 :            : #endif
      33                 :            : 
      34                 :            : #include <gelf.h>
      35                 :            : #include <stddef.h>
      36                 :            : 
      37                 :            : #include "libelfP.h"
      38                 :            : 
      39                 :            : 
      40                 :            : /* These are the sizes for all the known types.  */
      41                 :            : const size_t __libelf_type_sizes[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] =
      42                 :            : {
      43                 :            :   /* We have no entry for EV_NONE since we have to set an error.  */
      44                 :            :   [EV_CURRENT - 1] = {
      45                 :            :     [ELFCLASS32 - 1] = {
      46                 :            : #define TYPE_SIZES(LIBELFBITS) \
      47                 :            :       [ELF_T_ADDR]      = ELFW2(LIBELFBITS, FSZ_ADDR),                        \
      48                 :            :       [ELF_T_OFF]       = ELFW2(LIBELFBITS, FSZ_OFF),                         \
      49                 :            :       [ELF_T_BYTE]      = 1,                                                  \
      50                 :            :       [ELF_T_HALF]      = ELFW2(LIBELFBITS, FSZ_HALF),                        \
      51                 :            :       [ELF_T_WORD]      = ELFW2(LIBELFBITS, FSZ_WORD),                        \
      52                 :            :       [ELF_T_SWORD]     = ELFW2(LIBELFBITS, FSZ_SWORD),                       \
      53                 :            :       [ELF_T_XWORD]     = ELFW2(LIBELFBITS, FSZ_XWORD),                       \
      54                 :            :       [ELF_T_SXWORD]    = ELFW2(LIBELFBITS, FSZ_SXWORD),                      \
      55                 :            :       [ELF_T_EHDR]      = sizeof (ElfW2(LIBELFBITS, Ext_Ehdr)),               \
      56                 :            :       [ELF_T_SHDR]      = sizeof (ElfW2(LIBELFBITS, Ext_Shdr)),               \
      57                 :            :       [ELF_T_SYM]       = sizeof (ElfW2(LIBELFBITS, Ext_Sym)),                \
      58                 :            :       [ELF_T_REL]       = sizeof (ElfW2(LIBELFBITS, Ext_Rel)),                \
      59                 :            :       [ELF_T_RELA]      = sizeof (ElfW2(LIBELFBITS, Ext_Rela)),               \
      60                 :            :       [ELF_T_PHDR]      = sizeof (ElfW2(LIBELFBITS, Ext_Phdr)),               \
      61                 :            :       [ELF_T_DYN]       = sizeof (ElfW2(LIBELFBITS, Ext_Dyn)),                \
      62                 :            :       [ELF_T_VDEF]      = sizeof (ElfW2(LIBELFBITS, Ext_Verdef)),             \
      63                 :            :       [ELF_T_VDAUX]     = sizeof (ElfW2(LIBELFBITS, Ext_Verdaux)),            \
      64                 :            :       [ELF_T_VNEED]     = sizeof (ElfW2(LIBELFBITS, Ext_Verneed)),            \
      65                 :            :       [ELF_T_VNAUX]     = sizeof (ElfW2(LIBELFBITS, Ext_Vernaux)),            \
      66                 :            :       [ELF_T_NHDR]      = sizeof (ElfW2(LIBELFBITS, Ext_Nhdr)),               \
      67                 :            :       [ELF_T_SYMINFO]   = sizeof (ElfW2(LIBELFBITS, Ext_Syminfo)),            \
      68                 :            :       [ELF_T_MOVE]      = sizeof (ElfW2(LIBELFBITS, Ext_Move)),               \
      69                 :            :       [ELF_T_LIB]       = sizeof (ElfW2(LIBELFBITS, Ext_Lib)),                \
      70                 :            :       [ELF_T_AUXV]      = sizeof (ElfW2(LIBELFBITS, Ext_auxv_t)),             \
      71                 :            :       [ELF_T_GNUHASH]   = ELFW2(LIBELFBITS, FSZ_WORD)
      72                 :            :       TYPE_SIZES (32)
      73                 :            :     },
      74                 :            :     [ELFCLASS64 - 1] = {
      75                 :            :       TYPE_SIZES (64)
      76                 :            :     }
      77                 :            :   }
      78                 :            : };
      79                 :            : 
      80                 :            : 
      81                 :            : size_t
      82                 :      30217 : gelf_fsize (elf, type, count, version)
      83                 :            :      Elf *elf;
      84                 :            :      Elf_Type type;
      85                 :            :      size_t count;
      86                 :            :      unsigned int version;
      87                 :            : {
      88                 :            :   /* We do not have differences between file and memory sizes.  Better
      89                 :            :      not since otherwise `mmap' would not work.  */
      90         [ +  - ]:      30217 :   if (elf == NULL)
      91                 :            :     return 0;
      92                 :            : 
      93         [ -  + ]:      30217 :   if (version == EV_NONE || version >= EV_NUM)
      94                 :            :     {
      95                 :          0 :       __libelf_seterrno (ELF_E_UNKNOWN_VERSION);
      96                 :          0 :       return 0;
      97                 :            :     }
      98                 :            : 
      99         [ -  + ]:      30217 :   if (type >= ELF_T_NUM)
     100                 :            :     {
     101                 :          0 :       __libelf_seterrno (ELF_E_UNKNOWN_TYPE);
     102                 :          0 :       return 0;
     103                 :            :     }
     104                 :            : 
     105                 :            : #if EV_NUM != 2
     106                 :            :   return count * __libelf_type_sizes[version - 1][elf->class - 1][type];
     107                 :            : #else
     108                 :      30217 :   return count * __libelf_type_sizes[0][elf->class - 1][type];
     109                 :            : #endif
     110                 :            : }
     111                 :            : INTDEF(gelf_fsize)

Generated by: LCOV version 1.9