summaryrefslogtreecommitdiff
path: root/share/man/man3/dlfcn.3
blob: 2ea5f7808c3ee74da69d3f4cc50442741195144c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
.\"	$NetBSD: dlfcn.3,v 1.3 1996/01/09 19:43:34 pk Exp $
.\"
.\" Copyright (c) 1995 Paul Kranenburg
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"      This product includes software developed by Paul Kranenburg.
.\" 3. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 30, 1995
.Dt DLFCN 3
.Os
.Sh NAME
.Nm dlopen , dlclose , dlsym , dlctl , dlerror
.Nd dynamic link interface
.Sh SYNOPSIS
.Fd #include <dlfcn.h>
.Ft "void *"
.Fn dlopen "char *path" "int mode"
.Ft "int"
.Fn dlclose "void *handle"
.Ft "void *"
.Fn dlsym "void *handle" "char *symbol"
.Ft "int"
.Fn dlctl "void *handle" "int cmd" "void *data"
.Ft "char *"
.Fn dlerror "void"
.Sh DESCRIPTION
These functions provide an interface to the run-time linker
.Xr ld.so .
They allow new shared objects to be loaded into a process's address space
under program control.
The
.Fn dlopen
function takes a name of a shared object as its first argument. The
shared object is mapped into the address space, relocated and its external
references are resolved in the same way as is done with the implicitly loaded
shared libraries at program startup. The argument can either be an absolute
pathname or it can be of the form
.Sm off
.Do Xo lib Ao name Ac .so
.Op .xx Op .yy Xc
.Dc
.Sm on
in which case the same library search rules apply that are used for
.Dq intrinsic
shared library searches.
The second argument currently has no effect, but should be set to
.Dv DL_LAZY
for future compatibility.
.Fn dlopen
returns a handle to be used in calls to
.Fn dlclose ,
.Fn dlsym
and
.Fn dlctl .
If the named shared object has already
been loaded by a previous call to
.Fn dlopen
.Pq and not yet unloaded by Fn dlclose ,
a handle referring to the resident copy is returned.
.Pp
.Fn dlclose
unlinks and removes the object referred to by
.Fa handle
from the process address space. If multiple calls to
.Fn dlopen
have been done on this object
.Po or the object was once loaded at startup time
.Pc
the object is removed when its reference count drops to zero.
.Pp
.Fn dlsym
looks for a definition of
.Fa symbol
in the shared object designated by
.Fa handle .
The symbol's address is returned. If the symbol cannot be resolved,
.Dv NULL
is returned.
.Pp
.Fn dlctl
provides an interface similar to
.Xr ioctl 2
to control several aspects of the run-time linker's operation. This interface
is
.Ud .
.Pp
.Fn dlerror
returns a character string representing the most recent error that has
occurred while processing one of the other functions described here.
.Sh SEE ALSO
.Xr ld 1 ,
.Xr rtld 1 ,
.Xr link 5
.Sh HISTORY
Some of the
.Nm dl*
functions first appeared in SunOS 4.
.Sh BUGS
An error that occurs while processing a
.Fn dlopen
request results in the termination of the program.