gelf_newehdr(3)

gelf_newehdr3

Allocate and initialize a new elf file header

Usage

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

Overview

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.

Attributes

InterfaceAttributeValue
gelf_newehdr()Thread safetyMT-Safe

Reporting bugs

Report bugs to <[email protected]> or https://sourceware.org/bugzilla/.

From libelf 0.197-1 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.