LCOV - code coverage report
Current view: top level - elfutils/libasm - asm_newabssym.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 17 33 51.5 %
Date: 2013-03-08 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 24 29.2 %

           Branch data     Line data    Source code
       1                 :            : /* Create new ABS 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_abs_scn =
      45                 :            :   {
      46                 :            :     .data = {
      47                 :            :       .main = {
      48                 :            :         .scn = ASM_ABS_SCN
      49                 :            :       }
      50                 :            :     }
      51                 :            :   };
      52                 :            : 
      53                 :            : 
      54                 :            : AsmSym_t *
      55                 :          1 : asm_newabssym (ctx, name, size, value, type, binding)
      56                 :            :      AsmCtx_t *ctx;
      57                 :            :      const char *name;
      58                 :            :      GElf_Xword size;
      59                 :            :      GElf_Addr value;
      60                 :            :      int type;
      61                 :            :      int binding;
      62                 :            : {
      63                 :            :   AsmSym_t *result;
      64                 :            : 
      65         [ +  - ]:          1 :   if (ctx == NULL)
      66                 :            :     /* Something went wrong before.  */
      67                 :            :     return NULL;
      68                 :            : 
      69                 :            :   /* Common symbols are public.  Therefore the user must provide a
      70                 :            :      name.  */
      71         [ -  + ]:          1 :   if (name == NULL)
      72                 :            :     {
      73                 :          0 :       __libasm_seterrno (ASM_E_INVALID);
      74                 :          0 :       return NULL;
      75                 :            :     }
      76                 :            : 
      77                 :            :   rwlock_wrlock (ctx->lock);
      78                 :            : 
      79                 :          1 :   result = (AsmSym_t *) malloc (sizeof (AsmSym_t));
      80         [ +  - ]:          1 :   if (result == NULL)
      81                 :            :     return NULL;
      82                 :            : 
      83                 :          1 :   result->scn = (AsmScn_t *) &__libasm_abs_scn;
      84                 :          1 :   result->size = size;
      85                 :          1 :   result->type = type;
      86                 :          1 :   result->binding = binding;
      87                 :          1 :   result->symidx = 0;
      88                 :          1 :   result->strent = ebl_strtabadd (ctx->symbol_strtab, name, 0);
      89                 :            : 
      90                 :            :   /* The value of an ABS symbol must not be modified.  Since there are
      91                 :            :      no subsection and the initial offset of the section is 0 we can
      92                 :            :      get the alignment recorded by storing it into the offset
      93                 :            :      field.  */
      94                 :          1 :   result->offset = value;
      95                 :            : 
      96         [ -  + ]:          1 :   if (unlikely (ctx->textp))
      97                 :            :     {
      98                 :            :       /* An absolute symbol can be defined by giving a symbol a
      99                 :            :          specific value.  */
     100         [ #  # ]:          0 :       if (binding == STB_GLOBAL)
     101                 :          0 :         fprintf (ctx->out.file, "\t.globl %s\n", name);
     102         [ #  # ]:          0 :       else if (binding == STB_WEAK)
     103                 :          0 :         fprintf (ctx->out.file, "\t.weak %s\n", name);
     104                 :            : 
     105         [ #  # ]:          0 :       if (type == STT_OBJECT)
     106                 :          0 :         fprintf (ctx->out.file, "\t.type %s,@object\n", name);
     107         [ #  # ]:          0 :       else if (type == STT_FUNC)
     108                 :          0 :         fprintf (ctx->out.file, "\t.type %s,@function\n", name);
     109                 :            : 
     110                 :          0 :       fprintf (ctx->out.file, "%s = %llu\n",
     111                 :            :                name, (unsigned long long int) value);
     112                 :            : 
     113         [ #  # ]:          0 :       if (size != 0)
     114                 :          0 :         fprintf (ctx->out.file, "\t.size %s, %llu\n",
     115                 :            :                  name, (unsigned long long int) size);
     116                 :            :     }
     117                 :            :   else
     118                 :            :     {
     119                 :            :       /* Put the symbol in the hash table so that we can later find it.  */
     120         [ -  + ]:          1 :       if (asm_symbol_tab_insert (&ctx->symbol_tab, elf_hash (name), result)
     121                 :            :           != 0)
     122                 :            :         {
     123                 :            :           /* The symbol already exists.  */
     124                 :          0 :           __libasm_seterrno (ASM_E_DUPLSYM);
     125                 :          0 :           free (result);
     126                 :          0 :           result = NULL;
     127                 :            :         }
     128 [ +  - ][ +  - ]:          1 :       else if (name != NULL && asm_emit_symbol_p (name))
     129                 :            :         /* Only count non-private symbols.  */
     130                 :          1 :         ++ctx->nsymbol_tab;
     131                 :            :     }
     132                 :            : 
     133                 :            :   rwlock_unlock (ctx->lock);
     134                 :            : 
     135                 :          1 :   return result;
     136                 :            : }

Generated by: LCOV version 1.9