GELF_XLATETOM(3)
β¨ 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 (
ELFCLASS32orELFCLASS64) 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_sizeof dest should be at least as big as thed_sizeof src. don't skimp on the destination, bestie, it will not end well π - src β source data. for the
xlatetomfunctions, the source data should be in file representation. for thexlatetoffunctions, 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) orELFDATA2MSB(two's complement big-endian). for thexlatetomfunctions, this specifies the encoding of src. for thexlatetoffunctions, 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 isNULL, thenNULLis returned without settingelf_errno. so if you're out here checkingelf_errnofor a NULL-argument situation, you're gonna have a bad time. π
π₯ SEE ALSO π₯
elf32_xlatetof(3)elf32_xlatetom(3)elf64_xlatetof(3)elf64_xlatetom(3)elf_getdata(3)elf_rawdata(3)libelf(3)elf(5)
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
- alpine 3.24: elfutils-doc 0.195-r0 Β· GPL-3.0-or-later AND ( GPL-2.0-or-later OR LGPL-3.0-or-later )
- arch rolling: libelf 0.196-1
- arch rolling: libelf 0.197-1 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 10: elfutils-libelf-devel 0.197-1.el10 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 9: elfutils-libelf-devel 0.197-1.el9 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- centos-stream 9: elfutils-libelf-devel 0.197-1.el9 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.196-1.fc43
- fedora 43: elfutils-libelf-devel 0.196-1.fc43
- fedora 43: elfutils-libelf-devel 0.197-1.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 43: elfutils-libelf-devel 0.197-1.fc43 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.196-1.fc44
- fedora 44: elfutils-libelf-devel 0.196-1.fc44
- fedora 44: elfutils-libelf-devel 0.197-1.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- fedora 44: elfutils-libelf-devel 0.197-1.fc44 Β· GPL-2.0-or-later OR LGPL-3.0-or-later
- nixpkgs unstable: elfutils 0.195
- ubuntu stonking: libelf-dev 0.196-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms