ELF32_GETPHDR(3)
π 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_getphdrnumandelf64_getphdrnum's whole job. π - wanna resize the program header table, or just straight up delete it?
elf32_newphdrandelf64_newphdrgot you. - and listen β this part matters β if you're changing an element of the program header table, you absolutely must call
elf_flagphdrwithELF_C_SETandELF_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:
- email <elfutils-devel@sourceware.org>
- or go off in the bugzilla:
https://sourceware.org/bugzilla/
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
- alpine 3.22: elfutils-doc 0.193-r0 Β· GPL-3.0-or-later AND ( GPL-2.0-or-later OR LGPL-3.0-or-later )
- 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
- debian trixie: libelf-dev 0.192-4 Β· GPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.193-3.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.193-3.fc43 Β· 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
- opensuse-leap 16.0: libelf-devel 0.192-160000.3.1 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- opensuse-leap 16.0: libelf-devel 0.192-160000.3.1 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- opensuse-leap 16.0: libelf-devel 0.192-160000.3.1 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- opensuse-leap 16.0: libelf-devel 0.192-160000.3.1 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- ubuntu questing: libelf-dev 0.193-1
- 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