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 /* If the address is not recognized the call comes from the main
42 /* Find the highest-addressed object that CALLER is not below. */
43 for (l
= _dl_loaded
; l
!= NULL
; l
= l
->l_next
)
44 if (l
->l_addr
!= 0 && caller
>= l
->l_map_start
&& caller
< l
->l_map_end
)
46 /* There must be exactly one DSO for the range of the virtual
47 memory. Otherwise something is really broken. */
52 if (handle
== RTLD_DEFAULT
)
53 /* Search the global scope as seen in the caller object. */
54 result
= _dl_lookup_symbol (name
, match
, &ref
, match
->l_scope
, 0, 0);
57 if (handle
!= RTLD_NEXT
)
59 /* Search the scope of the given object. */
60 struct link_map
*map
= handle
;
62 result
= _dl_lookup_symbol (name
, match
, &ref
, map
->l_local_scope
,
67 if (__builtin_expect (match
== _dl_loaded
, 0))
68 _dl_signal_error (0, NULL
, N_("\
69 RTLD_NEXT used in code not dynamically loaded"));
72 while (l
->l_loader
!= NULL
)
75 result
= _dl_lookup_symbol_skip (name
, l
, &ref
, l
->l_local_scope
,
81 return DL_SYMBOL_ADDRESS (result
, ref
);
88 _dl_vsym (void *handle
, const char *name
, const char *version
, void *who
)
90 const ElfW(Sym
) *ref
= NULL
;
91 struct r_found_version vers
;
93 ElfW(Addr
) caller
= (ElfW(Addr
)) who
;
94 struct link_map
*match
;
97 /* Compute hash value to the version string. */
100 vers
.hash
= _dl_elf_hash (version
);
101 /* We don't have a specific file where the symbol can be found. */
102 vers
.filename
= NULL
;
104 /* If the address is not recognized the call comes from the main
105 program (we hope). */
108 /* Find the highest-addressed object that CALLER is not below. */
109 for (l
= _dl_loaded
; l
!= NULL
; l
= l
->l_next
)
110 if (l
->l_addr
!= 0 && caller
>= l
->l_map_start
&& caller
< l
->l_map_end
)
112 /* There must be exactly one DSO for the range of the virtual
113 memory. Otherwise something is really broken. */
118 if (handle
== RTLD_DEFAULT
)
119 /* Search the global scope. */
120 result
= _dl_lookup_versioned_symbol (name
, match
, &ref
, match
->l_scope
,
122 else if (handle
== RTLD_NEXT
)
124 if (match
== _dl_loaded
)
125 _dl_signal_error (0, NULL
, N_("\
126 RTLD_NEXT used in code not dynamically loaded"));
129 while (l
->l_loader
!= NULL
)
132 result
= _dl_lookup_versioned_symbol_skip (name
, l
, &ref
,
138 /* Search the scope of the given object. */
139 struct link_map
*map
= handle
;
140 result
= _dl_lookup_versioned_symbol (name
, map
, &ref
,
141 map
->l_local_scope
, &vers
, 0, 1);
145 return DL_SYMBOL_ADDRESS (result
, ref
);