1 .\" $NetBSD: dlfcn.3,v 1.22 2009/03/10 23:32:26 joerg Exp $
3 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Paul Kranenburg.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
40 .Nd dynamic link interface
42 (These functions are not in a library. They are included in every
43 dynamically linked program automatically.)
47 .Fn dlopen "const char *path" "int mode"
49 .Fn dlclose "void *handle"
51 .Fn dlsym "void * restrict handle" "const char * restrict symbol"
53 .Fn dladdr "void * restrict addr" "Dl_info * restrict dli"
55 .Fn dlctl "void *handle" "int cmd" "void *data"
59 These functions provide an interface to the run-time linker
61 They allow new shared objects to be loaded into the process' address space
62 under program control.
65 function takes a name of a shared object as the first argument.
66 The shared object is mapped into the address space, relocated and
67 its external references are resolved in the same way as is done
68 with the implicitly loaded shared libraries at program startup.
69 The argument can either be an absolute pathname or it can be of the form
71 .Do lib Ao name Ac .so Oo .xx Oo .yy Oc Oc
74 in which case the same library search rules apply that are used for
76 shared library searches.
77 If the first argument is
80 returns a handle on the global symbol object. This object
81 provides access to all symbols from an ordered set of objects consisting
82 of the original program image and any dependencies loaded during startup.
84 The second argument has currently no effect, but should be set to
86 for future compatibility.
88 returns a handle to be used in calls to
93 If the named shared object has already
94 been loaded by a previous call to
96 .Pq and not yet unloaded by Fn dlclose ,
97 a handle referring to the resident copy is returned.
100 unlinks and removes the object referred to by
102 from the process address space.
105 have been done on this object
106 .Po or the object was one loaded at startup time
108 the object is removed when its reference count drops to zero.
111 looks for a definition of
113 in the shared object designated by
115 The symbols address is returned.
116 If the symbol cannot be resolved,
121 examines all currently mapped shared objects for a symbol whose address --
122 as mapped in the process address space -- is closest to but not exceeding
123 the value passed in the first argument
125 The symbols of a shared object are only eligible if
127 is between the base address of the shared object and the value of the
130 in the same shared object. If no object for which this condition holds
133 will return 0. Otherwise, a non-zero value is returned and the
135 argument will be used to provide information on the selected symbol
136 and the shared object it is contained in.
139 argument points at a caller-provided
141 structure defined as follows:
142 .Bd -literal -offset indent
144 const char *dli_fname; /* File defining the symbol */
145 void *dli_fbase; /* Base address */
146 const char *dli_sname; /* Symbol name */
147 const void *dli_saddr; /* Symbol address */
153 points at the nul-terminated name of the selected symbol, and
155 is the actual address
156 .Pq as it appears in the process address space
160 points at the file name corresponding to the shared object in which the
161 symbol was found, while
163 is the base address at which this shared object is loaded in the process
168 may be zero if the symbol was found in the internally generated
175 which is not associated with a file.
176 Note: both strings pointed at by
180 reside in memory private to the run-time linker module and should not
181 be modified by the caller.
184 provides an interface similar to
186 to control several aspects of the run-time linker's operation.
191 returns a character string representing the most recent error that has
192 occurred while processing one of the other functions described here.
193 If no dynamic linking errors have occurred since the last invocation of
200 a second time, immediately following a prior invocation, will result in
210 functions first appeared in SunOS 4.
212 An error that occurs while processing a
214 request results in the termination of the program.