• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Create new section group.
2    Copyright (C) 2002 Red Hat, Inc.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4 
5    This program is Open Source software; you can redistribute it and/or
6    modify it under the terms of the Open Software License version 1.0 as
7    published by the Open Source Initiative.
8 
9    You should have received a copy of the Open Software License along
10    with this program; if not, you may obtain a copy of the Open Software
11    License version 1.0 from http://www.opensource.org/licenses/osl.php or
12    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13    3001 King Ranch Road, Ukiah, CA 95482.   */
14 
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 
19 #include <assert.h>
20 #include <stdlib.h>
21 #include <string.h>
22 
23 #include "libasmP.h"
24 #include <system.h>
25 
26 
27 
28 AsmScnGrp_t *
asm_newscngrp(ctx,grpname,signature,flags)29 asm_newscngrp (ctx, grpname, signature, flags)
30      AsmCtx_t *ctx;
31      const char *grpname;
32      AsmSym_t *signature;
33      Elf32_Word flags;
34 {
35   AsmScnGrp_t *result;
36   size_t grpname_len = strlen (grpname) + 1;
37 
38   if (ctx == NULL)
39     return NULL;
40 
41   if ((flags & ~GRP_COMDAT) != 0)
42     {
43       /* This is not a supported flag.  */
44       __libasm_seterrno (ASM_E_INVALID);
45       return NULL;
46     }
47 
48   result = (AsmScnGrp_t *) malloc (sizeof (AsmScnGrp_t) + grpname_len);
49   if (result == NULL)
50     return NULL;
51 
52   result->signature = signature;
53   result->members = NULL;
54   result->nmembers = 0;
55   result->flags = flags;
56 
57   memcpy (result->name, grpname, grpname_len);
58   result->strent = ebl_strtabadd (ctx->section_strtab, result->name,
59 				  grpname_len);
60 
61   if (unlikely (ctx->textp))
62     // XXX TBI.  What is the format?
63     abort ();
64   else
65     {
66       result->scn = elf_newscn (ctx->out.elf);
67       if (result->scn == NULL)
68 	{
69 	  /* Couldn't allocate a new section.  */
70 	  __libasm_seterrno (ASM_E_LIBELF);
71 	  free (result);
72 	  return NULL;
73 	}
74     }
75 
76   /* Enqueue is the context data structure.  */
77   if (ctx->ngroups == 0)
78     {
79       assert (ctx->groups == NULL);
80       ctx->groups = result->next = result;
81     }
82   else
83     {
84       result->next = ctx->groups->next;
85       ctx->groups = ctx->groups->next = result;
86     }
87   ++ctx->ngroups;
88 
89   return result;
90 }
91