nightly: remove unused BINARCHIVE
[unleashed.git] / share / man / man3c / dlopen.3c
blobb72d0705799356f47f4e681e0feeddf753fa5aa1
1 '\" te
2 .\"  Copyright 1989 AT&T Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH DLOPEN 3C "Sep 7, 2015"
7 .SH NAME
8 dlopen, dlmopen \- gain access to an executable object file
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <dlfcn.h>
13 #include <link.h>
15 \fBvoid *\fR\fBdlopen\fR(\fBconst char *\fR\fIpathname\fR, \fBint\fR \fImode\fR);
16 .fi
18 .LP
19 .nf
20 \fBvoid *\fR\fBdlmopen\fR(\fBLmid_t\fR \fIlmid\fR, \fBconst char *\fR\fIpathname\fR, \fBint\fR \fImode\fR);
21 .fi
23 .SH DESCRIPTION
24 .LP
25 The \fBdlopen()\fR function makes an executable object file available to a
26 running process. \fBdlopen()\fR returns to the process a \fIhandle\fR that the
27 process can use on subsequent calls to \fBdlsym\fR(3C), \fBdladdr\fR(3C),
28 \fBdlinfo\fR(3C), and \fBdlclose\fR(3C). The value of this \fIhandle\fR should
29 not be interpreted in any way by the process. The \fIpathname\fR argument is
30 the path name of the object to be opened. A path name containing an embedded
31 \fB\&'/'\fR is interpreted as an absolute path or relative to the current
32 directory. Otherwise, the set of search paths currently in effect by the
33 runtime linker are used to locate the specified file. See \fBNOTES\fR.
34 .sp
35 .LP
36 The \fBdlopen()\fR function also loads any dependencies recorded within
37 \fIpathname\fR. These dependencies are searched in the order in which the
38 dependencies were loaded to locate any additional dependencies. This process
39 continues until all the dependencies of \fIpathname\fR are loaded. This
40 dependency tree is referred to as a group.
41 .sp
42 .LP
43 If the value of \fIpathname\fR is \fB0\fR, \fBdlopen()\fR provides a
44 \fIhandle\fR on a set of global symbol objects. These objects consist of the
45 original program image file, any dependencies loaded at program startup, and
46 any objects loaded using \fBdlopen()\fR with the \fBRTLD_GLOBAL\fR flag.
47 Because the latter set of objects can change during process execution, the set
48 identified by \fIhandle\fR can also change dynamically.
49 .sp
50 .LP
51 The \fImode\fR argument describes how \fBdlopen()\fR operates on \fIpathname\fR
52 with respect to the processing of reference relocations. The \fImode\fR also
53 affects the scope of visibility of the symbols provided by \fIpathname\fR and
54 its dependencies. This visibility can affect how the resulting \fIhandle\fR is
55 used.
56 .sp
57 .LP
58 When an object is loaded, the object can contain references to symbols whose
59 addresses are not known until the object is loaded. These references must be
60 relocated before the symbols can be accessed. References are categorized as
61 either \fBimmediate\fR or \fBlazy\fR. Immediate references are typically
62 references to data items used by the object code. Immediate references include
63 pointers to functions and calls to functions made from position-dependent
64 shared objects. Lazy references are typically calls to global functions that
65 are made from position-independent shared objects. The \fImode\fR argument
66 governs when these references take place. The \fImode\fR argument can be one of
67 the following values:
68 .sp
69 .ne 2
70 .na
71 \fB\fBRTLD_LAZY\fR\fR
72 .ad
73 .RS 13n
74 Only immediate symbol references are relocated when the object is first loaded.
75 Lazy references are not relocated until a given function is called for the
76 first time. This value for \fImode\fR should improve performance, since a
77 process might not require all lazy references in any given object. This
78 behavior mimics the normal loading of dependencies during process
79 initialization. See \fBNOTES\fR.
80 .RE
82 .sp
83 .ne 2
84 .na
85 \fB\fBRTLD_NOW\fR\fR
86 .ad
87 .RS 13n
88 All necessary relocations are performed when the object is first loaded. This
89 process might waste some processing if relocations are performed for lazy
90 references that are never used. However, this mode ensures that when an object
91 is loaded, all symbols referenced during execution are available. This behavior
92 mimics the loading of dependencies when the environment variable
93 \fBLD_BIND_NOW\fR is in effect.
94 .RE
96 .sp
97 .LP
98 See the \fILinker and Libraries Guide\fR for more information about symbol
99 references.
102 The visibility of symbols that are available for relocation can be affected by
103 \fImode\fR. To specify the scope of visibility for symbols that are loaded with
104 a \fBdlopen()\fR call, \fImode\fR should be a bitwise-inclusive OR with one of
105 the following values:
107 .ne 2
109 \fB\fBRTLD_GLOBAL\fR\fR
111 .RS 15n
112 The object's global symbols are made available for the relocation processing of
113 any other object. In addition, symbol lookup using \fBdlopen(0,\fR
114 \fImode\fR\fB)\fR and an associated \fBdlsym()\fR allows objects that are
115 loaded with \fBRTLD_GLOBAL\fR to be searched.
119 .ne 2
121 \fB\fBRTLD_LOCAL\fR\fR
123 .RS 15n
124 The object's globals symbols are only available for the relocation processing
125 of other objects that include the same group.
130 The program image file and any objects loaded at program startup have the mode
131 \fBRTLD_GLOBAL\fR. The mode \fBRTLD_LOCAL\fR is the default mode for any
132 objects that are acquired with \fBdlopen()\fR. A local object can be a
133 dependency of more then one group. Any object of mode \fBRTLD_LOCAL\fR that is
134 referenced as a dependency of an object of mode \fBRTLD_GLOBAL\fR is promoted
135 to \fBRTLD_GLOBAL\fR. In other words, the \fBRTLD_LOCAL\fR mode is ignored.
138 Any object loaded by \fBdlopen()\fR that requires relocations against global
139 symbols can reference the symbols in any \fBRTLD_GLOBAL\fR object. Objects of
140 this mode are at least the program image file and any objects loaded at program
141 startup. A loaded object can also reference symbols from itself, and from any
142 dependencies the object references. However, the \fImode\fR parameter can also
143 be a bitwise-inclusive \fBOR\fR with one of the following values to affect the
144 scope of symbol availability:
146 .ne 2
148 \fB\fBRTLD_GROUP\fR\fR
150 .RS 15n
151 Only symbols from the associated group are made available for relocation. A
152 group is established from the defined object and all the dependencies of that
153 object. A group must be completely self-contained. All dependency relationships
154 between the members of the group must be sufficient to satisfy the relocation
155 requirements of each object that defines the group.
159 .ne 2
161 \fB\fBRTLD_PARENT\fR\fR
163 .RS 15n
164 The symbols of the object initiating the \fBdlopen()\fR call are made available
165 to the objects obtained by \fBdlopen()\fR. This option is useful when
166 hierarchical \fBdlopen()\fR families are created. Although the parent object
167 can supply symbols for the relocation of this object, the parent object is not
168 available to \fBdlsym()\fR through the returned \fIhandle\fR.
172 .ne 2
174 \fB\fBRTLD_WORLD\fR\fR
176 .RS 15n
177 Only symbols from \fBRTLD_GLOBAL\fR objects are made available for relocation.
182 The default modes for \fBdlopen()\fR are both \fBRTLD_WORLD\fR and
183 \fBRTLD_GROUP\fR. If an object is requires additional modes, the \fImode\fR
184 parameter can be the bitwise-inclusive OR of the required modes together with
185 the default modes.
188 The following modes provide additional capabilities outside of relocation
189 processing:
191 .ne 2
193 \fB\fBRTLD_NODELETE\fR\fR
195 .RS 17n
196 The specified object is tagged to prevent its deletion from the address space
197 as part of a \fBdlclose()\fR.
201 .ne 2
203 \fB\fBRTLD_NOLOAD\fR\fR
205 .RS 17n
206 The specified object is not loaded as part of the \fBdlopen()\fR. However, a
207 valid \fIhandle\fR is returned if the object already exists as part of the
208 process address space. Additional modes can be specified as a bitwise-inclusive
209 OR with the present mode of the object and its dependencies. The
210 \fBRTLD_NOLOAD\fR mode provides a means of querying the presence or promoting
211 the modes of an existing dependency.
216 The default use of a \fIhandle\fR with \fBdlsym()\fR allows a symbol search to
217 inspect all objects that are associated with the group of objects that are
218 loaded from \fBdlopen()\fR. The \fImode\fR parameter can also be a
219 bitwise-inclusive OR with the following value to restrict this symbol search:
221 .ne 2
223 \fB\fBRTLD_FIRST\fR\fR
225 .RS 14n
226 Use of this \fIhandle\fR with \fBdlsym()\fR, restricts the symbol search to the
227 first object associated with the \fIhandle\fR.
232 An object can be accessed from a process both with and without
233 \fBRTLD_FIRST\fR. Although the object will only be loaded once, two different
234 \fIhandle\fRs are created to provide for the different \fBdlsym()\fR
235 requirements.
238 The \fBdlmopen()\fR function is identical to \fBdlopen()\fR, except that an
239 identifying link-map ID \fI(lmid)\fR is provided. This link-map ID informs the
240 dynamic linking facilities upon which link-map list to load the object. See the
241 \fILinker and Libraries Guide\fR for details about link-maps.
244 The \fIlmid\fR passed to \fBdlmopen()\fR identifies the link-map list on which
245 the object is loaded. This parameter can be any valid \fBLmid_t\fR returned by
246 \fBdlinfo()\fR or one of the following special values:
248 .ne 2
250 \fB\fBLM_ID_BASE\fR\fR
252 .RS 15n
253 Load the object on the applications link-map list.
257 .ne 2
259 \fB\fBLM_ID_LDSO\fR\fR
261 .RS 15n
262 Load the object on the dynamic linkers (\fBld.so.1\fR) link-map list.
266 .ne 2
268 \fB\fBLM_ID_NEWLM\fR\fR
270 .RS 15n
271 Cause the object to create a new link-map list as part of loading. Objects that
272 are opened on a new link-map list must express all of their dependencies.
275 .SH RETURN VALUES
277 The \fBdlopen()\fR function returns \fINULL\fR if \fIpathname\fR cannot be
278 found, cannot be opened for reading, or is not a shared object or a relocatable
279 object. \fBdlopen()\fR also returns \fINULL\fR if an error occurs during the
280 process of loading \fIpathname\fR or relocating its symbolic references. See
281 \fBNOTES\fR. Additional diagnostic information is available through
282 \fBdlerror()\fR.
283 .SH USAGE
285 The \fBdlopen()\fR and \fBdlmopen()\fR functions are members of a family of
286 functions that give the user direct access to the dynamic linking facilities.
287 This family of functions is available only to dynamically-linked processes. See
288 the \fILinker and Libraries Guide\fR.
289 .SH ATTRIBUTES
291 See \fBattributes\fR(5) for descriptions of the following attributes:
296 box;
297 c | c
298 l | l .
299 ATTRIBUTE TYPE  ATTRIBUTE VALUE
301 Interface Stability     Standard
303 MT\(miLevel     MT\(miSafe
306 .SH SEE ALSO
308 \fBld\fR(1), \fBld.so.1\fR(1), \fBdladdr\fR(3C), \fBdlclose\fR(3C),
309 \fBdldump\fR(3C), \fBdlerror\fR(3C), \fBdlinfo\fR(3C), \fBdlsym\fR(3C),
310 \fBattributes\fR(5), \fBstandards\fR(5)
313 \fILinker and Libraries Guide\fR
314 .SH NOTES
316 If \fIpathname\fR has dependencies on other objects, these objects are
317 automatically loaded by \fBdlopen()\fR. The directory search path used to find
318 \fIpathname\fR and any dependencies can be affected by setting the environment
319 variable \fBLD_LIBRARY_PATH\fR. Any \fBLD_LIBRARY_PATH\fR variable is analyzed
320 once at process startup. The search path can also be affected from a runpath
321 setting within the object from which the call to \fBdlopen()\fR originates.
322 These search rules will only be applied to path names that do not contain an
323 embedded \fB\&'/'\fR. Objects whose names resolve to the same absolute path
324 name or relative path name can be opened any number of times using
325 \fBdlopen()\fR. However, the object that is referenced will only be loaded once
326 into the address space of the current process.
329 When loading shared objects, the application should open a specific version of
330 the shared object. Do not rely on the version of the shared object pointed to
331 by the symbolic link.
334 When building objects to be loaded on a new link-map list, some precautions
335 need to be taken. In general, all dependencies must be included when building
336 an object. Also, include \fB/usr/lib/libmapmalloc.so.1\fR before
337 \fB/lib/libc.so.1\fR when building an object.
340 When an object is loaded on a new link-map list, the object is isolated from
341 the main running program. Certain global resources are only usable from one
342 link-map list. A few examples are the \fBsbrk()\fR based \fBmalloc()\fR,
343 \fBlibthread()\fR, and the signal vectors. Care must be taken not to use any of
344 these resources other than from the primary link-map list. These issues are
345 discussed in further detail in the \fILinker and Libraries Guide\fR.
348 Some symbols defined in dynamic executables or shared objects can not be
349 available to the runtime linker. The symbol table created by \fBld\fR for use
350 by the runtime linker might contain only a subset of the symbols that are
351 defined in the object.
354 As part of loading a new object, initialization code within the object is
355 called \fBbefore\fR the \fBdlopen()\fR returns. This initialization is user
356 code, and as such, can produce errors that can not be caught by \fBdlopen()\fR.
357 For example, an object loaded using \fBRTLD_LAZY\fR that attempts to call a
358 function that can not be located results in process termination. Erroneous
359 programming practices within the initialization code can also result in process
360 termination. The runtime linkers debugging facility can offer help identifying
361 these types of error. See the \fBLD_DEBUG\fR environment variable of
362 \fBld.so.1\fR(1).
365 Loading relocatable objects is an expensive operation that requires converting
366 the relocatable object into a shared object memory image. This capability may
367 be useful in a debugging environment, but is not recommended for production
368 software.