GELF_NEWPHDR(3)

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

πŸ’– GELF_NEWPHDR(3) πŸ’–

ok so like, welcome to the libelf programmer's manual bestie, pull up a chair πŸŽ€


✨ NAME ✨

gelf_newphdr β€” allocate and initialize a new program header table


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <gelf.h>

void *gelf_newphdr(Elf *elf, size_t phnum);

🌸 DESCRIPTION 🌸

ok so here's the tea, girlboss: gelf_newphdr() makes you a brand new program header table with phnum entries for the ELF descriptor elf, and it zeros out every single entry. clean slate energy ✨

if a program header table already exists for elf? it gets discarded. gone. not your problem anymore πŸ’…

and if phnum is zero, any existing program header table just gets removed entirely. bye babe 🫢

🚨 IMPORTANT bestie: this array is maintained within the ELF descriptor and must NOT be freed directly. do not do it. do not even think about it. πŸ™ˆ

after you call gelf_newphdr(), any previously obtained program header pointers for the same descriptor become invalid β€” they're giving expired-milk energy, do not use them 😭

also: an ELF header must exist before you can create a program header table. no ELF header, no table. periodt. πŸ‘‘


πŸ’… PARAMETERS πŸ’…

  • elf β€” pointer to an ELF descriptor of kind ELF_K_ELF. that's the vibe check it has to pass.
  • phnum β€” the number of entries in your new program header table. if it's zero, any existing program header table gets removed. simple as.

⭐ RETURN VALUE ⭐

on success, you get a non-NULL void pointer to the shiny new program header table. slay πŸ’–

you can grab that new table as a GElf_Phdr * using gelf_getphdr(). you can also use elf32_getphdr() or elf64_getphdr() depending on the class of elf. iykyk 🌈

if phnum is 0, then any existing program header table is removed and NULL is returned.

on failure, NULL is returned and elf_errno gets set. classic. 😀

if elf is NULL, then NULL is returned without setting elf_errno β€” like, it's not even gonna bother.

🌸 lil heads up: other libelf implementations of gelf_newphdr() may use a different return type. so like, don't assume, okay?

πŸ‘€ SEE ALSO πŸ‘€


πŸŽ€ ATTRIBUTES πŸŽ€

  • Interface: gelf_newphdr()
  • Attribute: Thread safety
  • Value: MT-Safe
✨ translation: she's MT-Safe, she can hang in multithreaded spaces, no cap 🫢

πŸ› REPORTING BUGS πŸ›

found a bug? tell someone!! report bugs to <elfutils-devel@sourceware.org> or at https://sourceware.org/bugzilla/. they wanna hear it fr fr πŸ’œ


ok that's the whole page bestie, you're literally so good at this now πŸ’–βœ¨

this was brought to you by Libelf, dated 2025-09-23, and this iconic lil entry is filed under GELF_NEWPHDR(3). go forth and slay πŸ§šπŸ’…

πŸ“¦ where this page comes from