Blame libasm/asm_newscngrp.c

Packit 032894
/* Create new section group.
Packit 032894
   Copyright (C) 2002, 2016 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
   Written by Ulrich Drepper <drepper@redhat.com>, 2002.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of either
Packit 032894
Packit 032894
     * the GNU Lesser General Public License as published by the Free
Packit 032894
       Software Foundation; either version 3 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or
Packit 032894
Packit 032894
     * the GNU General Public License as published by the Free
Packit 032894
       Software Foundation; either version 2 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or both in parallel, as here.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 032894
   General Public License for more details.
Packit 032894
Packit 032894
   You should have received copies of the GNU General Public License and
Packit 032894
   the GNU Lesser General Public License along with this program.  If
Packit 032894
   not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifdef HAVE_CONFIG_H
Packit 032894
# include <config.h>
Packit 032894
#endif
Packit 032894
Packit 032894
#include <assert.h>
Packit 032894
#include <stdlib.h>
Packit 032894
#include <string.h>
Packit 032894
Packit 032894
#include "libasmP.h"
Packit 032894
#include <system.h>
Packit 032894
Packit 032894
Packit 032894
Packit 032894
AsmScnGrp_t *
Packit 032894
asm_newscngrp (AsmCtx_t *ctx, const char *grpname, AsmSym_t *signature,
Packit 032894
	       Elf32_Word flags)
Packit 032894
{
Packit 032894
  AsmScnGrp_t *result;
Packit 032894
  size_t grpname_len = strlen (grpname) + 1;
Packit 032894
Packit 032894
  if (ctx == NULL)
Packit 032894
    return NULL;
Packit 032894
Packit 032894
  if ((flags & ~GRP_COMDAT) != 0)
Packit 032894
    {
Packit 032894
      /* This is not a supported flag.  */
Packit 032894
      __libasm_seterrno (ASM_E_INVALID);
Packit 032894
      return NULL;
Packit 032894
    }
Packit 032894
Packit 032894
  result = (AsmScnGrp_t *) malloc (sizeof (AsmScnGrp_t) + grpname_len);
Packit 032894
  if (result == NULL)
Packit 032894
    return NULL;
Packit 032894
Packit 032894
  result->signature = signature;
Packit 032894
  result->members = NULL;
Packit 032894
  result->nmembers = 0;
Packit 032894
  result->flags = flags;
Packit 032894
Packit 032894
  memcpy (result->name, grpname, grpname_len);
Packit 032894
  result->strent = dwelf_strtab_add_len (ctx->section_strtab, result->name,
Packit 032894
					 grpname_len);
Packit 032894
Packit 032894
  if (unlikely (ctx->textp))
Packit 032894
    // XXX TBI.  What is the format?
Packit 032894
    abort ();
Packit 032894
  else
Packit 032894
    {
Packit 032894
      result->scn = elf_newscn (ctx->out.elf);
Packit 032894
      if (result->scn == NULL)
Packit 032894
	{
Packit 032894
	  /* Couldn't allocate a new section.  */
Packit 032894
	  __libasm_seterrno (ASM_E_LIBELF);
Packit 032894
	  free (result);
Packit 032894
	  return NULL;
Packit 032894
	}
Packit 032894
    }
Packit 032894
Packit 032894
  /* Enqueue is the context data structure.  */
Packit 032894
  if (ctx->ngroups == 0)
Packit 032894
    {
Packit 032894
      assert (ctx->groups == NULL);
Packit 032894
      ctx->groups = result->next = result;
Packit 032894
    }
Packit 032894
  else
Packit 032894
    {
Packit 032894
      result->next = ctx->groups->next;
Packit 032894
      ctx->groups = ctx->groups->next = result;
Packit 032894
    }
Packit 032894
  ++ctx->ngroups;
Packit 032894
Packit 032894
  return result;
Packit 032894
}