4660 update man pages for lofi in a zone
[unleashed.git] / usr / src / man / man3c / dlopen.3c
blob6555f230031e2e8d82d0b4d7f011c04f92ef98b6
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 "Feb 4, 2005"
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 .sp
25 .LP
26 The \fBdlopen()\fR function makes an executable object file available to a
27 running process. \fBdlopen()\fR returns to the process a \fIhandle\fR that the
28 process can use on subsequent calls to \fBdlsym\fR(3C), \fBdladdr\fR(3C),
29 \fBdlinfo\fR(3C), and \fBdlclose\fR(3C). The value of this \fIhandle\fR should
30 not be interpreted in any way by the process. The \fIpathname\fR argument is
31 the path name of the object to be opened. A path name containing an embedded
32 \fB\&'/'\fR is interpreted as an absolute path or relative to the current
33 directory. Otherwise, the set of search paths currently in effect by the
34 runtime linker are used to locate the specified file. See \fBNOTES\fR.
35 .sp
36 .LP
37 The \fBdlopen()\fR function also loads any dependencies recorded within
38 \fIpathname\fR. These dependencies are searched in the order in which the
39 dependencies were loaded to locate any additional dependencies. This process
40 continues until all the dependencies of \fIpathname\fR are loaded. This
41 dependency tree is referred to as a group.
42 .sp
43 .LP
44 If the value of \fIpathname\fR is \fB0\fR, \fBdlopen()\fR provides a
45 \fIhandle\fR on a set of global symbol objects. These objects consist of the
46 original program image file, any dependencies loaded at program startup, and
47 any objects loaded using \fBdlopen()\fR with the \fBRTLD_GLOBAL\fR flag.
48 Because the latter set of objects can change during process execution, the set
49 identified by \fIhandle\fR can also change dynamically.
50 .sp
51 .LP
52 The \fImode\fR argument describes how \fBdlopen()\fR operates on \fIpathname\fR
53 with respect to the processing of reference relocations. The \fImode\fR also
54 affects the scope of visibility of the symbols provided by \fIpathname\fR and
55 its dependencies. This visibility can affect how the resulting \fIhandle\fR is
56 used.
57 .sp
58 .LP
59 When an object is loaded, the object can contain references to symbols whose
60 addresses are not known until the object is loaded. These references must be
61 relocated before the symbols can be accessed. References are categorized as
62 either \fBimmediate\fR or \fBlazy\fR. Immediate references are typically
63 references to data items used by the object code. Immediate references include
64 pointers to functions and calls to functions made from position-dependent
65 shared objects. Lazy references are typically calls to global functions that
66 are made from position-independent shared objects. The \fImode\fR argument
67 governs when these references take place. The \fImode\fR argument can be one of
68 the following values:
69 .sp
70 .ne 2
71 .na
72 \fB\fBRTLD_LAZY\fR\fR
73 .ad
74 .RS 13n
75 Only immediate symbol references are relocated when the object is first loaded.
76 Lazy references are not relocated until a given function is called for the
77 first time. This value for \fImode\fR should improve performance, since a
78 process might not require all lazy references in any given object. This
79 behavior mimics the normal loading of dependencies during process
80 initialization. See \fBNOTES\fR.
81 .RE
83 .sp
84 .ne 2
85 .na
86 \fB\fBRTLD_NOW\fR\fR
87 .ad
88 .RS 13n
89 All necessary relocations are performed when the object is first loaded. This
90 process might waste some processing if relocations are performed for lazy
91 references that are never used. However, this mode ensures that when an object
92 is loaded, all symbols referenced during execution are available. This behavior
93 mimics the loading of dependencies when the environment variable
94 \fBLD_BIND_NOW\fR is in effect.
95 .RE
97 .sp
98 .LP
99 See the \fILinker and Libraries Guide\fR for more information about symbol
100 references.
103 The visibility of symbols that are available for relocation can be affected by
104 \fImode\fR. To specify the scope of visibility for symbols that are loaded with
105 a \fBdlopen()\fR call, \fImode\fR should be a bitwise-inclusive OR with one of
106 the following values:
108 .ne 2
110 \fB\fBRTLD_GLOBAL\fR\fR
112 .RS 15n
113 The object's global symbols are made available for the relocation processing of
114 any other object. In addition, symbol lookup using \fBdlopen(0,\fR
115 \fImode\fR\fB)\fR and an associated \fBdlsym()\fR allows objects that are
116 loaded with \fBRTLD_GLOBAL\fR to be searched.
120 .ne 2
122 \fB\fBRTLD_LOCAL\fR\fR
124 .RS 15n
125 The object's globals symbols are only available for the relocation processing
126 of other objects that include the same group.
131 The program image file and any objects loaded at program startup have the mode
132 \fBRTLD_GLOBAL\fR. The mode \fBRTLD_LOCAL\fR is the default mode for any
133 objects that are acquired with \fBdlopen()\fR. A local object can be a
134 dependency of more then one group. Any object of mode \fBRTLD_LOCAL\fR that is
135 referenced as a dependency of an object of mode \fBRTLD_GLOBAL\fR is promoted
136 to \fBRTLD_GLOBAL\fR. In other words, the \fBRTLD_LOCAL\fR mode is ignored.
139 Any object loaded by \fBdlopen()\fR that requires relocations against global
140 symbols can reference the symbols in any \fBRTLD_GLOBAL\fR object. Objects of
141 this mode are at least the program image file and any objects loaded at program
142 startup. A loaded object can also reference symbols from itself, and from any
143 dependencies the object references. However, the \fImode\fR parameter can also
144 be a bitwise-inclusive \fBOR\fR with one of the following values to affect the
145 scope of symbol availability:
147 .ne 2
149 \fB\fBRTLD_GROUP\fR\fR
151 .RS 15n
152 Only symbols from the associated group are made available for relocation. A
153 group is established from the defined object and all the dependencies of that
154 object. A group must be completely self-contained. All dependency relationships
155 between the members of the group must be sufficient to satisfy the relocation
156 requirements of each object that defines the group.
160 .ne 2
162 \fB\fBRTLD_PARENT\fR\fR
164 .RS 15n
165 The symbols of the object initiating the \fBdlopen()\fR call are made available
166 to the objects obtained by \fBdlopen()\fR. This option is useful when
167 hierarchical \fBdlopen()\fR families are created. Although the parent object
168 can supply symbols for the relocation of this object, the parent object is not
169 available to \fBdlsym()\fR through the returned \fIhandle\fR.
173 .ne 2
175 \fB\fBRTLD_WORLD\fR\fR
177 .RS 15n
178 Only symbols from \fBRTLD_GLOBAL\fR objects are made available for relocation.
183 The default modes for \fBdlopen()\fR are both \fBRTLD_WORLD\fR and
184 \fBRTLD_GROUP\fR. If an object is requires additional modes, the \fImode\fR
185 parameter can be the bitwise-inclusive OR of the required modes together with
186 the default modes.
189 The following modes provide additional capabilities outside of relocation
190 processing:
192 .ne 2
194 \fB\fBRTLD_NODELETE\fR\fR
196 .RS 17n
197 The specified object is tagged to prevent its deletion from the address space
198 as part of a \fBdlclose()\fR.
202 .ne 2
204 \fB\fBRTLD_NOLOAD\fR\fR
206 .RS 17n
207 The specified object is not loaded as part of the \fBdlopen()\fR. However, a
208 valid \fIhandle\fR is returned if the object already exists as part of the
209 process address space. Additional modes can be specified as a bitwise-inclusive
210 OR with the present mode of the object and its dependencies. The
211 \fBRTLD_NOLOAD\fR mode provides a means of querying the presence or promoting
212 the modes of an existing dependency.
217 The default use of a \fIhandle\fR with \fBdlsym()\fR allows a symbol search to
218 inspect all objects that are associated with the group of objects that are
219 loaded from \fBdlopen()\fR. The \fImode\fR parameter can also be a
220 bitwise-inclusive OR with the following value to restrict this symbol search:
222 .ne 2
224 \fB\fBRTLD_FIRST\fR\fR
226 .RS 14n
227 Use of this \fIhandle\fR with \fBdlsym()\fR, restricts the symbol search to the
228 first object associated with the \fIhandle\fR.
233 An object can be accessed from a process both with and without
234 \fBRTLD_FIRST\fR. Although the object will only be loaded once, two different
235 \fIhandle\fRs are created to provide for the different \fBdlsym()\fR
236 requirements.
239 The \fBdlmopen()\fR function is identical to \fBdlopen()\fR, except that an
240 identifying link-map ID \fI(lmid)\fR is provided. This link-map ID informs the
241 dynamic linking facilities upon which link-map list to load the object. See the
242 \fILinker and Libraries Guide\fR for details about link-maps.
245 The \fIlmid\fR passed to \fBdlmopen()\fR identifies the link-map list on which
246 the object is loaded. This parameter can be any valid \fBLmid_t\fR returned by
247 \fBdlinfo()\fR or one of the following special values:
249 .ne 2
251 \fB\fBLM_ID_BASE\fR\fR
253 .RS 15n
254 Load the object on the applications link-map list.
258 .ne 2
260 \fB\fBLM_ID_LDSO\fR\fR
262 .RS 15n
263 Load the object on the dynamic linkers (\fBld.so.1\fR) link-map list.
267 .ne 2
269 \fB\fBLM_ID_NEWLM\fR\fR
271 .RS 15n
272 Cause the object to create a new link-map list as part of loading. Objects that
273 are opened on a new link-map list must express all of their dependencies.
276 .SH RETURN VALUES
279 The \fBdlopen()\fR function returns \fINULL\fR if \fIpathname\fR cannot be
280 found, cannot be opened for reading, or is not a shared object or a relocatable
281 object. \fBdlopen()\fR also returns \fINULL\fR if an error occurs during the
282 process of loading \fIpathname\fR or relocating its symbolic references. See
283 \fBNOTES\fR. Additional diagnostic information is available through
284 \fBdlerror()\fR.
285 .SH USAGE
288 The \fBdlopen()\fR and \fBdlmopen()\fR functions are members of a family of
289 functions that give the user direct access to the dynamic linking facilities.
290 This family of functions is available only to dynamically-linked processes. See
291 the \fILinker and Libraries Guide\fR.
292 .SH ATTRIBUTES
295 See \fBattributes\fR(5) for descriptions of the following attributes:
300 box;
301 c | c
302 l | l .
303 ATTRIBUTE TYPE  ATTRIBUTE VALUE
305 Interface Stability     Standard
307 MT\(miLevel     MT\(miSafe
310 .SH SEE ALSO
313 \fBld\fR(1), \fBld.so.1\fR(1), \fBdladdr\fR(3C), \fBdlclose\fR(3C),
314 \fBdldump\fR(3C), \fBdlerror\fR(3C), \fBdlinfo\fR(3C), \fBdlsym\fR(3C),
315 \fBattributes\fR(5), \fBstandards\fR(5)
318 \fILinker and Libraries Guide\fR
319 .SH NOTES
322 If \fIpathname\fR has dependencies on other objects, these objects are
323 automatically loaded by \fBdlopen()\fR. The directory search path used to find
324 \fIpathname\fR and any dependencies can be affected by setting the environment
325 variable \fBLD_LIBRARY_PATH\fR. Any \fBLD_LIBRARY_PATH\fR variable is analyzed
326 once at process startup. The search path can also be affected from a runpath
327 setting within the object from which the call to \fBdlopen()\fR originates.
328 These search rules will only be applied to path names that do not contain an
329 embedded \fB\&'/'\fR. Objects whose names resolve to the same absolute path
330 name or relative path name can be opened any number of times using
331 \fBdlopen()\fR. However, the object that is referenced will only be loaded once
332 into the address space of the current process.
335 When loading shared objects, the application should open a specific version of
336 the shared object. Do not rely on the version of the shared object pointed to
337 by the symbolic link.
340 When building objects to be loaded on a new link-map list, some precautions
341 need to be taken. In general, all dependencies must be included when building
342 an object. Also, include \fB/usr/lib/libmapmalloc.so.1\fR before
343 \fB/lib/libc.so.1\fR when building an object.
346 When an object is loaded on a new link-map list, the object is isolated from
347 the main running program. Certain global resources are only usable from one
348 link-map list. A few examples are the \fBsbrk()\fR based \fBmalloc()\fR,
349 \fBlibthread()\fR, and the signal vectors. Care must be taken not to use any of
350 these resources other than from the primary link-map list. These issues are
351 discussed in further detail in the \fILinker and Libraries Guide\fR.
354 Some symbols defined in dynamic executables or shared objects can not be
355 available to the runtime linker. The symbol table created by \fBld\fR for use
356 by the runtime linker might contain only a subset of the symbols that are
357 defined in the object.
360 As part of loading a new object, initialization code within the object is
361 called \fBbefore\fR the \fBdlopen()\fR returns. This initialization is user
362 code, and as such, can produce errors that can not be caught by \fBdlopen()\fR.
363 For example, an object loaded using \fBRTLD_LAZY\fR that attempts to call a
364 function that can not be located results in process termination. Erroneous
365 programming practices within the initialization code can also result in process
366 termination. The runtime linkers debugging facility can offer help identifying
367 these types of error. See the \fBLD_DEBUG\fR environment variable of
368 \fBld.so.1\fR(1).
371 Loading relocatable objects is an expensive operation that requires converting
372 the relocatable object into a shared object memory image. This capability may
373 be useful in a debugging environment, but is not recommended for production
374 software.