Hi Aaron,

On Mon, 2026-03-09 at 14:43 -0400, Aaron Merey wrote:
> Signed-off-by: Aaron Merey <[email protected]>
> ---
> v2: Clarify how to find the size of the symbol table and which arguments
> may be NULL.

On comment, about an issue I just hit myself, which might be confusing,
so would be good to explicitly state.

> +.SH SYNOPSIS
> +.nf
> +.B #include <gelf.h>
> +
> +.BI "GElf_Sym *gelf_getsymshndx (Elf_Data *" symdata ", Elf_Data *" 
> shndxdata ", int " ndx ", GElf_Sym *" sym ", Elf32_Word *" xshndx ");"
> +
> +.SH DESCRIPTION
> +This function retrieves the symbol information for a symbol at index
> +.I ndx
> +in
> +.I symdata
> +of a section with type
> +.B SHT_SYMTAB
> +and stores it in
> +.IR sym .
> +This function also retrieves the symbol's extended section index from
> +.B shndxdata
> +of a section with type
> +.BR SHT_SYMTAB_SHNDX
> +and stores it in
> +.IR xshndx .

It should probably be noted that xshndx will only contain a non-zero
value for those symbols which have a st_shndx value of SHN_XINDEX,
otherwise the section value is only stored in the symbol st_shndx. So
to reliably get the actual section index that a symbol is associated
with you would do something like:

GElf_Sym sym;
Elf32_Word shndx;
if (gelf_getsymshndx (symdata, shndxdata, ndx, &sym, &shndx) != NULL
    && sym.st_shndx != SHN_XINDEX)
  shndx = sym.st_shndx;

Cheers,

Mark

Reply via email to