ELF\_CNTL(3) Libelf Programmer's Manual ELF\_CNTL(3)

# [NAME](#NAME)

elf\_cntl - perform control operations on an ELF descriptor

# [SYNOPSIS](#SYNOPSIS)

```
#include <libelf.h>
int elf_cntl(Elf *elf, Elf_Cmd cmd);
```

# [DESCRIPTION](#DESCRIPTION)

Perform control operations on the ELF descriptor *elf* according to the operation specified by *cmd*.

The following commands are supported:

[**ELF\_C\_FDDONE**](#ELF_C_FDDONE)

This command tells **libelf** that the application is done using the file descriptor associated with the *elf* object. The file descriptor may then be closed immediately without affecting the in-memory ELF data. Unless all data has been read from the file descriptor (see **ELF\_C\_FDREAD** below) future operation on the Elf descriptor may fail.

[**ELF\_C\_FDREAD**](#ELF_C_FDREAD)

This command causes **libelf** to read the entire contents of the underlying file into memory immediately. **libelf** generally reads and parses elements of ELF files only when they are required. This command instead triggers **libelf** to read all elements immediately. Using this command ensures that **ELF\_C\_FDDONE** may be used without causing future operations on the Elf descriptor to fail.

# [RETURN VALUE](#RETURN_VALUE)

On success, returns 0.

On failure, it returns -1 and sets an error that can be retrieved with [**elf\_errmsg**(3)](/man/os/elfutils/elf_errmsg.3).

# [SEE ALSO](#SEE_ALSO)

[**libelf**(3)](/man/os/elfutils/libelf.3), [**elf\_errmsg**(3)](/man/os/elfutils/elf_errmsg.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

**Interface Attribute Value** elf\_cntl () Thread safety MT-Safe

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to &lt;elfutils-devel@sourceware.org&gt; or https://sourceware.org/bugzilla/.

2025-06-17 Libelf

---

Document: elf_cntl(3) from elfutils 0.196-r1 (Chainguard OS)
Source: https://sourceware.org/git/elfutils.git
