DLINFO(3)

DLINFO(3) | Library Functions Manual | DLINFO(3)

# NAME

`dlinfo` —
information about a dynamically loaded object

# LIBRARY

(These functions are not in a library. They are included in every dynamically linked program automatically.)

# SYNOPSIS

`#include <link.h>`
`#include <dlfcn.h>`

int
`dlinfo`(void *handle, int request, void *p);

# DESCRIPTION

The `dlinfo`() function provides information about a dynamically loaded object. The action taken by `dlinfo`() and exact meaning and type of p argument depend on value of the request argument provided by caller.

The handle argument is either the value returned from the dlopen(3) function call or special handle `RTLD_SELF`. If handle is the value returned from dlopen(3), the information returned by the `dlinfo`() function pertains to the specified object. If handle is the special handle `RTLD_SELF`, the information returned pertains to the caller itself.

Possible values for the request argument are:

`RTLD_DI_LINKMAP`
  Retrieve the pointer to the Link_map for the specified handle. On successful return, the p argument is filled with the pointer to the Link_map structure (Link_map **p) describing a shared object specified by the handle argument. The Link_map structures are maintained as a doubly linked list by ld.so(1), in the same order as dlopen(3) and dlclose(3) are called.

  The Link_map structure is defined in `<link.h>` and has the following members:

      caddr_t         l_addr;    /* Base Address of library */
      #ifdef __mips__
      caddr_t         l_offs;    /* Load Offset of library */
      #endif
      const char      *l_name;   /* Absolute Path to Library */
      void            *l_ld;     /* Pointer to .dynamic in memory */
      struct link_map *l_next,   /* linked list of mapped libs */
                      *l_prev;

  l_addr
    The base address of the object loaded into memory.
  l_name
    The absolute pathname of the loaded shared object.
  l_ld
    The address of the dynamic linking information segment (`PT_DYNAMIC`) loaded into memory.
  l_next
    The next Link_map structure on the link-map list.
  l_prev
    The previous Link_map structure on the link-map list.

# RETURN VALUES

The `dlinfo`() function returns 0 on success, or -1 if an error occurred. Whenever an error has been detected, a message detailing it can be retrieved via a call to dlerror(3).

# EXAMPLES

Using `dlinfo`() to retrieve Link_map structure.

The following example shows how dynamic library can detect the list of shared libraries loaded after caller's one. For simplicity, error checking has been omitted.

    Link_map *map;

    dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map);

    while (map != NULL) {
    	printf("%p: %s\n", map->l_addr, map->l_name);
    	map = map->l_next;
    }

# SEE ALSO

rtld(1), dladdr(3), dlopen(3), dlsym(3)

# HISTORY

The `dlinfo`() function first appeared in the Solaris operating system. In NetBSD, it first appeared in NetBSD 5.1.

# AUTHORS

The NetBSD implementation of the `dlinfo`() function was written by Antti Kantee <pooka@NetBSD.org>.

The manual page for this function was written by Alexey Zelkin <phantom@FreeBSD.org> and adapted to NetBSD by Kamil Rytarowski <kamil@NetBSD.org>.

January 13, 2020 | NetBSD 10.0