]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/dlsym.3
membarrier.2: Remove redundant mention of return value of MEMBARRIER_CMD_SHARED
[thirdparty/man-pages.git] / man3 / dlsym.3
CommitLineData
15e1b31b
MK
1.\" Copyright 1995 Yggdrasil Computing, Incorporated.
2.\" and Copyright 2003, 2015 Michael Kerrisk (mtk.manpages@gmail.com).
3.\"
4.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5.\" This is free documentation; you can redistribute it and/or
6.\" modify it under the terms of the GNU General Public License as
7.\" published by the Free Software Foundation; either version 2 of
8.\" the License, or (at your option) any later version.
9.\"
10.\" The GNU General Public License's references to "object code"
11.\" and "executables" are to be interpreted as the output of any
12.\" document formatting or typesetting system, including
13.\" intermediate and printed output.
14.\"
15.\" This manual is distributed in the hope that it will be useful,
16.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18.\" GNU General Public License for more details.
19.\"
20.\" You should have received a copy of the GNU General Public
21.\" License along with this manual; if not, see
22.\" <http://www.gnu.org/licenses/>.
23.\" %%%LICENSE_END
24.\"
460495ca 25.TH DLSYM 3 2015-08-08 "Linux" "Linux Programmer's Manual"
15e1b31b
MK
26.SH NAME
27dlsym, dlvsym \- obtain address of a symbol in a shared object or executable
28.SH SYNOPSIS
29.B #include <dlfcn.h>
30.sp
31.BI "void *dlsym(void *" handle ", const char *" symbol );
32.sp
33.B #define _GNU_SOURCE
34.br
35.B #include <dlfcn.h>
36.sp
37.BI "void *dlvsym(void *" handle ", char *" symbol ", char *" version );
38.sp
39Link with \fI\-ldl\fP.
40.SH DESCRIPTION
41The function
42.BR dlsym ()
43takes a "handle" of a dynamic loaded shared object returned by
44.BR dlopen (3)
45along with a null-terminated symbol name,
46and returns the address where that symbol is
47loaded into memory.
48If the symbol is not found, in the specified
49object or any of the shared objects that were automatically loaded by
50.BR dlopen (3)
51when that object was loaded,
52.BR dlsym ()
53returns NULL.
54(The search performed by
55.BR dlsym ()
56is breadth first through the dependency tree of these shared objects.)
57
58Since the value of the symbol could actually be NULL (so that a
59NULL return from
60.BR dlsym ()
61need not indicate an error), the correct way to test for an error
62is to call
63.BR dlerror (3)
64to clear any old error conditions, then call
65.BR dlsym (),
66and then call
67.BR dlerror (3)
68again, saving its return value into a variable, and check whether
69this saved value is not NULL.
70.PP
71There are two special pseudo-handles that may be specified in
72.IR handle :
73.TP
74.B RTLD_DEFAULT
75Find the first occurrence of the desired symbol
76using the default shared object search order.
77The search will include global symbols in the executable
78and its dependencies,
79as well as symbols in shared objects that were dynamically loaded with the
80.BR RTLD_GLOBAL
81flag.
82.TP
83.BR RTLD_NEXT
84Find the next occurrence of the desired symbol in the search order
85after the current object.
86This allows one to provide a wrapper
87around a function in another shared object, so that, for example,
88the definition of a function in a preloaded shared object
89(see
90.B LD_PRELOAD
91in
92.BR ld.so (8))
93can find and invoke the "real" function provided in another shared object
94(or for that matter, the "next" definition of the function in cases
95where there are multiple layers of preloading).
96
97The function
98.BR dlvsym ()
99does the same as
100.BR dlsym ()
101but takes a version string as an additional argument.
102.SH RETURN VALUE
103On success,
104these functions return the address associated with
105.IR symbol .
106On failure, they return NULL;
107the cause of the error can be diagnosed using
108.BR dlerror (3).
109.SH VERSIONS
110.BR dlsym ()
111is present in glibc 2.0 and later.
112.BR dlvsym ()
113first appeared in glibc 2.1.
39720f03
MK
114.SH ATTRIBUTES
115For an explanation of the terms used in this section, see
116.BR attributes (7).
117.TS
118allbox;
119lb lb lb
120l l l.
121Interface Attribute Value
122T{
123.BR dlsym (),
124.BR dlvsym ()
125T} Thread safety MT-Safe
126.TE
15e1b31b
MK
127.SH CONFORMING TO
128POSIX.1-2001 describes
129.BR dlsym ().
130The
131.BR dlvsym ()
132function is a GNU extension.
133.SH NOTES
134.SS History
135The
136.BR dlsym ()
137function is part of the dlopen API, derived from SunOS.
138That system does not have
139.BR dlvsym ().
140.SH EXAMPLE
141See
142.BR dlopen (3).
143.SH SEE ALSO
144.BR dl_iterate_phdr (3),
145.BR dladdr (3),
936b64f6 146.BR dlerror (3),
15e1b31b
MK
147.BR dlinfo (3),
148.BR dlopen (3),
149.BR ld.so (8)