nlist.c revision cd8a250aa139016def485e91d2da49c87de3baec
1b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Extract symbol list from binary.
266c650e9c03734616425b467e83c8e93a4eeeb48Ulrich Drepper   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2007 Red Hat, Inc.
3361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   This file is part of Red Hat elfutils.
4b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   Written by Ulrich Drepper <drepper@redhat.com>, 1998.
5b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
6361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   Red Hat elfutils is free software; you can redistribute it and/or modify
7361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   it under the terms of the GNU General Public License as published by the
8361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   Free Software Foundation; version 2 of the License.
9b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
10361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   Red Hat elfutils is distributed in the hope that it will be useful, but
11361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   WITHOUT ANY WARRANTY; without even the implied warranty of
12361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   General Public License for more details.
14b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
15361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   You should have received a copy of the GNU General Public License along
16361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   with Red Hat elfutils; if not, write to the Free Software Foundation,
171e9ef50681e20ef14c2ba38aef37a71ff148be08Ulrich Drepper   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
18361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
19361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   In addition, as a special exception, Red Hat, Inc. gives You the
20361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   additional right to link the code of Red Hat elfutils with code licensed
21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   under any Open Source Initiative certified open source license
22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   (http://www.opensource.org/licenses/index.php) which requires the
23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   distribution of source code with any binary distribution and to
24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   distribute linked combinations of the two.  Non-GPL Code permitted under
25361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   this exception must only link to the code of Red Hat elfutils through
26361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   those well defined interfaces identified in the file named EXCEPTION
27361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   found in the source code files (the "Approved Interfaces").  The files
28361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   of Non-GPL Code may instantiate templates or use macros or inline
29361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   functions from the Approved Interfaces without causing the resulting
30361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   work to be covered by the GNU General Public License.  Only Red Hat,
31361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   Inc. may make changes or additions to the list of Approved Interfaces.
32361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   Red Hat's grant of this exception is conditioned upon your not adding
33361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   any new exceptions.  If you wish to add a new Approved Interface or
34361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   exception, please contact Red Hat.  You must obey the GNU General Public
35361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   License in all respects for all of the Red Hat elfutils code and other
36361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   code used in conjunction with Red Hat elfutils except the Non-GPL Code
37361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   covered by this exception.  If you modify this file, you may extend this
38361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   exception to your version of the file, but you are not obligated to do
39361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   so.  If you do not wish to provide this exception without modification,
40361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   you must delete this exception statement from your version and license
41361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   this file solely under the GPL without exception.
42361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
43361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   Red Hat elfutils is an included package of the Open Invention Network.
44361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   An included package of the Open Invention Network is a package for which
45361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   Open Invention Network licensees cross-license their patents.  No patent
46361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   license is granted, either expressly or impliedly, by designation as an
47361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   included package.  Should you wish to participate in the Open Invention
48361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   Network licensing program, please visit www.openinventionnetwork.com
49361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   <http://www.openinventionnetwork.com>.  */
50b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
51b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifdef HAVE_CONFIG_H
52b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper# include <config.h>
53b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif
54b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
55b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <fcntl.h>
56b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <gelf.h>
57b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libelf.h>
58b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <nlist.h>
59b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <unistd.h>
60b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
61b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include "libelfP.h"
62b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
63b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
64b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct hashentry
65b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
66b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  const char *str;
67b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  GElf_Sym sym;
68b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
69b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define TYPE struct hashentry
70b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* XXX Use a better hash function some day.  */
71b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define HASHFCT(str, len) INTUSE(elf_hash) (str)
72b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define COMPARE(p1, p2) strcmp ((p1)->str, (p2)->str)
73b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define CLASS static
74b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define PREFIX nlist_
75b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define xcalloc(n, m) calloc (n, m)
76b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define next_prime(s) __libelf_next_prime (s)
77b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <fixedsizehash.h>
78b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
79b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
80b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperint
81b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppernlist (const char *filename, struct nlist *nl)
82b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
83b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  int fd;
84b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf *elf;
85b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf_Scn *scn = NULL;
86b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf_Scn *symscn = NULL;
87b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  GElf_Shdr shdr_mem;
88b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  GElf_Shdr *shdr = NULL;
89b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf_Data *data;
90b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct nlist_fshash *table;
91b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t nsyms;
92b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t cnt;
93b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
94b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Open the file.  */
95b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  fd = open (filename, O_RDONLY);
96b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (fd == -1)
97b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    {
98b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      __libelf_seterrno (ELF_E_NOFILE);
99b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      goto fail;
100b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    }
101b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
102b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* For compatibility reasons (`nlist' existed before ELF and libelf)
103b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     we don't expect the caller to set the ELF version.  Do this here
104b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     if it hasn't happened yet.  */
105b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (__libelf_version_initialized == 0)
106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    INTUSE(elf_version) (EV_CURRENT);
107b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
108b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Now get an ELF descriptor.  */
109b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  elf = INTUSE(elf_begin) (fd, ELF_C_READ_MMAP, NULL);
110b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (elf == NULL)
111cd8a250aa139016def485e91d2da49c87de3baecUlrich Drepper    goto fail_fd;
112b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
113b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Find a symbol table.  We prefer the real symbol table but if it
114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     does not exist use the dynamic symbol table.  */
115b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  while ((scn = INTUSE(elf_nextscn) (elf, scn)) != NULL)
116b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    {
117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      shdr = INTUSE(gelf_getshdr) (scn, &shdr_mem);
118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      if (shdr == NULL)
119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	goto fail_close;
120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* That is what we are looking for.  */
122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      if (shdr->sh_type == SHT_SYMTAB)
123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	{
124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  symscn = scn;
125b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  break;
126b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	}
127b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
128b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* Better than nothing.  Remember this section.  */
129b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      if (shdr->sh_type == SHT_DYNSYM)
130b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	symscn = scn;
131b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    }
132b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (symscn == NULL)
134b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    /* We haven't found anything.  Fail.  */
135b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    goto fail_close;
136b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
137b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Re-get the section header in case we found only the dynamic symbol
138b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     table.  */
139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (scn == NULL)
140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    shdr = INTUSE(gelf_getshdr) (symscn, &shdr_mem);
141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* SHDR->SH_LINK now contains the index of the string section.  */
142b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
143b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Get the data for the symbol section.  */
144b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  data = INTUSE(elf_getdata) (symscn, NULL);
145b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (data == NULL)
146b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    goto fail_close;
147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
148b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* How many symbols are there?  */
149b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  nsyms = (shdr->sh_size
150b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	   / INTUSE(gelf_fsize) (elf, ELF_T_SYM, 1, data->d_version));
151b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
152b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Create the hash table.  */
153b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  table = nlist_fshash_init (nsyms);
154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (table == NULL)
155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    {
156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      __libelf_seterrno (ELF_E_NOMEM);
157b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      goto fail_close;
158b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    }
159b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
160b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Iterate over all the symbols in the section.  */
161b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  for (cnt = 0; cnt < nsyms; ++cnt)
162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    {
163b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      struct hashentry mem;
164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      GElf_Sym *sym;
165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* Get the symbol.  */
167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      sym = INTUSE(gelf_getsym) (data, cnt, &mem.sym);
168b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      if (sym == NULL)
169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	goto fail_dealloc;
170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
171b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* Get the name of the symbol.  */
172b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      mem.str = INTUSE(elf_strptr) (elf, shdr->sh_link, sym->st_name);
173b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      if (mem.str == NULL)
174b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	goto fail_dealloc;
175b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
176b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* Don't allow zero-length strings.  */
177b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      if (mem.str[0] == '\0')
178b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	continue;
179b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
180b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* And add it to the hash table.  Note that we are using the
181b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper         overwrite version.  This will ensure that
182b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	 a) global symbols are preferred over local symbols since
183b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	    they are all located at the end
184b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	 b) if there are multiple local symbols with the same name
185b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	    the last one is used.
186b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      */
187b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      (void) nlist_fshash_overwrite (table, mem.str, 0, &mem);
188b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    }
189b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
190b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Now it is time to look for the symbols the user asked for.
191b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     XXX What is a `null name/null string'?  This is what the
192b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     standard says terminates the list.  Is it a null pointer
193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     or a zero-length string?  We test for both...  */
194b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  while (nl->n_name != NULL && nl->n_name[0] != '\0')
195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    {
196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      struct hashentry search;
197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      const struct hashentry *found;
198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* Search for a matching entry in the hash table.  */
200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      search.str = nl->n_name;
201b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      found = nlist_fshash_find (table, nl->n_name, 0, &search);
202b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      if (found != NULL)
204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	{
205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  /* Found it.  */
206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_value = found->sym.st_value;
207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_scnum = found->sym.st_shndx;
208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_type = GELF_ST_TYPE (found->sym.st_info);
209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  /* XXX What shall we fill in the next fields?  */
210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_sclass = 0;
211b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_numaux = 0;
212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	}
213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      else
214b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	{
215b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  /* Not there.  */
216b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_value = 0;
217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_scnum = 0;
218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_type = 0;
219b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_sclass = 0;
220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	  nl->n_numaux = 0;
221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	}
222b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* Next search request.  */
224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      ++nl;
225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    }
226b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Free the resources.  */
228b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  nlist_fshash_fini (table);
229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* We do not need the ELF descriptor anymore.  */
231b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  (void) INTUSE(elf_end) (elf);
232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
233ecf2b124a22590ac47688a6e8c2ff8865d23f774Ulrich Drepper  /* Neither the file descriptor.  */
234ecf2b124a22590ac47688a6e8c2ff8865d23f774Ulrich Drepper  (void) close (fd);
235ecf2b124a22590ac47688a6e8c2ff8865d23f774Ulrich Drepper
236b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  return 0;
237b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
238b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fail_dealloc:
239b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  nlist_fshash_fini (table);
240b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
241b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fail_close:
242b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* We do not need the ELF descriptor anymore.  */
243b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  (void) INTUSE(elf_end) (elf);
244b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
245cd8a250aa139016def485e91d2da49c87de3baecUlrich Drepper fail_fd:
246ecf2b124a22590ac47688a6e8c2ff8865d23f774Ulrich Drepper  /* Neither the file descriptor.  */
247ecf2b124a22590ac47688a6e8c2ff8865d23f774Ulrich Drepper  (void) close (fd);
248ecf2b124a22590ac47688a6e8c2ff8865d23f774Ulrich Drepper
249b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fail:
250b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* We have to set all entries to zero.  */
251b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  while (nl->n_name != NULL && nl->n_name[0] != '\0')
252b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    {
253b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      nl->n_value = 0;
254b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      nl->n_scnum = 0;
255b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      nl->n_type = 0;
256b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      nl->n_sclass = 0;
257b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      nl->n_numaux = 0;
258b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
259b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      /* Next entry.  */
260b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      ++nl;
261b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    }
262b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
263b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  return -1;
264b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}
265