1 .\" This source code is a product of Sun Microsystems, Inc. and is provided
2 .\" for unrestricted use provided that this legend is included on all tape
3 .\" media and as a part of the software program in whole or part. Users
4 .\" may copy or modify this source code without charge, but are not authorized
5 .\" to license or distribute it to anyone else except as part of a product or
6 .\" program developed by the user.
8 .\" THIS PROGRAM CONTAINS SOURCE CODE COPYRIGHTED BY SUN MICROSYSTEMS, INC.
9 .\" SUN MICROSYSTEMS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABLITY
10 .\" OF SUCH SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
11 .\" EXPRESS OR IMPLIED WARRANTY OF ANY KIND. SUN MICROSYSTEMS, INC. DISCLAIMS
12 .\" ALL WARRANTIES WITH REGARD TO SUCH SOURCE CODE, INCLUDING ALL IMPLIED
13 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN
14 .\" NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT,
15 .\" INCIDENTAL, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
16 .\" FROM USE OF SUCH SOURCE CODE, REGARDLESS OF THE THEORY OF LIABILITY.
18 .\" This source code is provided with no support and without any obligation on
19 .\" the part of Sun Microsystems, Inc. to assist in its use, correction,
20 .\" modification or enhancement.
22 .\" SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
23 .\" INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS
24 .\" SOURCE CODE OR ANY PART THEREOF.
26 .\" Sun Microsystems, Inc.
27 .\" 2550 Garcia Avenue
28 .\" Mountain View, California 94043
30 .\" Copyright (c) 1991 Sun Microsystems, Inc.
32 .\" @(#) dlopen.3 1.6 90/01/31 SMI
33 .\" $FreeBSD: head/lib/libc/gen/dlopen.3 211397 2010-08-16 15:18:30Z joel $
41 .Nd returns handle to dynamically loaded shared object
43 This function is not in a library.
44 It is included in every dynamically linked program automatically.
48 .Fn dlopen "const char *name" "int mode"
50 .Fn fdlopen "int fd" "int mode"
55 provides access to the shared object in
57 returning a descriptor that can be used for later
58 references to the object in calls to other dl functions.
61 was not in the address space prior to the call to
63 it is placed in the address space.
64 When an object is first loaded into the address space in this way, its
67 if any, is called by the dynamic linker.
70 has already been placed in the address space in a previous call to
72 it is not added a second time, although a reference count of
77 A null pointer supplied for
79 is interpreted as a reference to the main
80 executable of the process.
84 controls the way in which external function references from the
85 loaded object are bound to their referents.
86 It must contain one of the following values, possibly ORed with
87 additional flags which will be described subsequently:
88 .Bl -tag -width ".Dv RTLD_NODELETE"
90 Each external function reference is resolved when the function is first
93 All external function references are bound immediately by
98 is normally preferred, for reasons of efficiency.
101 is useful to ensure that any undefined symbols are discovered during the
105 One of the following flags may be ORed into the
108 .Bl -tag -width ".Dv RTLD_NODELETE"
110 Symbols from this shared object and its directed acyclic graph (DAG)
111 of needed objects will be available for resolving undefined references
112 from all other shared objects.
114 Symbols in this shared object and its DAG of needed objects will be
115 available for resolving undefined references only from other objects
117 This is the default, but it may be specified
118 explicitly with this flag.
120 When set, causes dynamic linker to exit after loading all objects
121 needed by this shared object and printing a summary which includes
122 the absolute pathnames of all objects, to standard output.
125 will return to the caller only in the case of error.
127 Prevents unload of the loaded object on
129 The same behaviour may be requested by
131 option of the static linker
134 Only return valid handle for the object if it is already loaded in
135 the process address space, otherwise
138 Other mode flags may be specified, which will be applied for promotion
139 for the found object.
144 fails, it returns a null pointer, and sets an error condition which may
150 function is similar to
152 but it takes the file descriptor argument
154 which is used for the file operations needed to load an object
155 into the address space.
158 is not closed by the function regardless a result of execution,
159 but a duplicate of the file descriptor is.
160 This may be important if a
162 lock is held on the passed descriptor.
165 argument -1 is interpreted as a reference to the main
166 executable of the process, similar to
174 function can be used by the code that needs to perform
175 additional checks on the loaded objects, to prevent races with
176 symlinking or renames.
178 The functions return a null pointer in the event of an error.
179 Whenever an error has been detected, a message detailing it can be
180 retrieved via a call to
183 The following program will open any shared gcc library found
184 and display the directory in which it was found using the
192 main (int argc, char *argv[])
198 /* open shared gcc library */
199 handle = dlopen("libgcc_s.so", RTLD_LAZY);
201 fprintf (stderr, "%s\en", dlerror ());
205 /* get information about the library origin */
206 result = dlinfo (handle, RTLD_DI_ORIGIN, (void *)&origin);
208 fprintf (stderr, "%s\en", dlerror ());
213 /* Display the origin */
214 printf ("libgcc_s origin is %s\en", &origin[0]);