Home | History | Annotate | Download | only in libasm
      1 /* Create new section group.
      2    Copyright (C) 2002 Red Hat, Inc.
      3    This file is part of elfutils.
      4    Written by Ulrich Drepper <drepper (at) 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 asm_newscngrp (ctx, grpname, signature, flags)
     45      AsmCtx_t *ctx;
     46      const char *grpname;
     47      AsmSym_t *signature;
     48      Elf32_Word flags;
     49 {
     50   AsmScnGrp_t *result;
     51   size_t grpname_len = strlen (grpname) + 1;
     52 
     53   if (ctx == NULL)
     54     return NULL;
     55 
     56   if ((flags & ~GRP_COMDAT) != 0)
     57     {
     58       /* This is not a supported flag.  */
     59       __libasm_seterrno (ASM_E_INVALID);
     60       return NULL;
     61     }
     62 
     63   result = (AsmScnGrp_t *) malloc (sizeof (AsmScnGrp_t) + grpname_len);
     64   if (result == NULL)
     65     return NULL;
     66 
     67   result->signature = signature;
     68   result->members = NULL;
     69   result->nmembers = 0;
     70   result->flags = flags;
     71 
     72   memcpy (result->name, grpname, grpname_len);
     73   result->strent = ebl_strtabadd (ctx->section_strtab, result->name,
     74 				  grpname_len);
     75 
     76   if (unlikely (ctx->textp))
     77     // XXX TBI.  What is the format?
     78     abort ();
     79   else
     80     {
     81       result->scn = elf_newscn (ctx->out.elf);
     82       if (result->scn == NULL)
     83 	{
     84 	  /* Couldn't allocate a new section.  */
     85 	  __libasm_seterrno (ASM_E_LIBELF);
     86 	  free (result);
     87 	  return NULL;
     88 	}
     89     }
     90 
     91   /* Enqueue is the context data structure.  */
     92   if (ctx->ngroups == 0)
     93     {
     94       assert (ctx->groups == NULL);
     95       ctx->groups = result->next = result;
     96     }
     97   else
     98     {
     99       result->next = ctx->groups->next;
    100       ctx->groups = ctx->groups->next = result;
    101     }
    102   ++ctx->ngroups;
    103 
    104   return result;
    105 }
    106