---
name: "elf_flagelf"
section: "3"
platform: "linux"
package: "libelf"
version: "0.197-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/elf_flagelf"
---

# elf\_flagelf(3)

set or clear flags on ELF descriptors and components

## NAME

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

## 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

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)](/elf_getdata/3.md) or created with [**elf\_newdata**(3)](/elf_newdata/3.md).

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

**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**

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

- **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**

  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

- *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*

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

- *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

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

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

## ATTRIBUTES

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

## REPORTING BUGS

Report bugs to \<elfutils-devel@sourceware.org\> or https://sourceware.org/bugzilla/.
