ELF\_GETSHDRSTRNDX(3) Libelf Programmer's Manual ELF\_GETSHDRSTRNDX(3)

# [NAME](#NAME)

elf\_getshdrstrndx, elf\_getshstrndx - retrieve the section header string table index

# [SYNOPSIS](#SYNOPSIS)

```
#include <libelf.h>
int elf_getshdrstrndx("Elf *elf", size_t *dst );
int elf_getshstrndx("Elf *elf", size_t *dst ); (deprecated)
```

# [DESCRIPTION](#DESCRIPTION)

The **elf\_getshdrstrndx**() function retrieves the section header string table index from the ELF descriptor *elf*, and stores it in the location pointed to by *dst*.

A section's name can be aquired with [**elf\_strptr**(3)](/man/os/elfutils/elf_strptr.3). This function takes the section header string table index from **elf\_getshdrstrndx**() as well as the *sh\_name* field from the section's *Elf32\_Shdr* or *Elf64\_Shdr* (see **elf32\_getshdr** and **elf64\_getshdr**).

This function handles both standard ELF values and extended section indexing. In the latter case, if the section header string table index field of the ELF header contains **SHN\_XINDEX,** then the true index is stored in the **sh\_link** field of section 0.

The function **elf\_getshstrndx**() is a deprecated alias for **elf\_getshdrstrndx**() and should not be used in new code (see HISTORY).

# [PARAMETERS](#PARAMETERS)

[*elf*](#elf)

A pointer to an **Elf** descriptor. The descriptor must have kind **ELF\_K\_ELF .** If *elf* is NULL, then this function returns -1 without setting elf\_errno

[*dst*](#dst)

A pointer to a **size\_t** location where the index of the section header string table will be stored. Must not be NULL.

# [RETURN VALUE](#RETURN_VALUE)

Returns 0 on success and stores the section header string table index in *dst*. Returns -1 on failure and sets elf\_errno (if *elf* is not NULL).

# [SEE ALSO](#SEE_ALSO)

[**elf32\_getshdr**(3)](/man/os/elfutils/elf32_getshdr.3), [**elf64\_getshdr**(3)](/man/os/elfutils/elf64_getshdr.3), [**elf\_strptr**(3)](/man/os/elfutils/elf_strptr.3), [**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

**Interface** **Attribute** **Value** elf\_getshdrstrndx (), elf\_getshstrndx () Thread safety MT-Safe

# [REPORTING BUGS](#REPORTING_BUGS)

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

# [HISTORY](#HISTORY)

**elf\_getshdrstrndx** first appeared in elfutils 0.142. This function was added due to elf\_getshstrndx return value inconsistencies between different libelf implementations. **elf\_getshdrstrndx** was introduced to ensure that 0 is returned on success.

2025-06-30 Libelf

---

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