ELF32_NEWPHDR(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_NEWP HDR β€” wait, ELF32_NEWPHDR(3) ✨

okay bestie so this is a page from the Libelf Programmer's Manual, and it's all about elf32_newphdr and elf64_newphdr β€” the little functions that build you a whole new program header table for a 32-bit or 64-bit ELF object file. like, out with the old table, in with the new. πŸ’…


🌸 NAME 🌸

elf32_newphdr, elf64_newphdr β€” create a new program header table for a 32-bit or 64-bit ELF object file


πŸŽ€ SYNOPSIS πŸŽ€

#include <libelf.h>

Elf32_Phdr *elf32_newphdr(Elf *elf, size_t count);
Elf64_Phdr *elf64_newphdr(Elf *elf, size_t count);

πŸ’– DESCRIPTION πŸ’–

okay so the whole vibe here is: you're creating a brand new program header table for the ELF object file that elf points at. the number of entries in this fresh new table? that's what count is for. and listen β€” a count of zero straight-up removes the existing program header table. gone. deleted. not me being dramatic, that's literally what it does. 😭

what actually happens under the hood: the function allocates a new array of Elf32_Phdr and makes it the program header table for elf. the new program header contents get set to zero, and any previous program header table is discarded β€” like, it's not coming back. 🫢

⚠️ important bestie: an ELF header must exist before creating a program header table. don't skip that step, the vibe check will fail.

🌈 PARAMETERS 🌈

  • elf β€” pointer to the ELF object you want a new program header table created for. that's the target. the main character, if you will. πŸ‘‘
  • count β€” how many entries the new program header table has. and fr fr, a count of zero removes the existing program header table.

⭐ RETURN VALUE ⭐

  • on success, it returns a pointer to the first Elf32_Phdr in the newly created program header table. slay. ✨
  • if elf is NULL, then it returns NULL. that's it, that's the deal.
  • if an error occurs, it returns NULL and sets a libelf error code. so check elf_errno(3) if you're confused, bestie.

πŸ¦‹ SEE ALSO πŸ¦‹


πŸ’œ ATTRIBUTES πŸ’œ

for an explanation of the terms used in this section, see attributes(7).

  • elf32_newphdr(), elf64_newphdr() β€” Thread safety: MT-Safe πŸ”₯

(the original had this in a cute little table, but tables aren't the vibe here β€” same facts though, no cap.)


πŸ“ REPORTING BUGS πŸ“

found a bug? don't gatekeep it, report it to <elfutils-devel@sourceware.org> or hit up https://sourceware.org/bugzilla/. the maintainers wanna know. πŸ™ˆ


and that's the whole page, bestie πŸ’– this was Libelf, dated 2024-08-14 β€” ELF32_NEWPHDR(3), icon of building program header tables from scratch. periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from