GELF\_GETSYMSHNDX(3) Libelf Programmer's Manual GELF\_GETSYMSHNDX(3)

# [NAME](#NAME)

gelf\_getsymshndx - Retrieve symbol information and separate section index from the symbol table at the given index.

# [SYNOPSIS](#SYNOPSIS)

```
#include <gelf.h>
GElf_Sym *gelf_getsymshndx (Elf_Data *symdata, Elf_Data *shndxdata, int ndx, GElf_Sym *sym, Elf32_Word *xshndx);
```

# [DESCRIPTION](#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-&gt;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)](/man/os/elfutils/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)](/man/os/elfutils/elf_scnshndx.3), [**elf\_getscn**(3)](/man/os/elfutils/elf_getscn.3), and [**elf\_getdata**(3)](/man/os/elfutils/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](#PARAMETERS)

[*symdata*](#symdata)

Pointer to **Elf\_Data** for a **SHT\_SYMTAB** section.

[*shndxdata*](#shndxdata)

Pointer to **Elf\_Data** for a **SHT\_SYMTAB\_SHNDX** section. May be NULL.

[*ndx*](#ndx)

Zero-based index of the symbol table entry in **symdata** and extended section index entry in **shndxdata**.

[*sym*](#sym)

Pointer to a caller-provided **GElf\_Sym** structure for storing the symbol table entry. Must not be NULL.

[*xshndx*](#xshndx)

Pointer to a caller-provided **Elf32\_Word** for storing the extended section index associated with the symbol. May be NULL.

# [RETURN VALUE](#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](#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](#SEE_ALSO)

[**elf\_getdata**(3)](/man/os/elfutils/elf_getdata.3), [**elf\_getscn**(3)](/man/os/elfutils/elf_getscn.3), [**elf\_scnshndx**(3)](/man/os/elfutils/elf_scnshndx.3), [**gelf\_fsize**(3)](/man/os/elfutils/gelf_fsize.3), [**gelf\_getsym**(3)](/man/os/elfutils/gelf_getsym.3), [**gelf\_update\_symshndx**(3)](/man/os/elfutils/gelf_update_symshndx.3), [**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

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

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to &lt;elfutils-devel@sourceware.org&gt; or https://sourceware.org/bugzilla/.

2025-12-30 Libelf

---

Document: gelf_getsymshndx(3) from elfutils 0.196-r0 (Chainguard OS)
Source: https://sourceware.org/git/elfutils.git
