1 /* Update symbol information and section index in symbol table at the
3 Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
4 This file is part of elfutils.
5 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
7 This file is free software; you can redistribute it and/or modify
8 it under the terms of either
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at
12 your option) any later version
16 * the GNU General Public License as published by the Free
17 Software Foundation; either version 2 of the License, or (at
18 your option) any later version
20 or both in parallel, as here.
22 elfutils is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received copies of the GNU General Public License and
28 the GNU Lesser General Public License along with this program. If
29 not, see <http://www.gnu.org/licenses/>. */
43 gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
50 Elf_Data_Scn *symdata_scn = (Elf_Data_Scn *) symdata;
51 Elf_Data_Scn *shndxdata_scn = (Elf_Data_Scn *) shndxdata;
53 Elf32_Word *shndx = NULL;
59 if (unlikely (ndx < 0))
61 __libelf_seterrno (ELF_E_INVALID_INDEX);
65 if (unlikely (symdata_scn->d.d_type != ELF_T_SYM))
67 /* The type of the data better should match. */
68 __libelf_seterrno (ELF_E_DATA_MISMATCH);
73 /* We simply have to believe the user that the two sections belong to
75 rwlock_wrlock (scn->elf->lock);
77 /* The user is not required to pass a data descriptor for an extended
78 section index table. */
79 if (shndxdata_scn != NULL)
81 if (unlikely ((ndx + 1) * sizeof (Elf32_Word) > shndxdata_scn->d.d_size))
83 __libelf_seterrno (ELF_E_INVALID_INDEX);
87 shndx = &((Elf32_Word *) shndxdata_scn->d.d_buf)[ndx];
89 /* But if s/he does not the extended sectio index must be zero. */
90 else if (unlikely (srcshndx != 0))
92 __libelf_seterrno (ELF_E_INVALID_INDEX);
96 if (scn->elf->class == ELFCLASS32)
100 /* There is the possibility that the values in the input are
102 if (unlikely (src->st_value > 0xffffffffull)
103 || unlikely (src->st_size > 0xffffffffull))
105 __libelf_seterrno (ELF_E_INVALID_DATA);
109 /* Check whether we have to resize the data buffer. */
110 if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size))
112 __libelf_seterrno (ELF_E_INVALID_INDEX);
116 sym = &((Elf32_Sym *) symdata_scn->d.d_buf)[ndx];
119 sym->name = src->name
123 /* Please note that we can simply copy the `st_info' element since
124 the definitions of ELFxx_ST_BIND and ELFxx_ST_TYPE are the same
125 for the 64 bit variant. */
132 /* Check whether we have to resize the data buffer. */
133 if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size))
135 __libelf_seterrno (ELF_E_INVALID_INDEX);
139 ((Elf64_Sym *) symdata_scn->d.d_buf)[ndx] = *src;
142 /* Now we can store the section index. */
148 /* Mark the section as modified. */
149 scn->flags |= ELF_F_DIRTY;
152 rwlock_unlock (scn->elf->lock);