ELF_GETSHDRSTRNDX(3)
π ELF_GETSHDRSTRNDX(3) π
okay bestie, welcome to the Libelf Programmer's Manual, section 3 β this is the page for elf_getshdrstrndx and its lil deprecated twin elf_getshstrndx. we're getting the section header string table index and we're gonna be so normal about it π
β¨ NAME β¨
elf_getshdrstrndx, elf_getshstrndx β retrieve the section header string table index π
β¨ SYNOPSIS β¨
#include <libelf.h>
int elf_getshdrstrndx("Elf *elf", size_t *dst );
int elf_getshstrndx("Elf *elf", size_t *dst ); (deprecated)
yes bestie, those quotes are literally in there. we don't make the rules, we just transcribe them. π
β¨ DESCRIPTION β¨
so the way that elf_getshdrstrndx() works is: it grabs the section header string table index out of the ELF descriptor elf, and it drops it right into the spot that dst is pointing at. that's it. that's the whole job. π«Ά
if you wanna actually get a section's name, you hit up elf_strptr(3). and listen β that function needs two things from you: the section header string table index that elf_getshdrstrndx() just handed you, plus the sh_name field from the section's Elf32_Shdr or Elf64_Shdr (peep elf32_getshdr and elf64_getshdr for those). iykyk πΈ
now here's the spicy part: this function handles both standard ELF values and extended section indexing. so in that extended case, if the section header string table index field of the ELF header contains SHN_XINDEX, then the real index is chilling in the sh_link field of section 0. sneaky but iconic. π
and elf_getshstrndx()? that's just a deprecated alias for elf_getshdrstrndx(). do not use it in new code, bestie, i'm begging (see HISTORY). it's giving legacy. π
β¨ PARAMETERS β¨
- elf β a pointer to an
Elfdescriptor. it must have kindELF_K_ELF. and if elf isNULL, then this function returns-1without settingelf_errno. no drama, no errno, just a-1. π - dst β a pointer to a
size_tlocation where the index of the section header string table gets stored. must not beNULL. fr fr, don't do it.
β¨ RETURN VALUE β¨
- returns
0on success and stores the section header string table index in dst. slay. β¨ - returns
-1on failure and setself_errno(as long as elf is notNULL).
β¨ SEE ALSO β¨
elf32_getshdr(3), elf64_getshdr(3), elf_strptr(3), libelf(3), elf(5)
go read those next, bestie, they're the supporting cast π¦
β¨ ATTRIBUTES β¨
here's the vibe check on thread safety:
- Interface:
elf_getshdrstrndx(),elf_getshstrndx() - Attribute: Thread safety
- Value: MT-Safe π₯
so yeah, she's thread safe. go forth and multithread. π
β¨ REPORTING BUGS β¨
found a bug? spill it to <elfutils-devel@sourceware.org> or hit up https://sourceware.org/bugzilla/. we wanna know. π
β¨ HISTORY β¨
elf_getshdrstrndx first appeared in elfutils 0.142. why does it exist, you ask? because elf_getshstrndx had return value inconsistencies between different libelf implementations. messy. so elf_getshdrstrndx was introduced to ensure that 0 is returned on success. consistency queen behavior, honestly. π
lowkey the whole moral of this page: useelf_getshdrstrndx(), not the deprecated one, and check that dst isn'tNULL. periodt. π
okay that's the whole page, you ate it π this was Libelf, dated 2025-06-30 β mwah, go write some ELF code and text me when it compiles πβ¨π¦
π¦ 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