ELF\_NEWSCN(3) Libelf Programmer's Manual ELF\_NEWSCN(3)

# [NAME](#NAME)

elf\_newscn - create a new section for an ELF descriptor

# [SYNOPSIS](#SYNOPSIS)

```
#include <libelf.h>
Elf_Scn *elf_newscn(Elf * elf");"
```

# [DESCRIPTION](#DESCRIPTION)

The **elf\_newscn**() function creates a new section descriptor for the ELF descriptor *elf.*

Each call to **elf\_newscn**() appends a new section to the internal list of sections for the ELF descriptor. It also creates a corresponding empty section header, which is zero-initialized and marked dirty. If *elf* does not have any sections yet then **elf\_newscn** will also create the null section with *sh\_type* **SHT\_NULL** at section index 0.

A newly created section has no name or type and must be properly initialized before calling **elf\_update**(). Use **elf32\_getshdr**() or **elf64\_getshdr**() to obtain the section header structure, then populate the required fields. Use **elf\_newdata**() to associate one or more data buffers with the new section.

The section with index 0 (the null section) is reserved and cannot have data added to it. **elf\_newscn**() will never return this section.

# [PARAMETERS](#PARAMETERS)

[*elf*](#elf)

An ELF descriptor that must at least have an *Elf32\_Ehdr* or *Elf64\_Ehdr* associated with it.

# [RETURN VALUE](#RETURN_VALUE)

On success, **elf\_newscn**() returns a pointer to a new section descriptor. On failure, it returns NULL and sets elf\_errno. If *elf* is NULL, then NULL is returned without setting elf\_errno.

# [SEE ALSO](#SEE_ALSO)

[**elf32\_getshdr**(3)](/man/os/elfutils/elf32_getshdr.3), [**elf64\_getshdr**(3)](/man/os/elfutils/elf64_getshdr.3), [**elf\_getdata**(3)](/man/os/elfutils/elf_getdata.3), [**elf\_newdata**(3)](/man/os/elfutils/elf_newdata.3), [**elf\_update**(3)](/man/os/elfutils/elf_update.3), [**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

**Interface** **Attribute** **Value** elf\_newscn () Thread safety MT-Safe

# [REPORTING BUGS](#REPORTING_BUGS)

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

2025-06-30 Libelf

---

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