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

NAME

6       dlsym - obtain the address of a symbol from a dlopen object
7

SYNOPSIS

9       #include <dlfcn.h>
10
11       void *dlsym(void *restrict handle, const char *restrict name);
12
13

DESCRIPTION

15       The  dlsym()  function  shall  obtain  the  address of a symbol defined
16       within an object made accessible through a dlopen()  call.  The  handle
17       argument  is  the value returned from a call to dlopen() (and which has
18       not since been released via a call to dlclose()), and name is the  sym‐
19       bol's name as a character string.
20
21       The  dlsym()  function shall search for the named symbol in all objects
22       loaded automatically as a result of loading the  object  referenced  by
23       handle  (see  dlopen()  ).  Load ordering is used in dlsym() operations
24       upon the global symbol object. The  symbol  resolution  algorithm  used
25       shall be dependency order as described in dlopen() .
26
27       The RTLD_DEFAULT and RTLD_NEXT flags are reserved for future use.
28

RETURN VALUE

30       If  handle  does  not refer to a valid object opened by dlopen(), or if
31       the named symbol cannot be found within any of the  objects  associated
32       with handle, dlsym() shall return NULL. More detailed diagnostic infor‐
33       mation shall be available through dlerror() .
34

ERRORS

36       No errors are defined.
37
38       The following sections are informative.
39

EXAMPLES

41       The following example shows how dlopen() and dlsym()  can  be  used  to
42       access  either function or data objects. For simplicity, error checking
43       has been omitted.
44
45
46              void    *handle;
47              int     *iptr, (*fptr)(int);
48
49
50              /* open the needed object */
51              handle = dlopen("/usr/home/me/libfoo.so", RTLD_LOCAL | RTLD_LAZY);
52
53
54              /* find the address of function and data objects */
55              *(void **)(&fptr) = dlsym(handle, "my_function");
56              iptr = (int *)dlsym(handle, "my_object");
57
58
59              /* invoke function, passing value of integer as a parameter */
60              (*fptr)(*iptr);
61

APPLICATION USAGE

63       Special purpose values for handle are reserved for future  use.   These
64       values and their meanings are:
65
66       RTLD_DEFAULT
67              The symbol lookup happens in the normal global scope; that is, a
68              search for a symbol using this handle would find the same  defi‐
69              nition as a direct use of this symbol in the program code.
70
71       RTLD_NEXT
72              Specifies  the  next  object  after  this one that defines name.
73              This one refers to  the  object  containing  the  invocation  of
74              dlsym().  The  next object is the one found upon the application
75              of a load order symbol resolution algorithm (see dlopen() ). The
76              next object is either one of global scope (because it was intro‐
77              duced as part of the original process image or  because  it  was
78              added with a dlopen() operation including the RTLD_GLOBAL flag),
79              or is an object that was included in the same dlopen() operation
80              that loaded this one.
81
82       The RTLD_NEXT flag is useful to navigate an intentionally created hier‐
83       archy of multiply-defined symbols created  through  interposition.  For
84       example,  if  a  program wished to create an implementation of malloc()
85       that embedded some statistics gathering about memory allocations,  such
86       an implementation could use the real malloc() definition to perform the
87       memory allocation-and itself only embed the necessary logic  to  imple‐
88       ment the statistics gathering function.
89
90

RATIONALE

92       The  ISO C  standard does not require that pointers to functions can be
93       cast back and forth to pointers to data.  Indeed,  the  ISO C  standard
94       does  not require that an object of type void * can hold a pointer to a
95       function. Implementations supporting the  XSI  extension,  however,  do
96       require that an object of type void * can hold a pointer to a function.
97       The result of converting a pointer to a  function  into  a  pointer  to
98       another  data  type  (except  void *) is still undefined, however. Note
99       that compilers conforming to the ISO C standard are required to  gener‐
100       ate  a  warning  if  a  conversion  from a void * pointer to a function
101       pointer is attempted as in:
102
103
104              fptr = (int (*)(int))dlsym(handle, "my_function");
105
106       Due to the problem noted here, a future version may either  add  a  new
107       function  to  return function pointers, or the current interface may be
108       deprecated in favor of two new functions: one that returns data  point‐
109       ers and the other that returns function pointers.
110

FUTURE DIRECTIONS

112       None.
113

SEE ALSO

115       dlclose()  ,  dlerror()  ,  dlopen()  ,  the Base Definitions volume of
116       IEEE Std 1003.1-2001, <dlfcn.h>
117
119       Portions of this text are reprinted and reproduced in  electronic  form
120       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
121       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
122       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
123       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
124       event of any discrepancy between this version and the original IEEE and
125       The Open Group Standard, the original IEEE and The Open Group  Standard
126       is  the  referee document. The original Standard can be obtained online
127       at http://www.opengroup.org/unix/online.html .
128
129
130
131IEEE/The Open Group                  2003                             DLSYM(P)
Impressum