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

# elf\_getshdrstrndx(3)

retrieve the section header string table index

## NAME

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

## SYNOPSIS

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

## 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)](/elf_strptr/3.md). 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

- *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*

  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

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

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

## ATTRIBUTES

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

## REPORTING BUGS

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

## 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.
