Blame libebl/libebl.h

Packit 032894
/* Interface for libebl.
Packit 032894
   Copyright (C) 2000-2010, 2013, 2014, 2015, 2016, 2017 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
Packit 032894
/* This is the interface for the Elfutils Backend Library.
Packit 032894
   It is a completely UNSUPPORTED interface.  Don't use any libebl
Packit 032894
   function directly.  These are only for internal elfutils backends
Packit 032894
   and tools.  There is NO source or binary compatible guarantee.  */
Packit 032894
Packit 032894
Packit 032894
#ifndef _LIBEBL_H
Packit 032894
#define _LIBEBL_H 1
Packit 032894
Packit 032894
#include <gelf.h>
Packit 032894
#include "libdw.h"
Packit 032894
#include <stdbool.h>
Packit 032894
#include <stddef.h>
Packit 032894
#include <stdint.h>
Packit 032894
Packit 032894
#include "elf-knowledge.h"
Packit 032894
Packit 032894
Packit 032894
/* Opaque type for the handle.  */
Packit 032894
typedef struct ebl Ebl;
Packit 032894
Packit 032894
Packit 032894
#ifdef __cplusplus
Packit 032894
extern "C" {
Packit 032894
#endif
Packit 032894
Packit 032894
/* Get backend handle for object associated with ELF handle.  */
Packit 032894
extern Ebl *ebl_openbackend (Elf *elf);
Packit 032894
/* Similar but without underlying ELF file.  */
Packit 032894
extern Ebl *ebl_openbackend_machine (GElf_Half machine);
Packit 032894
/* Similar but with emulation name given.  */
Packit 032894
extern Ebl *ebl_openbackend_emulation (const char *emulation);
Packit 032894
Packit 032894
/* Free resources allocated for backend handle.  */
Packit 032894
extern void ebl_closebackend (Ebl *bh);
Packit 032894
Packit 032894
Packit 032894
/* Information about the descriptor.  */
Packit 032894
Packit 032894
/* Get ELF machine.  */
Packit 032894
extern int ebl_get_elfmachine (Ebl *ebl) __pure_attribute__;
Packit 032894
Packit 032894
/* Get ELF class.  */
Packit 032894
extern int ebl_get_elfclass (Ebl *ebl) __pure_attribute__;
Packit 032894
Packit 032894
/* Get ELF data encoding.  */
Packit 032894
extern int ebl_get_elfdata (Ebl *ebl) __pure_attribute__;
Packit 032894
Packit 032894
Packit 032894
/* Function to call the callback functions including default ELF
Packit 032894
   handling.  */
Packit 032894
Packit 032894
/* Return backend name.  */
Packit 032894
extern const char *ebl_backend_name (Ebl *ebl);
Packit 032894
Packit 032894
/* Return relocation type name.  */
Packit 032894
extern const char *ebl_reloc_type_name (Ebl *ebl, int reloc,
Packit 032894
					char *buf, size_t len);
Packit 032894
Packit 032894
/* Check relocation type.  */
Packit 032894
extern bool ebl_reloc_type_check (Ebl *ebl, int reloc);
Packit 032894
Packit 032894
/* Check relocation type use.  */
Packit 032894
extern bool ebl_reloc_valid_use (Ebl *ebl, int reloc);
Packit 032894
Packit 032894
/* Check if relocation type is for simple absolute relocations.
Packit 032894
   Return ELF_T_{BYTE,HALF,SWORD,SXWORD} for a simple type, else ELF_T_NUM.
Packit 032894
   If the relocation type is an ADD or SUB relocation, set *ADDSUB to 1 or -1,
Packit 032894
   resp.  */
Packit 032894
extern Elf_Type ebl_reloc_simple_type (Ebl *ebl, int reloc, int *addsub);
Packit 032894
Packit 032894
/* Return true if the symbol type is that referencing the GOT.  E.g.,
Packit 032894
   R_386_GOTPC.  */
Packit 032894
extern bool ebl_gotpc_reloc_check (Ebl *ebl, int reloc);
Packit 032894
Packit 032894
/* Return segment type name.  */
Packit 032894
extern const char *ebl_segment_type_name (Ebl *ebl, int segment,
Packit 032894
					  char *buf, size_t len);
Packit 032894
Packit 032894
/* Return section type name.  */
Packit 032894
extern const char *ebl_section_type_name (Ebl *ebl, int section,
Packit 032894
					  char *buf, size_t len);
Packit 032894
Packit 032894
/* Return section name.  */
Packit 032894
extern const char *ebl_section_name (Ebl *ebl, int section, int xsection,
Packit 032894
				     char *buf, size_t len,
Packit 032894
				     const char *scnnames[], size_t shnum);
Packit 032894
Packit 032894
/* Return machine flag names.  */
Packit 032894
extern const char *ebl_machine_flag_name (Ebl *ebl, GElf_Word flags,
Packit 032894
					  char *buf, size_t len);
Packit 032894
Packit 032894
/* Check whether machine flag is valid.  */
Packit 032894
extern bool ebl_machine_flag_check (Ebl *ebl, GElf_Word flags);
Packit 032894
Packit 032894
/* Check whether SHF_MASKPROC flags are valid.  */
Packit 032894
extern bool ebl_machine_section_flag_check (Ebl *ebl, GElf_Xword flags);
Packit 032894
Packit 032894
/* Check whether the section with the given index, header, and name
Packit 032894
   is a special machine section that is valid despite a combination
Packit 032894
   of flags or other details that are not generically valid.  */
Packit 032894
extern bool ebl_check_special_section (Ebl *ebl, int ndx,
Packit 032894
				       const GElf_Shdr *shdr, const char *name);
Packit 032894
Packit 032894
/* Return symbol type name.  */
Packit 032894
extern const char *ebl_symbol_type_name (Ebl *ebl, int symbol,
Packit 032894
					 char *buf, size_t len);
Packit 032894
Packit 032894
/* Return symbol binding name.  */
Packit 032894
extern const char *ebl_symbol_binding_name (Ebl *ebl, int binding,
Packit 032894
					    char *buf, size_t len);
Packit 032894
Packit 032894
/* Return dynamic tag name.  */
Packit 032894
extern const char *ebl_dynamic_tag_name (Ebl *ebl, int64_t tag,
Packit 032894
					 char *buf, size_t len);
Packit 032894
Packit 032894
/* Check dynamic tag.  */
Packit 032894
extern bool ebl_dynamic_tag_check (Ebl *ebl, int64_t tag);
Packit 032894
Packit 032894
/* Check whether given symbol's st_value and st_size are OK despite failing
Packit 032894
   normal checks.  */
Packit 032894
extern bool ebl_check_special_symbol (Ebl *ebl,
Packit 032894
				      const GElf_Sym *sym, const char *name,
Packit 032894
				      const GElf_Shdr *destshdr);
Packit 032894
Packit 032894
/* Check if this is a data marker symbol.  e.g. '$d' symbols for ARM.  */
Packit 032894
extern bool ebl_data_marker_symbol (Ebl *ebl, const GElf_Sym *sym,
Packit 032894
				    const char *sname);
Packit 032894
Packit 032894
/* Check whether only valid bits are set on the st_other symbol flag.  */
Packit 032894
extern bool ebl_check_st_other_bits (Ebl *ebl, unsigned char st_other);
Packit 032894
Packit 032894
/* Return symbolic representation of OS ABI.  */
Packit 032894
extern const char *ebl_osabi_name (Ebl *ebl, int osabi, char *buf, size_t len);
Packit 032894
Packit 032894
Packit 032894
/* Return name of the note section type for a core file.  */
Packit 032894
extern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf,
Packit 032894
					    size_t len);
Packit 032894
Packit 032894
/* Return name of the note section type for an object file.  */
Packit 032894
extern const char *ebl_object_note_type_name (Ebl *ebl, const char *name,
Packit 032894
					      uint32_t type, GElf_Word descsz,
Packit 032894
					      char *buf, size_t len);
Packit 032894
Packit 032894
/* Print information about object note if available.  */
Packit 032894
extern void ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name,
Packit 032894
			     uint32_t type, uint32_t descsz, const char *desc);
Packit 032894
Packit 032894
/* Check whether an attribute in a .gnu_attributes section is recognized.
Packit 032894
   Fills in *TAG_NAME with the name for this tag.
Packit 032894
   If VALUE is a known value for that tag, also fills in *VALUE_NAME.  */
Packit 032894
extern bool ebl_check_object_attribute (Ebl *ebl, const char *vendor,
Packit 032894
					int tag, uint64_t value,
Packit 032894
					const char **tag_name,
Packit 032894
					const char **value_name);
Packit 032894
Packit 032894
/* Check whether a section type is a valid reloc target.  */
Packit 032894
extern bool ebl_check_reloc_target_type (Ebl *ebl, Elf64_Word sh_type);
Packit 032894
Packit 032894
Packit 032894
/* Check section name for being that of a debug informatino section.  */
Packit 032894
extern bool ebl_debugscn_p (Ebl *ebl, const char *name);
Packit 032894
Packit 032894
/* Check whether given relocation is a copy relocation.  */
Packit 032894
extern bool ebl_copy_reloc_p (Ebl *ebl, int reloc);
Packit 032894
Packit 032894
/* Check whether given relocation is a no-op relocation.  */
Packit 032894
extern bool ebl_none_reloc_p (Ebl *ebl, int reloc);
Packit 032894
Packit 032894
/* Check whether given relocation is a relative relocation.  */
Packit 032894
extern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
Packit 032894
Packit 032894
/* Check whether section should be stripped.  */
Packit 032894
extern bool ebl_section_strip_p (Ebl *ebl,
Packit 032894
				 const GElf_Shdr *shdr, const char *name,
Packit 032894
				 bool remove_comment, bool only_remove_debug);
Packit 032894
Packit 032894
/* Check if backend uses a bss PLT in this file.  */
Packit 032894
extern bool ebl_bss_plt_p (Ebl *ebl);
Packit 032894
Packit 032894
/* Return size of entry in SysV-style hash table.  */
Packit 032894
extern int ebl_sysvhash_entrysize (Ebl *ebl);
Packit 032894
Packit 032894
/* Return location expression to find return value given a
Packit 032894
   DW_TAG_subprogram, DW_TAG_subroutine_type, or similar DIE describing
Packit 032894
   function itself (whose DW_AT_type attribute describes its return type).
Packit 032894
   Returns -1 for a libdw error (see dwarf_errno).
Packit 032894
   Returns -2 for an unrecognized type formation.
Packit 032894
   Returns zero if the function has no return value (e.g. "void" in C).
Packit 032894
   Otherwise, *LOCOPS gets a location expression to find the return value,
Packit 032894
   and returns the number of operations in the expression.  The pointer is
Packit 032894
   permanently allocated at least as long as the Ebl handle is open.  */
Packit 032894
extern int ebl_return_value_location (Ebl *ebl,
Packit 032894
				      Dwarf_Die *functypedie,
Packit 032894
				      const Dwarf_Op **locops);
Packit 032894
Packit 032894
/* Fill in register information given DWARF register numbers.
Packit 032894
   If NAME is null, return the maximum REGNO + 1 that has a name.
Packit 032894
   Otherwise, store in NAME the name for DWARF register number REGNO
Packit 032894
   and return the number of bytes written (including '\0' terminator).
Packit 032894
   Return -1 if NAMELEN is too short or REGNO is negative or too large.
Packit 032894
   Return 0 if REGNO is unused (a gap in the DWARF number assignment).
Packit 032894
   On success, set *SETNAME to a description like "integer" or "FPU"
Packit 032894
   fit for "%s registers" title display, and *PREFIX to the string
Packit 032894
   that precedes NAME in canonical assembler syntax (e.g. "%" or "$").
Packit 032894
   The NAME string contains identifier characters only (maybe just digits).  */
Packit 032894
extern ssize_t ebl_register_info (Ebl *ebl,
Packit 032894
				  int regno, char *name, size_t namelen,
Packit 032894
				  const char **prefix, const char **setname,
Packit 032894
				  int *bits, int *type);
Packit 032894
Packit 032894
/* Fill in the DWARF register numbers for the registers used in system calls.
Packit 032894
   The SP and PC are what kernel reports call the user stack pointer and PC.
Packit 032894
   The CALLNO and ARGS are the system call number and incoming arguments.
Packit 032894
   Each of these is filled with the DWARF register number corresponding,
Packit 032894
   or -1 if there is none.  Returns zero when the information is available.  */
Packit 032894
extern int ebl_syscall_abi (Ebl *ebl, int *sp, int *pc,
Packit 032894
			    int *callno, int args[6]);
Packit 032894
Packit 032894
/* Supply the ABI-specified state of DWARF CFI before CIE initial programs.
Packit 032894
Packit 032894
   The DWARF 3.0 spec says that the default initial states of all registers
Packit 032894
   are "undefined", unless otherwise specified by the machine/compiler ABI.
Packit 032894
Packit 032894
   This default is wrong for every machine with the CFI generated by GCC.
Packit 032894
   The EH unwinder does not really distinguish "same_value" and "undefined",
Packit 032894
   since it doesn't matter for unwinding (in either case there is no change
Packit 032894
   to make for that register).  GCC generates CFI that says nothing at all
Packit 032894
   about registers it hasn't spilled somewhere.  For our unwinder to give
Packit 032894
   the true story, the backend must supply an initial state that uses
Packit 032894
   "same_value" rules for all the callee-saves registers.
Packit 032894
Packit 032894
   This can fill in the initial_instructions, initial_instructions_end
Packit 032894
   members of *ABI_INFO to point at a CFI instruction stream to process
Packit 032894
   before each CIE's initial instructions.  It should set the
Packit 032894
   data_alignment_factor member if it affects the initial instructions.
Packit 032894
Packit 032894
   The callback should not use the register rules DW_CFA_expression or
Packit 032894
   DW_CFA_val_expression.  Defining the CFA using DW_CFA_def_cfa_expression
Packit 032894
   is allowed.  This is an implementation detail since register rules
Packit 032894
   store expressions as offsets from the .eh_frame or .debug_frame data.
Packit 032894
Packit 032894
   As a shorthand for some common cases, for this instruction stream
Packit 032894
   we overload some CFI instructions that cannot be used in a CIE:
Packit 032894
Packit 032894
	DW_CFA_restore		-- Change default rule for all unmentioned
Packit 032894
				   registers from undefined to same_value.
Packit 032894
Packit 032894
   This function can also fill in ABI_INFO->return_address_register with the
Packit 032894
   DWARF register number that identifies the actual PC in machine state.
Packit 032894
   If there is no canonical DWARF register number with that meaning, it's
Packit 032894
   left unchanged (callers usually initialize with (Dwarf_Word) -1).
Packit 032894
   This value is not used by CFI per se.
Packit 032894
Packit 032894
   Function returns 0 on success and -1 for error or unsupported by the
Packit 032894
   backend.  */
Packit 032894
extern int ebl_abi_cfi (Ebl *ebl, Dwarf_CIE *abi_info)
Packit 032894
  __nonnull_attribute__ (2);
Packit 032894
Packit 032894
/* Register map info. */
Packit 032894
typedef struct
Packit 032894
{
Packit 032894
  Dwarf_Half offset;		/* Byte offset in register data block.  */
Packit 032894
  Dwarf_Half regno;		/* DWARF register number.  */
Packit 032894
  uint8_t bits;			/* Bits of data for one register.  */
Packit 032894
  uint8_t pad;			/* Bytes of padding after register's data.  */
Packit 032894
  Dwarf_Half count;		/* Consecutive register numbers here.  */
Packit 032894
  bool pc_register;
Packit 032894
} Ebl_Register_Location;
Packit 032894
Packit 032894
/* Non-register data items in core notes.  */
Packit 032894
typedef struct
Packit 032894
{
Packit 032894
  const char *name;		/* Printable identifier.  */
Packit 032894
  const char *group;		/* Identifier for category of related items.  */
Packit 032894
  Dwarf_Half offset;		/* Byte offset in note data.  */
Packit 032894
  Dwarf_Half count;
Packit 032894
  Elf_Type type;
Packit 032894
  char format;
Packit 032894
  bool thread_identifier;
Packit 032894
  bool pc_register;
Packit 032894
} Ebl_Core_Item;
Packit 032894
Packit 032894
/* Describe the format of a core file note with the given header and NAME.
Packit 032894
   NAME is not guaranteed terminated, it's NHDR->n_namesz raw bytes.  */
Packit 032894
extern int ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr,
Packit 032894
			  const char *name, const char *desc,
Packit 032894
			  GElf_Word *regs_offset, size_t *nregloc,
Packit 032894
			  const Ebl_Register_Location **reglocs,
Packit 032894
			  size_t *nitems, const Ebl_Core_Item **items)
Packit 032894
  __nonnull_attribute__ (1, 2, 3, 4, 5, 6, 7, 8);
Packit 032894
Packit 032894
/* Describe the auxv type number.  */
Packit 032894
extern int ebl_auxv_info (Ebl *ebl, GElf_Xword a_type,
Packit 032894
			  const char **name, const char **format)
Packit 032894
  __nonnull_attribute__ (1, 3, 4);
Packit 032894
Packit 032894
/* Callback type for ebl_set_initial_registers_tid.
Packit 032894
   Register -1 is mapped to PC (if arch PC has no DWARF number).
Packit 032894
   If FIRSTREG is -1 then NREGS has to be 1.  */
Packit 032894
typedef bool (ebl_tid_registers_t) (int firstreg, unsigned nregs,
Packit 032894
				    const Dwarf_Word *regs, void *arg)
Packit 032894
  __nonnull_attribute__ (3);
Packit 032894
Packit 032894
/* Callback to fetch process data from live TID.
Packit 032894
   EBL architecture has to have EBL_FRAME_NREGS > 0, otherwise the
Packit 032894
   backend doesn't support unwinding and this function call may crash.  */
Packit 032894
extern bool ebl_set_initial_registers_tid (Ebl *ebl,
Packit 032894
					   pid_t tid,
Packit 032894
					   ebl_tid_registers_t *setfunc,
Packit 032894
					   void *arg)
Packit 032894
  __nonnull_attribute__ (1, 3);
Packit 032894
Packit 032894
/* Number of registers to allocate for ebl_set_initial_registers_tid.
Packit 032894
   EBL architecture can unwind iff EBL_FRAME_NREGS > 0.  */
Packit 032894
extern size_t ebl_frame_nregs (Ebl *ebl)
Packit 032894
  __nonnull_attribute__ (1);
Packit 032894
Packit 032894
/* Offset to apply to the value of the return_address_register, as
Packit 032894
   fetched from a Dwarf CFI.  This is used by some backends, where the
Packit 032894
   return_address_register actually contains the call address.  */
Packit 032894
extern int ebl_ra_offset (Ebl *ebl)
Packit 032894
  __nonnull_attribute__ (1);
Packit 032894
Packit 032894
/* Mask to use for function symbol or unwind return addresses in case
Packit 032894
   the architecture adds some extra non-address bits to it.  This is
Packit 032894
   different from ebl_resolve_sym_value which only works for actual
Packit 032894
   symbol addresses (in non-ET_REL files) that might resolve to an
Packit 032894
   address in a different section.  ebl_func_addr_mask is called to
Packit 032894
   turn a given function value into the a real address or offset (the
Packit 032894
   original value might not be a real address).  This works for all
Packit 032894
   cases where an actual function address (or offset in ET_REL symbol
Packit 032894
   tables) is needed.  */
Packit 032894
extern GElf_Addr ebl_func_addr_mask (Ebl *ebl);
Packit 032894
Packit 032894
/* Convert *REGNO as is in DWARF to a lower range suitable for
Packit 032894
   Dwarf_Frame->REGS indexing.  */
Packit 032894
extern bool ebl_dwarf_to_regno (Ebl *ebl, unsigned *regno)
Packit 032894
  __nonnull_attribute__ (1, 2);
Packit 032894
Packit 032894
/* Modify PC as fetched from inferior data into valid PC.  */
Packit 032894
extern void ebl_normalize_pc (Ebl *ebl, Dwarf_Addr *pc)
Packit 032894
  __nonnull_attribute__ (1, 2);
Packit 032894
Packit 032894
/* Callback type for ebl_unwind's parameter getfunc.  */
Packit 032894
typedef bool (ebl_tid_registers_get_t) (int firstreg, unsigned nregs,
Packit 032894
					Dwarf_Word *regs, void *arg)
Packit 032894
  __nonnull_attribute__ (3);
Packit 032894
Packit 032894
/* Callback type for ebl_unwind's parameter readfunc.  */
Packit 032894
typedef bool (ebl_pid_memory_read_t) (Dwarf_Addr addr, Dwarf_Word *data,
Packit 032894
				      void *arg)
Packit 032894
  __nonnull_attribute__ (3);
Packit 032894
Packit 032894
/* Get previous frame state for an existing frame state.  Method is called only
Packit 032894
   if unwinder could not find CFI for current PC.  PC is for the
Packit 032894
   existing frame.  SETFUNC sets register in the previous frame.  GETFUNC gets
Packit 032894
   register from the existing frame.  Note that GETFUNC vs. SETFUNC act on
Packit 032894
   a disjunct set of registers.  READFUNC reads memory.  ARG has to be passed
Packit 032894
   for SETFUNC, GETFUNC and READFUNC.  *SIGNAL_FRAMEP is initialized to false,
Packit 032894
   it can be set to true if existing frame is a signal frame.  SIGNAL_FRAMEP is
Packit 032894
   never NULL.  */
Packit 032894
extern bool ebl_unwind (Ebl *ebl, Dwarf_Addr pc, ebl_tid_registers_t *setfunc,
Packit 032894
			ebl_tid_registers_get_t *getfunc,
Packit 032894
			ebl_pid_memory_read_t *readfunc, void *arg,
Packit 032894
			bool *signal_framep)
Packit 032894
  __nonnull_attribute__ (1, 3, 4, 5, 7);
Packit 032894
Packit 032894
/* Returns true if the value can be resolved to an address in an
Packit 032894
   allocated section, which will be returned in *ADDR
Packit 032894
   (e.g. function descriptor resolving)  */
Packit 032894
extern bool ebl_resolve_sym_value (Ebl *ebl, GElf_Addr *addr)
Packit 032894
   __nonnull_attribute__ (2);
Packit 032894
Packit 032894
#ifdef __cplusplus
Packit 032894
}
Packit 032894
#endif
Packit 032894
Packit 032894
#endif	/* libebl.h */