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

# elf\_newscn(3)

create a new section for an ELF descriptor

## NAME

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

## SYNOPSIS

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

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

- *elf*

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

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

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

## ATTRIBUTES

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

## REPORTING BUGS

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