ELF32_GETPHDR(3)

πŸ“¦
version 0.197 Β· 2 versions
  • 0.197 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 15.1 Β· freebsd 14.5, freebsd 15.1, nixpkgs unstable
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– ELF32_GETPHDR(3) πŸ’–

okay bestie, welcome to the Libelf Programmer's Manual ✨ today we're talking about elf32_getphdr and elf64_getphdr β€” the little duo that pulls the program header table out of a 32-bit or 64-bit ELF object file. no cap, they're giving librarian energy and we love that for them πŸ“š


✨ NAME ✨

elf32_getphdr, elf64_getphdr β€” retrieve the program header table for a 32-bit or 64-bit ELF object file πŸ¦‹


🌸 SYNOPSIS 🌸

#include <libelf.h>

Elf32_Phdr *elf32_getphdr(Elf *elf);
Elf64_Phdr *elf64_getphdr(Elf *elf);

πŸ’… DESCRIPTION πŸ’…

so basically, you hand it an ELF descriptor elf, and it hands you back the program header table for that file. that's the whole vibe. πŸŽ€

now, quick side quests you're gonna want to know about:

  • wanna know how many elements are chillin' in that program header table? that's elf32_getphdrnum and elf64_getphdrnum's whole job. πŸ‘‘
  • wanna resize the program header table, or just straight up delete it? elf32_newphdr and elf64_newphdr got you.
  • and listen β€” this part matters β€” if you're changing an element of the program header table, you absolutely must call elf_flagphdr with ELF_C_SET and ELF_F_DIRTY, otherwise your new data is never gonna make it to disk. it's giving "wrote it but didn't hit save" πŸ’€ don't be that girl.

πŸ“ PARAMETERS πŸ“

  • elf β€” the ELF descriptor you're pulling the program header table out of. that's it, that's the one. 🫢

⭐ RETURN VALUE ⭐

  • on success? you get a pointer to the program header table. slay. ✨
  • if there's no program header? you get NULL. it's not a fail, it's just... nothing there. πŸ™ˆ
  • on failure? also NULL β€” but this time it also sets a libelf error code. check it, bestie.

🌈 SEE ALSO 🌈

elf32_newphdr(3), elf_errno(3), elf_getphdrnum(3), libelf(3), elf(5)


πŸ’œ ATTRIBUTES πŸ’œ

for the whole explanation of what these terms even mean, go peek at attributes(7). but here's the tea for our two faves:

  • Interface: elf32_getphdr(), elf64_getphdr()
  • Attribute: Thread safety
  • Value: MT-Safe πŸ”₯
translation: they're thread safe, they don't start drama across threads, we stan.

😭 REPORTING BUGS 😭

found a bug? don't gatekeep, tell somebody:


and that's the whole page, bestie!! 🧚 thanks for reading, go write some beautiful ELF code, and remember: flag your phdr or it never happened πŸ’…

this has been the Libelf manual, dated 2024-08-14, page ELF32_GETPHDR(3) β€” mwah, love u, bye πŸŽ€

πŸ“¦ where this page comes from