]>
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 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
)
33 const ElfW(Sym
) *ref
= NULL
;
35 if (handle
== RTLD_DEFAULT
)
36 /* Search the global scope. */
37 loadbase
= _dl_lookup_symbol (name
, NULL
, &ref
, _dl_global_scope
, 0);
38 else if (handle
== RTLD_NEXT
)
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
))
50 _dl_signal_error (0, NULL
, _("\
51 RTLD_NEXT used in code not dynamically loaded"));
57 loadbase
= _dl_lookup_symbol_skip (name
, l
, &ref
, l
->l_local_scope
,
62 /* Search the scope of the given object. */
63 struct link_map
*map
= handle
;
64 loadbase
= _dl_lookup_symbol (name
, map
, &ref
, map
->l_local_scope
, 0);
68 return (void *) (loadbase
+ ref
->st_value
);
75 _dl_vsym (void *handle
, const char *name
, const char *version
, void *who
)
78 const ElfW(Sym
) *ref
= NULL
;
79 struct r_found_version vers
;
81 /* Compute hash value to the version string. */
84 vers
.hash
= _dl_elf_hash (version
);
85 /* We don't have a specific file where the symbol can be found. */
88 if (handle
== RTLD_DEFAULT
)
89 /* Search the global scope. */
90 loadbase
= _dl_lookup_versioned_symbol (name
, NULL
, &ref
, _dl_global_scope
,
92 else if (handle
== RTLD_NEXT
)
94 struct link_map
*l
, *match
;
95 ElfW(Addr
) caller
= (ElfW(Addr
)) who
;
97 /* Find the highest-addressed object that CALLER is not below. */
99 for (l
= _dl_loaded
; l
; l
= l
->l_next
)
100 if (caller
>= l
->l_addr
&& (!match
|| match
->l_addr
< l
->l_addr
))
104 _dl_signal_error (0, NULL
, _("\
105 RTLD_NEXT used in code not dynamically loaded"));
111 loadbase
= _dl_lookup_versioned_symbol_skip (name
, l
, &ref
,
117 /* Search the scope of the given object. */
118 struct link_map
*map
= handle
;
119 loadbase
= _dl_lookup_versioned_symbol (name
, map
, &ref
,
120 map
->l_local_scope
, &vers
, 0);
124 return (void *) (loadbase
+ ref
->st_value
);
This page took 0.046465 seconds and 6 git commands to generate.