---
name: "gelf_getshdr"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/elf32_getshdr"
---

# gelf\_getshdr(3)

retrieve the class-dependent section header

Part of [elf32\_getshdr(3)](/elf32_getshdr/3.md).

## NAME

**elf32\_getshdr**, **elf64\_getshdr**, **gelf\_getshdr** – retrieve the class-dependent section header

## LIBRARY

library “libelf”

## SYNOPSIS

**#include \<libelf.h\>**

*Elf32\_Shdr \**\

**elf32\_getshdr**(*Elf\_Scn \*scn*);

*Elf64\_Shdr \**\

**elf64\_getshdr**(*Elf\_Scn \*scn*);

**#include \<gelf.h\>**

*GElf\_Shdr \**\

**gelf\_getshdr**(*Elf\_Scn \*scn*, *GElf\_Shdr \*shdr*);

## DESCRIPTION

These functions return a pointer to the ELF Section Header data structure associated with section descriptor *scn*.

Function **elf32\_getshdr**() retrieves a pointer to an *Elf32\_Shdr* structure. Section descriptor *scn* must be associated with an ELF descriptor of class ELFCLASS32.

Function **elf64\_getshdr**() retrieves a pointer to an *Elf64\_Shdr* structure. Section descriptor *scn* must be associated with an ELF descriptor of class ELFCLASS64.

Function **gelf\_getshdr**() copies the values in the section header associated with argument *scn* to the structure pointed to be argument *dst*. The *GElf\_Shdr* data structure is described in [gelf(3)](/gelf/3.md).

## RETURN VALUES

Functions **elf32\_getshdr**() and **elf64\_getshdr**() return a valid pointer to the appropriate section header on success or NULL if an error was encountered.

Function **gelf\_getshdr**() returns argument *dst* if successful, or NULL if an error was encountered.

## ERRORS

These functions may fail with the following errors:

- \[ELF\_E\_ARGUMENT\]

  Arguments *scn* or *shdr* were NULL.

- \[ELF\_E\_ARGUMENT\]

  Argument *scn* was not associated a descriptor for an ELF object.

- \[ELF\_E\_CLASS\]

  The ELF class associated with the section descriptor *scn* did not match the class expected by the API.

## SEE ALSO

[elf(3)](/elf/3.md), [elf\_getscn(3)](/elf_getscn/3.md), [gelf(3)](/gelf/3.md), [gelf\_update\_shdr(3)](/gelf_update_shdr/3.md)
