Scroll to navigation

GELF_GETNOTE(3) Libelf Programmer's Manual GELF_GETNOTE(3)

NAME

gelf_getnote - Get class-independent note information at the supplied offset

SYNOPSIS

#include <gelf.h>
size_t gelf_getnote (Elf_Data *data, size_t offset, GElf_Nhdr *result, size_t *name_offset, size_t *desc_offset);

DESCRIPTION

Retrieve the ELF note header from data at offset offset and store it in a class-independent representation pointed to by result. The note name and note descriptor offsets relative to the start of data are stored in *name_offset and *desc_offset, respectively. GElf_Nhdr fields n_namesz, n_descsz, and n_type describe the note's name length, descriptor length and type, respectively. Alignment and padding of the note data entry are handled automatically by this function. See elf(5) for more information regarding ELF notes.

PARAMETERS

Pointer to an Elf_Data associated with a SHT_NOTE section or a PT_NOTE segment. data->d_type should be ELF_T_NHDR or ELF_T_NHDR8.

Offset of a note header within data.

Pointer to a caller-provided GElf_Nhdr structure for storing the requested note header. result must not be NULL.

Pointer to a caller-provided size_t for storing the name offset of the requested note. This offset is relative to data->d_buf. name_offset must not be NULL.

Pointer to a caller-provided size_t for storing the descriptor offset of the requested note. This offset is relative to data->d_buf. desc_offset must not be NULL.

RETURN VALUE

On success, this function updates *result, *name_offset, and *desc_offset and returns the offset of the next note. If there are no notes remaining then the return value will be greater than or equal to the d_size of data. On failure, this function returns zero and sets elf_errno. If data is NULL then zero is returned without setting elf_errno.

EXAMPLE


size_t offset = 0;
GElf_Nhdr nhdr;
size_t name_offset;
size_t desc_offset;
while (offset < data->d_size
&& (offset = gelf_getnote (data, offset,
&nhdr, &name_offset, &desc_offset)) > 0)
{
const char *name = nhdr.n_namesz == 0 ? "" : data->d_buf + name_offset;
const char *desc = nhdr.n_descsz == 0 ? "" : data->d_buf + desc_offset;
/* Process note here. name and desc are not guaranteed to be
zero-terminated. The presence of null characters should be
verified using n_namesz and n_descsz. */
[...]
}

SEE ALSO

libelf(3), elf(5)

ATTRIBUTES

Interface Attribute Value
gelf_getnote () Thread safety MT-Safe

REPORTING BUGS

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

HISTORY

gelf_getnote first appeared in elfutils 0.130. This function is an elfutils libelf extension and may not be available in other libelf implementations.

2025-12-31 Libelf