table of contents
- experimental 0.194+20260315-1
| GELF_GETSYMSHNDX(3) | Libelf Programmer's Manual | GELF_GETSYMSHNDX(3) |
NAME¶
gelf_getsymshndx - Retrieve symbol information and separate section index from the symbol table at the given index.
SYNOPSIS¶
#include <gelf.h> GElf_Sym *gelf_getsymshndx (Elf_Data *symdata, Elf_Data *shndxdata, int ndx, GElf_Sym *sym, Elf32_Word *xshndx);
DESCRIPTION¶
This function retrieves the symbol information for a symbol at index ndx in symdata of a section with type SHT_SYMTAB and stores it in sym. This function also retrieves the symbol's extended section index from shndxdata of a section with type SHT_SYMTAB_SHNDX and stores it in xshndx.
xshndx will contain a non-zero value only for the symbols which have an st_shndx value of SHN_XINDEX. See EXAMPLE below.
The number of symbols in the symbol table can be calculated by dividing the size of symdata by the size of a symbol table entry. The size of symdata can be obtained from symdata->d_size or from the corresponding section header's sh_size. The size of a symbol table entry can be obtained from gelf_fsize(3) with ELF_T_SYM or from the corresponding section header's sh_entsize.
A SHT_SYMTAB_SHNDX section is present in ELF binaries when the number of sections is too large to be represented as an unsigned 16-bit value. In this case the st_shndx field of a GElf_Sym will be set to SHN_XINDEX to indicate that the symbol's section index can be found in the SHT_SYMTAB_SHNDX section. shndxdata for this section can be acquired using elf_scnshndx(3), elf_getscn(3), and elf_getdata(3). The number of entries in shndxdata must be equal to the number of entries in symdata. Entry ndx in shndxdata corresponds to entry ndx in symdata.
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.
- 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. xshndx is set only if both itself and shndxdata are not NULL.
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 ALSO¶
elf_getdata(3), elf_getscn(3), elf_scnshndx(3), gelf_fsize(3), gelf_getsym(3), gelf_update_symshndx(3), libelf(3), elf(5)
ATTRIBUTES¶
| Interface | Attribute | Value |
| gelf_getsymshndx () | Thread safety | MT-Safe |
REPORTING BUGS¶
Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.
| 2025-12-30 | Libelf |