|
Packit |
032894 |
/* Interfaces for libdwelf. DWARF ELF Low-level Functions.
|
|
Packit |
032894 |
Copyright (C) 2014, 2015, 2016, 2018 Red Hat, Inc.
|
|
Packit |
032894 |
This file is part of elfutils.
|
|
Packit |
032894 |
|
|
Packit |
032894 |
This file is free software; you can redistribute it and/or modify
|
|
Packit |
032894 |
it under the terms of either
|
|
Packit |
032894 |
|
|
Packit |
032894 |
* the GNU Lesser General Public License as published by the Free
|
|
Packit |
032894 |
Software Foundation; either version 3 of the License, or (at
|
|
Packit |
032894 |
your option) any later version
|
|
Packit |
032894 |
|
|
Packit |
032894 |
or
|
|
Packit |
032894 |
|
|
Packit |
032894 |
* the GNU General Public License as published by the Free
|
|
Packit |
032894 |
Software Foundation; either version 2 of the License, or (at
|
|
Packit |
032894 |
your option) any later version
|
|
Packit |
032894 |
|
|
Packit |
032894 |
or both in parallel, as here.
|
|
Packit |
032894 |
|
|
Packit |
032894 |
elfutils is distributed in the hope that it will be useful, but
|
|
Packit |
032894 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
032894 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
032894 |
General Public License for more details.
|
|
Packit |
032894 |
|
|
Packit |
032894 |
You should have received copies of the GNU General Public License and
|
|
Packit |
032894 |
the GNU Lesser General Public License along with this program. If
|
|
Packit |
032894 |
not, see <http://www.gnu.org/licenses/>. */
|
|
Packit |
032894 |
|
|
Packit |
032894 |
#ifndef _LIBDWELF_H
|
|
Packit |
032894 |
#define _LIBDWELF_H 1
|
|
Packit |
032894 |
|
|
Packit |
032894 |
#include "libdw.h"
|
|
Packit |
032894 |
|
|
Packit |
032894 |
#ifdef __cplusplus
|
|
Packit |
032894 |
extern "C" {
|
|
Packit |
032894 |
#endif
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* DWARF ELF Low-level Functions (dwelf).
|
|
Packit |
032894 |
Functions starting with dwelf_elf will take a (libelf) Elf object as
|
|
Packit |
032894 |
first argument and might set elf_errno on error. Functions starting
|
|
Packit |
032894 |
with dwelf_dwarf will take a (libdw) Dwarf object as first argument
|
|
Packit |
032894 |
and might set dwarf_errno on error. */
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Returns the name and the CRC32 of the separate debug file from the
|
|
Packit |
032894 |
.gnu_debuglink section if found in the ELF. Return NULL if the ELF
|
|
Packit |
032894 |
file didn't have a .gnu_debuglink section, had malformed data in the
|
|
Packit |
032894 |
section or some other error occured. */
|
|
Packit |
032894 |
extern const char *dwelf_elf_gnu_debuglink (Elf *elf, GElf_Word *crc);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Returns the name and build ID from the .gnu_debugaltlink section if
|
|
Packit |
032894 |
found in the ELF. On success, pointers to the name and build ID
|
|
Packit |
032894 |
are written to *NAMEP and *BUILDID_P, and the positive length of
|
|
Packit |
032894 |
the build ID is returned. Returns 0 if the ELF lacks a
|
|
Packit |
032894 |
.gnu_debugaltlink section. Returns -1 in case of malformed data or
|
|
Packit |
032894 |
other errors. */
|
|
Packit |
032894 |
extern ssize_t dwelf_dwarf_gnu_debugaltlink (Dwarf *dwarf,
|
|
Packit |
032894 |
const char **namep,
|
|
Packit |
032894 |
const void **build_idp);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Returns the build ID as found in a NT_GNU_BUILD_ID note from either
|
|
Packit |
032894 |
a SHT_NOTE section or from a PT_NOTE segment if the ELF file
|
|
Packit |
032894 |
doesn't contain any section headers. On success a pointer to the
|
|
Packit |
032894 |
build ID is written to *BUILDID_P, and the positive length of the
|
|
Packit |
032894 |
build ID is returned. Returns 0 if the ELF lacks a NT_GNU_BUILD_ID
|
|
Packit |
032894 |
note. Returns -1 in case of malformed data or other errors. */
|
|
Packit |
032894 |
extern ssize_t dwelf_elf_gnu_build_id (Elf *elf, const void **build_idp);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Returns the size of the uncompressed data of a GNU compressed
|
|
Packit |
032894 |
section. The section name should start with .zdebug (but this
|
|
Packit |
032894 |
isn't checked by this function). If the section isn't compressed
|
|
Packit |
032894 |
(the section data doesn't start with ZLIB) -1 is returned. If an
|
|
Packit |
032894 |
error occured -1 is returned and elf_errno is set. */
|
|
Packit |
032894 |
extern ssize_t dwelf_scn_gnu_compressed_size (Elf_Scn *scn);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* ELF/DWARF string table handling. */
|
|
Packit |
032894 |
typedef struct Dwelf_Strtab Dwelf_Strtab;
|
|
Packit |
032894 |
typedef struct Dwelf_Strent Dwelf_Strent;
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Create a new ELF/DWARF string table object in memory. ELF string
|
|
Packit |
032894 |
tables have a required zero length null string at offset zero.
|
|
Packit |
032894 |
DWARF string tables don't require such a null entry (unless they
|
|
Packit |
032894 |
are shared with an ELF string table). If NULLSTR is true then a
|
|
Packit |
032894 |
null entry is always created (even if the string table is empty
|
|
Packit |
032894 |
otherwise). */
|
|
Packit |
032894 |
extern Dwelf_Strtab *dwelf_strtab_init (bool nullstr);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Add string STR to string table ST. Returns NULL if no memory could
|
|
Packit |
032894 |
be allocated. The given STR is owned by the called and must be
|
|
Packit |
032894 |
valid till dwelf_strtab_free is called. dwelf_strtab_finalize
|
|
Packit |
032894 |
might copy the string into the final table and dwelf_strent_str
|
|
Packit |
032894 |
might return it, or a reference to an identical copy/substring
|
|
Packit |
032894 |
added to the string table. */
|
|
Packit |
032894 |
extern Dwelf_Strent *dwelf_strtab_add (Dwelf_Strtab *st, const char *str)
|
|
Packit |
032894 |
__nonnull_attribute__ (1, 2);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* This is an optimized version of dwelf_strtab_add if the length of
|
|
Packit |
032894 |
the string is already known. LEN is the length of STR including
|
|
Packit |
032894 |
zero terminator. Calling dwelf_strtab_add (st, str) is similar to
|
|
Packit |
032894 |
calling dwelf_strtab_len (st, str, strlen (str) + 1). */
|
|
Packit |
032894 |
extern Dwelf_Strent *dwelf_strtab_add_len (Dwelf_Strtab *st,
|
|
Packit |
032894 |
const char *str, size_t len)
|
|
Packit |
032894 |
__nonnull_attribute__ (1, 2);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Finalize string table ST and store size and memory location
|
|
Packit |
032894 |
information in DATA d_size and d_buf. DATA d_type will be set to
|
|
Packit |
032894 |
ELF_T_BYTE, d_off will be zero, d_align will be 1 and d_version
|
|
Packit |
032894 |
will be set to EV_CURRENT. If no memory could be allocated NULL is
|
|
Packit |
032894 |
returned and DATA->d_buf will be set to NULL. Otherwise DATA will
|
|
Packit |
032894 |
be returned. */
|
|
Packit |
032894 |
extern Elf_Data *dwelf_strtab_finalize (Dwelf_Strtab *st,
|
|
Packit |
032894 |
Elf_Data *data)
|
|
Packit |
032894 |
__nonnull_attribute__ (1, 2);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Get offset in string table for string associated with entry. Only
|
|
Packit |
032894 |
valid after dwelf_strtab_finalize has been called. */
|
|
Packit |
032894 |
extern size_t dwelf_strent_off (Dwelf_Strent *se)
|
|
Packit |
032894 |
__nonnull_attribute__ (1);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Return the string associated with the entry. */
|
|
Packit |
032894 |
extern const char *dwelf_strent_str (Dwelf_Strent *se)
|
|
Packit |
032894 |
__nonnull_attribute__ (1);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Free resources allocated for the string table. This invalidates
|
|
Packit |
032894 |
any Dwelf_Strent references returned earlier. */
|
|
Packit |
032894 |
extern void dwelf_strtab_free (Dwelf_Strtab *st)
|
|
Packit |
032894 |
__nonnull_attribute__ (1);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Creates a read-only Elf handle from the given file handle. The
|
|
Packit |
032894 |
file may be compressed and/or contain a linux kernel image header,
|
|
Packit |
032894 |
in which case it is eagerly decompressed in full and the Elf handle
|
|
Packit |
032894 |
is created as if created with elf_memory (). On decompression or
|
|
Packit |
032894 |
file errors NULL is returned (and elf_errno will be set). If there
|
|
Packit |
032894 |
was no error, but the file is not an ELF file, then an ELF_K_NONE
|
|
Packit |
032894 |
Elf handle is returned (just like with elf_begin). The Elf handle
|
|
Packit |
032894 |
should be closed with elf_end (). The file handle will not be
|
|
Packit |
032894 |
closed. */
|
|
Packit |
032894 |
extern Elf *dwelf_elf_begin (int fd);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
/* Returns a human readable string for the given ELF header e_machine
|
|
Packit |
032894 |
value, or NULL if the given number isn't currently known. */
|
|
Packit |
032894 |
extern const char *dwelf_elf_e_machine_string (int machine);
|
|
Packit |
032894 |
|
|
Packit |
032894 |
#ifdef __cplusplus
|
|
Packit |
032894 |
}
|
|
Packit |
032894 |
#endif
|
|
Packit |
032894 |
|
|
Packit |
032894 |
#endif /* libdwelf.h */
|