---
name: "elf64_xlatetom"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/elf32_xlatetof"
---

# elf64\_xlatetom(3)

translate data between files and memory

Part of [elf32\_xlatetof(3)](/elf32_xlatetof/3.md).

## NAME

**elf32\_xlatetof**, **elf32\_xlatetom**, **elf64\_xlatetof**, **elf64\_xlatetom**, **gelf\_xlatetof**, **gelf\_xlatetom** – translate data between files and memory

## LIBRARY

library “libelf”

## SYNOPSIS

**#include \<libelf.h\>**

*Elf\_Data \**\

**elf32\_xlatetof**(*Elf\_Data \*dst*, *Elf\_Data \*src*, *unsigned int file\_encoding*);

*Elf\_Data \**\

**elf32\_xlatetom**(*Elf\_Data \*dst*, *Elf\_Data \*src*, *unsigned int file\_encoding*);

*Elf\_Data \**\

**elf64\_xlatetof**(*Elf\_Data \*dst*, *Elf\_Data \*src*, *unsigned int file\_encoding*);

*Elf\_Data \**\

**elf64\_xlatetom**(*Elf\_Data \*dst*, *Elf\_Data \*src*, *unsigned int file\_encoding*);

**#include \<gelf.h\>**

*Elf\_Data \**\

**gelf\_xlatetof**(*Elf \*elf*, *Elf\_Data \*dst*, *Elf\_Data \*src*, *unsigned int file\_encoding*);

*Elf\_Data \**\

**gelf\_xlatetom**(*Elf \*elf*, *Elf\_Data \*dst*, *Elf\_Data \*src*, *unsigned int file\_encoding*);

## DESCRIPTION

These functions translate between the file and memory representations of ELF data structures. The in-memory representation of an ELF data structure would conform to the byte ordering and data alignment restrictions dictated by the host processor. As described in [elf(3)](/elf/3.md), the file representation of this data structure could use a different byte ordering from that of the host, or could use a different layout within the file.

Functions **elf32\_xlatetom**(), **elf64\_xlatetom**(), and **gelf\_xlatetom**() translate data from file representations to native, in-memory representations. Functions **elf32\_xlatetof**(), **elf64\_xlatetof**(), and **gelf\_xlatetof**() translate data from in-memory representations to file representations.

Argument *src* denotes an *Elf\_Data* descriptor describing the source to be translated. The following elements of the descriptor need to be set before invoking these functions:

- *d\_buf*

  Set to a valid pointer value denoting the beginning of the data area to be translated.

- *d\_size*

  Set to the total size in bytes of the source data area to be translated.

- *d\_type*

  Set to the type of the source data being translated. This value is one of the values defined in the *Elf\_Type* enumeration. The *Elf\_Type* enumeration is described in [elf(3)](/elf/3.md).

- *d\_version*

  Set to the version number of the ELF data structures being translated. Currently only version EV\_CURRENT is supported.

Argument *dst* describes the destination buffer. The following elements of the *Elf\_Data* descriptor need to be set before invoking these functions:

- *d\_buf*

  Set to a valid pointer value that denotes the start of the destination buffer that will hold translated data. This value may be the same as that of the source buffer, in which case an in-place conversion will be attempted.

- *d\_size*

  Set to the size of the destination buffer in bytes. This value will be modified if the function call succeeds.

- *d\_version*

  Set to the desired version number of the destination. Currently only version EV\_CURRENT is supported.

These translations routines allow the source and destination buffers to coincide, in which case an in-place translation will be done if the destination is large enough to hold the translated data. Other kinds of overlap between the source and destination buffers are not permitted.

On successful completion of the translation request the following fields of the *dst* descriptor would be modified:

- *d\_size*

  Set to the size in bytes of the translated data.

- *d\_type*

  Set to the *d\_type* value of the source data descriptor.

Argument *file\_encoding* specifies the encoding in which the file objects are represented. It must be one of:

- ELFDATANONE

  File objects use the library's native byte ordering.

- ELFDATA2LSB

  File objects use a little-endian ordering.

- ELFDATA2MSB

  File objects use a big-endian ordering.

The functions **gelf\_xlatetof**() and **gelf\_xlatetom**() select the appropriate translation scheme based on the properties of argument *elf*.

## RETURN VALUES

These functions return argument *dst* if successful, or NULL in case of an error.

## EXAMPLES

To translate a *GElf\_Rel* structure to its LSB file representation use:

```
Elf_Data dst, src;
GElf_Rel rel;
Elf *e;
e = ...; /* See elf_begin(3). */
/* Set up the 'src' descriptor. */
memset(&src, 0, sizeof src);
src.d_buf = &rel;
src.d_size = sizeof(rel);
src.d_type = ELF_T_REL;
src.d_version = EV_CURRENT;
/* Set up the 'dst' descriptor. */
memset(&dst, 0, sizeof dst);
dst.d_buf = filebuf;
dst.d_size = gelf_fsize(e, ELF_T_REL, 1, EV_CURRENT);
dst.d_version = EV_CURRENT;
if (gelf_xlatetof(e, &dst, &src, ELFDATA2LSB) == NULL) {
	printf("error: %s", elf_errmsg(0));
}
```

## ERRORS

These functions may fail with the following errors:

- \[ELF\_E\_ARGUMENT\]

  One of arguments *src*, *dst* or *elf* was NULL.

- \[ELF\_E\_ARGUMENT\]

  Arguments *src* and *dst* were equal.

- \[ELF\_E\_ARGUMENT\]

  The desired encoding parameter was not one of ELFDATANONE, ELFDATA2LSB or ELFDATA2MSB.

- \[ELF\_E\_ARGUMENT\]

  The *d\_type* field of argument *src* specified an unsupported type.

- \[ELF\_E\_DATA\]

  The *src* argument specified a buffer size that was not an integral multiple of its underlying type.

- \[ELF\_E\_DATA\]

  The *dst* argument specified a buffer size that was too small.

- \[ELF\_E\_DATA\]

  Argument *dst* specified a destination buffer that overlaps with the source buffer.

- \[ELF\_E\_DATA\]

  The destination buffer for a conversion to memory had an alignment inappropriate for the underlying ELF type.

- \[ELF\_E\_DATA\]

  The source buffer for a conversion to file had an alignment inappropriate for the underlying ELF type.

- \[ELF\_E\_UNIMPL\]

  The version numbers for arguments *dst* and *src* were not identical.

- \[ELF\_E\_UNIMPL\]

  The argument *src* requested conversion for a type which is not currently supported.

- \[ELF\_E\_VERSION\]

  Argument *src* specified an unsupported version number.

## SEE ALSO

[elf(3)](/elf/3.md), [elf\_getdata(3)](/elf_getdata/3.md), [gelf(3)](/gelf/3.md)
