1 /* Interface for libebl.
2 Copyright (C) 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
4 This program is Open Source software; you can redistribute it and/or
5 modify it under the terms of the Open Software License version 1.0 as
6 published by the Open Source Initiative.
8 You should have received a copy of the Open Software License along
9 with this program; if not, you may obtain a copy of the Open Software
10 License version 1.0 from http://www.opensource.org/licenses/osl.php or
11 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12 3001 King Ranch Road, Ukiah, CA 95482. */
22 #include <elf-knowledge.h>
25 /* Opaque type for the handle. */
26 typedef struct ebl Ebl;
29 /* Get backend handle for object associated with ELF handle. */
30 extern Ebl *ebl_openbackend (Elf *elf);
31 /* Similar but without underlying ELF file. */
32 extern Ebl *ebl_openbackend_machine (GElf_Half machine);
33 /* Similar but with emulation name given. */
34 extern Ebl *ebl_openbackend_emulation (const char *emulation);
36 /* Free resources allocated for backend handle. */
37 extern void ebl_closebackend (Ebl *bh);
40 /* Information about the descriptor. */
42 /* Get ELF machine. */
43 extern int ebl_get_elfmachine (Ebl *ebl) __attribute__ ((__pure__));
46 extern int ebl_get_elfclass (Ebl *ebl) __attribute__ ((__pure__));
48 /* Get ELF data encoding. */
49 extern int ebl_get_elfdata (Ebl *ebl) __attribute__ ((__pure__));
52 /* Function to call the callback functions including default ELF
55 /* Return backend name. */
56 extern const char *ebl_backend_name (Ebl *ebl);
58 /* Return relocation type name. */
59 extern const char *ebl_object_type_name (Ebl *ebl, int object,
60 char *buf, size_t len);
62 /* Return relocation type name. */
63 extern const char *ebl_reloc_type_name (Ebl *ebl, int reloc,
64 char *buf, size_t len);
66 /* Check relocation type. */
67 extern bool ebl_reloc_type_check (Ebl *ebl, int reloc);
69 /* Check relocation type use. */
70 extern bool ebl_reloc_valid_use (Ebl *ebl, int reloc);
72 /* Check if relocation type is for simple absolute relocations.
73 Return ELF_T_{BYTE,HALF,SWORD,SXWORD} for a simple type, else ELF_T_NUM. */
74 extern Elf_Type ebl_reloc_simple_type (Ebl *ebl, int reloc);
76 /* Return true if the symbol type is that referencing the GOT. E.g.,
78 extern bool ebl_gotpc_reloc_check (Ebl *ebl, int reloc);
80 /* Return segment type name. */
81 extern const char *ebl_segment_type_name (Ebl *ebl, int segment,
82 char *buf, size_t len);
84 /* Return section type name. */
85 extern const char *ebl_section_type_name (Ebl *ebl, int section,
86 char *buf, size_t len);
88 /* Return section name. */
89 extern const char *ebl_section_name (Ebl *ebl, int section, int xsection,
90 char *buf, size_t len,
91 const char *scnnames[], size_t shnum);
93 /* Return machine flag names. */
94 extern const char *ebl_machine_flag_name (Ebl *ebl, GElf_Word flags,
95 char *buf, size_t len);
97 /* Check whether machine flag is valid. */
98 extern bool ebl_machine_flag_check (Ebl *ebl, GElf_Word flags);
100 /* Return symbol type name. */
101 extern const char *ebl_symbol_type_name (Ebl *ebl, int symbol,
102 char *buf, size_t len);
104 /* Return symbol binding name. */
105 extern const char *ebl_symbol_binding_name (Ebl *ebl, int binding,
106 char *buf, size_t len);
108 /* Return dynamic tag name. */
109 extern const char *ebl_dynamic_tag_name (Ebl *ebl, int64_t tag,
110 char *buf, size_t len);
112 /* Check dynamic tag. */
113 extern bool ebl_dynamic_tag_check (Ebl *ebl, int64_t tag);
115 /* Return combined section header flags value. */
116 extern GElf_Word ebl_sh_flags_combine (Ebl *ebl, GElf_Word flags1,
119 /* Return symbolic representation of OS ABI. */
120 extern const char *ebl_osabi_name (Ebl *ebl, int osabi, char *buf, size_t len);
123 /* Return name of the note section type for a core file. */
124 extern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf,
127 /* Return name of the note section type for an object file. */
128 extern const char *ebl_object_note_type_name (Ebl *ebl, uint32_t type,
129 char *buf, size_t len);
131 /* Print information about core note if available. */
132 extern void ebl_core_note (Ebl *ebl, const char *name, uint32_t type,
133 uint32_t descsz, const char *desc);
135 /* Print information about object note if available. */
136 extern void ebl_object_note (Ebl *ebl, const char *name, uint32_t type,
137 uint32_t descsz, const char *desc);
139 /* Check section name for being that of a debug informatino section. */
140 extern bool ebl_debugscn_p (Ebl *ebl, const char *name);
142 /* Check whether given relocation is a copy relocation. */
143 extern bool ebl_copy_reloc_p (Ebl *ebl, int reloc);
146 /* CHeck whether section should be stripped. */
147 extern bool ebl_section_strip_p (Ebl *ebl, const GElf_Ehdr *ehdr,
148 const GElf_Shdr *shdr, const char *name,
149 bool remove_comment, bool only_remove_debug);
152 /* ELF string table handling. */
156 /* Create new ELF string table object in memory. */
157 extern struct Ebl_Strtab *ebl_strtabinit (bool nullstr);
159 /* Free resources allocated for ELF string table ST. */
160 extern void ebl_strtabfree (struct Ebl_Strtab *st);
162 /* Add string STR (length LEN is != 0) to ELF string table ST. */
163 extern struct Ebl_Strent *ebl_strtabadd (struct Ebl_Strtab *st,
164 const char *str, size_t len);
166 /* Finalize string table ST and store size and memory location information
168 extern void ebl_strtabfinalize (struct Ebl_Strtab *st, Elf_Data *data);
170 /* Get offset in string table for string associated with SE. */
171 extern size_t ebl_strtaboffset (struct Ebl_Strent *se);
173 /* Return the string associated with SE. */
174 extern const char *ebl_string (struct Ebl_Strent *se);
177 /* ELF wide char string table handling. */
181 /* Create new ELF wide char string table object in memory. */
182 extern struct Ebl_WStrtab *ebl_wstrtabinit (bool nullstr);
184 /* Free resources allocated for ELF wide char string table ST. */
185 extern void ebl_wstrtabfree (struct Ebl_WStrtab *st);
187 /* Add string STR (length LEN is != 0) to ELF string table ST. */
188 extern struct Ebl_WStrent *ebl_wstrtabadd (struct Ebl_WStrtab *st,
189 const wchar_t *str, size_t len);
191 /* Finalize string table ST and store size and memory location information
193 extern void ebl_wstrtabfinalize (struct Ebl_WStrtab *st, Elf_Data *data);
195 /* Get offset in wide char string table for string associated with SE. */
196 extern size_t ebl_wstrtaboffset (struct Ebl_WStrent *se);
199 /* Generic string table handling. */
203 /* Create new string table object in memory. */
204 extern struct Ebl_GStrtab *ebl_gstrtabinit (unsigned int width, bool nullstr);
206 /* Free resources allocated for string table ST. */
207 extern void ebl_gstrtabfree (struct Ebl_GStrtab *st);
209 /* Add string STR (length LEN is != 0) to string table ST. */
210 extern struct Ebl_GStrent *ebl_gstrtabadd (struct Ebl_GStrtab *st,
211 const char *str, size_t len);
213 /* Finalize string table ST and store size and memory location information
215 extern void ebl_gstrtabfinalize (struct Ebl_GStrtab *st, Elf_Data *data);
217 /* Get offset in wide char string table for string associated with SE. */
218 extern size_t ebl_gstrtaboffset (struct Ebl_GStrent *se);
220 #endif /* libebl.h */