---
name: "dlinfo"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/dlinfo"
---

# dlinfo(3)

information about dynamically loaded object

## NAME

**dlinfo** – information about dynamically loaded object

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<link.h\>**

**#include \<dlfcn.h\>**

*int*\

**dlinfo**(*void \* restrict handle*, *int request*, *void \* restrict p*);

## DESCRIPTION

The **dlinfo**() function provides information about 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)](/dlopen/3.md) function call or special handle RTLD\_SELF. If *handle* is the value returned from [dlopen(3)](/dlopen/3.md), 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 *Link\_map* (*struct link\_map*) structure pointer 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)](/ld.so/1.md), in the same order as [dlopen(3)](/dlopen/3.md) and [dlclose(3)](/dlclose/3.md) are called. See EXAMPLES, example 1.

  The *Link\_map* structure is defined in ⟨link.h⟩ and has the following members:

  ```
  caddr_t         l_base;    /* Base Address of library */
  const char      *l_name;   /* Absolute Path to Library */
  const void      *l_ld;     /* Pointer to .dynamic in memory */
  struct link_map *l_next,   /* linked list of mapped libs */
                  *l_prev;
  caddr_t         l_addr;     /* Load Offset of library */
  const char      *l_refname; /* Object this one filters for */
  ```

  - *l\_base*

    The base address of the object loaded into memory.

  - *l\_name*

    The full name 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.

  - *l\_addr*

    The load offset of the object, that is, the difference between the actual load address and the base virtual address the object was linked at.

  - *l\_refname*

    A name of the object this object filters for, if any. If there are more then one filtee, a name from the first DT\_FILTER dynamic entry is supplied.

- RTLD\_DI\_SERINFO

  Retrieve the library search paths associated with the given *handle* argument. The *p* argument should point to *Dl\_serinfo* structure buffer (*Dl\_serinfo \*p*). The *Dl\_serinfo* structure must be initialized first with the RTLD\_DI\_SERINFOSIZE request.

  The returned *Dl\_serinfo* structure contains *dls\_cnt* *Dl\_serpath* entries. Each entry's *dlp\_name* field points to the search path. The corresponding *dlp\_info* field contains one of more flags indicating the origin of the path (see the LA\_SER\_\* flags defined in the ⟨link.h⟩ header file). See EXAMPLES, example 2, for a usage example.

- RTLD\_DI\_SERINFOSIZE

  Initialize a *Dl\_serinfo* structure for use in a RTLD\_DI\_SERINFO request. Both the *dls\_cnt* and *dls\_size* fields are returned to indicate the number of search paths applicable to the handle, and the total size of a *Dl\_serinfo* buffer required to hold *dls\_cnt* *Dl\_serpath* entries and the associated search path strings. See EXAMPLES, example 2, for a usage example.

- *RTLD\_DI\_ORIGIN*

  Retrieve the origin of the dynamic object associated with the handle. On successful return, *p* argument is filled with the *char* pointer (*char \*p*).

## 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)](/dlerror/3.md).

## EXAMPLES

Example 1: 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;
}
```

Example 2: Using **dlinfo**() to retrieve the library search paths.

The following example shows how a dynamic object can inspect the library search paths that would be used to locate a simple filename with [dlopen(3)](/dlopen/3.md). For simplicity, error checking has been omitted.

```
Dl_serinfo	 _info, *info = &_info;
Dl_serpath	*path;
unsigned int	 cnt;
/* determine search path count and required buffer size */
dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info);
/* allocate new buffer and initialize */
info = malloc(_info.dls_size);
info->dls_size = _info.dls_size;
info->dls_cnt = _info.dls_cnt;
/* obtain sarch path information */
dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info);
path = &info->dls_serpath[0];
for (cnt = 1; cnt <= info->dls_cnt; cnt++, path++) {
	(void) printf("%2d: %s\n", cnt, path->dls_name);
}
```

## SEE ALSO

[rtld(1)](/rtld/1.md), [dladdr(3)](/dladdr/3.md), [dlopen(3)](/dlopen/3.md), [dlsym(3)](/dlsym/3.md)

## HISTORY

The **dlinfo**() function first appeared in the Solaris operating system. In FreeBSD, it first appeared in FreeBSD 4.8.

## AUTHORS

The FreeBSD implementation of the **dlinfo**() function was originally written by Alexey Zelkin ⟨*phantom@FreeBSD.org*⟩ and later extended and improved by Alexander Kabaev ⟨*kan@FreeBSD.org*⟩.

The manual page for this function was written by Alexey Zelkin ⟨*phantom@FreeBSD.org*⟩.
