---
name: "dl_iterate_phdr"
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/dl_iterate_phdr"
---

# dl\_iterate\_phdr(3)

iterate over program headers

## NAME

**dl\_iterate\_phdr** – iterate over program headers

## LIBRARY

For the dynamically linked binaries, the service is provided by [ld-elf.so.1(1)](/ld-elf.so.1/1.md) dynamic linker. Statically linked programs use an implementation of **dl\_iterate\_phdr**() from libc.

## SYNOPSIS

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

*int*\

**dl\_iterate\_phdr**(*int (\*callback)(struct dl\_phdr\_info \*, size\_t, void \*)*, *void \*data*);

## DESCRIPTION

The **dl\_iterate\_phdr**() function iterates over all ELF objects loaded into a process's address space, calling *callback* for each object, passing it information about the object's program headers and the *data* argument. The iteration is aborted when all objects are passed, or when the next *callback* call returns non-zero value. The information about the program headers is passed in a structure that is defined as:

```
struct dl_phdr_info {
	Elf_Addr	dlpi_addr;
	const char	*dlpi_name;
	const Elf_Phdr	*dlpi_phdr;
	Elf_Half	dlpi_phnum;
	unsigned long long int dlpi_adds;
	unsigned long long int dlpi_subs;
	size_t		dlpi_tls_modid;
	void		*dlpi_tls_data;
};
```

The members of struct dl\_phdr\_info have the following meaning:

- *dlpi\_addr*

  The base address at which the object is mapped into the address space of the calling process.

- *dlpi\_name*

  The pathname of the ELF object.

- *dlpi\_phdr*

  A pointer to the object's program headers.

- *dlpi\_phnum*

  The number of program headers in the object.

- *dlpi\_adds*

  The counter of the object loads performed by the dynamic linker.

- *dlpi\_subs*

  The counter of the object unloads performed by the dynamic linker.

- *dlpi\_tls\_modid*

  The TLS index of the object.

- *dlpi\_tls\_data*

  A pointer to the calling thread' TLS data segment for this module, if it was allocated, NULL otherwise.

Future versions of FreeBSD might add more members to this structure. To make it possible for programs to check whether any new members have been added, the size of the structure is passed as an second argument to *callback*.

The third argument to callback is the *data* value passed to the call to **dl\_iterate\_phdr**(), allowing the *callback* to have a context.

## RETURN VALUES

The **dl\_iterate\_phdr**() returns the value returned by the last *callback* call executed.

## SEE ALSO

[ld(1)](/ld/1.md), [ld-elf.so.1(1)](/ld-elf.so.1/1.md), [dlopen(3)](/dlopen/3.md), [elf(5)](/elf/5.md)

## HISTORY

The **dl\_iterate\_phdr** function first appeared in FreeBSD 7.0.
