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

# elf\_flagarhdr(3)

manipulate flags associated with ELF data structures

## NAME

**elf\_flagarhdr**, **elf\_flagdata**, **elf\_flagehdr**, **elf\_flagelf**, **elf\_flagphdr**, **elf\_flagscn**, **elf\_flagshdr** – manipulate flags associated with ELF data structures

## LIBRARY

library “libelf”

## SYNOPSIS

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

*unsigned int*\

**elf\_flagarhdr**(*Elf\_Arhdr \*arhdr*, *Elf\_Cmd cmd*, *unsigned int flags*);

*unsigned int*\

**elf\_flagdata**(*Elf\_Data \*data*, *Elf\_Cmd cmd*, *unsigned int flags*);

*unsigned int*\

**elf\_flagehdr**(*Elf \*elf*, *Elf\_Cmd cmd*, *unsigned int flags*);

*unsigned int*\

**elf\_flagelf**(*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*);

## DESCRIPTION

These functions are used to query, set or reset flags on data structures associated with an ELF file.

Arguments *arhdr*, *data*, *elf* and *scn* denote the data structures whose flags need to be changed. These values should have been returned by prior calls to functions in the [elf(3)](/elf/3.md) API set:

- Argument *arhdr* should have been returned by a prior call to [elf\_getarhdr(3)](/elf_getarhdr/3.md).

- Argument *data* should have been returned by a prior call to one of [elf\_newdata(3)](/elf_newdata/3.md), [elf\_getdata(3)](/elf_getdata/3.md) or [elf\_rawdata(3)](/elf_rawdata/3.md).

- Argument *elf* should have been allocated by a prior call to one of [elf\_begin(3)](/elf_begin/3.md) or [elf\_memory(3)](/elf_memory/3.md).

- Argument *scn* should have been returned by a prior call to one of [elf\_getscn(3)](/elf_getscn/3.md), [elf\_newscn(3)](/elf_newscn/3.md) or [elf\_nextscn(3)](/elf_nextscn/3.md).

These values are allowed to be NULL to simplify error handling in application code.

Argument *cmd* may have the following values:

- ELF\_C\_CLR

  The argument *flags* specifies the flags to be cleared.

- ELF\_C\_SET

  The argument *flags* specifies the flags to be set.

The argument *flags* is allowed to have the following flags set:

- ELF\_F\_ARCHIVE

  This flag is only valid with the **elf\_flagelf**() API. It informs the library that the application desires to create an [ar(1)](/ar/1.md) archive. Argument *elf* should have been opened for writing using the ELF\_C\_WRITE command to function **elf\_begin**().

- ELF\_F\_ARCHIVE\_SYSV

  This flag is used in conjunction with the ELF\_F\_ARCHIVE flag to indicate that library should create archives that conform to System V layout rules. The default is to create BSD style archives.

- ELF\_F\_DIRTY

  Mark the associated data structure as needing to be written back to the underlying file. A subsequent call to [elf\_update(3)](/elf_update/3.md) will resynchronize the library's internal data structures.

- ELF\_F\_LAYOUT

  This flag is only valid with the **elf\_flagelf**() API. It informs the library that the application will take responsibility for the layout of the file and that the library is not to insert any padding in between sections.

Marking a given data structure as “dirty” affects all of its contained elements. Thus marking an ELF descriptor *elf* with **elf\_flagelf**(*elf*, *ELF\_C\_SET*, *ELF\_F\_DIRTY*) means that the entire contents of the descriptor are “dirty”.

Using a value of zero for argument *flags* will return the current set of flags for the data structure being queried.

## RETURN VALUES

These functions return the updated flags if successful, or zero if an error is detected.

## COMPATIBILITY

The **elf\_flagarhdr**() function and the ELF\_F\_ARCHIVE and ELF\_F\_ARCHIVE\_SYSV flags are an extension to the [elf(3)](/elf/3.md) API.

## ERRORS

These functions may fail with the following errors:

- \[ELF\_E\_ARGUMENT\]

  An unsupported value was used for the *cmd* argument.

- \[ELF\_E\_ARGUMENT\]

  Argument *flags* had unsupported flags set.

- \[ELF\_E\_ARGUMENT\]

  The argument *elf* was not a descriptor for an ELF object.

- \[ELF\_E\_MODE\]

  The ELF\_F\_ARCHIVE flag was used with an ELF descriptor that had not been opened for writing.

- \[ELF\_E\_SEQUENCE\]

  Function **elf\_flagehdr**() was called without an executable header being allocated.

- \[ELF\_E\_SEQUENCE\]

  Function **elf\_flagphdr**() was called without a program header being allocated.

## SEE ALSO

[elf(3)](/elf/3.md), [elf32\_newehdr(3)](/elf32_newehdr/3.md), [elf32\_newphdr(3)](/elf32_newphdr/3.md), [elf64\_newehdr(3)](/elf64_newehdr/3.md), [elf64\_newphdr(3)](/elf64_newphdr/3.md), [elf\_newdata(3)](/elf_newdata/3.md), [elf\_update(3)](/elf_update/3.md), [gelf(3)](/gelf/3.md), [gelf\_newehdr(3)](/gelf_newehdr/3.md), [gelf\_newphdr(3)](/gelf_newphdr/3.md), [gelf\_update\_dyn(3)](/gelf_update_dyn/3.md), [gelf\_update\_move(3)](/gelf_update_move/3.md), [gelf\_update\_rel(3)](/gelf_update_rel/3.md), [gelf\_update\_rela(3)](/gelf_update_rela/3.md), [gelf\_update\_sym(3)](/gelf_update_sym/3.md), [gelf\_update\_syminfo(3)](/gelf_update_syminfo/3.md)
