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 Red Hat elfutils.
      4    Written by Ulrich Drepper <drepper (at) redhat.com>, 2002.
      5 
      6    Red Hat elfutils is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by the
      8    Free Software Foundation; version 2 of the License.
      9 
     10    Red Hat elfutils is distributed in the hope that it will be useful, but
     11    WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13    General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License along
     16    with Red Hat elfutils; if not, write to the Free Software Foundation,
     17    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
     18 
     19    Red Hat elfutils is an included package of the Open Invention Network.
     20    An included package of the Open Invention Network is a package for which
     21    Open Invention Network licensees cross-license their patents.  No patent
     22    license is granted, either expressly or impliedly, by designation as an
     23    included package.  Should you wish to participate in the Open Invention
     24    Network licensing program, please visit www.openinventionnetwork.com
     25    <http://www.openinventionnetwork.com>.  */
     26 
     27 #ifdef HAVE_CONFIG_H
     28 # include <config.h>
     29 #endif
     30 
     31 #include <assert.h>
     32 #include <stdlib.h>
     33 #include <string.h>
     34 
     35 #include "libasmP.h"
     36 #include <system.h>
     37 
     38 
     39 
     40 AsmScnGrp_t *
     41 asm_newscngrp (ctx, grpname, signature, flags)
     42      AsmCtx_t *ctx;
     43      const char *grpname;
     44      AsmSym_t *signature;
     45      Elf32_Word flags;
     46 {
     47   AsmScnGrp_t *result;
     48   size_t grpname_len = strlen (grpname) + 1;
     49 
     50   if (ctx == NULL)
     51     return NULL;
     52 
     53   if ((flags & ~GRP_COMDAT) != 0)
     54     {
     55       /* This is not a supported flag.  */
     56       __libasm_seterrno (ASM_E_INVALID);
     57       return NULL;
     58     }
     59 
     60   result = (AsmScnGrp_t *) malloc (sizeof (AsmScnGrp_t) + grpname_len);
     61   if (result == NULL)
     62     return NULL;
     63 
     64   result->signature = signature;
     65   result->members = NULL;
     66   result->nmembers = 0;
     67   result->flags = flags;
     68 
     69   memcpy (result->name, grpname, grpname_len);
     70   result->strent = ebl_strtabadd (ctx->section_strtab, result->name,
     71 				  grpname_len);
     72 
     73   if (unlikely (ctx->textp))
     74     // XXX TBI.  What is the format?
     75     abort ();
     76   else
     77     {
     78       result->scn = elf_newscn (ctx->out.elf);
     79       if (result->scn == NULL)
     80 	{
     81 	  /* Couldn't allocate a new section.  */
     82 	  __libasm_seterrno (ASM_E_LIBELF);
     83 	  free (result);
     84 	  return NULL;
     85 	}
     86     }
     87 
     88   /* Enqueue is the context data structure.  */
     89   if (ctx->ngroups == 0)
     90     {
     91       assert (ctx->groups == NULL);
     92       ctx->groups = result->next = result;
     93     }
     94   else
     95     {
     96       result->next = ctx->groups->next;
     97       ctx->groups = ctx->groups->next = result;
     98     }
     99   ++ctx->ngroups;
    100 
    101   return result;
    102 }
    103