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

# elftc\_string\_table\_create(3)

convenience routines for handling ELF string tables

## NAME

**elftc\_string\_table\_create**, **elftc\_string\_table\_destroy**, **elftc\_string\_table\_from\_section**, **elftc\_string\_table\_image**, **elftc\_string\_table\_insert**, **elftc\_string\_table\_lookup**, **elftc\_string\_table\_remove**, **elftc\_string\_table\_to\_string** – convenience routines for handling ELF string tables

## SYNOPSIS

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

*Elftc\_String\_Table \**\

**elftc\_string\_table\_create**(*size\_t sizehint*);

*void*\

**elftc\_string\_table\_destroy**(*Elftc\_String\_Table \*table*);

*Elftc\_String\_Table \**\

**elftc\_string\_table\_from\_section**(*Elf\_Scn \*scn*, *size\_t sizehint*);

*const char \**\

**elftc\_string\_table\_image**(*Elftc\_String\_Table \*table*, *size\_t \*size*);

*size\_t*\

**elftc\_string\_table\_insert**(*Elftc\_String\_Table \*table*, *const char \*string*);

*size\_t*\

**elftc\_string\_table\_lookup**(*Elftc\_String\_Table \*table*, *const char \*string*);

*int*\

**elftc\_string\_table\_remove**(*Elftc\_String\_Table \*table*, *const char \*string*);

*const char \**\

**elftc\_string\_table\_to\_string**(*Elftc\_String\_Table \*table*, *size\_t offset*);

## DESCRIPTION

This manual page documents convenience routines for handling ELF string tables.

Function **elftc\_string\_table\_create**() creates a new, empty string table. The argument *sizehint* provides a hint about the expected number of bytes of string data in the table. If the argument *sizehint* is zero, an implementation-defined default will be used instead.

Function **elftc\_string\_table\_destroy**() destroys the previously allocated string table specified by argument *table*, and frees the internal resources allocated for it.

Function **elftc\_string\_table\_from\_section**() creates a new string table and initializes it based on the contents of the section specified by argument *scn*. This section must be of type SHT\_STRTAB. The argument *sizehint* provides a hint about expected number of bytes of string data in the table. If the value of *sizehint* is zero, an implementation-default will be used instead.

Function **elftc\_string\_table\_image**() returns a pointer to the ELF representation of the contents of the string table specified by argument *table*. If argument *size* is not NULL, the size of the ELF representation of the string table is stored in the location pointed to by argument *size*. The function **elftc\_string\_table\_image**() will compact the string table if the table contains deleted strings. The string offsets returned by prior calls to **elftc\_string\_table\_insert**() and **elftc\_string\_table\_lookup**() should be treated as invalid after a call to this function.

Function **elftc\_string\_table\_insert**() inserts the NUL-terminated string pointed to by argument *string* into the string table specified by argument *table*, and returns an offset value usable in ELF data structures. Multiple insertions of the same content will return the same offset. The offset returned will remain valid until the next call to **elftc\_string\_table\_image**().

Function **elftc\_string\_table\_lookup**() looks up the string referenced by argument *string* in the string table specified by argument *table*, and if found, returns the offset associated with the string. The returned offset will be valid until the next call to **elftc\_string\_table\_image**().

Function **elftc\_string\_table\_remove**() removes the string pointed by argument *string* from the string table referenced by argument *table*, if it is present in the string table.

Function **elftc\_string\_table\_to\_string**() returns a pointer to the NUL-terminated string residing at argument *offset* in the string table specified by argument *table*. The value of argument *offset* should be one returned by a prior call to **elftc\_string\_table\_insert**() or **elftc\_string\_table\_lookup**(). The returned pointer will remain valid until the next call to **elftc\_string\_table\_insert**() or **elftc\_string\_table\_image**().

### Memory Management

The library “libelftc” library manages its own memory allocations. The application should not free the pointers returned by the string table functions.

## IMPLEMENTATION NOTES

The current implementation is optimized for the case where strings are added to a string table, but rarely removed from it.

The functions **elftc\_string\_table\_insert**(), **elftc\_string\_table\_lookup**(), **elftc\_string\_table\_remove**() and **elftc\_string\_table\_to\_string**() have O(1) asymptotic behavior. The function **elftc\_string\_table\_image**() can have O(size) asymptotic behavior, where *size* denotes the size of the string table.

## RETURN VALUES

Functions **elftc\_string\_table\_create**() and **elftc\_string\_table\_from\_section**() return a valid pointer to an opaque structure of type *Elftc\_String\_Table* on success, or NULL in case of an error.

The function **elftc\_string\_table\_image**() returns a pointer to an in-memory representation of an ELF string table on success, or NULL in case of an error.

Functions **elftc\_string\_table\_insert**() and **elftc\_string\_table\_lookup**() return a non-zero offset on success, or zero in case of an error.

Function **elftc\_string\_table\_remove**() returns a positive value on success, or zero in case of an error.

Function **elftc\_string\_table\_to\_string**() returns a valid pointer on success, or NULL in case of an error.

## SEE ALSO

[dwarf(3)](/dwarf/3.md), [elf(3)](/elf/3.md), [elftc(3)](/elftc/3.md)
