2 .\" Copyright 1995 Yggdrasil Computing, Incorporated.
3 .\" and Copyright 2003, 2015 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" SPDX-License-Identifier: GPL-2.0-or-later
7 .TH dlsym 3 (date) "Linux man-pages (unreleased)"
9 dlsym, dlvsym \- obtain address of a symbol in a shared object or executable
11 Dynamic linking library
12 .RI ( libdl ", " \-ldl )
17 .BI "void *dlsym(void *restrict " handle ", const char *restrict " symbol );
19 .B #define _GNU_SOURCE
22 .BI "void *dlvsym(void *restrict " handle ", const char *restrict " symbol ,
23 .BI " const char *restrict " version );
28 takes a "handle" of a dynamic loaded shared object returned by
30 along with a null-terminated symbol name,
31 and returns the address where that symbol is
33 If the symbol is not found, in the specified
34 object or any of the shared objects that were automatically loaded by
36 when that object was loaded,
39 (The search performed by
41 is breadth first through the dependency tree of these shared objects.)
43 In unusual cases (see NOTES) the value of the symbol could actually be NULL.
44 Therefore, a NULL return from
46 need not indicate an error.
47 The correct way to distinguish an error from a symbol whose value is NULL
50 to clear any old error conditions, then call
54 again, saving its return value into a variable, and check whether
55 this saved value is not NULL.
57 There are two special pseudo-handles that may be specified in
61 Find the first occurrence of the desired symbol
62 using the default shared object search order.
63 The search will include global symbols in the executable
65 as well as symbols in shared objects that were dynamically loaded with the
70 Find the next occurrence of the desired symbol in the search order
71 after the current object.
72 This allows one to provide a wrapper
73 around a function in another shared object, so that, for example,
74 the definition of a function in a preloaded shared object
79 can find and invoke the "real" function provided in another shared object
80 (or for that matter, the "next" definition of the function in cases
81 where there are multiple layers of preloading).
85 feature test macro must be defined in order to obtain the
97 but takes a version string as an additional argument.
100 these functions return the address associated with
102 On failure, they return NULL;
103 the cause of the error can be diagnosed using
107 is present in glibc 2.0 and later.
109 first appeared in glibc 2.1.
111 For an explanation of the terms used in this section, see
119 Interface Attribute Value
123 T} Thread safety MT-Safe
129 POSIX.1-2001 describes
133 function is a GNU extension.
135 There are several scenarios when the address of a global symbol is NULL.
136 For example, a symbol can be placed at zero address by the linker, via
137 a linker script or with
140 Undefined weak symbols also have NULL value.
141 Finally, the symbol value may be the result of
142 a GNU indirect function (IFUNC) resolver function that returns
143 NULL as the resolved value.
146 also returns NULL without error.
147 However, in the former two cases, the
148 behavior of GNU dynamic linker is inconsistent: relocation processing
149 succeeds and the symbol can be observed to have NULL value, but
153 indicates a lookup error.
158 function is part of the dlopen API, derived from SunOS.
159 That system does not have
165 .BR dl_iterate_phdr (3),