GELF_UPDATE_SYMSHNDX(3)

πŸ“¦
version 0.197 Β· 2 versions
, in alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixpkgs unstable, ubuntu stonking

πŸ’– GELF_UPDATE_SYMSHNDX πŸ’–

okay bestie, so this one lives in the Libelf Programmer's Manual, and it's GELF_UPDATE_SYMSHNDX(3) β€” say that three times fast, I dare you 🫢


✨ NAME ✨

gelf_update_symshndx β€” update class-independent symbol information and extended section index in the symbol table πŸ’…


🌸 SYNOPSIS 🌸

#include <gelf.h>

int gelf_update_symshndx (Elf_Data *symdata, Elf_Data *shndxdata, int ndx, GElf_Sym *sym, Elf32_Word xshndx);

πŸ¦‹ DESCRIPTION πŸ¦‹

So what this cutie does: it updates symdata and shndxdata, at index ndx, with the class-independent symbol info from sym plus the section index xshndx. Two-for-one deal, we love to see it πŸ’–

Real talk on the requirements though β€” symdata needs to be an Elf_Data pointer for an SHT_SYMTAB or SHT_DYNSYM section, and shndxdata needs to be an Elf_Data pointer for an SHT_SYMTAB_SHNDX section. No mixing and matching, okay? πŸ‘‘

Wanna know how many symbols are in your symbol table? Divide the size of symdata by the size of a symbol table entry, easy peasy πŸ“ And where do you get those numbers?

  • The size of symdata comes from symdata->d_size, or from the corresponding section header's sh_size.
  • The size of a symbol table entry comes from gelf_fsize() with ELF_T_SYM, or from the corresponding section header's sh_entsize.

Now here's the lore, iykyk: an SHT_SYMTAB_SHNDX section shows up in ELF binaries when there are too many sections to fit in an unsigned 16-bit value 😭 When that happens, the st_shndx field of a GElf_Sym gets set to SHN_XINDEX to flag that the symbol's section index is actually chillin' over in the SHT_SYMTAB_SHNDX section. You can grab shndxdata for that section using elf_scnshndx(3), elf_getscn(3), and elf_getdata(3) β€” the holy trinity ✨

Important, no cap: the number of entries in shndxdata must be equal to the number of entries in symdata. And entry ndx in shndxdata corresponds to entry ndx in symdata. They're matching, periodt πŸ’…

πŸŽ€ PARAMETERS πŸŽ€

  • symdata β€” Pointer to Elf_Data for a section with type SHT_SYMTAB or SHT_DYNSYM. 🌈
  • shndxdata β€” Pointer to Elf_Data for a section with type SHT_SYMTAB_SHNDX. shndxdata may be NULL. And if shndxdata is NULL, then xshndx must be zero. Rules are rules, bestie πŸ™ˆ
  • ndx β€” Zero-based index of the symbol table entry and the extended section index entry that's getting updated. Zero-based, so the first one is 0, not 1 β€” don't come for me πŸ’€
  • sym β€” Pointer to a caller-provided symbol table entry. For ELFCLASS32 binaries, st_value and st_size should be able to fit within unsigned 32-bit values. Also, sym must not be NULL. Like, ever. 🚫
  • xshndx β€” The updated extended section index entry to be associated with sym. Must be zero if shndxdata is NULL. And if sym->st_shndx is not SHN_XINDEX, then xshndx should be SHN_UNDEF. Keep that straight, k? πŸ’œ

πŸ‘‘ RETURN VALUE πŸ‘‘

On success? You get a non-zero value back, and the entries at index ndx in symdata and shndxdata (if it's not NULL) get updated with sym and xshndx, respectively πŸŽ‰ The sections associated with symdata and shndxdata also get flagged with ELF_F_DIRTY.

On failure? Zero comes back, and elf_errno is set. Sad girl hours 😭

Weird little plot twist: if sym is NULL, then NULL is returned without setting elf_errno. Not a typo, that's just how it is πŸ’€

🌟 SEE ALSO 🌟

elf_getdata(3), elf_getscn(3), elf_scnshndx(3), gelf_fsize(3), gelf_getsymshndx(3), gelf_update_sym(3), libelf(3), elf(5)

Go read those too, they're all part of the same friend group 🫢


πŸ’… ATTRIBUTES πŸ’…

  • Interface: gelf_update_symshndx()
  • Attribute: Thread safety
  • Value: MT-Safe

Yup, she's MT-Safe β€” thread safe and unbothered, main character energy fr fr ✨


πŸ“’ REPORTING BUGS πŸ“’

Found a bug? Report it to <elfutils-devel@sourceware.org> or hit up https://sourceware.org/bugzilla/ β€” they wanna hear about it, promise πŸ›


okay that's the whole page, you're literally a libelf girlie now, I'm so proud πŸ˜­πŸ’–

this was Libelf, dated 2025-12-30, and yes it's still GELF_UPDATE_SYMSHNDX(3) β€” slay, bye bestie! πŸ‘‘πŸŒΈ

πŸ“¦ where this page comes from