blob: aff9ca5ea59ec71312a0f769bb940a900b7e0396 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Interface for libebl.
2 Copyright (C) 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
3
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.
7
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. */
13
14#ifndef _LIBEBL_H
15#define _LIBEBL_H 1
16
17#include <gelf.h>
18#include <stdbool.h>
19#include <stddef.h>
20#include <stdint.h>
21
22#include <elf-knowledge.h>
23
24
25/* Opaque type for the handle. */
26typedef struct ebl Ebl;
27
28
29/* Get backend handle for object associated with ELF handle. */
30extern Ebl *ebl_openbackend (Elf *elf);
31/* Similar but without underlying ELF file. */
32extern Ebl *ebl_openbackend_machine (GElf_Half machine);
33/* Similar but with emulation name given. */
34extern Ebl *ebl_openbackend_emulation (const char *emulation);
35
36/* Free resources allocated for backend handle. */
37extern void ebl_closebackend (Ebl *bh);
38
39
40/* Function to call the callback functions including default ELF
41 handling. */
42
43/* Return backend name. */
44extern const char *ebl_backend_name (Ebl *ebl);
45
46/* Return relocation type name. */
47extern const char *ebl_object_type_name (Ebl *ebl, int object,
48 char *buf, size_t len);
49
50/* Return relocation type name. */
51extern const char *ebl_reloc_type_name (Ebl *ebl, int reloc,
52 char *buf, size_t len);
53
54/* Check relocation type. */
55extern bool ebl_reloc_type_check (Ebl *ebl, int reloc);
56
57/* Check relocation type use. */
58extern bool ebl_reloc_valid_use (Ebl *ebl, int reloc);
59
60/* Check if relocation type is for simple absolute relocations.
61 Return ELF_T_{BYTE,HALF,SWORD,SXWORD} for a simple type, else ELF_T_NUM. */
62extern Elf_Type ebl_reloc_simple_type (Ebl *ebl, int reloc);
63
64/* Return true if the symbol type is that referencing the GOT. E.g.,
65 R_386_GOTPC. */
66extern bool ebl_gotpc_reloc_check (Ebl *ebl, int reloc);
67
68/* Return segment type name. */
69extern const char *ebl_segment_type_name (Ebl *ebl, int segment,
70 char *buf, size_t len);
71
72/* Return section type name. */
73extern const char *ebl_section_type_name (Ebl *ebl, int section,
74 char *buf, size_t len);
75
76/* Return section name. */
77extern const char *ebl_section_name (Ebl *ebl, int section, int xsection,
78 char *buf, size_t len,
79 const char *scnnames[], size_t shnum);
80
81/* Return machine flag names. */
82extern const char *ebl_machine_flag_name (Ebl *ebl, GElf_Word flags,
83 char *buf, size_t len);
84
85/* Check whether machine flag is valid. */
86extern bool ebl_machine_flag_check (Ebl *ebl, GElf_Word flags);
87
88/* Return symbol type name. */
89extern const char *ebl_symbol_type_name (Ebl *ebl, int symbol,
90 char *buf, size_t len);
91
92/* Return symbol binding name. */
93extern const char *ebl_symbol_binding_name (Ebl *ebl, int binding,
94 char *buf, size_t len);
95
96/* Return dynamic tag name. */
97extern const char *ebl_dynamic_tag_name (Ebl *ebl, int64_t tag,
98 char *buf, size_t len);
99
100/* Check dynamic tag. */
101extern bool ebl_dynamic_tag_check (Ebl *ebl, int64_t tag);
102
103/* Return combined section header flags value. */
104extern GElf_Word ebl_sh_flags_combine (Ebl *ebl, GElf_Word flags1,
105 GElf_Word flags2);
106
107/* Return symbolic representation of OS ABI. */
108extern const char *ebl_osabi_name (Ebl *ebl, int osabi, char *buf, size_t len);
109
110
111/* Return name of the note section type for a core file. */
112extern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf,
113 size_t len);
114
115/* Return name of the note section type for an object file. */
116extern const char *ebl_object_note_type_name (Ebl *ebl, uint32_t type,
117 char *buf, size_t len);
118
119/* Print information about core note if available. */
120extern void ebl_core_note (Ebl *ebl, const char *name, uint32_t type,
121 uint32_t descsz, const char *desc);
122
123/* Print information about object note if available. */
124extern void ebl_object_note (Ebl *ebl, const char *name, uint32_t type,
125 uint32_t descsz, const char *desc);
126
127/* Check section name for being that of a debug informatino section. */
128extern bool ebl_debugscn_p (Ebl *ebl, const char *name);
129
130/* Check whether given relocation is a copy relocation. */
131extern bool ebl_copy_reloc_p (Ebl *ebl, int reloc);
132
133
134/* CHeck whether section should be stripped. */
135extern bool ebl_section_strip_p (Ebl *ebl, const GElf_Ehdr *ehdr,
136 const GElf_Shdr *shdr, const char *name,
137 bool remove_comment, bool only_remove_debug);
138
139
140/* ELF string table handling. */
141struct Ebl_Strtab;
142struct Ebl_Strent;
143
144/* Create new ELF string table object in memory. */
145extern struct Ebl_Strtab *ebl_strtabinit (bool nullstr);
146
147/* Free resources allocated for ELF string table ST. */
148extern void ebl_strtabfree (struct Ebl_Strtab *st);
149
150/* Add string STR (length LEN is != 0) to ELF string table ST. */
151extern struct Ebl_Strent *ebl_strtabadd (struct Ebl_Strtab *st,
152 const char *str, size_t len);
153
154/* Finalize string table ST and store size and memory location information
155 in DATA. */
156extern void ebl_strtabfinalize (struct Ebl_Strtab *st, Elf_Data *data);
157
158/* Get offset in string table for string associated with SE. */
159extern size_t ebl_strtaboffset (struct Ebl_Strent *se);
160
161/* Return the string associated with SE. */
162extern const char *ebl_string (struct Ebl_Strent *se);
163
164
165/* ELF wide char string table handling. */
166struct Ebl_WStrtab;
167struct Ebl_WStrent;
168
169/* Create new ELF wide char string table object in memory. */
170extern struct Ebl_WStrtab *ebl_wstrtabinit (bool nullstr);
171
172/* Free resources allocated for ELF wide char string table ST. */
173extern void ebl_wstrtabfree (struct Ebl_WStrtab *st);
174
175/* Add string STR (length LEN is != 0) to ELF string table ST. */
176extern struct Ebl_WStrent *ebl_wstrtabadd (struct Ebl_WStrtab *st,
177 const wchar_t *str, size_t len);
178
179/* Finalize string table ST and store size and memory location information
180 in DATA. */
181extern void ebl_wstrtabfinalize (struct Ebl_WStrtab *st, Elf_Data *data);
182
183/* Get offset in wide char string table for string associated with SE. */
184extern size_t ebl_wstrtaboffset (struct Ebl_WStrent *se);
185
186
187/* Generic string table handling. */
188struct Ebl_GStrtab;
189struct Ebl_GStrent;
190
191/* Create new string table object in memory. */
192extern struct Ebl_GStrtab *ebl_gstrtabinit (unsigned int width, bool nullstr);
193
194/* Free resources allocated for string table ST. */
195extern void ebl_gstrtabfree (struct Ebl_GStrtab *st);
196
197/* Add string STR (length LEN is != 0) to string table ST. */
198extern struct Ebl_GStrent *ebl_gstrtabadd (struct Ebl_GStrtab *st,
199 const char *str, size_t len);
200
201/* Finalize string table ST and store size and memory location information
202 in DATA. */
203extern void ebl_gstrtabfinalize (struct Ebl_GStrtab *st, Elf_Data *data);
204
205/* Get offset in wide char string table for string associated with SE. */
206extern size_t ebl_gstrtaboffset (struct Ebl_GStrent *se);
207
208#endif /* libebl.h */