]> sourceware.org Git - glibc.git/blob - elf/dl-sym.c
Update.
[glibc.git] / 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.
4
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.
9
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.
14
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. */
19
20 #include <stddef.h>
21 #include <setjmp.h>
22 #include <libintl.h>
23
24 #include <dlfcn.h>
25 #include <ldsodefs.h>
26 #include <dl-hash.h>
27
28 void *
29 internal_function
30 _dl_sym (void *handle, const char *name, void *who)
31 {
32 ElfW(Addr) loadbase;
33 const ElfW(Sym) *ref = NULL;
34
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)
39 {
40 struct link_map *l, *match;
41 ElfW(Addr) caller = (ElfW(Addr)) who;
42
43 /* Find the highest-addressed object that CALLER is not below. */
44 match = NULL;
45 for (l = _dl_loaded; l; l = l->l_next)
46 if (caller >= l->l_addr && (!match || match->l_addr < l->l_addr))
47 match = l;
48
49 if (! match)
50 _dl_signal_error (0, NULL, _("\
51 RTLD_NEXT used in code not dynamically loaded"));
52
53 l = match;
54 while (l->l_loader)
55 l = l->l_loader;
56
57 loadbase = _dl_lookup_symbol_skip (name, l, &ref, l->l_local_scope,
58 match);
59 }
60 else
61 {
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);
65 }
66
67 if (loadbase)
68 return (void *) (loadbase + ref->st_value);
69
70 return NULL;
71 }
72
73 void *
74 internal_function
75 _dl_vsym (void *handle, const char *name, const char *version, void *who)
76 {
77 ElfW(Addr) loadbase;
78 const ElfW(Sym) *ref = NULL;
79 struct r_found_version vers;
80
81 /* Compute hash value to the version string. */
82 vers.name = version;
83 vers.hidden = 1;
84 vers.hash = _dl_elf_hash (version);
85 /* We don't have a specific file where the symbol can be found. */
86 vers.filename = NULL;
87
88 if (handle == RTLD_DEFAULT)
89 /* Search the global scope. */
90 loadbase = _dl_lookup_versioned_symbol (name, NULL, &ref, _dl_global_scope,
91 &vers, 0);
92 else if (handle == RTLD_NEXT)
93 {
94 struct link_map *l, *match;
95 ElfW(Addr) caller = (ElfW(Addr)) who;
96
97 /* Find the highest-addressed object that CALLER is not below. */
98 match = NULL;
99 for (l = _dl_loaded; l; l = l->l_next)
100 if (caller >= l->l_addr && (!match || match->l_addr < l->l_addr))
101 match = l;
102
103 if (! match)
104 _dl_signal_error (0, NULL, _("\
105 RTLD_NEXT used in code not dynamically loaded"));
106
107 l = match;
108 while (l->l_loader)
109 l = l->l_loader;
110
111 loadbase = _dl_lookup_versioned_symbol_skip (name, l, &ref,
112 l->l_local_scope,
113 &vers, match);
114 }
115 else
116 {
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);
121 }
122
123 if (loadbase)
124 return (void *) (loadbase + ref->st_value);
125
126 return NULL;
127 }
This page took 0.046465 seconds and 6 git commands to generate.