GELF\_NEWEHDR(3) Libelf Programmer's Manual GELF\_NEWEHDR(3)

# [NAME](#NAME)

gelf\_newehdr - allocate and initialize a new ELF file header

# [SYNOPSIS](#SYNOPSIS)

```
#include <gelf.h>
void *gelf_newehdr(Elf *elf, int class);
```

# [DESCRIPTION](#DESCRIPTION)

**gelf\_newehdr**() allocates and initializes a new ELF header for *elf*, if a header does not already exist. When a new ELF header is created, all of its fields are zero-initialized.

The caller must specify the ELF class via *class*, which must be either:

[**ELFCLASS32**](#ELFCLASS32)

Request a 32-bit ELF file header.

[**ELFCLASS64**](#ELFCLASS64)

Request a 64-bit ELF file header.

# [PARAMETERS](#PARAMETERS)

[*elf*](#elf)

Pointer to an ELF descriptor of kind **ELF\_K\_ELF**.

[*class*](#class)

The requested ELF class for the new header. Must be **ELFCLASS32** or **ELFCLASS64**.

# [RETURN VALUE](#RETURN_VALUE)

On success, **gelf\_newehdr**() will return a non-zero value. The ELF header of *elf* can be retrieved using **gelf\_getehdr**(). **elf32\_getehdr**() or **elf64\_getehdr**() can also be used depending on the ELF class specified by *class*.

On failure, NULL is returned and elf\_errno is set. If *elf* is NULL then NULL is returned without setting elf\_errno.

In other libelf implementations the **gelf\_newehdr**() return value may be a different type.

# [SEE ALSO](#SEE_ALSO)

**elf32\_getehdr**() **elf64\_getehdr**() [**gelf\_getehdr**(3)](/man/os/elfutils/gelf_getehdr.3), [**gelf\_update\_ehdr**(3)](/man/os/elfutils/gelf_update_ehdr.3), [**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

**Interface** **Attribute** **Value** gelf\_newehdr () Thread safety MT-Safe

# [REPORTING BUGS](#REPORTING_BUGS)

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

2025-09-17 Libelf

---

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