ELF_GETSHDRNUM(3)
π ELF_GETSHDRNUM(3) β the libelf glow-up π
okay bestie, sit down, hydrate, because we're about to learn how to count section headers in an ELF file and honestly? it's giving β¨main character energyβ¨. this is libelf, and this page is about elf_getshdrnum (and its kinda cringe deprecated cousin elf_getshnum). π¦
πΈ NAME πΈ
elf_getshdrnum, elf_getshnum β retrieve the number of section headers in an ELF file π
β¨ SYNOPSIS β¨
#include <libelf.h>
int elf_getshdrnum("Elf *elf", size_t *dst );
int elf_getshnum("Elf *elf", size_t *dst ); (deprecated)
π DESCRIPTION π
so. elf_getshdrnum() takes the number of section headers (aka sections) that are associated with the ELF descriptor elf, and stores it into the variable that dst points at. literally that's it, that's the whole job, and it does it flawlessly. π
the way that it's lowkey a genius function: it transparently handles both standard and extended section header counts. like, if the number of section headers exceeds the representable range of the e_shnum field in the ELF header, the ELF specification allows the true count to be encoded in section header 0's sh_size field, and sets e_shnum to 0. this function handles that case transparently. no cap, it just deals with it for you so you never have to think about it. π
meanwhile elf_getshnum() is a deprecated alias for elf_getshdrnum() and should not be used in new code (go peek at HISTORY if you want the tea β).
π PARAMETERS π
elfβ a pointer to anElfdescriptor opened withelf_begin(3). the descriptor has to represent a file of kindELF_K_ELF. and if it'sNULL? the function returns-1without settingelf_errno. rude but fair. πdstβ pointer to asize_tvariable. on success, the number of section headers gets written right here. it must not beNULL. π
β RETURN VALUE β
returns 0 on success and stores the result in dst. returns -1 on failure. that's the whole vibe check: zero good, negative one bad. π«Ά
π SEE ALSO π
elf32_getshdr(3), elf64_getshdr(3), libelf(3), elf(5)
π ATTRIBUTES π
elf_getshdrnum(),elf_getshnum()β Thread safety β MT-Safe
so yes, you can absolutely bring this function to the group chat, it's thread-safe bestie. MT-Safe and unbothered. π
π REPORTING BUGS π
found a bug? report it to <elfutils-devel@sourceware.org> or hit up https://sourceware.org/bugzilla/. they want to know, fr fr. πΈ
π HISTORY π
elf_getshdrnum first appeared in elfutils 0.142. it got added because elf_getshnum had return value inconsistencies between different libelf implementations (messy, honestly π). elf_getshdrnum was introduced to ensure that 0 is returned on success across all libelf implementations. consistency slay. periodt. β¨
and that's the page, bestie β written up as part of the Libelf Programmer's Manual, dated 2025-06-30, tagged ELF_GETSHDRNUM(3). go forth and count those section headers. mwah ππ¦π
π¦ where this page comes from
- 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
- 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
- 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