LCOV - code coverage report
Current view: top level - libasm - asm_newscngrp.c (source / functions) Hit Total Coverage
Test: elfutils-0.192 Lines: 23 29 79.3 %
Date: 2024-11-08 23:03:42 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 14 57.1 %

           Branch data     Line data    Source code
       1                 :            : /* Create new section group.
       2                 :            :    Copyright (C) 2002, 2016 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 <assert.h>
      35                 :            : #include <stdlib.h>
      36                 :            : #include <string.h>
      37                 :            : 
      38                 :            : #include "libasmP.h"
      39                 :            : #include <system.h>
      40                 :            : 
      41                 :            : 
      42                 :            : 
      43                 :            : AsmScnGrp_t *
      44                 :      44000 : asm_newscngrp (AsmCtx_t *ctx, const char *grpname, AsmSym_t *signature,
      45                 :            :                Elf32_Word flags)
      46                 :            : {
      47                 :      44000 :   AsmScnGrp_t *result;
      48                 :      44000 :   size_t grpname_len = strlen (grpname) + 1;
      49                 :            : 
      50         [ -  + ]:      44000 :   if (ctx == NULL)
      51                 :            :     return NULL;
      52                 :            : 
      53         [ -  + ]:      44000 :   if ((flags & ~GRP_COMDAT) != 0)
      54                 :            :     {
      55                 :            :       /* This is not a supported flag.  */
      56                 :          0 :       __libasm_seterrno (ASM_E_INVALID);
      57                 :          0 :       return NULL;
      58                 :            :     }
      59                 :            : 
      60                 :      44000 :   result = malloc (sizeof (AsmScnGrp_t) + grpname_len);
      61         [ -  + ]:      44000 :   if (result == NULL)
      62                 :            :     return NULL;
      63                 :            : 
      64                 :      44000 :   result->signature = signature;
      65                 :      44000 :   result->members = NULL;
      66                 :      44000 :   result->nmembers = 0;
      67                 :      44000 :   result->flags = flags;
      68                 :            : 
      69                 :      44000 :   memcpy (result->name, grpname, grpname_len);
      70                 :      44000 :   result->strent = dwelf_strtab_add_len (ctx->section_strtab, result->name,
      71                 :            :                                          grpname_len);
      72                 :            : 
      73         [ -  + ]:      44000 :   if (unlikely (ctx->textp))
      74                 :            :     // XXX TBI.  What is the format?
      75                 :          0 :     abort ();
      76                 :            :   else
      77                 :            :     {
      78                 :      44000 :       result->scn = elf_newscn (ctx->out.elf);
      79         [ -  + ]:      44000 :       if (result->scn == NULL)
      80                 :            :         {
      81                 :            :           /* Couldn't allocate a new section.  */
      82                 :          0 :           __libasm_seterrno (ASM_E_LIBELF);
      83                 :          0 :           free (result);
      84                 :          0 :           return NULL;
      85                 :            :         }
      86                 :            :     }
      87                 :            : 
      88                 :            :   /* Enqueue is the context data structure.  */
      89         [ +  + ]:      44000 :   if (ctx->ngroups == 0)
      90                 :            :     {
      91         [ -  + ]:          2 :       assert (ctx->groups == NULL);
      92                 :          2 :       ctx->groups = result->next = result;
      93                 :            :     }
      94                 :            :   else
      95                 :            :     {
      96                 :      43998 :       result->next = ctx->groups->next;
      97                 :      43998 :       ctx->groups = ctx->groups->next = result;
      98                 :            :     }
      99                 :      44000 :   ++ctx->ngroups;
     100                 :            : 
     101                 :      44000 :   return result;
     102                 :            : }

Generated by: LCOV version 1.16