---
name: "elf_newdata"
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_newdata"
---

# elf\_newdata(3)

Add a new Elf\_Data descriptor to a section

## NAME

elf\_newdata - Add a new Elf\_Data descriptor to a section

## SYNOPSIS

```
#include <libelf.h>
Elf_Data * elf_newdata(Elf_Scn *scn);
```

## DESCRIPTION

The **elf\_newdata**() function creates a new **Elf\_Data** descriptor and associates it with the section referred to by *scn .* This descriptor can be used to describe new section contents for an ELF object being constructed or modified.

The section must not be the null section (index 0).  If the section has no data associated with it yet, or was created using **elf\_newscn**(), this function creates the first **Elf\_Data** descriptor for the section.

Subsequent calls to **elf\_newdata**() will append new data descriptors to the section.

The returned descriptor is marked dirty so that it will be included during **elf\_update**()**.** The returned descriptor is also initialized to represent no data with *d\_buf* set to NULL, *d\_type* set to **ELF\_T\_BYTE**, *d\_version* set to **EV\_CURRENT**, *d\_size*, *d\_off*, set to zero, and *d\_align* set to one.

## PARAMETERS

- *scn*

  A section descriptor to which the new data descriptor should be attached. Must not be section zero, the null section.  If *scn* is NULL this function returns NULL.

## RETURN VALUE

On success, a pointer to a new, writable **Elf\_Data** descriptor is returned. On failure, NULL is returned an elf\_errno is set. If *scn* is NULL, then NULL is returned and elf\_errno is not set.

The caller is responsible for configuring the return value (see DESCRIPTION for default field values).

## SEE ALSO

[**elf\_getdata**(3)](/elf_getdata/3.md), [**elf\_newscn**(3)](/elf_newscn/3.md), [**elf\_update**(3)](/elf_update/3.md), [**libelf**(3)](/libelf/3.md), [**elf**(5)](/elf/5.md)

## ATTRIBUTES

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

## REPORTING BUGS

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