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

# [NAME](#NAME)

gelf\_newphdr - allocate and initialize a new program header table

# [SYNOPSIS](#SYNOPSIS)

```
#include <gelf.h>
void *gelf_newphdr(Elf *elf, size_t phnum);
```

# [DESCRIPTION](#DESCRIPTION)

**gelf\_newphdr**() creates a new program header table with *phnum* entries for the ELF descriptor *elf*, zeroing all entries. If a program header table already exists for *elf*, it is discarded. If *phnum* is zero, any existing program header table is removed.

This array is maintained within the ELF descriptor and must not be freed directly. After calling **gelf\_newphdr**(), any previously obtained program header pointers for the same descriptor become invalid. An ELF header must exist before creating a program header table.

# [PARAMETERS](#PARAMETERS)

[*elf*](#elf)

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

[*phnum*](#phnum)

Number of entries in the new program header table. If zero, any existing program header table is removed.

# [RETURN VALUE](#RETURN_VALUE)

On success, returns a non-NULL void pointer to the new program header table. The new program header table can be retrieved as a **GElf\_Phdr \*** using **gelf\_getphdr**(). **elf32\_getphdr**() or **elf64\_getphdr**() can also be used depending on the class of *elf*. If *phnum* is 0, then any existing program header table is removed and NULL is returned. On failure, NULL is returned and elf\_errno is set. If *elf* is NULL, then NULL is returned without setting elf\_errno.

Other libelf implementations of **gelf\_newphdr**() may use a different return type.

# [SEE ALSO](#SEE_ALSO)

[**gelf\_getphdr**(3)](/man/os/elfutils/gelf_getphdr.3), [**gelf\_update\_phdr**(3)](/man/os/elfutils/gelf_update_phdr.3), [**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

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

# [REPORTING BUGS](#REPORTING_BUGS)

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

2025-09-23 Libelf

---

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