GELF_GETSYMSHNDX(3)

πŸ“¦
version 0.197 Β· 2 versions
, in alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixpkgs unstable, ubuntu stonking

πŸ’– 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 symdata by the size of a symbol table entry.
  • the size of symdata comes from symdata->d_size or from the corresponding section header's sh_size.
  • the size of a symbol table entry comes from gelf_fsize(3) with ELF_T_SYM or from the corresponding section header's sh_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 in shndxdata must be equal to the number of entries in symdata. and entry ndx in shndxdata corresponds to entry ndx in symdata. matching sets, periodt. πŸ‘‘

πŸ’œ PARAMETERS πŸ’œ

  • symdata β€” Pointer to Elf_Data for a SHT_SYMTAB section. πŸ“
  • shndxdata β€” Pointer to Elf_Data for a SHT_SYMTAB_SHNDX section. May be NULL.
  • ndx β€” Zero-based index of the symbol table entry in symdata and extended section index entry in shndxdata. (zero-based bestie, don't forget πŸ’€)
  • sym β€” Pointer to a caller-provided GElf_Sym structure for storing the symbol table entry. Must not be NULL. 🚨
  • xshndx β€” Pointer to a caller-provided Elf32_Word for storing the extended section index associated with the symbol. May be NULL.

⭐ 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