ELF32_XLATETOM(3)

📦
version 0.197 · 3 versions
  • 0.197 · alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 14.5 · freebsd 14.5
  • 15.1 · freebsd 15.1, nixpkgs unstable
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

💖 ELF32_XLATETOM 💖

okay bestie, welcome to the libelf programmer's manual, page ELF32_XLATETOM(3) — yes it's giving "why is the title in all caps" energy but that's just how manpages are, we don't question it 🎀


✨ NAME ✨

elf32_xlatetom, elf64_xlatetom — translate 32-bit or 64-bit ELF data from file representation to memory representation 🦋

elf32_xlatetof, elf64_xlatetof — translate 32-bit or 64-bit ELF data from memory representation to file representation 🌸


✨ SYNOPSIS ✨

#include <libelf.h>

int elf32_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding);
int elf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding);

int elf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding);
int elf64_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding);

✨ DESCRIPTION ✨

So basically 💅 these functions translate ELF data from file representation to memory representation, or the other way around. Flip it, reverse it, we love a two-way street.

File and memory representations of ELF data can differ in terms of endianness — yeah, the whole "which byte comes first" drama. Data in file representation normally comes from elf_rawdata, while data in memory representation normally comes from elf_getdata. iykyk 🔥

When there is no difference between file and memory representations, these functions simply copy the ELF data from src to dst. No thoughts, just vibes, just a copy. 🫶

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 to know the memory encoding for a program you can #include <endian.h> and check BYTE_ORDER == LITTLE_ENDIAN (corresponding to ELFDATA2LSB) or BYTE_ORDER == BIG_ENDIAN (corresponding to ELFDATA2MSB). Iconic little preprocessor moment, honestly. 👑


✨ PARAMETERS ✨

  • dst — Destination where the translated data will be stored. The d_size of dst should be at least as big as the d_size of src. like bestie, give it room to breathe 😭
  • 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. read the room, know your direction 💫
  • encoding — 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 dst. yes the direction matters, this is not a drill 🎀

✨ RETURN VALUE ✨

On success, return dst, which will contain the translated data. If there is no difference between the file and memory representations, dst will contain a copy of the source data. The d_type and d_size of dst will be set to those of src. slay, it literally hands you the thing you asked for ✨

If an error occurs, return NULL and set a libelf error code. 💀


✨ SEE ALSO ✨

the friend group 🫶 go read them, they're all part of the same cinematic universe 🌈


✨ ATTRIBUTES ✨

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

  • Interface: elf32_xlatetom(), elf64_xlatetom(), elf32_xlatetof(), elf64_xlatetof()
  • Attribute: Thread safety
  • Value: MT-Safe
translation girlies stay MT-Safe, periodt. no cap. 💅

✨ REPORTING BUGS ✨

Report bugs to <elfutils-devel@sourceware.org> or https://sourceware.org/bugzilla/.

not me asking you to file a bug report but like... if it's broken, tell the devs, they wanna know 💜


and that's the whole page, bestie!! this was page ELF32_XLATETOM(3) from the Libelf Programmer's Manual, dated 2024-08-14 — mwah, go translate something, you're doing amazing sweetie 🧚✨

📦 where this page comes from