summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2017/man3p/dlsym.3p
blob: 474b2bae608f7da61a6ccb96314c14db8091dfc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
'\" et
.TH DLSYM "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
dlsym
\(em get the address of a symbol from a symbol table handle
.SH SYNOPSIS
.LP
.nf
#include <dlfcn.h>
.P
void *dlsym(void *restrict \fIhandle\fP, const char *restrict \fIname\fP);
.fi
.SH DESCRIPTION
The
\fIdlsym\fR()
function shall obtain the address of a symbol (a function identifier or
a data object identifier) defined in the symbol table identified by the
.IR handle
argument. The
.IR handle
argument is a symbol table handle returned from a call to
\fIdlopen\fR()
(and which has not since been released by a call to
\fIdlclose\fR()),
and
.IR name
is the symbol's name as a character string. The return value from
\fIdlsym\fR(),
cast to a pointer to the type of the named symbol, can be used to call
(in the case of a function) or access the contents of (in the case of
a data object) the named symbol.
.P
The
\fIdlsym\fR()
function shall search for the named symbol in the symbol table
referenced by
.IR handle .
If the symbol table was created with lazy loading
(see RTLD_LAZY in
\fIdlopen\fR()),
load ordering shall be used in
\fIdlsym\fR()
operations to relocate executable object files needed to resolve the
symbol. The symbol resolution algorithm used shall be dependency order
as described in
\fIdlopen\fR().
.P
The RTLD_DEFAULT and RTLD_NEXT symbolic constants (which may be defined in
.IR <dlfcn.h> )
are reserved for future use as special values that applications may be
allowed to use for
.IR handle .
.SH "RETURN VALUE"
Upon successful completion, if
.IR name
names a function identifier,
\fIdlsym\fR()
shall return the address of the function converted from type pointer to
function to type pointer to
.BR void ;
otherwise,
\fIdlsym\fR()
shall return the address of the data object associated with the data
object identifier named by
.IR name
converted from a pointer to the type of the data object to a pointer to
.BR void .
If
.IR handle
does not refer to a valid symbol table handle or if the symbol named by
.IR name
cannot be found in the symbol table associated with
.IR handle ,
\fIdlsym\fR()
shall return a null pointer.
.P
More detailed diagnostic information shall be available through
\fIdlerror\fR().
.SH ERRORS
No errors are defined.
.LP
.IR "The following sections are informative."
.SH "EXAMPLES"
The following example shows how
\fIdlopen\fR()
and
\fIdlsym\fR()
can be used to access either a function or a data object. For simplicity,
error checking has been omitted.
.sp
.RS 4
.nf

void *handle;
int (*fptr)(int), *iptr, result;
/* open the needed symbol table */
handle = dlopen("/usr/home/me/libfoo.so", RTLD_LOCAL | RTLD_LAZY);
/* find the address of the function my_function */
fptr = (int (*)(int))dlsym(handle, "my_function");
/* find the address of the data object my_object */
iptr = (int *)dlsym(handle, "my_OBJ");
/* invoke my_function, passing the value of my_OBJ as the parameter */
result = (*fptr)(*iptr);
.fi
.P
.RE
.SH "APPLICATION USAGE"
The following special purpose values for
.IR handle
are reserved for future use and have the indicated meanings:
.IP RTLD_DEFAULT 12
The identifier lookup happens in the normal global scope; that is,
a search for an identifier using
.IR handle
would find the same definition as a direct use of this identifier in
the program code.
.IP RTLD_NEXT 12
Specifies the next executable object file after this one that defines
.IR name .
This one refers to the executable object file containing the invocation of
\fIdlsym\fR().
The next executable object file is the one found upon the application
of a load order symbol resolution algorithm (see
\fIdlopen\fR()).
The next symbol is either one of global scope (because it was introduced
as part of the original process image or because it was added with a
\fIdlopen\fR()
operation including the RTLD_GLOBAL flag), or is in an executable object
file that was included in the same
\fIdlopen\fR()
operation that loaded this one.
.P
The RTLD_NEXT flag is useful to navigate an intentionally created
hierarchy of multiply-defined symbols created through interposition. For
example, if a program wished to create an implementation of
\fImalloc\fR()
that embedded some statistics gathering about memory allocations, such
an implementation could use the real
\fImalloc\fR()
definition to perform the memory allocation \(em and itself only embed
the necessary logic to implement the statistics gathering function.
.P
Note that conversion from a
.BR "void *"
pointer to a function pointer as in:
.sp
.RS 4
.nf

fptr = (int (*)(int))dlsym(handle, "my_function");
.fi
.P
.RE
.P
is not defined by the ISO\ C standard. This standard requires this conversion to
work correctly on conforming implementations.
.SH RATIONALE
None.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIdlclose\fR\^(\|)",
.IR "\fIdlerror\fR\^(\|)",
.IR "\fIdlopen\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<dlfcn.h>\fP"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .