1DLOPEN(3P)                 POSIX Programmer's Manual                DLOPEN(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       dlopen — open a symbol table handle
13

SYNOPSIS

15       #include <dlfcn.h>
16
17       void *dlopen(const char *file, int mode);
18

DESCRIPTION

20       The dlopen() function shall make the symbols (function identifiers  and
21       data  object  identifiers)  in  the executable object file specified by
22       file available to the calling program.
23
24       The class of executable object files eligible for  this  operation  and
25       the  manner  of  their  construction are implementation-defined, though
26       typically such files are shared libraries or programs.
27
28       Implementations may permit the construction of embedded dependencies in
29       executable object files. In such cases, a dlopen() operation shall load
30       those dependencies in addition to the executable object file  specified
31       by  file.   Implementations may also impose specific constraints on the
32       construction of programs that can employ dlopen() and its related  ser‐
33       vices.
34
35       A  successful  dlopen()  shall  return  a symbol table handle which the
36       caller may use on subsequent calls to dlsym() and dlclose().
37
38       The value of this symbol table handle should not be interpreted in  any
39       way by the caller.
40
41       The  file  argument  is  used to construct a pathname to the executable
42       object file. If file contains a <slash> character, the file argument is
43       used as the pathname for the file. Otherwise, file is used in an imple‐
44       mentation-defined manner to yield a pathname.
45
46       If file is a null pointer, dlopen() shall return a global symbol  table
47       handle  for the currently running process image. This symbol table han‐
48       dle shall provide access to the symbols from an  ordered  set  of  exe‐
49       cutable object files consisting of the original program image file, any
50       executable object files loaded at program start-up as specified by that
51       process file (for example, shared libraries), and the set of executable
52       object files loaded using  dlopen()  operations  with  the  RTLD_GLOBAL
53       flag.  As  the  latter set of executable object files can change during
54       execution, the set of symbols made available by this symbol table  han‐
55       dle can also change dynamically.
56
57       Only  a  single copy of an executable object file shall be brought into
58       the address space, even if dlopen() is invoked multiple times in refer‐
59       ence to the executable object file, and even if different pathnames are
60       used to reference the executable object file.
61
62       The mode parameter describes how dlopen() shall operate upon file  with
63       respect to the processing of relocations and the scope of visibility of
64       the symbols provided within file.  When an executable  object  file  is
65       brought  into the address space of a process, it may contain references
66       to symbols whose addresses are not known until  the  executable  object
67       file is loaded.
68
69       These references shall be relocated before the symbols can be accessed.
70       The mode parameter governs when these relocations take  place  and  may
71       have the following values:
72
73       RTLD_LAZY   Relocations shall be performed at an implementation-defined
74                   time, ranging from the time of the dlopen() call until  the
75                   first  reference  to  a  given  symbol  occurs.  Specifying
76                   RTLD_LAZY should  improve  performance  on  implementations
77                   supporting dynamic symbol binding since a process might not
78                   reference all of the symbols in an executable object  file.
79                   And,  for  systems supporting dynamic symbol resolution for
80                   normal process execution, this behavior mimics  the  normal
81                   handling of process execution.
82
83       RTLD_NOW    All  necessary relocations shall be performed when the exe‐
84                   cutable object file is first loaded. This  may  waste  some
85                   processing  if  relocations  are performed for symbols that
86                   are never referenced.  This  behavior  may  be  useful  for
87                   applications  that need to know that all symbols referenced
88                   during execution will be available before dlopen() returns.
89
90       Any executable object file loaded by dlopen() that requires relocations
91       against  global  symbols  can  reference  the  symbols  in the original
92       process image file, any  executable  object  files  loaded  at  program
93       start-up,  from  the  initial process image itself, from any other exe‐
94       cutable object file included in the same dlopen() invocation,  and  any
95       executable object files that were loaded in any dlopen() invocation and
96       which specified the RTLD_GLOBAL flag. To determine the scope  of  visi‐
97       bility  for  the  symbols  loaded  with a dlopen() invocation, the mode
98       parameter should be a bitwise-inclusive OR with one  of  the  following
99       values:
100
101       RTLD_GLOBAL The  executable  object file's symbols shall be made avail‐
102                   able for relocation  processing  of  any  other  executable
103                   object    file.    In   addition,   symbol   lookup   using
104                   dlopen(NULL,mode) and an  associated  dlsym()  allows  exe‐
105                   cutable object files loaded with this mode to be searched.
106
107       RTLD_LOCAL  The  executable  object  file's  symbols  shall not be made
108                   available for relocation processing of any other executable
109                   object file.
110
111       If  neither RTLD_GLOBAL nor RTLD_LOCAL is specified, the default behav‐
112       ior is unspecified.
113
114       If an executable object file is specified in multiple dlopen()  invoca‐
115       tions, mode is interpreted at each invocation.
116
117       If  RTLD_NOW  has  been specified, all relocations shall have been com‐
118       pleted rendering further RTLD_NOW operations redundant and any  further
119       RTLD_LAZY operations irrelevant.
120
121       If  RTLD_GLOBAL  has  been  specified, the executable object file shall
122       maintain the RTLD_GLOBAL status regardless of any  previous  or  future
123       specification  of  RTLD_LOCAL,  as  long  as the executable object file
124       remains in the address space (see dlclose()).
125
126       Symbols introduced into the process image through calls to dlopen() may
127       be  used  in relocation activities. Symbols so introduced may duplicate
128       symbols already defined by the program or previous dlopen() operations.
129       To  resolve the ambiguities such a situation might present, the resolu‐
130       tion of a symbol reference to symbol definition is based  on  a  symbol
131       resolution  order.  Two  such resolution orders are defined: load order
132       and dependency order. Load order establishes an ordering  among  symbol
133       definitions,  such  that the first definition loaded (including defini‐
134       tions from the process image file and any dependent  executable  object
135       files  loaded  with it) has priority over executable object files added
136       later (by dlopen()).  Load ordering is used in  relocation  processing.
137       Dependency  ordering  uses  a breadth-first order starting with a given
138       executable object file, then all of its dependencies, then  any  depen‐
139       dents  of  those,  iterating until all dependencies are satisfied. With
140       the exception of the global symbol table handle obtained via a dlopen()
141       operation with a null pointer as the file argument, dependency ordering
142       is used by the dlsym() function. Load ordering is used in dlsym() oper‐
143       ations upon the global symbol table handle.
144
145       When  an  executable object file is first made accessible via dlopen(),
146       it and its dependent executable object files are  added  in  dependency
147       order.  Once all the executable object files are added, relocations are
148       performed using load order. Note that if an executable object  file  or
149       its  dependencies  had  been previously loaded, the load and dependency
150       orders may yield different resolutions.
151
152       The symbols introduced by dlopen()  operations  and  available  through
153       dlsym()  are  at  a  minimum those which are exported as identifiers of
154       global scope by the executable object file. Typically, such identifiers
155       shall  be  those  that were specified in (for example) C source code as
156       having extern linkage. The precise manner in  which  an  implementation
157       constructs the set of exported symbols for an executable object file is
158       implementation-defined.
159

RETURN VALUE

161       Upon successful completion, dlopen() shall return a symbol  table  han‐
162       dle.  If  file cannot be found, cannot be opened for reading, is not of
163       an  appropriate  executable  object  file  format  for  processing   by
164       dlopen(),  or  if an error occurs during the process of loading file or
165       relocating its  symbolic  references,  dlopen()  shall  return  a  null
166       pointer.  More  detailed  diagnostic  information  shall  be  available
167       through dlerror().
168

ERRORS

170       No errors are defined.
171
172       The following sections are informative.
173

EXAMPLES

175       Refer to dlsym().
176

APPLICATION USAGE

178       None.
179

RATIONALE

181       None.
182

FUTURE DIRECTIONS

184       None.
185

SEE ALSO

187       dlclose(), dlerror(), dlsym()
188
189       The Base Definitions volume of POSIX.1‐2017, <dlfcn.h>
190
192       Portions of this text are reprinted and reproduced in  electronic  form
193       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
194       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
195       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
196       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
197       event of any discrepancy between this version and the original IEEE and
198       The Open Group Standard, the original IEEE and The Open Group  Standard
199       is  the  referee document. The original Standard can be obtained online
200       at http://www.opengroup.org/unix/online.html .
201
202       Any typographical or formatting errors that appear  in  this  page  are
203       most likely to have been introduced during the conversion of the source
204       files to man page format. To report such errors,  see  https://www.ker
205       nel.org/doc/man-pages/reporting_bugs.html .
206
207
208
209IEEE/The Open Group                  2017                           DLOPEN(3P)
Impressum