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
;
34 ElfW(Addr
) caller
= (ElfW(Addr
)) who
;
35 struct link_map
*match
;
38 /* Find the highest-addressed object that CALLER is not below. */
40 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
41 if (caller
>= l
->l_addr
&& (!match
|| match
->l_addr
< l
->l_addr
))
44 if (handle
== RTLD_DEFAULT
)
45 /* Search the global scope. */
46 result
= _dl_lookup_symbol (name
, match
, &ref
, _dl_global_scope
, 0, 0);
49 if (handle
!= RTLD_NEXT
)
51 /* Search the scope of the given object. */
52 struct link_map
*map
= handle
;
55 /* If the address is not recognized the call comes from the
56 main program (we hope). */
59 result
= _dl_lookup_symbol (name
, match
, &ref
, map
->l_local_scope
,
65 _dl_signal_error (0, NULL
, N_("\
66 RTLD_NEXT used in code not dynamically loaded"));
72 result
= _dl_lookup_symbol_skip (name
, l
, &ref
, l
->l_local_scope
,
78 return DL_SYMBOL_ADDRESS (result
, ref
);
85 _dl_vsym (void *handle
, const char *name
, const char *version
, void *who
)
87 const ElfW(Sym
) *ref
= NULL
;
88 struct r_found_version vers
;
90 ElfW(Addr
) caller
= (ElfW(Addr
)) who
;
91 struct link_map
*match
;
94 /* Compute hash value to the version string. */
97 vers
.hash
= _dl_elf_hash (version
);
98 /* We don't have a specific file where the symbol can be found. */
101 /* Find the highest-addressed object that CALLER is not below. */
103 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
104 if (caller
>= l
->l_addr
&& (!match
|| match
->l_addr
< l
->l_addr
))
107 if (handle
== RTLD_DEFAULT
)
108 /* Search the global scope. */
109 result
= _dl_lookup_versioned_symbol (name
, match
, &ref
, _dl_global_scope
,
111 else if (handle
== RTLD_NEXT
)
114 _dl_signal_error (0, NULL
, N_("\
115 RTLD_NEXT used in code not dynamically loaded"));
121 result
= _dl_lookup_versioned_symbol_skip (name
, l
, &ref
,
127 /* Search the scope of the given object. */
128 struct link_map
*map
= handle
;
129 result
= _dl_lookup_versioned_symbol (name
, map
, &ref
,
130 map
->l_local_scope
, &vers
, 0, 1);
134 return DL_SYMBOL_ADDRESS (result
, ref
);