2 x.remscn.c - implementation of the elfx_remscn(3) function.
3 Copyright (C) 1995 - 2001, 2003 Michael Riepe
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 static const char rcsid[] = "@(#) $Id: x.remscn.c,v 1.15 2008/05/23 08:15:35 michael Exp $";
27 elfx_remscn(Elf *elf, Elf_Scn *scn) {
36 elf_assert(elf->e_magic == ELF_MAGIC);
37 if (elf->e_kind != ELF_K_ELF) {
41 elf_assert(scn->s_magic == SCN_MAGIC);
42 elf_assert(elf->e_ehdr);
43 if (scn->s_elf != elf) {
44 seterr(ERROR_ELFSCNMISMATCH);
47 elf_assert(elf->e_scn_1);
48 if (scn == elf->e_scn_1) {
49 seterr(ERROR_NULLSCN);
54 * Find previous section.
56 for (pscn = elf->e_scn_1; pscn->s_link; pscn = pscn->s_link) {
57 if (pscn->s_link == scn) {
61 if (pscn->s_link != scn) {
62 seterr(ERROR_ELFSCNMISMATCH);
69 if (elf->e_scn_n == scn) {
72 pscn->s_link = scn->s_link;
76 * Free section descriptor and data.
78 for (sd = scn->s_data_1; sd; sd = tmp) {
79 elf_assert(sd->sd_magic == DATA_MAGIC);
80 elf_assert(sd->sd_scn == scn);
82 if (sd->sd_free_data && sd->sd_memdata) {
89 if ((sd = scn->s_rawdata)) {
90 elf_assert(sd->sd_magic == DATA_MAGIC);
91 elf_assert(sd->sd_scn == scn);
92 if (sd->sd_free_data && sd->sd_memdata) {
100 elf_assert(scn->s_index > 0);
105 * Adjust section indices.
107 for (scn = pscn->s_link; scn; scn = scn->s_link) {
108 elf_assert(scn->s_index > index);
113 * Adjust section count in ELF header
115 if (_elf_update_shnum(elf, elf->e_scn_n->s_index + 1)) {