ELF_NEWDATA(3)

πŸ“¦
version 0.197 Β· 3 versions
, in alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixpkgs unstable, ubuntu stonking

✨ ELF_NEWDATA(3) ✨

okay bestie, welcome to the Libelf Programmer's Manual πŸ’– this is elf_newdata, and she's here to hand you a fresh blank canvas for your ELF sections. let's go 🫢


🌸 NAME 🌸

elf_newdata β€” add a new Elf_Data descriptor to a section. that's it, that's the job πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <libelf.h>

Elf_Data * elf_newdata(Elf_Scn *scn);

✨ DESCRIPTION ✨

so elf_newdata() does the cute thing: it creates a brand-new Elf_Data descriptor and associates it with the section that scn points to. this descriptor is literally your tool for describing new section contents for an ELF object that's being constructed or modified. main character energy πŸ”₯

okay important, listen up πŸ‘‘: the section must not be the null section (index 0). like, that one's off limits, no cap.

if the section has no data associated with it yet, or it was created using elf_newscn(), then this function creates the first Elf_Data descriptor for the section. slay, first one's free πŸ’–

and then? every subsequent call to elf_newdata() will append new data descriptors to the section. so you can just keep stacking them, one after another, like charms on a bracelet πŸŽ€

the returned descriptor is marked dirty so that it will be included during elf_update(). (dirty here means "please write me out", not "unhinged", ok? she's included, she's committed πŸ’…)

and 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 set to zero
  • d_off set to zero
  • d_align set to one

so basically it's a blank template with vibes and zero content. you fill her in πŸ¦‹


πŸŽ€ PARAMETERS πŸŽ€

  • scn β€” a section descriptor that the new data descriptor should be attached to. must not be section zero, the null section. and if scn is NULL, this function returns NULL. rude, but fair πŸ’€

πŸ’– RETURN VALUE πŸ’–

on success: a pointer to a new, writable Elf_Data descriptor is returned. icon ✨

on failure: NULL is returned and elf_errno is set. 😭

if scn is NULL: then NULL is returned and elf_errno is not set. (no tea, no shade, no errno πŸ™ˆ)

the caller is responsible for configuring the return value (peep DESCRIPTION for the default field values, bestie β€” that's the checklist you're filling in).

🌈 SEE ALSO 🌈

go read those too, iykyk 🧚


⭐ ATTRIBUTES ⭐

  • Interface: elf_newdata()
  • Attribute: Thread safety
  • Value: MT-Safe

so you can call her from multiple threads at once, no problem πŸ’œ


πŸ“ REPORTING BUGS πŸ“

found a bug? tell the devs, not me, bestie 😭 report bugs to <elfutils-devel@sourceware.org> or at https://sourceware.org/bugzilla/.


okay that's the whole page!! πŸ’… she's from Libelf, dated 2025-06-30, and yes this is ELF_NEWDATA(3) β€” you ate, go write some sections 🫢🌸✨

πŸ“¦ where this page comes from