GELF_XLATETOM(3)

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

✨ GELF_XLATETOM(3) ✨

okay bestie, welcome to the Libelf Programmer's Manual, page GELF_XLATETOM(3). this is the one where we translate ELF data back and forth between file brain and memory brain. no cap, it's giving "glow-up but for bytes" πŸ’…


🌸 NAME 🌸

gelf_xlatetom β€” translate class-independent ELF data from file representation to memory representation, bestie πŸ’–

gelf_xlatetof β€” translate class-independent ELF data from memory representation to file representation, fr fr πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

#include <gelf.h>

Elf_Data gelf_xlatetom (Elf *elf, Elf_Data *dest, const Elf_Data *src, unsigned int encode);
Elf_Data gelf_xlatetof (Elf *elf, Elf_Data *dest, const Elf_Data *src, unsigned int encode);

πŸ’œ DESCRIPTION πŸ’œ

so basically, these two icons translate ELF data from file representation to memory representation, or the other way around. file and memory representations of ELF data can differ in terms of endianness β€” that's the whole plot twist, iykyk.

gelf_xlatetom() is lowkey just a wrapper around elf32_xlatetom() and elf64_xlatetom(). and gelf_xlatetof() is a wrapper around elf32_xlatetof() and elf64_xlatetof(). the binary class (ELFCLASS32 or ELFCLASS64) of elf is what decides β€” automatically β€” which of the elf32 or elf64 version of each function gets picked. main character auto-selection behavior, honestly πŸ‘‘

data in file representation normally comes from elf_rawdata, while data in memory representation normally comes from elf_getdata. and here's the cute part: when there is no difference between file and memory representations, these functions simply copy the ELF data from src to dest. periodt.

otherwise, the encoding will swap between ELFDATA2LSB (two's complement little-endian) and ELFDATA2MSB (two's complement big-endian). the encoding of an ELF file is specified in the Elf32_Ehdr or Elf64_Ehdr e_ident[EI_DATA] member. πŸ’«

and if you wanna know the memory encoding for a program? you can #include <endian.h> and check BYTE_ORDER == LITTLE_ENDIAN (which corresponds to ELFDATA2LSB) or BYTE_ORDER == BIG_ENDIAN (which corresponds to ELFDATA2MSB). see, told you, useful stuff 🫢


🌈 PARAMETERS 🌈

  • elf β€” the ELF descriptor that determines the binary class (ELFCLASS32 or ELFCLASS64) used to translate between file and memory representation. it's the vibe-setter of the whole operation 🧚
  • dest β€” the destination where the translated data will be stored. the d_size of dest should be at least as big as the d_size of src. don't skimp on the destination, bestie, it will not end well 😭
  • src β€” source data. for the xlatetom functions, the source data should be in file representation. for the xlatetof functions, the source data should be in memory representation. match the function to the format, okay? πŸ‘€
  • encode β€” specifies an encoding. can be either ELFDATA2LSB (two's complement little-endian) or ELFDATA2MSB (two's complement big-endian). for the xlatetom functions, this specifies the encoding of src. for the xlatetof functions, this specifies the encoding of dest. so yeah, it means different things depending on which one you called. read twice, call once πŸ’…

⭐ RETURN VALUE ⭐

on success, these return dest, which will contain the translated data. and if there is no difference between the file and memory representations, dest will contain a copy of the source data. the d_type and d_size of dest will be set to those of src. slay, consistent.

on failure, they return NULL and set elf_errno.

careful, bestie: if elf, src or dest is NULL, then NULL is returned without setting elf_errno. so if you're out here checking elf_errno for a NULL-argument situation, you're gonna have a bad time. πŸ’€

πŸ”₯ SEE ALSO πŸ”₯

the whole friend group, right there 🫢✨


πŸ’… ATTRIBUTES πŸ’…

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

translation: it's thread-safe, so you can bring all your threads to the party. πŸŽ€


πŸ› REPORTING BUGS πŸ›

found a bug? not the vibe. report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/. they wanna hear about it, fr fr πŸ™ˆ


and that's the page, bestie. brought to you by the Libelf crew, dated 2025-12-28, filed under GELF_XLATETOM(3). go translate something iconic πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from