ELF_GETBASE(3)

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

πŸ’– NAME πŸ’–

elf_getbase β€” bestie, this is the lil' function that tells you the base offset of an ELF object file. That's it. That's the whole job. She's simple, she's reliable, she's giving minimal effort, maximum impact ✨


🌸 SYNOPSIS 🌸

#include <libelf.h>

int64_t elf_getbase(Elf *elf);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: you hand elf_getbase an ELF descriptor β€” we're calling her elf β€” and she hands you back the file offset of the very first byte of that descriptor. Like, the actual "she starts right here" coordinate in the file. πŸ“

Now here's the plot twist πŸ‘€ β€” if elf is a member of an archive, meaning its ELF kind is ELF_K_AR, then the base offset she gives you is the offset of the ELF object within the archive. So it's the position of the member inside the big archive container, not some absolute file position, iykyk.

And for every other ELF object type? The base offset is just 0. Simple. Clean. No drama. πŸ’…


πŸŽ€ PARAMETERS πŸŽ€

  • elf β€” the ELF descriptor. That's the one and only thing you're passing in here, bestie. Just the descriptor. 🫢

✨ RETURN VALUE ✨

So what do you actually get back? Here's the vibe check:

  • If elf's ELF kind is ELF_K_AR, you get the base offset of elf. πŸŽ‰
  • Otherwise, you get 0.
  • And if elf is NULL? You get -1. Yeah. She said no. πŸ™ˆ

πŸ’œ SEE ALSO πŸ’œ

go read those too, they're all part of the same friend group fr fr 🧚


πŸ‘‘ ATTRIBUTES πŸ‘‘

For an explanation of the terms used in this section, see attributes(7).

  • elf_getbase() β€” Thread safety: MT-Safe 🌈

πŸ’€ REPORTING BUGS πŸ’€

Found a bug? Not the vibe, but okay, spill πŸ“ β€” report it to <elfutils-devel@sourceware.org> or hit up https://sourceware.org/bugzilla/.


okay that's the whole page, you ate that, periodt πŸ’…βœ¨ this was Libelf, dated 2025-03-31, and you were reading ELF_GETBASE(3) β€” go forth and compute those offsets, bestie 🫢🌸

πŸ“¦ where this page comes from