1DLSYM(3)                   Linux Programmer's Manual                  DLSYM(3)
2
3
4

NAME

6       dlsym,  dlvsym  - obtain address of a symbol in a shared object or exe‐
7       cutable
8

SYNOPSIS

10       #include <dlfcn.h>
11
12       void *dlsym(void *handle, const char *symbol);
13
14       #define _GNU_SOURCE
15       #include <dlfcn.h>
16
17       void *dlvsym(void *handle, char *symbol, char *version);
18
19       Link with -ldl.
20

DESCRIPTION

22       The function dlsym() takes a "handle" of a dynamic loaded shared object
23       returned  by  dlopen(3)  along  with a null-terminated symbol name, and
24       returns the address where that symbol is loaded into  memory.   If  the
25       symbol  is  not  found,  in  the  specified object or any of the shared
26       objects that were automatically loaded by dlopen(3)  when  that  object
27       was  loaded, dlsym() returns NULL.  (The search performed by dlsym() is
28       breadth first through the dependency tree of these shared objects.)
29
30       In unusual cases (see NOTES) the value of the symbol could actually  be
31       NULL.   Therefore,  a  NULL  return  from  dlsym() need not indicate an
32       error.  The correct way to distinguish an error  from  a  symbol  whose
33       value  is NULL is to call dlerror(3) to clear any old error conditions,
34       then call dlsym(), and then call dlerror(3) again,  saving  its  return
35       value into a variable, and check whether this saved value is not NULL.
36
37       There are two special pseudo-handles that may be specified in handle:
38
39       RTLD_DEFAULT
40              Find  the  first  occurrence  of  the  desired  symbol using the
41              default shared object search order.   The  search  will  include
42              global  symbols  in the executable and its dependencies, as well
43              as symbols in shared objects that were dynamically  loaded  with
44              the RTLD_GLOBAL flag.
45
46       RTLD_NEXT
47              Find  the  next  occurrence  of the desired symbol in the search
48              order after the current object.  This allows one  to  provide  a
49              wrapper around a function in another shared object, so that, for
50              example, the definition of a  function  in  a  preloaded  shared
51              object  (see  LD_PRELOAD  in  ld.so(8))  can find and invoke the
52              "real" function provided in another shared object (or  for  that
53              matter,  the  "next"  definition  of the function in cases where
54              there are multiple layers of preloading).
55
56       The _GNU_SOURCE feature test macro must be defined in order  to  obtain
57       the definitions of RTLD_DEFAULT and RTLD_NEXT from <dlfcn.h>.
58
59       The  function  dlvsym()  does  the  same as dlsym() but takes a version
60       string as an additional argument.
61

RETURN VALUE

63       On success, these functions return the address associated with  symbol.
64       On  failure,  they return NULL; the cause of the error can be diagnosed
65       using dlerror(3).
66

VERSIONS

68       dlsym() is present in glibc 2.0 and later.  dlvsym() first appeared  in
69       glibc 2.1.
70

ATTRIBUTES

72       For   an   explanation   of   the  terms  used  in  this  section,  see
73       attributes(7).
74
75       ┌──────────────────┬───────────────┬─────────┐
76Interface         Attribute     Value   
77       ├──────────────────┼───────────────┼─────────┤
78dlsym(), dlvsym() │ Thread safety │ MT-Safe │
79       └──────────────────┴───────────────┴─────────┘

CONFORMING TO

81       POSIX.1-2001 describes dlsym().  The dlvsym() function is a GNU  exten‐
82       sion.
83

NOTES

85       The  value  of  a  symbol returned by dlsym() will never be NULL if the
86       shared object is the result of normal compilation, since a global  sym‐
87       bol  is never placed at the NULL address.  There are nevertheless cases
88       where a lookup using dlsym() may return NULL as the value of a  symbol.
89       For example, the symbol value may be the result of a GNU indirect func‐
90       tion (IFUNC) resolver function that returns NULL as the resolved value.
91
92   History
93       The dlsym() function is part of the dlopen  API,  derived  from  SunOS.
94       That system does not have dlvsym().
95

EXAMPLE

97       See dlopen(3).
98

SEE ALSO

100       dl_iterate_phdr(3),   dladdr(3),   dlerror(3),   dlinfo(3),  dlopen(3),
101       ld.so(8)
102

COLOPHON

104       This page is part of release 5.04 of the Linux  man-pages  project.   A
105       description  of  the project, information about reporting bugs, and the
106       latest    version    of    this    page,    can     be     found     at
107       https://www.kernel.org/doc/man-pages/.
108
109
110
111Linux                             2019-03-06                          DLSYM(3)
Impressum