1DLOPEN(P) POSIX Programmer's Manual DLOPEN(P)
2
3
4
6 dlopen - gain access to an executable object file
7
9 #include <dlfcn.h>
10
11 void *dlopen(const char *file, int mode);
12
13
15 The dlopen() function shall make an executable object file specified by
16 file available to the calling program. The class of files eligible for
17 this operation and the manner of their construction are implementation-
18 defined, though typically such files are executable objects such as
19 shared libraries, relocatable files, or programs. Note that some imple‐
20 mentations permit the construction of dependencies between such objects
21 that are embedded within files. In such cases, a dlopen() operation
22 shall load such dependencies in addition to the object referenced by
23 file. Implementations may also impose specific constraints on the con‐
24 struction of programs that can employ dlopen() and its related ser‐
25 vices.
26
27 A successful dlopen() shall return a handle which the caller may use on
28 subsequent calls to dlsym() and dlclose(). The value of this handle
29 should not be interpreted in any way by the caller.
30
31 The file argument is used to construct a pathname to the object file.
32 If file contains a slash character, the file argument is used as the
33 pathname for the file. Otherwise, file is used in an implementation-
34 defined manner to yield a pathname.
35
36 If the value of file is 0, dlopen() shall provide a handle on a global
37 symbol object. This object shall provide access to the symbols from an
38 ordered set of objects consisting of the original program image file,
39 together with any objects loaded at program start-up as specified by
40 that process image file (for example, shared libraries), and the set of
41 objects loaded using a dlopen() operation together with the RTLD_GLOBAL
42 flag. As the latter set of objects can change during execution, the set
43 identified by handle can also change dynamically.
44
45 Only a single copy of an object file is brought into the address space,
46 even if dlopen() is invoked multiple times in reference to the file,
47 and even if different pathnames are used to reference the file.
48
49 The mode parameter describes how dlopen() shall operate upon file with
50 respect to the processing of relocations and the scope of visibility of
51 the symbols provided within file. When an object is brought into the
52 address space of a process, it may contain references to symbols whose
53 addresses are not known until the object is loaded. These references
54 shall be relocated before the symbols can be accessed. The mode parame‐
55 ter governs when these relocations take place and may have the follow‐
56 ing values:
57
58 RTLD_LAZY
59 Relocations shall be performed at an implementation-defined
60 time, ranging from the time of the dlopen() call until the first
61 reference to a given symbol occurs. Specifying RTLD_LAZY should
62 improve performance on implementations supporting dynamic symbol
63 binding as a process may not reference all of the functions in
64 any given object. And, for systems supporting dynamic symbol
65 resolution for normal process execution, this behavior mimics
66 the normal handling of process execution.
67
68 RTLD_NOW
69 All necessary relocations shall be performed when the object is
70 first loaded. This may waste some processing if relocations are
71 performed for functions that are never referenced. This behavior
72 may be useful for applications that need to know as soon as an
73 object is loaded that all symbols referenced during execution
74 are available.
75
76
77 Any object loaded by dlopen() that requires relocations against global
78 symbols can reference the symbols in the original process image file,
79 any objects loaded at program start-up, from the object itself as well
80 as any other object included in the same dlopen() invocation, and any
81 objects that were loaded in any dlopen() invocation and which specified
82 the RTLD_GLOBAL flag. To determine the scope of visibility for the sym‐
83 bols loaded with a dlopen() invocation, the mode parameter should be a
84 bitwise-inclusive OR with one of the following values:
85
86 RTLD_GLOBAL
87 The object's symbols shall be made available for the relocation
88 processing of any other object. In addition, symbol lookup using
89 dlopen(0, mode) and an associated dlsym() allows objects loaded
90 with this mode to be searched.
91
92 RTLD_LOCAL
93 The object's symbols shall not be made available for the reloca‐
94 tion processing of any other object.
95
96
97 If neither RTLD_GLOBAL nor RTLD_LOCAL are specified, then an implemen‐
98 tation-defined default behavior shall be applied.
99
100 If a file is specified in multiple dlopen() invocations, mode is inter‐
101 preted at each invocation. Note, however, that once RTLD_NOW has been
102 specified all relocations shall have been completed rendering further
103 RTLD_NOW operations redundant and any further RTLD_LAZY operations
104 irrelevant. Similarly, note that once RTLD_GLOBAL has been specified
105 the object shall maintain the RTLD_GLOBAL status regardless of any pre‐
106 vious or future specification of RTLD_LOCAL, as long as the object
107 remains in the address space (see dlclose() ).
108
109 Symbols introduced into a program through calls to dlopen() may be used
110 in relocation activities. Symbols so introduced may duplicate symbols
111 already defined by the program or previous dlopen() operations. To
112 resolve the ambiguities such a situation might present, the resolution
113 of a symbol reference to symbol definition is based on a symbol resolu‐
114 tion order. Two such resolution orders are defined: load or dependency
115 ordering. Load order establishes an ordering among symbol definitions,
116 such that the definition first loaded (including definitions from the
117 image file and any dependent objects loaded with it) has priority over
118 objects added later (via dlopen()). Load ordering is used in relocation
119 processing. Dependency ordering uses a breadth-first order starting
120 with a given object, then all of its dependencies, then any dependents
121 of those, iterating until all dependencies are satisfied. With the
122 exception of the global symbol object obtained via a dlopen() operation
123 on a file of 0, dependency ordering is used by the dlsym() function.
124 Load ordering is used in dlsym() operations upon the global symbol
125 object.
126
127 When an object is first made accessible via dlopen() it and its depen‐
128 dent objects are added in dependency order. Once all the objects are
129 added, relocations are performed using load order. Note that if an
130 object or its dependencies had been previously loaded, the load and
131 dependency orders may yield different resolutions.
132
133 The symbols introduced by dlopen() operations and available through
134 dlsym() are at a minimum those which are exported as symbols of global
135 scope by the object. Typically such symbols shall be those that were
136 specified in (for example) C source code as having extern linkage. The
137 precise manner in which an implementation constructs the set of
138 exported symbols for a dlopen() object is specified by that implementa‐
139 tion.
140
142 If file cannot be found, cannot be opened for reading, is not of an
143 appropriate object format for processing by dlopen(), or if an error
144 occurs during the process of loading file or relocating its symbolic
145 references, dlopen() shall return NULL. More detailed diagnostic infor‐
146 mation shall be available through dlerror() .
147
149 No errors are defined.
150
151 The following sections are informative.
152
154 None.
155
157 None.
158
160 None.
161
163 None.
164
166 dlclose() , dlerror() , dlsym() , the Base Definitions volume of
167 IEEE Std 1003.1-2001, <dlfcn.h>
168
170 Portions of this text are reprinted and reproduced in electronic form
171 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
172 -- Portable Operating System Interface (POSIX), The Open Group Base
173 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
174 Electrical and Electronics Engineers, Inc and The Open Group. In the
175 event of any discrepancy between this version and the original IEEE and
176 The Open Group Standard, the original IEEE and The Open Group Standard
177 is the referee document. The original Standard can be obtained online
178 at http://www.opengroup.org/unix/online.html .
179
180
181
182IEEE/The Open Group 2003 DLOPEN(P)