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

# [NAME](#NAME)

elf\_flagelf, elf\_flagdata, elf\_flagehdr, elf\_flagphdr, elf\_flagscn, elf\_flagshdr - set or clear flags on ELF descriptors and components

# [SYNOPSIS](#SYNOPSIS)

```
#include <libelf.h>
unsigned int elf_flagelf(Elf * elf, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagehdr(Elf * elf, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagphdr(Elf * elf, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagscn(Elf_Scn * scn, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagshdr(Elf_Scn * scn, Elf_Cmd cmd, unsigned int flags);
unsigned int elf_flagdata(Elf_Data * data, Elf_Cmd cmd, unsigned int flags);
```

# [DESCRIPTION](#DESCRIPTION)

These functions allow the caller to set or clear flags on various ELF components managed by **libelf .** They are typically used to indicate that a component has been modified (dirty), or to control layout behavior during output.

**elf\_flagelf**() modifies flags on the top-level **Elf** descriptor.

**elf\_flagdata**() modifies flags on an **Elf\_Data** descriptor, typically retrieved using [**elf\_getdata**(3)](/man/os/elfutils/elf_getdata.3) or created with [**elf\_newdata**(3)](/man/os/elfutils/elf_newdata.3).

**elf\_flagehdr**() modifies flags on the ELF header for a ELF descriptor (e.g., the result of [**gelf\_getehdr**(3)](/man/os/elfutils/gelf_getehdr.3)).

**elf\_flagphdr**() modifies flags on the program header table of an ELF descriptor.

**elf\_flagscn**() modifies flags on an **Elf\_Scn** (section) descriptor.

**elf\_flagshdr**() modifies flags on the section header of a given **Elf\_Scn .**

The *cmd* argument determines whether the given flags should be set ( **ELF\_C\_SET** ) or cleared ( **ELF\_C\_CLR** ).

The following flag values may be passed via the *flags* parameter:

[**ELF\_F\_DIRTY**](#ELF_F_DIRTY)

Marks the object as modified. This ensures changes to the component is written out during [**elf\_update**(3)](/man/os/elfutils/elf_update.3).

[**ELF\_F\_LAYOUT**](#ELF_F_LAYOUT)

Indicates that the layout of the ELF component is managed manually. Offsets and sizes will be preserved as provided. This flag is only used with **elf\_flagelf**() and is ignored when used with other functions. If this flag is set the user must set Ehdr *e\_phoff*, *e\_shoff*, as well as **Elf\_Data** *d\_off* and Shdr *sh\_offset*. If not set, then these offsets will be recalculated when **elf\_update** is called. If **ELF\_F\_LAYOUT** is set then changes to phdr offsets will prevent elf\_update from automatically adjusting shdr offsets.

[**ELF\_F\_PERMISSIVE**](#ELF_F_PERMISSIVE)

Enables relaxed validation of object structure. This flag permits nonstandard layouts without strict checks. Specifically this removes a check in **elf\_update**() that the section *sh\_size* is a multiple of the section *sh\_entsize* (if not zero). This flag is only used with **elf\_flagelf**() and is ignored when used with other functions. **ELF\_F\_PERMISSIVE** is an elfutils libelf extention and may not be available in other libelf implementations.

# [PARAMETERS](#PARAMETERS)

[*obj*](#obj)

The object to be modified: For **elf\_flagelf**, **elf\_flagehdr**, **elf\_flagphdr**, this is an **Elf \*** descriptor. For **elf\_flagscn** and **elf\_flagshdr ,** this is an **Elf\_Scn \*** descriptor. For **elf\_flagdata ,** an **Elf\_Data \*** buffer.

[*cmd*](#cmd)

Must be either: **ELF\_C\_SET** to set the given flags, or **ELF\_C\_CLR** to clear them.

[*flags*](#flags)

Bitmask of flags to modify. May include any combination of **ELF\_F\_DIRTY ,** **ELF\_F\_LAYOUT ,** and **ELF\_F\_PERMISSIVE .**

Note that **ELF\_F\_LAYOUT** and **ELF\_F\_PERMISSIVE** are only used with **elf\_flagelf**() and are ignored for other functions.

# [RETURN VALUE](#RETURN_VALUE)

Returns the new value of the flags after the set/clear operation.

Returns 0 on error, and sets an error code retrievable via [**elf\_errmsg**(3)](/man/os/elfutils/elf_errmsg.3). If the first argument is NULL then 0 is return and no error code is set.

If the last flag is cleared, 0 will be returned as the new flag value. In this case 0 is not an error indicator and no error code is set.

# [SEE ALSO](#SEE_ALSO)

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

# [ATTRIBUTES](#ATTRIBUTES)

**Interface** **Attribute** **Value** elf\_flagelf (), elf\_flagehdr(), elf\_flagphdr(), elf\_flagscn(), elf\_flagshdr(), elf\_flagdata() Thread safety MT-Unsafe race

# [REPORTING BUGS](#REPORTING_BUGS)

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

2025-06-23 Libelf

---

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