GELF_GETSYMSHNDX(3)
π GELF_GETSYMSHNDX π
okay bestie, welcome to the gelf_getsymshndx page from the Libelf Programmer's Manual β it's giving "grab a symbol AND its extended section index in one go" and honestly? iconic. π
β¨ NAME β¨
gelf_getsymshndx β Retrieve symbol information and separate section index from the symbol table at the given index.
like. it fetches the symbol stuff. and the separate section index. at whatever index you point at. slay. π
πΈ SYNOPSIS πΈ
#include <gelf.h>
GElf_Sym *gelf_getsymshndx (Elf_Data *symdata, Elf_Data *shndxdata, int ndx, GElf_Sym *sym, Elf32_Word *xshndx);
yes that's the whole signature, no cap. π«Ά
π¦ DESCRIPTION π¦
okay so here's the vibe. This function retrieves the symbol information for a symbol at index ndx in symdata β that's a section with type SHT_SYMTAB β and stores it in sym. and that's not all β¨ it ALSO retrieves the symbol's extended section index from shndxdata, which is a section with type SHT_SYMTAB_SHNDX, and stashes it in xshndx.
here's the tea tho, bestie: xshndx will contain a non-zero value only for the symbols which have an st_shndx value of SHN_XINDEX. See EXAMPLE below. π
now, wanna know how many symbols live in the symbol table? it's just math, and math is cute:
- divide the size of
symdataby the size of a symbol table entry. - the size of
symdatacomes fromsymdata->d_sizeor from the corresponding section header'ssh_size. - the size of a symbol table entry comes from
gelf_fsize(3)withELF_T_SYMor from the corresponding section header'ssh_entsize.
A SHT_SYMTAB_SHNDX section shows up in ELF binaries when the number of sections is too large to be represented as an unsigned 16-bit value π. When that happens, the st_shndx field of a GElf_Sym gets set to SHN_XINDEX to indicate that the symbol's section index can be found in the SHT_SYMTAB_SHNDX section. and you can acquire shndxdata for this section using elf_scnshndx(3), elf_getscn(3), and elf_getdata(3). π
lowkey important: the number of entries inshndxdatamust be equal to the number of entries insymdata. and entry ndx inshndxdatacorresponds to entry ndx insymdata. matching sets, periodt. π
π PARAMETERS π
symdataβ Pointer toElf_Datafor aSHT_SYMTABsection. πshndxdataβ Pointer toElf_Datafor aSHT_SYMTAB_SHNDXsection. May beNULL.ndxβ Zero-based index of the symbol table entry insymdataand extended section index entry inshndxdata. (zero-based bestie, don't forget π)symβ Pointer to a caller-providedGElf_Symstructure for storing the symbol table entry. Must not beNULL. π¨xshndxβ Pointer to a caller-providedElf32_Wordfor storing the extended section index associated with the symbol. May beNULL.
β RETURN VALUE β
On success, this function updates sym and xshndx (if not NULL) and returns sym. π
On failure, it returns NULL and sets elf_errno. π
if symdata is NULL, then NULL is returned and elf_errno is not set (sneaky, right?).
and heads up: xshndx is set only if both itself and shndxdata are not NULL. both or nothing, babe. π«Ά
π§ EXAMPLE π§
GElf_Sym sym;
Elf32_Word shndx;
/* If the symbol uses an extended section index, gelf_getsymshndx stores
it in shndx. Otherwise the symbol's section index is taken directly
from sym.st_shndx. */
if (gelf_getsymshndx (symdata, shndxdata, ndx, &sym, &shndx) != NULL
&& sym.st_shndx != SHN_XINDEX)
shndx = sym.st_shndx;
see how it falls back? main character energy fr fr. β¨
π SEE ALSO π
elf_getdata(3), elf_getscn(3), elf_scnshndx(3), gelf_fsize(3), gelf_getsym(3), gelf_update_symshndx(3), libelf(3), elf(5)
the whole friend group, all linked up π
π ATTRIBUTES π
no tables allowed in this group chat so here it is, unpacked:
- Interface:
gelf_getsymshndx() - Attribute: Thread safety
- Value:
MT-Safe
so yes bestie, it's thread safe. go off. π₯
π REPORTING BUGS π
Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.
(they're nice, i promise, just be specific π)
that's the whole page, you ate it. π
β¨ this was the Libelf gelf_getsymshndx(3) page, dated 2025-12-30 β mwah, go compile something gorgeous. πΈπ¦π
π¦ where this page comes from
- 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.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
- nixpkgs unstable: elfutils 0.195
- 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