1 /* Create new section, which is member of a group, in output file. 2 Copyright (C) 2002 Red Hat, Inc. 3 Written by Ulrich Drepper <drepper (at) 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 21 #include "libasmP.h" 22 23 24 AsmScn_t * 25 asm_newscn_ingrp (ctx, scnname, type, flags, grp) 26 AsmCtx_t *ctx; 27 const char *scnname; 28 GElf_Word type; 29 GElf_Xword flags; 30 AsmScnGrp_t *grp; 31 { 32 AsmScn_t *result = __asm_newscn_internal (ctx, scnname, type, flags); 33 34 if (likely (result != NULL)) 35 { 36 /* We managed to create a section group. Add it to the section 37 group. */ 38 if (grp->nmembers == 0) 39 { 40 assert (grp->members == NULL); 41 grp->members = result->data.main.next_in_group = result; 42 } 43 else 44 { 45 result->data.main.next_in_group 46 = grp->members->data.main.next_in_group; 47 grp->members = grp->members->data.main.next_in_group = result; 48 } 49 50 ++grp->nmembers; 51 52 /* Set the SHF_GROUP flag. */ 53 if (likely (! ctx->textp)) 54 { 55 GElf_Shdr shdr_mem; 56 GElf_Shdr *shdr = gelf_getshdr (result->data.main.scn, &shdr_mem); 57 58 assert (shdr != NULL); 59 shdr->sh_flags |= SHF_GROUP; 60 61 (void) gelf_update_shdr (result->data.main.scn, shdr); 62 } 63 } 64 65 return result; 66 } 67