ELF32_FSIZE(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_FSIZE(3) πŸ’–

okay bestie, welcome to the Libelf Programmer's Manual, section 3, and today's episode is elf32_fsize and elf64_fsize β€” aka the girlies who do the math so you don't have to. no cap.


✨ NAME ✨

elf32_fsize, elf64_fsize β€” calculate the file size of an ELF data structure πŸ¦‹


🌸 SYNOPSIS 🌸

#include <libelf.h>

size_t elf32_fsize(Elf_Type type, size_t count, unsigned int version);
size_t elf64_fsize(Elf_Type type, size_t count, unsigned int version);

πŸ’… DESCRIPTION πŸ’…

so here's the vibe: you hand her an Elf_Type that represents some core ELF structure, you tell her how many of them you've got, and she hands you back the number of bytes you'd need for the on-disk representation in a 32-bit or a 64-bit ELF file. that's it. that's the whole job. she ate and left no crumbs πŸ’…

the on-disk and in-memory representations of Elf_Type are assumed to be the same, which is lowkey important β€” she's not converting anything, she's just trusting that they match.

if you wanna know more about what Elf_Type even is, go read libelf(3), she explains it way better than I could rn 🫢


πŸŽ€ PARAMETERS πŸŽ€

  • type β€” the ELF data structure type you want the file size of. like, which shape are we counting here, bestie.
  • count β€” how many elements of that type. one? forty? the limit does not exist (well, kind of β€” see RETURN VALUE πŸ‘€).
  • version β€” the ELF version. set this to EV_CURRENT. that is the only valid value. periodt. πŸ’€

⭐ RETURN VALUE ⭐

she returns the size in bytes of the data structure type you asked for, times however many you asked for. simple math, iconic behavior ✨

but β€” if version isn't set to EV_CURRENT, or if type isn't a valid Elf_Type? she returns 0 and sets a libelf error code. not her problem, she told you. πŸ™ˆ

🚨 heads up bestie: integer overflow can occur if the size of type multiplied by count is greater than SIZE_MAX. so like... don't do that. this is the part where you do a vibe check on your numbers first. 😭

πŸ‘‘ SEE ALSO πŸ‘‘

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


🌈 ATTRIBUTES 🌈

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

  • Interface: elf32_fsize(), elf64_fsize()
  • Attribute: Thread safety
  • Value: MT-Safe

so yeah β€” she's MT-Safe, meaning multiple threads can call her at once and she won't spiral. main character energy fr fr πŸ”₯


πŸ’€ REPORTING BUGS πŸ’€

found a bug? not me manifesting that, but okay. report it to <elfutils-devel@sourceware.org> or hit up https://sourceware.org/bugzilla/ and tell them everything 🫢


this page is from Libelf, dated 2024-08-14 β€” and that's the whole manual page, bestie. you're officially fluent. go forth and calculate those file sizes. slay πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from