ELF_GETPHDRNUM(3)

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

✨ 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 an Elf descriptor. and listen, this descriptor must represent an ELF binary with Elf_Kind ELF_K_ELF. no exceptions, she's picky like that πŸ’…
  • dst β€” on success, the number of program headers in elf gets written right here. Must not be NULL. like genuinely do not pass NULL, that's not it chief 😭

⭐ RETURN VALUE ⭐

  • Returns 0 on success and stores the result in dst. slay βœ…
  • Returns -1 on failure and sets elf_errno. sad girl hours πŸ˜”
  • Returns -1 without setting errno if elf is NULL. yeah she just... does that. no errno, 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