1 /* Internal definitions for libasm.
2 Copyright (C) 2002, 2004, 2005 Red Hat, Inc.
3 This file is part of elfutils.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
8 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
18 or both in parallel, as here.
20 elfutils is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
36 /* gettext helper macros. */
37 #define _(Str) dgettext ("elfutils", Str)
40 /* Known error codes. */
44 ASM_E_NOMEM, /* No more memory. */
45 ASM_E_CANNOT_CREATE, /* Output file cannot be created. */
46 ASM_E_INVALID, /* Invalid parameters. */
47 ASM_E_CANNOT_CHMOD, /* Cannot change mode of output file. */
48 ASM_E_CANNOT_RENAME, /* Cannot rename output file. */
49 ASM_E_DUPLSYM, /* Duplicate symbol definition. */
50 ASM_E_LIBELF, /* Refer to error in libelf. */
51 ASM_E_TYPE, /* Invalid section type for operation. */
52 ASM_E_IOERROR, /* Error during output of data. */
53 ASM_E_ENOSUP, /* No backend support. */
54 ASM_E_NUM /* Keep this entry as the last. */
58 /* Special sections. */
59 #define ASM_ABS_SCN ((Elf_Scn *) 1)
60 #define ASM_COM_SCN ((Elf_Scn *) 2)
63 /* And the hash table for symbols. */
64 #include <symbolhash.h>
67 /* Descriptor for a section. */
70 /* The underlying assembler context. */
74 unsigned int subsection_id;
81 /* Data only stored in the record for subsection zero. */
84 /* The ELF section. */
87 /* Entry in the section header string table. */
88 struct Ebl_Strent *strent;
90 /* Next member of group. */
91 struct AsmScn *next_in_group;
94 /* Pointer to the record for subsection zero. */
98 /* Current offset in the (sub)section. */
100 /* Maximum alignment of the section so far. */
103 /* Section content. */
106 /* Currently used number of bytes in the block. */
109 /* Number of bytes allocated. */
112 /* Pointer to the next block. */
113 struct AsmData *next;
115 /* The actual data. */
116 char data[flexarr_size];
123 char bytes[flexarr_size];
126 /* Next subsection. */
129 /* List of all allocated sections. */
132 /* Name of the section. */
133 char name[flexarr_size];
137 /* Descriptor used for the assembling session. */
140 /* File descriptor of the temporary file. */
143 /* True if text output is wanted. */
146 /* Output file handle. */
149 /* ELF descriptor of the temporary file. */
151 /* I/O stream for text output. */
156 /* List with defined sections. */
157 AsmScn_t *section_list;
158 /* Section header string table. */
159 struct Ebl_Strtab *section_strtab;
161 /* Table with defined symbols. */
162 asm_symbol_tab symbol_tab;
163 /* Number of symbols in the table. */
164 unsigned int nsymbol_tab;
165 /* Symbol string table. */
166 struct Ebl_Strtab *symbol_strtab;
168 /* List of section groups. */
169 struct AsmScnGrp *groups;
170 /* Number of section groups. */
173 /* Current required alignment for common symbols. */
174 GElf_Word common_align;
176 /* Lock to handle multithreaded programs. */
177 rwlock_define (,lock);
179 /* Counter for temporary symbols. */
180 unsigned int tempsym_count;
182 /* Name of the output file. */
184 /* The name of the temporary file. */
185 char tmp_fname[flexarr_size];
189 /* Descriptor for a symbol. */
192 /* Reference to the section which contains the symbol. */
195 /* Type of the symbol. */
197 /* Binding of the symbol. */
200 /* Size of the symbol. */
203 /* Offset in the section. */
206 /* Symbol table index of the symbol in the symbol table. */
209 /* Reference to name of the symbol. */
210 struct Ebl_Strent *strent;
214 /* Descriptor for section group. */
217 /* Entry in the section header string table. */
218 struct Ebl_Strent *strent;
220 /* The ELF section. */
224 struct AsmSym *signature;
227 struct AsmScn *members;
228 /* Number of members. */
235 struct AsmScnGrp *next;
237 /* Name of the section group. */
238 char name[flexarr_size];
242 /* Descriptor for disassembler. */
245 /* Handle for the backend library with the disassembler routine. */
248 /* ELF file containing all the data passed to the function. This
249 allows to look up symbols. */
252 /* Callback function to determine symbol names. */
253 DisasmGetSymCB_t symcb;
257 /* The default fill pattern: one zero byte. */
258 extern const struct FillPattern *__libasm_default_pattern
262 /* Ensure there are at least LEN bytes available in the output buffer
264 extern int __libasm_ensure_section_space (AsmScn_t *asmscn, size_t len)
267 /* Free all resources associated with the assembler context. */
268 extern void __libasm_finictx (AsmCtx_t *ctx) internal_function;
270 /* Set error code. */
271 extern void __libasm_seterrno (int err) internal_function;
273 /* Return handle for the named section. If it was not used before
275 extern AsmScn_t *__asm_newscn_internal (AsmCtx_t *ctx, const char *scnname,
276 GElf_Word type, GElf_Xword flags)
280 /* Internal aliases of the asm_addintXX functions. */
281 extern int __asm_addint8_internal (AsmScn_t *asmscn, int8_t num)
283 extern int __asm_addint16_internal (AsmScn_t *asmscn, int16_t num)
285 extern int __asm_addint32_internal (AsmScn_t *asmscn, int32_t num)
287 extern int __asm_addint64_internal (AsmScn_t *asmscn, int64_t num)
291 /* Produce disassembly output for given memory and output it using the
292 given callback functions. */
293 extern int __disasm_cb_internal (DisasmCtx_t *ctx, const uint8_t **startp,
294 const uint8_t *end, GElf_Addr addr,
295 const char *fmt, DisasmOutputCB_t outcb,
296 void *outcbarp, void *symcbarg)
300 /* Test whether given symbol is an internal symbol and if yes, whether
301 we should nevertheless emit it in the symbol table. */
302 // XXX The second part should probably be controlled by an option which
303 // isn't implemented yet
304 // XXX Also, the format will change with the backend.
305 #define asm_emit_symbol_p(name) (strncmp (name, ".L", 2) != 0)
307 #endif /* libasmP.h */