1 /* Create new subsection section in given section. 2 Copyright (C) 2002 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 <stdlib.h> 35 36 #include <libasmP.h> 37 #include <system.h> 38 39 40 AsmScn_t * asm_newsubscn(AsmScn_t * asmscn,unsigned int nr)41asm_newsubscn (AsmScn_t *asmscn, unsigned int nr) 42 { 43 AsmScn_t *runp; 44 AsmScn_t *newp; 45 46 /* Just return if no section is given. The error must have been 47 somewhere else. */ 48 if (asmscn == NULL) 49 return NULL; 50 51 /* Determine whether there is already a subsection with this number. */ 52 runp = asmscn->subsection_id == 0 ? asmscn : asmscn->data.up; 53 while (1) 54 { 55 if (runp->subsection_id == nr) 56 /* Found it. */ 57 return runp; 58 59 if (runp->subnext == NULL || runp->subnext->subsection_id > nr) 60 break; 61 62 runp = runp->subnext; 63 } 64 65 newp = (AsmScn_t *) malloc (sizeof (AsmScn_t)); 66 if (newp == NULL) 67 return NULL; 68 69 /* Same assembler context than the original section. */ 70 newp->ctx = runp->ctx; 71 72 /* User provided the subsectio nID. */ 73 newp->subsection_id = nr; 74 75 /* Inherit the parent's type. */ 76 newp->type = runp->type; 77 78 /* Pointer to the zeroth subsection. */ 79 newp->data.up = runp->subsection_id == 0 ? runp : runp->data.up; 80 81 /* We start at offset zero. */ 82 newp->offset = 0; 83 /* And generic alignment. */ 84 newp->max_align = 1; 85 86 /* No output yet. */ 87 newp->content = NULL; 88 89 /* Inherit the fill pattern from the section this one is derived from. */ 90 newp->pattern = asmscn->pattern; 91 92 /* Enqueue at the right position in the list. */ 93 newp->subnext = runp->subnext; 94 runp->subnext = newp; 95 96 return newp; 97 } 98