ELF_GETPHDRNUM(3)
β¨ ELF_GETPHDRNUM(3) β¨
okay bestie, welcome to the Libelf Programmer's Manual π this one's a lil baby function that counts program headers and it's honestly so helpful, no cap.
πΈ NAME πΈ
elf_getphdrnum β retrieve the number of program headers in an ELF file
π SYNOPSIS π
#include <libelf.h>
int elf_getphdrnum("Elf *elf", size_t *dst );
π¦ DESCRIPTION π¦
so basically, elf_getphdrnum() takes the number of program headers chillin' with the ELF descriptor elf and stores that count into the variable pointed to by dst. that's it. that's the whole job. she's simple, she's effective, she ate π
now here's the tea tho π« β if the number of program headers is too big for the e_phnum field in the ELF header to even represent, the ELF spec is like "okay no worries, we'll hide the real count in section header 0's sh_info field and just set e_phnum to the reserved value PN_XNUM (always 0xFFFF)". and this function? she transparently handles that case for you. iconic behavior fr fr β¨
she also makes sure the returned count of program headers does not exceed the number that can actually be addressed in the program header table. which is lowkey important when you're indexing into the array returned by elf32_getphdr() or elf64_getphdr() β like bestie, don't be out here indexing past the end, that's not the vibe π
π PARAMETERS π
elfβ a pointer to anElfdescriptor. and listen, this descriptor must represent an ELF binary withElf_KindELF_K_ELF. no exceptions, she's picky like that πdstβ on success, the number of program headers inelfgets written right here. Must not beNULL. like genuinely do not passNULL, that's not it chief π
β RETURN VALUE β
- Returns
0on success and stores the result indst. slay β - Returns
-1on failure and setself_errno. sad girl hours π - Returns
-1without settingerrnoifelfisNULL. yeah she just... does that. noerrno, no explanation, main character energy π
π SEE ALSO π
elf32_getphdr(3), elf64_getphdr(3), libelf(3), elf(5)
π ATTRIBUTES π
- Interface:
elf_getphdrnum() - Attribute: Thread safety
- Value:
MT-Safe
so yeah, she's MT-Safe, you can run her in multiple threads, she's not gonna start drama π§
π REPORTING BUGS π
found a bug? spill the tea to <elfutils-devel@sourceware.org> or hit up https://sourceware.org/bugzilla/. they wanna know, fr fr π«Ά
and that's the whole page bestie!! this gem is from Libelf, dated 2025-06-30, and it lives at ELF_GETPHDRNUM(3). go forth and count those program headers responsibly πβ¨π
π¦ where this page comes from
- alpine 3.23: elfutils-doc 0.194-r0 Β· GPL-3.0-or-later AND ( GPL-2.0-or-later OR LGPL-3.0-or-later )
- 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.194-5.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.194-5.fc44 Β· 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
- nixos 26.05: elfutils 0.194
- nixpkgs unstable: elfutils 0.195
- ubuntu resolute: libelf-dev 0.194-4 Β· GPL-3.0-or-later
- 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