2 x.movscn.c - implementation of the elfx_movscn(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.movscn.c,v 1.14 2008/05/23 08:15:35 michael Exp $";
27 elfx_movscn(Elf *elf, Elf_Scn *scn, Elf_Scn *after) {
32 if (!elf || !scn || !after) {
35 elf_assert(elf->e_magic == ELF_MAGIC);
36 if (elf->e_kind != ELF_K_ELF) {
40 elf_assert(scn->s_magic == SCN_MAGIC);
41 elf_assert(after->s_magic == SCN_MAGIC);
42 if (scn->s_elf != elf || after->s_elf != elf) {
43 seterr(ERROR_ELFSCNMISMATCH);
46 elf_assert(elf->e_scn_1);
47 if (scn == elf->e_scn_1) {
48 seterr(ERROR_NULLSCN);
51 if (scn == after || scn == after->s_link) {
57 * Find previous section.
60 for (tmp = elf->e_scn_1; tmp->s_link; tmp = tmp->s_link) {
61 if (tmp->s_link == scn) {
66 elf_assert(prev != NULL);
69 * Update section indices
72 for (tmp = elf->e_scn_1; tmp; tmp = tmp->s_link) {
79 else if (tmp == scn) {
88 prev->s_link = scn->s_link;
89 scn->s_link = after->s_link;
91 scn->s_index = after->s_index + 1;
92 if (elf->e_scn_n == scn) {
95 else if (elf->e_scn_n == after) {
101 * Check section indices
104 elf_assert(tmp->s_index == 0);
105 while (tmp->s_link) {
106 elf_assert(tmp->s_link->s_index == tmp->s_index + 1);
109 #endif /* ENABLE_DEBUG */