Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:01

0001 /* Interfaces for libdwelf. DWARF ELF Low-level Functions.
0002    Copyright (C) 2014, 2015, 2016, 2018 Red Hat, Inc.
0003    This file is part of elfutils.
0004 
0005    This file is free software; you can redistribute it and/or modify
0006    it under the terms of either
0007 
0008      * the GNU Lesser General Public License as published by the Free
0009        Software Foundation; either version 3 of the License, or (at
0010        your option) any later version
0011 
0012    or
0013 
0014      * the GNU General Public License as published by the Free
0015        Software Foundation; either version 2 of the License, or (at
0016        your option) any later version
0017 
0018    or both in parallel, as here.
0019 
0020    elfutils is distributed in the hope that it will be useful, but
0021    WITHOUT ANY WARRANTY; without even the implied warranty of
0022    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0023    General Public License for more details.
0024 
0025    You should have received copies of the GNU General Public License and
0026    the GNU Lesser General Public License along with this program.  If
0027    not, see <http://www.gnu.org/licenses/>.  */
0028 
0029 #ifndef _LIBDWELF_H
0030 #define _LIBDWELF_H 1
0031 
0032 #include "libdw.h"
0033 
0034 #ifdef __cplusplus
0035 extern "C" {
0036 #endif
0037 
0038 /* DWARF ELF Low-level Functions (dwelf).
0039    Functions starting with dwelf_elf will take a (libelf) Elf object as
0040    first argument and might set elf_errno on error.  Functions starting
0041    with dwelf_dwarf will take a (libdw) Dwarf object as first argument
0042    and might set dwarf_errno on error.  */
0043 
0044 /* Returns the name and the CRC32 of the separate debug file from the
0045    .gnu_debuglink section if found in the ELF.  Return NULL if the ELF
0046    file didn't have a .gnu_debuglink section, had malformed data in the
0047    section or some other error occurred.  */
0048 extern const char *dwelf_elf_gnu_debuglink (Elf *elf, GElf_Word *crc);
0049 
0050 /* Returns the name and build ID from the .gnu_debugaltlink section if
0051    found in the ELF.  On success, pointers to the name and build ID
0052    are written to *NAMEP and *BUILDID_P, and the positive length of
0053    the build ID is returned.  Returns 0 if the ELF lacks a
0054    .gnu_debugaltlink section.  Returns -1 in case of malformed data or
0055    other errors.  */
0056 extern ssize_t dwelf_dwarf_gnu_debugaltlink (Dwarf *dwarf,
0057                          const char **namep,
0058                          const void **build_idp);
0059 
0060 /* Returns the build ID as found in a NT_GNU_BUILD_ID note from either
0061    a SHT_NOTE section or from a PT_NOTE segment if the ELF file
0062    doesn't contain any section headers.  On success a pointer to the
0063    build ID is written to *BUILDID_P, and the positive length of the
0064    build ID is returned.  Returns 0 if the ELF lacks a NT_GNU_BUILD_ID
0065    note.  Returns -1 in case of malformed data or other errors.  */
0066 extern ssize_t dwelf_elf_gnu_build_id (Elf *elf, const void **build_idp);
0067 
0068 /* Returns the size of the uncompressed data of a GNU compressed
0069    section.  The section name should start with .zdebug (but this
0070    isn't checked by this function).  If the section isn't compressed
0071    (the section data doesn't start with ZLIB) -1 is returned. If an
0072    error occurred -1 is returned and elf_errno is set.  */
0073 extern ssize_t dwelf_scn_gnu_compressed_size (Elf_Scn *scn);
0074 
0075 /* ELF/DWARF string table handling.  */
0076 typedef struct Dwelf_Strtab Dwelf_Strtab;
0077 typedef struct Dwelf_Strent Dwelf_Strent;
0078 
0079 /* Create a new ELF/DWARF string table object in memory.  ELF string
0080    tables have a required zero length null string at offset zero.
0081    DWARF string tables don't require such a null entry (unless they
0082    are shared with an ELF string table).  If NULLSTR is true then a
0083    null entry is always created (even if the string table is empty
0084    otherwise).  */
0085 extern Dwelf_Strtab *dwelf_strtab_init (bool nullstr);
0086 
0087 /* Add string STR to string table ST.  Returns NULL if no memory could
0088    be allocated.  The given STR is owned by the called and must be
0089    valid till dwelf_strtab_free is called.  dwelf_strtab_finalize
0090    might copy the string into the final table and dwelf_strent_str
0091    might return it, or a reference to an identical copy/substring
0092    added to the string table.  */
0093 extern Dwelf_Strent *dwelf_strtab_add (Dwelf_Strtab *st, const char *str)
0094   __nonnull_attribute__ (1, 2);
0095 
0096 /* This is an optimized version of dwelf_strtab_add if the length of
0097    the string is already known.  LEN is the length of STR including
0098    zero terminator.  Calling dwelf_strtab_add (st, str) is similar to
0099    calling dwelf_strtab_len (st, str, strlen (str) + 1).  */
0100 extern Dwelf_Strent *dwelf_strtab_add_len (Dwelf_Strtab *st,
0101                        const char *str, size_t len)
0102   __nonnull_attribute__ (1, 2);
0103 
0104 /* Finalize string table ST and store size and memory location
0105    information in DATA d_size and d_buf.  DATA d_type will be set to
0106    ELF_T_BYTE, d_off will be zero, d_align will be 1 and d_version
0107    will be set to EV_CURRENT.  If no memory could be allocated NULL is
0108    returned and DATA->d_buf will be set to NULL.  Otherwise DATA will
0109    be returned.  */
0110 extern Elf_Data *dwelf_strtab_finalize (Dwelf_Strtab *st,
0111                     Elf_Data *data)
0112   __nonnull_attribute__ (1, 2);
0113 
0114 /* Get offset in string table for string associated with entry.  Only
0115    valid after dwelf_strtab_finalize has been called.  */
0116 extern size_t dwelf_strent_off (Dwelf_Strent *se)
0117   __nonnull_attribute__ (1);
0118 
0119 /* Return the string associated with the entry.  */
0120 extern const char *dwelf_strent_str (Dwelf_Strent *se)
0121   __nonnull_attribute__ (1);
0122 
0123 /* Free resources allocated for the string table.  This invalidates
0124    any Dwelf_Strent references returned earlier. */
0125 extern void dwelf_strtab_free (Dwelf_Strtab *st)
0126   __nonnull_attribute__ (1);
0127 
0128 /* Creates a read-only Elf handle from the given file handle.  The
0129    file may be compressed and/or contain a linux kernel image header,
0130    in which case it is eagerly decompressed in full and the Elf handle
0131    is created as if created with elf_memory ().  On decompression or
0132    file errors NULL is returned (and elf_errno will be set).  If there
0133    was no error, but the file is not an ELF file, then an ELF_K_NONE
0134    Elf handle is returned (just like with elf_begin).  The Elf handle
0135    should be closed with elf_end ().  The file handle will not be
0136    closed.  */
0137 extern Elf *dwelf_elf_begin (int fd);
0138 
0139 /* Returns a human readable string for the given ELF header e_machine
0140    value, or NULL if the given number isn't currently known.  */
0141 extern const char *dwelf_elf_e_machine_string (int machine);
0142 
0143 #ifdef __cplusplus
0144 }
0145 #endif
0146 
0147 #endif  /* libdwelf.h */