ELF32_FSIZE(3)
π 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 toEV_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 oftypemultiplied bycountis greater thanSIZE_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
- 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