blob: 9274b142268deff8863409860fdd074668ba1441 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Get symbol version information at the given index.
2 Copyright (C) 1999, 2000, 2001, 2002 Red Hat, Inc.
3 Written by Ulrich Drepper <drepper@redhat.com>, 1999.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 2.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
22#include <assert.h>
23#include <gelf.h>
24#include <string.h>
25
26#include "libelfP.h"
27
28
29GElf_Versym *
30gelf_getversym (data, ndx, dst)
31 Elf_Data *data;
32 int ndx;
33 GElf_Versym *dst;
34{
35 Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
36 Elf_Scn *scn;
37 GElf_Versym *result;
38
39 if (data == NULL)
40 return NULL;
41
42 if (unlikely (data->d_type != ELF_T_HALF))
43 {
44 __libelf_seterrno (ELF_E_INVALID_HANDLE);
45 return NULL;
46 }
47
48 /* This is the one place where we have to take advantage of the fact
49 that an `Elf_Data' pointer is also a pointer to `Elf_Data_Scn'.
50 The interface is broken so that it requires this hack. */
51 scn = data_scn->s;
52
53 /* It's easy to handle this type. It has the same size for 32 and
54 64 bit objects. */
55 assert (sizeof (GElf_Versym) == sizeof (Elf32_Versym));
56 assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
57
58 rwlock_rdlock (scn->elf->lock);
59
60 /* The data is already in the correct form. Just make sure the
61 index is OK. */
62 if (unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size))
63 {
64 __libelf_seterrno (ELF_E_INVALID_INDEX);
65 result = NULL;
66 }
67 else
68 {
69 *dst = ((GElf_Versym *) data->d_buf)[ndx];
70
71 result = dst;
72 }
73
74 rwlock_unlock (scn->elf->lock);
75
76 return result;
77}