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

# gelf\_newehdr(3)

allocate and initialize a new ELF file header

## NAME

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

## SYNOPSIS

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

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

  Request a 32-bit ELF file header.

- **ELFCLASS64**

  Request a 64-bit ELF file header.

## PARAMETERS

- *elf*

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

- *class*

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

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

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

## ATTRIBUTES

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

## REPORTING BUGS

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