GELF_NEWPHDR(3)
π 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 kindELF_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
- alpine 3.24: elfutils-doc 0.195-r0 Β· GPL-3.0-or-later AND ( GPL-2.0-or-later OR LGPL-3.0-or-later )
- arch rolling: libelf 0.196-1
- arch rolling: libelf 0.197-1 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 10: elfutils-libelf-devel 0.197-1.el10 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 9: elfutils-libelf-devel 0.197-1.el9 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 9: elfutils-libelf-devel 0.197-1.el9 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.196-1.fc43
- fedora 43: elfutils-libelf-devel 0.196-1.fc43
- fedora 43: elfutils-libelf-devel 0.197-1.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.197-1.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.196-1.fc44
- fedora 44: elfutils-libelf-devel 0.196-1.fc44
- fedora 44: elfutils-libelf-devel 0.197-1.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.197-1.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- nixpkgs unstable: elfutils 0.195
- ubuntu stonking: libelf-dev 0.196-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms