]>
sourceware.org Git - glibc.git/blob - elf/dl-sym.c
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);
40 struct link_map
*l
, *match
;
41 ElfW(Addr
) caller
= (ElfW(Addr
)) who
;
43 /* Find the highest-addressed object that CALLER is not below. */
45 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
46 if (caller
>= l
->l_addr
&& (!match
|| match
->l_addr
< l
->l_addr
))
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
, _("\
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
;
91 /* Compute hash value to the version string. */
94 vers
.hash
= _dl_elf_hash (version
);
95 /* We don't have a specific file where the symbol can be found. */
98 if (handle
== RTLD_DEFAULT
)
99 /* Search the global scope. */
100 result
= _dl_lookup_versioned_symbol (name
, NULL
, &ref
, _dl_global_scope
,
102 else if (handle
== RTLD_NEXT
)
104 struct link_map
*l
, *match
;
105 ElfW(Addr
) caller
= (ElfW(Addr
)) who
;
107 /* Find the highest-addressed object that CALLER is not below. */
109 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
110 if (caller
>= l
->l_addr
&& (!match
|| match
->l_addr
< l
->l_addr
))
114 _dl_signal_error (0, NULL
, _("\
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);
134 return DL_SYMBOL_ADDRESS (result
, ref
);
This page took 0.046627 seconds and 6 git commands to generate.