---
name: "elf_getarsym"
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/elf_getarsym"
---

# elf\_getarsym(3)

retrieve the symbol table of an archive

## NAME

**elf\_getarsym** – retrieve the symbol table of an archive

## LIBRARY

library “libelf”

## SYNOPSIS

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

*Elf\_Arsym \**\

**elf\_getarsym**(*Elf \*elf*, *size\_t \*ptr*);

## DESCRIPTION

The function **elf\_getarsym**() retrieves the symbol table for an [ar(1)](/ar/1.md) archive, if one is available.

Argument *elf* should be a descriptor for an [ar(1)](/ar/1.md) archive opened using **elf\_begin**() or **elf\_memory**().

If the archive *elf* contains a symbol table with n entries, this function returns a pointer to an array of n+1 *Elf\_Arsym* structures. An *Elf\_Arsym* structure has the following elements:

- *char \** *as\_name*

  This structure member is a pointer to a null-terminated symbol name.

- *off\_t* *as\_off*

  This structure member contains the byte offset from the beginning of the archive to the header for the archive member. This value is suitable for use with [elf\_rand(3)](/elf_rand/3.md).

- *unsigned long* *as\_hash*

  This structure member contains a portable hash value for the symbol name, as computed by [elf\_hash(3)](/elf_hash/3.md).

The last entry of the returned array will have a NULL value for member *as\_name*, a zero value for member *as\_off* and an illegal value of ~0UL for *as\_hash*.

If argument *ptr* is non-null, the **elf\_getarsym**() function will store the number of table entries returned (including the sentinel entry at the end) into the location it points to.

## RETURN VALUES

Function **elf\_getarsym**() returns a pointer to an array of *Elf\_Arsym* structures if successful, or a NULL pointer if an error was encountered.

If argument *ptr* is non-null and there was no error, the library will store the number of archive symbol entries returned into the location it points to. If argument *ptr* is non-null and an error was encountered, the library will set the location pointed to by it to zero.

## ERRORS

Function **elf\_getarsym**() may fail with the following errors:

- \[ELF\_E\_ARGUMENT\]

  Argument *elf* was NULL.

- \[ELF\_E\_ARGUMENT\]

  Argument *elf* was not a descriptor for an [ar(1)](/ar/1.md) archive.

## SEE ALSO

[elf(3)](/elf/3.md), [elf\_begin(3)](/elf_begin/3.md), [elf\_getarhdr(3)](/elf_getarhdr/3.md), [elf\_hash(3)](/elf_hash/3.md), [elf\_memory(3)](/elf_memory/3.md), [elf\_next(3)](/elf_next/3.md), [elf\_rand(3)](/elf_rand/3.md)
