1 /* Look up a symbol in the loaded objects.
2 Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C 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 the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
21 # define FCT do_lookup_versioned
22 # define ARG const struct r_found_version *const version,
24 # define FCT do_lookup
28 /* Inner part of the lookup functions. We return a value > 0 if we
29 found the symbol, the value 0 if nothing is found and < 0 if
30 something bad happened. */
32 FCT (const char *undef_name
, struct link_map
*undef_map
,
33 unsigned long int hash
, const ElfW(Sym
) *ref
, struct sym_val
*result
,
34 struct r_scope_elem
*scope
, size_t i
, ARG
struct link_map
*skip
,
35 int noexec
, int noplt
)
37 struct link_map
**list
= scope
->r_list
;
38 size_t n
= scope
->r_nlist
;
43 const ElfW(Sym
) *symtab
;
45 const ElfW(Half
) *verstab
;
50 const ElfW(Sym
) *versioned_sym
= NULL
;
55 /* Here come the extra test needed for `_dl_lookup_symbol_skip'. */
56 if (skip
!= NULL
&& map
== skip
)
59 /* Don't search the executable when resolving a copy reloc. */
60 if (noexec
&& map
->l_type
== lt_executable
)
63 /* Print some debugging info if wanted. */
64 if (__builtin_expect (_dl_debug_symbols
, 0))
65 _dl_debug_message (1, "symbol=", undef_name
, "; lookup in file=",
66 map
->l_name
[0] ? map
->l_name
: _dl_argv
[0],
69 symtab
= (const void *) D_PTR (map
, l_info
[DT_SYMTAB
]);
70 strtab
= (const void *) D_PTR (map
, l_info
[DT_STRTAB
]);
71 verstab
= map
->l_versyms
;
73 /* Search the appropriate hash bucket in this object's symbol table
74 for a definition for the same symbol name. */
75 for (symidx
= map
->l_buckets
[hash
% map
->l_nbuckets
];
77 symidx
= map
->l_chain
[symidx
])
79 sym
= &symtab
[symidx
];
81 if (sym
->st_value
== 0 || /* No value. */
82 (noplt
&& sym
->st_shndx
== SHN_UNDEF
))
85 if (ELFW(ST_TYPE
) (sym
->st_info
) > STT_FUNC
)
86 /* Ignore all but STT_NOTYPE, STT_OBJECT and STT_FUNC entries
87 since these are no code/data definitions. */
90 if (sym
!= ref
&& strcmp (strtab
+ sym
->st_name
, undef_name
))
91 /* Not the symbol we are looking for. */
95 if (__builtin_expect (verstab
== NULL
, 0))
97 /* We need a versioned symbol but haven't found any. If
98 this is the object which is referenced in the verneed
99 entry it is a bug in the library since a symbol must
100 not simply disappear.
102 It would also be a bug in the object since it means that
103 the list of required versions is incomplete and so the
104 tests in dl-version.c haven't found a problem.*/
105 assert (version
->filename
== NULL
106 || ! _dl_name_match_p (version
->filename
, map
));
108 /* Otherwise we accept the symbol. */
112 /* We can match the version information or use the
113 default one if it is not hidden. */
114 ElfW(Half
) ndx
= verstab
[symidx
] & 0x7fff;
115 if ((map
->l_versions
[ndx
].hash
!= version
->hash
116 || strcmp (map
->l_versions
[ndx
].name
, version
->name
))
117 && (version
->hidden
|| map
->l_versions
[ndx
].hash
118 || (verstab
[symidx
] & 0x8000)))
119 /* It's not the version we want. */
123 /* No specific version is selected. When the object file
124 also does not define a version we have a match.
125 Otherwise we accept the default version, or in case there
126 is only one version defined, this one version. */
129 ElfW(Half
) ndx
= verstab
[symidx
] & 0x7fff;
130 if (ndx
> 2) /* map->l_versions[ndx].hash != 0) */
132 /* Don't accept hidden symbols. */
133 if ((verstab
[symidx
] & 0x8000) == 0 && num_versions
++ == 0)
134 /* No version so far. */
141 /* There cannot be another entry for this symbol so stop here. */
145 /* If we have seen exactly one versioned symbol while we are
146 looking for an unversioned symbol and the version is not the
147 default version we still accept this symbol since there are
148 no possible ambiguities. */
152 sym
= num_versions
== 1 ? versioned_sym
: NULL
;
158 switch (ELFW(ST_BIND
) (sym
->st_info
))
161 /* Weak definition. Use this value if we don't find another. */
162 if (__builtin_expect (_dl_dynamic_weak
, 0))
173 /* Global definition. Just what we need. */
178 /* Local symbols are ignored. */
184 /* If this current map is the one mentioned in the verneed entry
185 and we have not found a weak entry, it is a bug. */
186 if (symidx
== STN_UNDEF
&& version
->filename
!= NULL
187 && __builtin_expect (_dl_name_match_p (version
->filename
, map
), 0))
193 /* We have not found anything until now. */