1DLSYM(3) Linux Programmer's Manual DLSYM(3)
2
3
4
6 dlsym, dlvsym - obtain address of a symbol in a shared object or exe‐
7 cutable
8
10 #include <dlfcn.h>
11
12 void *dlsym(void *handle, const char *symbol);
13
14 #define _GNU_SOURCE
15 #include <dlfcn.h>
16
17 void *dlvsym(void *handle, char *symbol, char *version);
18
19 Link with -ldl.
20
22 The function dlsym() takes a "handle" of a dynamic loaded shared object
23 returned by dlopen(3) along with a null-terminated symbol name, and
24 returns the address where that symbol is loaded into memory. If the
25 symbol is not found, in the specified object or any of the shared
26 objects that were automatically loaded by dlopen(3) when that object
27 was loaded, dlsym() returns NULL. (The search performed by dlsym() is
28 breadth first through the dependency tree of these shared objects.)
29
30 Since the value of the symbol could actually be NULL (so that a NULL
31 return from dlsym() need not indicate an error), the correct way to
32 test for an error is to call dlerror(3) to clear any old error condi‐
33 tions, then call dlsym(), and then call dlerror(3) again, saving its
34 return value into a variable, and check whether this saved value is not
35 NULL.
36
37 There are two special pseudo-handles that may be specified in handle:
38
39 RTLD_DEFAULT
40 Find the first occurrence of the desired symbol using the
41 default shared object search order. The search will include
42 global symbols in the executable and its dependencies, as well
43 as symbols in shared objects that were dynamically loaded with
44 the RTLD_GLOBAL flag.
45
46 RTLD_NEXT
47 Find the next occurrence of the desired symbol in the search
48 order after the current object. This allows one to provide a
49 wrapper around a function in another shared object, so that, for
50 example, the definition of a function in a preloaded shared
51 object (see LD_PRELOAD in ld.so(8)) can find and invoke the
52 "real" function provided in another shared object (or for that
53 matter, the "next" definition of the function in cases where
54 there are multiple layers of preloading).
55
56 The _GNU_SOURCE feature test macro must be defined in order to obtain
57 the definitions of RTLD_DEFAULT and RTLD_NEXT from <dlfcn.h>.
58
59 The function dlvsym() does the same as dlsym() but takes a version
60 string as an additional argument.
61
63 On success, these functions return the address associated with symbol.
64 On failure, they return NULL; the cause of the error can be diagnosed
65 using dlerror(3).
66
68 dlsym() is present in glibc 2.0 and later. dlvsym() first appeared in
69 glibc 2.1.
70
72 For an explanation of the terms used in this section, see
73 attributes(7).
74
75 ┌──────────────────┬───────────────┬─────────┐
76 │Interface │ Attribute │ Value │
77 ├──────────────────┼───────────────┼─────────┤
78 │dlsym(), dlvsym() │ Thread safety │ MT-Safe │
79 └──────────────────┴───────────────┴─────────┘
81 POSIX.1-2001 describes dlsym(). The dlvsym() function is a GNU exten‐
82 sion.
83
85 History
86 The dlsym() function is part of the dlopen API, derived from SunOS.
87 That system does not have dlvsym().
88
90 See dlopen(3).
91
93 dl_iterate_phdr(3), dladdr(3), dlerror(3), dlinfo(3), dlopen(3),
94 ld.so(8)
95
97 This page is part of release 4.15 of the Linux man-pages project. A
98 description of the project, information about reporting bugs, and the
99 latest version of this page, can be found at
100 https://www.kernel.org/doc/man-pages/.
101
102
103
104Linux 2017-09-15 DLSYM(3)