---
name: "gelf_getsymshndx"
section: "3"
platform: "linux"
package: "libelf"
version: "0.197-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/gelf_getsymshndx"
---

# gelf\_getsymshndx(3)

Retrieve symbol information and separate section index from the symbol table at the given index.

## 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)](/gelf_fsize/3.md) 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_scnshndx/3.md), [**elf\_getscn**(3)](/elf_getscn/3.md), and [**elf\_getdata**(3)](/elf_getdata/3.md). 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_getdata/3.md), [**elf\_getscn**(3)](/elf_getscn/3.md), [**elf\_scnshndx**(3)](/elf_scnshndx/3.md), [**gelf\_fsize**(3)](/gelf_fsize/3.md), [**gelf\_getsym**(3)](/gelf_getsym/3.md), [**gelf\_update\_symshndx**(3)](/gelf_update_symshndx/3.md), [**libelf**(3)](/libelf/3.md), [**elf**(5)](/elf/5.md)

## ATTRIBUTES

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **gelf\_getsymshndx**() | Thread safety | MT-Safe |

## REPORTING BUGS

Report bugs to \<elfutils-devel@sourceware.org\> or https://sourceware.org/bugzilla/.
