CINXE.COM

dlsym

<html> <head> <title>dlsym</title> <META NAME="KEYWORDS" CONTENT="dlsym"> </head> <body BGCOLOR="#ffffff" LINK="#0000ff" VLINK="#0000ff" ALINK="#0000ff" TEXT="#000000"> <center> <h1><b>dlsym</b></h1></center> <PRE> <STRONG><A HREF="/man3/DLSYM">DLSYM(3)</A></STRONG> Linux Programmer's Manual <STRONG><A HREF="/man3/DLSYM">DLSYM(3)</A></STRONG> NAME dlsym, dlvsym - obtain address of a symbol in a shared object or exe- cutable SYNOPSIS #include &lt;dlfcn.h&gt; void *dlsym(void *handle, const char *symbol); #define _GNU_SOURCE #include &lt;dlfcn.h&gt; void *dlvsym(void *handle, char *symbol, char *version); Link with -ldl. DESCRIPTION The function dlsym() takes a "handle" of a dynamic loaded shared object returned by <STRONG><A HREF="/man3/dlopen">dlopen(3)</A></STRONG> along with a null-terminated symbol name, and re- turns the address where that symbol is loaded into memory. If the sym- bol is not found, in the specified object or any of the shared objects that were automatically loaded by <STRONG><A HREF="/man3/dlopen">dlopen(3)</A></STRONG> when that object was loaded, dlsym() returns NULL. (The search performed by dlsym() is breadth first through the dependency tree of these shared objects.) In unusual cases (see NOTES) the value of the symbol could actually be NULL. Therefore, a NULL return from dlsym() need not indicate an er- ror. The correct way to distinguish an error from a symbol whose value is NULL is to call <STRONG><A HREF="/man3/dlerror">dlerror(3)</A></STRONG> to clear any old error conditions, then call dlsym(), and then call <STRONG><A HREF="/man3/dlerror">dlerror(3)</A></STRONG> again, saving its return value into a variable, and check whether this saved value is not NULL. There are two special pseudo-handles that may be specified in handle: RTLD_DEFAULT Find the first occurrence of the desired symbol using the de- fault shared object search order. The search will include global symbols in the executable and its dependencies, as well as symbols in shared objects that were dynamically loaded with the RTLD_GLOBAL flag. RTLD_NEXT Find the next occurrence of the desired symbol in the search or- der after the current object. This allows one to provide a wrapper around a function in another shared object, so that, for example, the definition of a function in a preloaded shared ob- ject (see LD_PRELOAD in <STRONG><A HREF="/man8/ld.so">ld.so(8)</A></STRONG>) can find and invoke the "real" function provided in another shared object (or for that matter, the "next" definition of the function in cases where there are multiple layers of preloading). The _GNU_SOURCE feature test macro must be defined in order to obtain the definitions of RTLD_DEFAULT and RTLD_NEXT from &lt;dlfcn.h&gt;. The function dlvsym() does the same as dlsym() but takes a version string as an additional argument. RETURN VALUE On success, these functions return the address associated with symbol. On failure, they return NULL; the cause of the error can be diagnosed using <STRONG><A HREF="/man3/dlerror">dlerror(3)</A></STRONG>. VERSIONS dlsym() is present in glibc 2.0 and later. dlvsym() first appeared in glibc 2.1. ATTRIBUTES For an explanation of the terms used in this section, see at- <STRONG><A HREF="/man7/tributes">tributes(7)</A></STRONG>. +------------------+---------------+---------+ |Interface | Attribute | Value | +------------------+---------------+---------+ |dlsym(), dlvsym() | Thread safety | MT-Safe | +------------------+---------------+---------+ CONFORMING TO POSIX.1-2001 describes dlsym(). The dlvsym() function is a GNU exten- sion. NOTES The value of a symbol returned by dlsym() will never be NULL if the shared object is the result of normal compilation, since a global sym- bol is never placed at the NULL address. There are nevertheless cases where a lookup using dlsym() may return NULL as the value of a symbol. For example, the symbol value may be the result of a GNU indirect func- tion (IFUNC) resolver function that returns NULL as the resolved value. History The dlsym() function is part of the dlopen API, derived from SunOS. That system does not have dlvsym(). EXAMPLE See <STRONG><A HREF="/man3/dlopen">dlopen(3)</A></STRONG>. SEE ALSO <STRONG><A HREF="/man3/dl_iterate_phdr">dl_iterate_phdr(3)</A></STRONG>, <STRONG><A HREF="/man3/dladdr">dladdr(3)</A></STRONG>, <STRONG><A HREF="/man3/dlerror">dlerror(3)</A></STRONG>, <STRONG><A HREF="/man3/dlinfo">dlinfo(3)</A></STRONG>, <STRONG><A HREF="/man3/dlopen">dlopen(3)</A></STRONG>, <STRONG><A HREF="/man8/ld.so">ld.so(8)</A></STRONG> COLOPHON This page is part of release 5.05 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2019-03-06 <STRONG><A HREF="/man3/DLSYM">DLSYM(3)</A></STRONG></PRE> <center> <h6>Man Pages Copyright Respective Owners. Site Copyright (C) 1994 - 2025 <a href="http://www.he.net">Hurricane Electric</a>. All Rights Reserved.</h6></center> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10