xref: /aosp_15_r20/external/elfutils/libebl/libebl.h (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker /* Interface for libebl.
2*7304104dSAndroid Build Coastguard Worker    Copyright (C) 2000-2010, 2013, 2014, 2015, 2016, 2017 Red Hat, Inc.
3*7304104dSAndroid Build Coastguard Worker    This file is part of elfutils.
4*7304104dSAndroid Build Coastguard Worker 
5*7304104dSAndroid Build Coastguard Worker    This file is free software; you can redistribute it and/or modify
6*7304104dSAndroid Build Coastguard Worker    it under the terms of either
7*7304104dSAndroid Build Coastguard Worker 
8*7304104dSAndroid Build Coastguard Worker      * the GNU Lesser General Public License as published by the Free
9*7304104dSAndroid Build Coastguard Worker        Software Foundation; either version 3 of the License, or (at
10*7304104dSAndroid Build Coastguard Worker        your option) any later version
11*7304104dSAndroid Build Coastguard Worker 
12*7304104dSAndroid Build Coastguard Worker    or
13*7304104dSAndroid Build Coastguard Worker 
14*7304104dSAndroid Build Coastguard Worker      * the GNU General Public License as published by the Free
15*7304104dSAndroid Build Coastguard Worker        Software Foundation; either version 2 of the License, or (at
16*7304104dSAndroid Build Coastguard Worker        your option) any later version
17*7304104dSAndroid Build Coastguard Worker 
18*7304104dSAndroid Build Coastguard Worker    or both in parallel, as here.
19*7304104dSAndroid Build Coastguard Worker 
20*7304104dSAndroid Build Coastguard Worker    elfutils is distributed in the hope that it will be useful, but
21*7304104dSAndroid Build Coastguard Worker    WITHOUT ANY WARRANTY; without even the implied warranty of
22*7304104dSAndroid Build Coastguard Worker    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23*7304104dSAndroid Build Coastguard Worker    General Public License for more details.
24*7304104dSAndroid Build Coastguard Worker 
25*7304104dSAndroid Build Coastguard Worker    You should have received copies of the GNU General Public License and
26*7304104dSAndroid Build Coastguard Worker    the GNU Lesser General Public License along with this program.  If
27*7304104dSAndroid Build Coastguard Worker    not, see <http://www.gnu.org/licenses/>.  */
28*7304104dSAndroid Build Coastguard Worker 
29*7304104dSAndroid Build Coastguard Worker 
30*7304104dSAndroid Build Coastguard Worker /* This is the interface for the Elfutils Backend Library.
31*7304104dSAndroid Build Coastguard Worker    It is a completely UNSUPPORTED interface.  Don't use any libebl
32*7304104dSAndroid Build Coastguard Worker    function directly.  These are only for internal elfutils backends
33*7304104dSAndroid Build Coastguard Worker    and tools.  There is NO source or binary compatible guarantee.  */
34*7304104dSAndroid Build Coastguard Worker 
35*7304104dSAndroid Build Coastguard Worker 
36*7304104dSAndroid Build Coastguard Worker #ifndef _LIBEBL_H
37*7304104dSAndroid Build Coastguard Worker #define _LIBEBL_H 1
38*7304104dSAndroid Build Coastguard Worker 
39*7304104dSAndroid Build Coastguard Worker #include <gelf.h>
40*7304104dSAndroid Build Coastguard Worker #include "libdw.h"
41*7304104dSAndroid Build Coastguard Worker #include <stdbool.h>
42*7304104dSAndroid Build Coastguard Worker #include <stddef.h>
43*7304104dSAndroid Build Coastguard Worker #include <stdint.h>
44*7304104dSAndroid Build Coastguard Worker 
45*7304104dSAndroid Build Coastguard Worker #include "elf-knowledge.h"
46*7304104dSAndroid Build Coastguard Worker 
47*7304104dSAndroid Build Coastguard Worker 
48*7304104dSAndroid Build Coastguard Worker /* Opaque type for the handle.  libasm.h defined the same thing.  */
49*7304104dSAndroid Build Coastguard Worker #ifndef _LIBASM_H
50*7304104dSAndroid Build Coastguard Worker typedef struct ebl Ebl;
51*7304104dSAndroid Build Coastguard Worker #endif
52*7304104dSAndroid Build Coastguard Worker 
53*7304104dSAndroid Build Coastguard Worker 
54*7304104dSAndroid Build Coastguard Worker #ifdef __cplusplus
55*7304104dSAndroid Build Coastguard Worker extern "C" {
56*7304104dSAndroid Build Coastguard Worker #endif
57*7304104dSAndroid Build Coastguard Worker 
58*7304104dSAndroid Build Coastguard Worker /* Get backend handle for object associated with ELF handle.  */
59*7304104dSAndroid Build Coastguard Worker extern Ebl *ebl_openbackend (Elf *elf);
60*7304104dSAndroid Build Coastguard Worker /* Similar but without underlying ELF file.  */
61*7304104dSAndroid Build Coastguard Worker extern Ebl *ebl_openbackend_machine (GElf_Half machine);
62*7304104dSAndroid Build Coastguard Worker /* Similar but with emulation name given.  */
63*7304104dSAndroid Build Coastguard Worker extern Ebl *ebl_openbackend_emulation (const char *emulation);
64*7304104dSAndroid Build Coastguard Worker 
65*7304104dSAndroid Build Coastguard Worker /* Free resources allocated for backend handle.  */
66*7304104dSAndroid Build Coastguard Worker extern void ebl_closebackend (Ebl *bh);
67*7304104dSAndroid Build Coastguard Worker 
68*7304104dSAndroid Build Coastguard Worker 
69*7304104dSAndroid Build Coastguard Worker /* Information about the descriptor.  */
70*7304104dSAndroid Build Coastguard Worker 
71*7304104dSAndroid Build Coastguard Worker /* Get ELF machine.  */
72*7304104dSAndroid Build Coastguard Worker extern int ebl_get_elfmachine (Ebl *ebl) __pure_attribute__;
73*7304104dSAndroid Build Coastguard Worker 
74*7304104dSAndroid Build Coastguard Worker /* Get ELF class.  */
75*7304104dSAndroid Build Coastguard Worker extern int ebl_get_elfclass (Ebl *ebl) __pure_attribute__;
76*7304104dSAndroid Build Coastguard Worker 
77*7304104dSAndroid Build Coastguard Worker /* Get ELF data encoding.  */
78*7304104dSAndroid Build Coastguard Worker extern int ebl_get_elfdata (Ebl *ebl) __pure_attribute__;
79*7304104dSAndroid Build Coastguard Worker 
80*7304104dSAndroid Build Coastguard Worker 
81*7304104dSAndroid Build Coastguard Worker /* Function to call the callback functions including default ELF
82*7304104dSAndroid Build Coastguard Worker    handling.  */
83*7304104dSAndroid Build Coastguard Worker 
84*7304104dSAndroid Build Coastguard Worker /* Return backend name.  */
85*7304104dSAndroid Build Coastguard Worker extern const char *ebl_backend_name (Ebl *ebl);
86*7304104dSAndroid Build Coastguard Worker 
87*7304104dSAndroid Build Coastguard Worker /* Return relocation type name.  */
88*7304104dSAndroid Build Coastguard Worker extern const char *ebl_reloc_type_name (Ebl *ebl, int reloc,
89*7304104dSAndroid Build Coastguard Worker 					char *buf, size_t len);
90*7304104dSAndroid Build Coastguard Worker 
91*7304104dSAndroid Build Coastguard Worker /* Check relocation type.  */
92*7304104dSAndroid Build Coastguard Worker extern bool ebl_reloc_type_check (Ebl *ebl, int reloc);
93*7304104dSAndroid Build Coastguard Worker 
94*7304104dSAndroid Build Coastguard Worker /* Check relocation type use.  */
95*7304104dSAndroid Build Coastguard Worker extern bool ebl_reloc_valid_use (Ebl *ebl, int reloc);
96*7304104dSAndroid Build Coastguard Worker 
97*7304104dSAndroid Build Coastguard Worker /* Check if relocation type is for simple absolute relocations.
98*7304104dSAndroid Build Coastguard Worker    Return ELF_T_{BYTE,HALF,SWORD,SXWORD} for a simple type, else ELF_T_NUM.
99*7304104dSAndroid Build Coastguard Worker    If the relocation type is an ADD or SUB relocation, set *ADDSUB to 1 or -1,
100*7304104dSAndroid Build Coastguard Worker    resp.  */
101*7304104dSAndroid Build Coastguard Worker extern Elf_Type ebl_reloc_simple_type (Ebl *ebl, int reloc, int *addsub);
102*7304104dSAndroid Build Coastguard Worker 
103*7304104dSAndroid Build Coastguard Worker /* Return true if the symbol type is that referencing the GOT.  E.g.,
104*7304104dSAndroid Build Coastguard Worker    R_386_GOTPC.  */
105*7304104dSAndroid Build Coastguard Worker extern bool ebl_gotpc_reloc_check (Ebl *ebl, int reloc);
106*7304104dSAndroid Build Coastguard Worker 
107*7304104dSAndroid Build Coastguard Worker /* Return segment type name.  */
108*7304104dSAndroid Build Coastguard Worker extern const char *ebl_segment_type_name (Ebl *ebl, int segment,
109*7304104dSAndroid Build Coastguard Worker 					  char *buf, size_t len);
110*7304104dSAndroid Build Coastguard Worker 
111*7304104dSAndroid Build Coastguard Worker /* Return section type name.  */
112*7304104dSAndroid Build Coastguard Worker extern const char *ebl_section_type_name (Ebl *ebl, int section,
113*7304104dSAndroid Build Coastguard Worker 					  char *buf, size_t len);
114*7304104dSAndroid Build Coastguard Worker 
115*7304104dSAndroid Build Coastguard Worker /* Return section name.  */
116*7304104dSAndroid Build Coastguard Worker extern const char *ebl_section_name (Ebl *ebl, int section, int xsection,
117*7304104dSAndroid Build Coastguard Worker 				     char *buf, size_t len,
118*7304104dSAndroid Build Coastguard Worker 				     const char *scnnames[], size_t shnum);
119*7304104dSAndroid Build Coastguard Worker 
120*7304104dSAndroid Build Coastguard Worker /* Return machine flag names.  */
121*7304104dSAndroid Build Coastguard Worker extern const char *ebl_machine_flag_name (Ebl *ebl, GElf_Word flags,
122*7304104dSAndroid Build Coastguard Worker 					  char *buf, size_t len);
123*7304104dSAndroid Build Coastguard Worker 
124*7304104dSAndroid Build Coastguard Worker /* Check whether machine flag is valid.  */
125*7304104dSAndroid Build Coastguard Worker extern bool ebl_machine_flag_check (Ebl *ebl, GElf_Word flags);
126*7304104dSAndroid Build Coastguard Worker 
127*7304104dSAndroid Build Coastguard Worker /* Check whether SHF_MASKPROC flags are valid.  */
128*7304104dSAndroid Build Coastguard Worker extern bool ebl_machine_section_flag_check (Ebl *ebl, GElf_Xword flags);
129*7304104dSAndroid Build Coastguard Worker 
130*7304104dSAndroid Build Coastguard Worker /* Check whether the section with the given index, header, and name
131*7304104dSAndroid Build Coastguard Worker    is a special machine section that is valid despite a combination
132*7304104dSAndroid Build Coastguard Worker    of flags or other details that are not generically valid.  */
133*7304104dSAndroid Build Coastguard Worker extern bool ebl_check_special_section (Ebl *ebl, int ndx,
134*7304104dSAndroid Build Coastguard Worker 				       const GElf_Shdr *shdr, const char *name);
135*7304104dSAndroid Build Coastguard Worker 
136*7304104dSAndroid Build Coastguard Worker /* Return symbol type name.  */
137*7304104dSAndroid Build Coastguard Worker extern const char *ebl_symbol_type_name (Ebl *ebl, int symbol,
138*7304104dSAndroid Build Coastguard Worker 					 char *buf, size_t len);
139*7304104dSAndroid Build Coastguard Worker 
140*7304104dSAndroid Build Coastguard Worker /* Return symbol binding name.  */
141*7304104dSAndroid Build Coastguard Worker extern const char *ebl_symbol_binding_name (Ebl *ebl, int binding,
142*7304104dSAndroid Build Coastguard Worker 					    char *buf, size_t len);
143*7304104dSAndroid Build Coastguard Worker 
144*7304104dSAndroid Build Coastguard Worker /* Return dynamic tag name.  */
145*7304104dSAndroid Build Coastguard Worker extern const char *ebl_dynamic_tag_name (Ebl *ebl, int64_t tag,
146*7304104dSAndroid Build Coastguard Worker 					 char *buf, size_t len);
147*7304104dSAndroid Build Coastguard Worker 
148*7304104dSAndroid Build Coastguard Worker /* Check dynamic tag.  */
149*7304104dSAndroid Build Coastguard Worker extern bool ebl_dynamic_tag_check (Ebl *ebl, int64_t tag);
150*7304104dSAndroid Build Coastguard Worker 
151*7304104dSAndroid Build Coastguard Worker /* Check whether given symbol's st_value and st_size are OK despite failing
152*7304104dSAndroid Build Coastguard Worker    normal checks.  */
153*7304104dSAndroid Build Coastguard Worker extern bool ebl_check_special_symbol (Ebl *ebl,
154*7304104dSAndroid Build Coastguard Worker 				      const GElf_Sym *sym, const char *name,
155*7304104dSAndroid Build Coastguard Worker 				      const GElf_Shdr *destshdr);
156*7304104dSAndroid Build Coastguard Worker 
157*7304104dSAndroid Build Coastguard Worker /* Check if this is a data marker symbol.  e.g. '$d' symbols for ARM.  */
158*7304104dSAndroid Build Coastguard Worker extern bool ebl_data_marker_symbol (Ebl *ebl, const GElf_Sym *sym,
159*7304104dSAndroid Build Coastguard Worker 				    const char *sname);
160*7304104dSAndroid Build Coastguard Worker 
161*7304104dSAndroid Build Coastguard Worker /* Check whether only valid bits are set on the st_other symbol flag.  */
162*7304104dSAndroid Build Coastguard Worker extern bool ebl_check_st_other_bits (Ebl *ebl, unsigned char st_other);
163*7304104dSAndroid Build Coastguard Worker 
164*7304104dSAndroid Build Coastguard Worker /* Return symbolic representation of OS ABI.  */
165*7304104dSAndroid Build Coastguard Worker extern const char *ebl_osabi_name (Ebl *ebl, int osabi, char *buf, size_t len);
166*7304104dSAndroid Build Coastguard Worker 
167*7304104dSAndroid Build Coastguard Worker 
168*7304104dSAndroid Build Coastguard Worker /* Return name of the note section type for a core file.  */
169*7304104dSAndroid Build Coastguard Worker extern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf,
170*7304104dSAndroid Build Coastguard Worker 					    size_t len);
171*7304104dSAndroid Build Coastguard Worker 
172*7304104dSAndroid Build Coastguard Worker /* Return name of the note section type for an object file.  */
173*7304104dSAndroid Build Coastguard Worker extern const char *ebl_object_note_type_name (Ebl *ebl, const char *name,
174*7304104dSAndroid Build Coastguard Worker 					      uint32_t type, GElf_Word descsz,
175*7304104dSAndroid Build Coastguard Worker 					      char *buf, size_t len);
176*7304104dSAndroid Build Coastguard Worker 
177*7304104dSAndroid Build Coastguard Worker /* Print information about object note if available.  */
178*7304104dSAndroid Build Coastguard Worker extern void ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name,
179*7304104dSAndroid Build Coastguard Worker 			     uint32_t type, uint32_t descsz, const char *desc);
180*7304104dSAndroid Build Coastguard Worker 
181*7304104dSAndroid Build Coastguard Worker /* Check whether an attribute in a .gnu_attributes section is recognized.
182*7304104dSAndroid Build Coastguard Worker    Fills in *TAG_NAME with the name for this tag.
183*7304104dSAndroid Build Coastguard Worker    If VALUE is a known value for that tag, also fills in *VALUE_NAME.  */
184*7304104dSAndroid Build Coastguard Worker extern bool ebl_check_object_attribute (Ebl *ebl, const char *vendor,
185*7304104dSAndroid Build Coastguard Worker 					int tag, uint64_t value,
186*7304104dSAndroid Build Coastguard Worker 					const char **tag_name,
187*7304104dSAndroid Build Coastguard Worker 					const char **value_name);
188*7304104dSAndroid Build Coastguard Worker 
189*7304104dSAndroid Build Coastguard Worker /* Check whether a section type is a valid reloc target.  */
190*7304104dSAndroid Build Coastguard Worker extern bool ebl_check_reloc_target_type (Ebl *ebl, Elf64_Word sh_type);
191*7304104dSAndroid Build Coastguard Worker 
192*7304104dSAndroid Build Coastguard Worker 
193*7304104dSAndroid Build Coastguard Worker /* Check section name for being that of a debug informatino section.  */
194*7304104dSAndroid Build Coastguard Worker extern bool ebl_debugscn_p (Ebl *ebl, const char *name);
195*7304104dSAndroid Build Coastguard Worker 
196*7304104dSAndroid Build Coastguard Worker /* Check whether given relocation is a copy relocation.  */
197*7304104dSAndroid Build Coastguard Worker extern bool ebl_copy_reloc_p (Ebl *ebl, int reloc);
198*7304104dSAndroid Build Coastguard Worker 
199*7304104dSAndroid Build Coastguard Worker /* Check whether given relocation is a no-op relocation.  */
200*7304104dSAndroid Build Coastguard Worker extern bool ebl_none_reloc_p (Ebl *ebl, int reloc);
201*7304104dSAndroid Build Coastguard Worker 
202*7304104dSAndroid Build Coastguard Worker /* Check whether given relocation is a relative relocation.  */
203*7304104dSAndroid Build Coastguard Worker extern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
204*7304104dSAndroid Build Coastguard Worker 
205*7304104dSAndroid Build Coastguard Worker /* Check whether section should be stripped.  */
206*7304104dSAndroid Build Coastguard Worker extern bool ebl_section_strip_p (Ebl *ebl,
207*7304104dSAndroid Build Coastguard Worker 				 const GElf_Shdr *shdr, const char *name,
208*7304104dSAndroid Build Coastguard Worker 				 bool remove_comment, bool only_remove_debug);
209*7304104dSAndroid Build Coastguard Worker 
210*7304104dSAndroid Build Coastguard Worker /* Check if backend uses a bss PLT in this file.  */
211*7304104dSAndroid Build Coastguard Worker extern bool ebl_bss_plt_p (Ebl *ebl);
212*7304104dSAndroid Build Coastguard Worker 
213*7304104dSAndroid Build Coastguard Worker /* Return size of entry in SysV-style hash table.  */
214*7304104dSAndroid Build Coastguard Worker extern int ebl_sysvhash_entrysize (Ebl *ebl);
215*7304104dSAndroid Build Coastguard Worker 
216*7304104dSAndroid Build Coastguard Worker /* Return location expression to find return value given a
217*7304104dSAndroid Build Coastguard Worker    DW_TAG_subprogram, DW_TAG_subroutine_type, or similar DIE describing
218*7304104dSAndroid Build Coastguard Worker    function itself (whose DW_AT_type attribute describes its return type).
219*7304104dSAndroid Build Coastguard Worker    Returns -1 for a libdw error (see dwarf_errno).
220*7304104dSAndroid Build Coastguard Worker    Returns -2 for an unrecognized type formation.
221*7304104dSAndroid Build Coastguard Worker    Returns zero if the function has no return value (e.g. "void" in C).
222*7304104dSAndroid Build Coastguard Worker    Otherwise, *LOCOPS gets a location expression to find the return value,
223*7304104dSAndroid Build Coastguard Worker    and returns the number of operations in the expression.  The pointer is
224*7304104dSAndroid Build Coastguard Worker    permanently allocated at least as long as the Ebl handle is open.  */
225*7304104dSAndroid Build Coastguard Worker extern int ebl_return_value_location (Ebl *ebl,
226*7304104dSAndroid Build Coastguard Worker 				      Dwarf_Die *functypedie,
227*7304104dSAndroid Build Coastguard Worker 				      const Dwarf_Op **locops);
228*7304104dSAndroid Build Coastguard Worker 
229*7304104dSAndroid Build Coastguard Worker /* Fill in register information given DWARF register numbers.
230*7304104dSAndroid Build Coastguard Worker    If NAME is null, return the maximum REGNO + 1 that has a name.
231*7304104dSAndroid Build Coastguard Worker    Otherwise, store in NAME the name for DWARF register number REGNO
232*7304104dSAndroid Build Coastguard Worker    and return the number of bytes written (including '\0' terminator).
233*7304104dSAndroid Build Coastguard Worker    Return -1 if NAMELEN is too short or REGNO is negative or too large.
234*7304104dSAndroid Build Coastguard Worker    Return 0 if REGNO is unused (a gap in the DWARF number assignment).
235*7304104dSAndroid Build Coastguard Worker    On success, set *SETNAME to a description like "integer" or "FPU"
236*7304104dSAndroid Build Coastguard Worker    fit for "%s registers" title display, and *PREFIX to the string
237*7304104dSAndroid Build Coastguard Worker    that precedes NAME in canonical assembler syntax (e.g. "%" or "$").
238*7304104dSAndroid Build Coastguard Worker    The NAME string contains identifier characters only (maybe just digits).  */
239*7304104dSAndroid Build Coastguard Worker extern ssize_t ebl_register_info (Ebl *ebl,
240*7304104dSAndroid Build Coastguard Worker 				  int regno, char *name, size_t namelen,
241*7304104dSAndroid Build Coastguard Worker 				  const char **prefix, const char **setname,
242*7304104dSAndroid Build Coastguard Worker 				  int *bits, int *type);
243*7304104dSAndroid Build Coastguard Worker 
244*7304104dSAndroid Build Coastguard Worker /* Supply the ABI-specified state of DWARF CFI before CIE initial programs.
245*7304104dSAndroid Build Coastguard Worker 
246*7304104dSAndroid Build Coastguard Worker    The DWARF 3.0 spec says that the default initial states of all registers
247*7304104dSAndroid Build Coastguard Worker    are "undefined", unless otherwise specified by the machine/compiler ABI.
248*7304104dSAndroid Build Coastguard Worker 
249*7304104dSAndroid Build Coastguard Worker    This default is wrong for every machine with the CFI generated by GCC.
250*7304104dSAndroid Build Coastguard Worker    The EH unwinder does not really distinguish "same_value" and "undefined",
251*7304104dSAndroid Build Coastguard Worker    since it doesn't matter for unwinding (in either case there is no change
252*7304104dSAndroid Build Coastguard Worker    to make for that register).  GCC generates CFI that says nothing at all
253*7304104dSAndroid Build Coastguard Worker    about registers it hasn't spilled somewhere.  For our unwinder to give
254*7304104dSAndroid Build Coastguard Worker    the true story, the backend must supply an initial state that uses
255*7304104dSAndroid Build Coastguard Worker    "same_value" rules for all the callee-saves registers.
256*7304104dSAndroid Build Coastguard Worker 
257*7304104dSAndroid Build Coastguard Worker    This can fill in the initial_instructions, initial_instructions_end
258*7304104dSAndroid Build Coastguard Worker    members of *ABI_INFO to point at a CFI instruction stream to process
259*7304104dSAndroid Build Coastguard Worker    before each CIE's initial instructions.  It should set the
260*7304104dSAndroid Build Coastguard Worker    data_alignment_factor member if it affects the initial instructions.
261*7304104dSAndroid Build Coastguard Worker 
262*7304104dSAndroid Build Coastguard Worker    The callback should not use the register rules DW_CFA_expression or
263*7304104dSAndroid Build Coastguard Worker    DW_CFA_val_expression.  Defining the CFA using DW_CFA_def_cfa_expression
264*7304104dSAndroid Build Coastguard Worker    is allowed.  This is an implementation detail since register rules
265*7304104dSAndroid Build Coastguard Worker    store expressions as offsets from the .eh_frame or .debug_frame data.
266*7304104dSAndroid Build Coastguard Worker 
267*7304104dSAndroid Build Coastguard Worker    As a shorthand for some common cases, for this instruction stream
268*7304104dSAndroid Build Coastguard Worker    we overload some CFI instructions that cannot be used in a CIE:
269*7304104dSAndroid Build Coastguard Worker 
270*7304104dSAndroid Build Coastguard Worker 	DW_CFA_restore		-- Change default rule for all unmentioned
271*7304104dSAndroid Build Coastguard Worker 				   registers from undefined to same_value.
272*7304104dSAndroid Build Coastguard Worker 
273*7304104dSAndroid Build Coastguard Worker    This function can also fill in ABI_INFO->return_address_register with the
274*7304104dSAndroid Build Coastguard Worker    DWARF register number that identifies the actual PC in machine state.
275*7304104dSAndroid Build Coastguard Worker    If there is no canonical DWARF register number with that meaning, it's
276*7304104dSAndroid Build Coastguard Worker    left unchanged (callers usually initialize with (Dwarf_Word) -1).
277*7304104dSAndroid Build Coastguard Worker    This value is not used by CFI per se.
278*7304104dSAndroid Build Coastguard Worker 
279*7304104dSAndroid Build Coastguard Worker    Function returns 0 on success and -1 for error or unsupported by the
280*7304104dSAndroid Build Coastguard Worker    backend.  */
281*7304104dSAndroid Build Coastguard Worker extern int ebl_abi_cfi (Ebl *ebl, Dwarf_CIE *abi_info)
282*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (2);
283*7304104dSAndroid Build Coastguard Worker 
284*7304104dSAndroid Build Coastguard Worker /* Register map info. */
285*7304104dSAndroid Build Coastguard Worker typedef struct
286*7304104dSAndroid Build Coastguard Worker {
287*7304104dSAndroid Build Coastguard Worker   Dwarf_Half offset;		/* Byte offset in register data block.  */
288*7304104dSAndroid Build Coastguard Worker   Dwarf_Half regno;		/* DWARF register number.  */
289*7304104dSAndroid Build Coastguard Worker   uint8_t bits;			/* Bits of data for one register.  */
290*7304104dSAndroid Build Coastguard Worker   uint8_t pad;			/* Bytes of padding after register's data.  */
291*7304104dSAndroid Build Coastguard Worker   Dwarf_Half count;		/* Consecutive register numbers here.  */
292*7304104dSAndroid Build Coastguard Worker   bool pc_register;
293*7304104dSAndroid Build Coastguard Worker } Ebl_Register_Location;
294*7304104dSAndroid Build Coastguard Worker 
295*7304104dSAndroid Build Coastguard Worker /* Non-register data items in core notes.  */
296*7304104dSAndroid Build Coastguard Worker typedef struct
297*7304104dSAndroid Build Coastguard Worker {
298*7304104dSAndroid Build Coastguard Worker   const char *name;		/* Printable identifier.  */
299*7304104dSAndroid Build Coastguard Worker   const char *group;		/* Identifier for category of related items.  */
300*7304104dSAndroid Build Coastguard Worker   Dwarf_Half offset;		/* Byte offset in note data.  */
301*7304104dSAndroid Build Coastguard Worker   Dwarf_Half count;
302*7304104dSAndroid Build Coastguard Worker   Elf_Type type;
303*7304104dSAndroid Build Coastguard Worker   char format;
304*7304104dSAndroid Build Coastguard Worker   bool thread_identifier;
305*7304104dSAndroid Build Coastguard Worker   bool pc_register;
306*7304104dSAndroid Build Coastguard Worker } Ebl_Core_Item;
307*7304104dSAndroid Build Coastguard Worker 
308*7304104dSAndroid Build Coastguard Worker /* Describe the format of a core file note with the given header and NAME.
309*7304104dSAndroid Build Coastguard Worker    NAME is not guaranteed terminated, it's NHDR->n_namesz raw bytes.  */
310*7304104dSAndroid Build Coastguard Worker extern int ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr,
311*7304104dSAndroid Build Coastguard Worker 			  const char *name, const char *desc,
312*7304104dSAndroid Build Coastguard Worker 			  GElf_Word *regs_offset, size_t *nregloc,
313*7304104dSAndroid Build Coastguard Worker 			  const Ebl_Register_Location **reglocs,
314*7304104dSAndroid Build Coastguard Worker 			  size_t *nitems, const Ebl_Core_Item **items)
315*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 2, 3, 4, 5, 6, 7, 8);
316*7304104dSAndroid Build Coastguard Worker 
317*7304104dSAndroid Build Coastguard Worker /* Describe the auxv type number.  */
318*7304104dSAndroid Build Coastguard Worker extern int ebl_auxv_info (Ebl *ebl, GElf_Xword a_type,
319*7304104dSAndroid Build Coastguard Worker 			  const char **name, const char **format)
320*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 3, 4);
321*7304104dSAndroid Build Coastguard Worker 
322*7304104dSAndroid Build Coastguard Worker /* Callback type for ebl_set_initial_registers_tid.
323*7304104dSAndroid Build Coastguard Worker    Register -1 is mapped to PC (if arch PC has no DWARF number).
324*7304104dSAndroid Build Coastguard Worker    If FIRSTREG is -1 then NREGS has to be 1.  */
325*7304104dSAndroid Build Coastguard Worker typedef bool (ebl_tid_registers_t) (int firstreg, unsigned nregs,
326*7304104dSAndroid Build Coastguard Worker 				    const Dwarf_Word *regs, void *arg)
327*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (3);
328*7304104dSAndroid Build Coastguard Worker 
329*7304104dSAndroid Build Coastguard Worker /* Callback to fetch process data from live TID.
330*7304104dSAndroid Build Coastguard Worker    EBL architecture has to have EBL_FRAME_NREGS > 0, otherwise the
331*7304104dSAndroid Build Coastguard Worker    backend doesn't support unwinding and this function call may crash.  */
332*7304104dSAndroid Build Coastguard Worker extern bool ebl_set_initial_registers_tid (Ebl *ebl,
333*7304104dSAndroid Build Coastguard Worker 					   pid_t tid,
334*7304104dSAndroid Build Coastguard Worker 					   ebl_tid_registers_t *setfunc,
335*7304104dSAndroid Build Coastguard Worker 					   void *arg)
336*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 3);
337*7304104dSAndroid Build Coastguard Worker 
338*7304104dSAndroid Build Coastguard Worker /* Number of registers to allocate for ebl_set_initial_registers_tid.
339*7304104dSAndroid Build Coastguard Worker    EBL architecture can unwind iff EBL_FRAME_NREGS > 0.  */
340*7304104dSAndroid Build Coastguard Worker extern size_t ebl_frame_nregs (Ebl *ebl)
341*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
342*7304104dSAndroid Build Coastguard Worker 
343*7304104dSAndroid Build Coastguard Worker /* Offset to apply to the value of the return_address_register, as
344*7304104dSAndroid Build Coastguard Worker    fetched from a Dwarf CFI.  This is used by some backends, where the
345*7304104dSAndroid Build Coastguard Worker    return_address_register actually contains the call address.  */
346*7304104dSAndroid Build Coastguard Worker extern int ebl_ra_offset (Ebl *ebl)
347*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1);
348*7304104dSAndroid Build Coastguard Worker 
349*7304104dSAndroid Build Coastguard Worker /* Mask to use for function symbol or unwind return addresses in case
350*7304104dSAndroid Build Coastguard Worker    the architecture adds some extra non-address bits to it.  This is
351*7304104dSAndroid Build Coastguard Worker    different from ebl_resolve_sym_value which only works for actual
352*7304104dSAndroid Build Coastguard Worker    symbol addresses (in non-ET_REL files) that might resolve to an
353*7304104dSAndroid Build Coastguard Worker    address in a different section.  ebl_func_addr_mask is called to
354*7304104dSAndroid Build Coastguard Worker    turn a given function value into the a real address or offset (the
355*7304104dSAndroid Build Coastguard Worker    original value might not be a real address).  This works for all
356*7304104dSAndroid Build Coastguard Worker    cases where an actual function address (or offset in ET_REL symbol
357*7304104dSAndroid Build Coastguard Worker    tables) is needed.  */
358*7304104dSAndroid Build Coastguard Worker extern GElf_Addr ebl_func_addr_mask (Ebl *ebl);
359*7304104dSAndroid Build Coastguard Worker 
360*7304104dSAndroid Build Coastguard Worker /* Convert *REGNO as is in DWARF to a lower range suitable for
361*7304104dSAndroid Build Coastguard Worker    Dwarf_Frame->REGS indexing.  */
362*7304104dSAndroid Build Coastguard Worker extern bool ebl_dwarf_to_regno (Ebl *ebl, unsigned *regno)
363*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 2);
364*7304104dSAndroid Build Coastguard Worker 
365*7304104dSAndroid Build Coastguard Worker /* Modify PC as fetched from inferior data into valid PC.  */
366*7304104dSAndroid Build Coastguard Worker extern void ebl_normalize_pc (Ebl *ebl, Dwarf_Addr *pc)
367*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 2);
368*7304104dSAndroid Build Coastguard Worker 
369*7304104dSAndroid Build Coastguard Worker /* Callback type for ebl_unwind's parameter getfunc.  */
370*7304104dSAndroid Build Coastguard Worker typedef bool (ebl_tid_registers_get_t) (int firstreg, unsigned nregs,
371*7304104dSAndroid Build Coastguard Worker 					Dwarf_Word *regs, void *arg)
372*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (3);
373*7304104dSAndroid Build Coastguard Worker 
374*7304104dSAndroid Build Coastguard Worker /* Callback type for ebl_unwind's parameter readfunc.  */
375*7304104dSAndroid Build Coastguard Worker typedef bool (ebl_pid_memory_read_t) (Dwarf_Addr addr, Dwarf_Word *data,
376*7304104dSAndroid Build Coastguard Worker 				      void *arg)
377*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (3);
378*7304104dSAndroid Build Coastguard Worker 
379*7304104dSAndroid Build Coastguard Worker /* Get previous frame state for an existing frame state.  Method is called only
380*7304104dSAndroid Build Coastguard Worker    if unwinder could not find CFI for current PC.  PC is for the
381*7304104dSAndroid Build Coastguard Worker    existing frame.  SETFUNC sets register in the previous frame.  GETFUNC gets
382*7304104dSAndroid Build Coastguard Worker    register from the existing frame.  Note that GETFUNC vs. SETFUNC act on
383*7304104dSAndroid Build Coastguard Worker    a disjunct set of registers.  READFUNC reads memory.  ARG has to be passed
384*7304104dSAndroid Build Coastguard Worker    for SETFUNC, GETFUNC and READFUNC.  *SIGNAL_FRAMEP is initialized to false,
385*7304104dSAndroid Build Coastguard Worker    it can be set to true if existing frame is a signal frame.  SIGNAL_FRAMEP is
386*7304104dSAndroid Build Coastguard Worker    never NULL.  */
387*7304104dSAndroid Build Coastguard Worker extern bool ebl_unwind (Ebl *ebl, Dwarf_Addr pc, ebl_tid_registers_t *setfunc,
388*7304104dSAndroid Build Coastguard Worker 			ebl_tid_registers_get_t *getfunc,
389*7304104dSAndroid Build Coastguard Worker 			ebl_pid_memory_read_t *readfunc, void *arg,
390*7304104dSAndroid Build Coastguard Worker 			bool *signal_framep)
391*7304104dSAndroid Build Coastguard Worker   __nonnull_attribute__ (1, 3, 4, 5, 7);
392*7304104dSAndroid Build Coastguard Worker 
393*7304104dSAndroid Build Coastguard Worker /* Returns true if the value can be resolved to an address in an
394*7304104dSAndroid Build Coastguard Worker    allocated section, which will be returned in *ADDR
395*7304104dSAndroid Build Coastguard Worker    (e.g. function descriptor resolving)  */
396*7304104dSAndroid Build Coastguard Worker extern bool ebl_resolve_sym_value (Ebl *ebl, GElf_Addr *addr)
397*7304104dSAndroid Build Coastguard Worker    __nonnull_attribute__ (2);
398*7304104dSAndroid Build Coastguard Worker 
399*7304104dSAndroid Build Coastguard Worker #ifdef __cplusplus
400*7304104dSAndroid Build Coastguard Worker }
401*7304104dSAndroid Build Coastguard Worker #endif
402*7304104dSAndroid Build Coastguard Worker 
403*7304104dSAndroid Build Coastguard Worker #endif	/* libebl.h */
404