LCOV - code coverage report
Current view: top level - elfutils/libasm - asm_newcomsym.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 17 23 73.9 %
Date: 2012-10-31 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 14 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* Create new COMMON symbol.
       2                 :            :    Copyright (C) 2002 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
       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 <inttypes.h>
      35                 :            : #include <stdio.h>
      36                 :            : #include <stdlib.h>
      37                 :            : #include <string.h>
      38                 :            : 
      39                 :            : #include <libasmP.h>
      40                 :            : #include <system.h>
      41                 :            : 
      42                 :            : 
      43                 :            : /* Object for special COMMON section.  */
      44                 :            : static const AsmScn_t __libasm_com_scn =
      45                 :            :   {
      46                 :            :     .data = {
      47                 :            :       .main = {
      48                 :            :         .scn = ASM_COM_SCN
      49                 :            :       }
      50                 :            :     }
      51                 :            :   };
      52                 :            : 
      53                 :            : 
      54                 :            : AsmSym_t *
      55                 :          1 : asm_newcomsym (ctx, name, size, align)
      56                 :            :      AsmCtx_t *ctx;
      57                 :            :      const char *name;
      58                 :            :      GElf_Xword size;
      59                 :            :      GElf_Addr align;
      60                 :            : {
      61                 :            :   AsmSym_t *result;
      62                 :            : 
      63         [ +  - ]:          1 :   if (ctx == NULL)
      64                 :            :     /* Something went wrong before.  */
      65                 :            :     return NULL;
      66                 :            : 
      67                 :            :   /* Common symbols are public.  Therefore the user must provide a
      68                 :            :      name.  */
      69         [ -  + ]:          1 :   if (name == NULL)
      70                 :            :     {
      71                 :          0 :       __libasm_seterrno (ASM_E_INVALID);
      72                 :          0 :       return NULL;
      73                 :            :     }
      74                 :            : 
      75                 :            :   rwlock_wrlock (ctx->lock);
      76                 :            : 
      77                 :          1 :   result = (AsmSym_t *) malloc (sizeof (AsmSym_t));
      78         [ +  - ]:          1 :   if (result == NULL)
      79                 :            :     return NULL;
      80                 :            : 
      81                 :          1 :   result->scn = (AsmScn_t *) &__libasm_com_scn;
      82                 :          1 :   result->size = size;
      83                 :            :   /* XXX Do we have to allow a different type?  */
      84                 :          1 :   result->type = STT_OBJECT;
      85                 :            :   /* XXX Do we have to allow a different binding?  */
      86                 :          1 :   result->binding = STB_GLOBAL;
      87                 :          1 :   result->symidx = 0;
      88                 :          1 :   result->strent = ebl_strtabadd (ctx->symbol_strtab, name, 0);
      89                 :            : 
      90                 :            :   /* The value of a COM symbol is the alignment.  Since there are no
      91                 :            :      subsection and the initial offset of the section is 0 we can get
      92                 :            :      the alignment recorded by storing it into the offset field.  */
      93                 :          1 :   result->offset = align;
      94                 :            : 
      95         [ -  + ]:          1 :   if (unlikely (ctx->textp))
      96                 :          0 :     fprintf (ctx->out.file, "\t.comm %s, %" PRIuMAX ", %" PRIuMAX "\n",
      97                 :            :              name, (uintmax_t) size, (uintmax_t) align);
      98                 :            :   else
      99                 :            :     {
     100                 :            :       /* Put the symbol in the hash table so that we can later find it.  */
     101         [ -  + ]:          1 :       if (asm_symbol_tab_insert (&ctx->symbol_tab, elf_hash (name), result)
     102                 :            :           != 0)
     103                 :            :         {
     104                 :            :           /* The symbol already exists.  */
     105                 :          0 :           __libasm_seterrno (ASM_E_DUPLSYM);
     106                 :          0 :           free (result);
     107                 :          0 :           result = NULL;
     108                 :            :         }
     109 [ +  - ][ +  - ]:          1 :       else if (name != NULL && asm_emit_symbol_p (name))
     110                 :            :         /* Only count non-private symbols.  */
     111                 :          1 :         ++ctx->nsymbol_tab;
     112                 :            :     }
     113                 :            : 
     114                 :            :   rwlock_unlock (ctx->lock);
     115                 :            : 
     116                 :          1 :   return result;
     117                 :            : }

Generated by: LCOV version 1.9