1 /* Look up a symbol in a shared object loaded by `dlopen'.
2 Copyright (C) 1999, 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. */
30 _dl_sym (void *handle
, const char *name
, void *who
)
32 const ElfW(Sym
) *ref
= NULL
;
35 if (handle
== RTLD_DEFAULT
)
36 /* Search the global scope. */
37 result
= _dl_lookup_symbol (name
, NULL
, &ref
, _dl_global_scope
, 0);
41 struct link_map
*match
;
42 ElfW(Addr
) caller
= (ElfW(Addr
)) who
;
44 /* Find the highest-addressed object that CALLER is not below. */
46 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
47 if (caller
>= l
->l_addr
&& (!match
|| match
->l_addr
< l
->l_addr
))
50 if (handle
!= RTLD_NEXT
)
52 /* Search the scope of the given object. */
53 struct link_map
*map
= handle
;
56 /* If the address is not recognized the call comes from the
57 main program (we hope). */
60 result
= _dl_lookup_symbol (name
, match
, &ref
, map
->l_local_scope
,
66 _dl_signal_error (0, NULL
, N_("\
67 RTLD_NEXT used in code not dynamically loaded"));
73 result
= _dl_lookup_symbol_skip (name
, l
, &ref
, l
->l_local_scope
,
79 return DL_SYMBOL_ADDRESS (result
, ref
);
86 _dl_vsym (void *handle
, const char *name
, const char *version
, void *who
)
88 const ElfW(Sym
) *ref
= NULL
;
89 struct r_found_version vers
;
92 /* Compute hash value to the version string. */
95 vers
.hash
= _dl_elf_hash (version
);
96 /* We don't have a specific file where the symbol can be found. */
99 if (handle
== RTLD_DEFAULT
)
100 /* Search the global scope. */
101 result
= _dl_lookup_versioned_symbol (name
, NULL
, &ref
, _dl_global_scope
,
103 else if (handle
== RTLD_NEXT
)
106 struct link_map
*match
;
107 ElfW(Addr
) caller
= (ElfW(Addr
)) who
;
109 /* Find the highest-addressed object that CALLER is not below. */
111 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
112 if (caller
>= l
->l_addr
&& (!match
|| match
->l_addr
< l
->l_addr
))
116 _dl_signal_error (0, NULL
, N_("\
117 RTLD_NEXT used in code not dynamically loaded"));
123 result
= _dl_lookup_versioned_symbol_skip (name
, l
, &ref
,
129 /* Search the scope of the given object. */
130 struct link_map
*map
= handle
;
131 result
= _dl_lookup_versioned_symbol (name
, map
, &ref
,
132 map
->l_local_scope
, &vers
, 0);
136 return DL_SYMBOL_ADDRESS (result
, ref
);