1 /* Internal definitions for libasm.
2 Copyright (C) 2002, 2004, 2005 Red Hat, Inc.
3 This file is part of Red Hat elfutils.
5 Red Hat elfutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by the
7 Free Software Foundation; version 2 of the License.
9 Red Hat elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with Red Hat elfutils; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
18 Red Hat elfutils is an included package of the Open Invention Network.
19 An included package of the Open Invention Network is a package for which
20 Open Invention Network licensees cross-license their patents. No patent
21 license is granted, either expressly or impliedly, by designation as an
22 included package. Should you wish to participate in the Open Invention
23 Network licensing program, please visit www.openinventionnetwork.com
24 <http://www.openinventionnetwork.com>. */
33 /* gettext helper macros. */
34 #define _(Str) dgettext ("elfutils", Str)
37 /* Known error codes. */
41 ASM_E_NOMEM, /* No more memory. */
42 ASM_E_CANNOT_CREATE, /* Output file cannot be created. */
43 ASM_E_INVALID, /* Invalid parameters. */
44 ASM_E_CANNOT_CHMOD, /* Cannot change mode of output file. */
45 ASM_E_CANNOT_RENAME, /* Cannot rename output file. */
46 ASM_E_DUPLSYM, /* Duplicate symbol definition. */
47 ASM_E_LIBELF, /* Refer to error in libelf. */
48 ASM_E_TYPE, /* Invalid section type for operation. */
49 ASM_E_IOERROR, /* Error during output of data. */
50 ASM_E_ENOSUP, /* No backend support. */
51 ASM_E_NUM /* Keep this entry as the last. */
55 /* Special sections. */
56 #define ASM_ABS_SCN ((Elf_Scn *) 1)
57 #define ASM_COM_SCN ((Elf_Scn *) 2)
60 /* And the hash table for symbols. */
61 #include <symbolhash.h>
64 /* Descriptor for a section. */
67 /* The underlying assembler context. */
71 unsigned int subsection_id;
78 /* Data only stored in the record for subsection zero. */
81 /* The ELF section. */
84 /* Entry in the section header string table. */
85 struct Ebl_Strent *strent;
87 /* Next member of group. */
88 struct AsmScn *next_in_group;
91 /* Pointer to the record for subsection zero. */
95 /* Current offset in the (sub)section. */
97 /* Maximum alignment of the section so far. */
100 /* Section content. */
103 /* Currently used number of bytes in the block. */
106 /* Number of bytes allocated. */
109 /* Pointer to the next block. */
110 struct AsmData *next;
112 /* The actual data. */
113 char data[flexarr_size];
120 char bytes[flexarr_size];
123 /* Next subsection. */
126 /* List of all allocated sections. */
129 /* Name of the section. */
130 char name[flexarr_size];
134 /* Descriptor used for the assembling session. */
137 /* File descriptor of the temporary file. */
140 /* True if text output is wanted. */
143 /* Output file handle. */
146 /* ELF descriptor of the temporary file. */
148 /* I/O stream for text output. */
153 /* List with defined sections. */
154 AsmScn_t *section_list;
155 /* Section header string table. */
156 struct Ebl_Strtab *section_strtab;
158 /* Table with defined symbols. */
159 asm_symbol_tab symbol_tab;
160 /* Number of symbols in the table. */
161 unsigned int nsymbol_tab;
162 /* Symbol string table. */
163 struct Ebl_Strtab *symbol_strtab;
165 /* List of section groups. */
166 struct AsmScnGrp *groups;
167 /* Number of section groups. */
170 /* Current required alignment for common symbols. */
171 GElf_Word common_align;
173 /* Lock to handle multithreaded programs. */
174 rwlock_define (,lock);
176 /* Counter for temporary symbols. */
177 unsigned int tempsym_count;
179 /* Name of the output file. */
181 /* The name of the temporary file. */
182 char tmp_fname[flexarr_size];
186 /* Descriptor for a symbol. */
189 /* Reference to the section which contains the symbol. */
192 /* Type of the symbol. */
194 /* Binding of the symbol. */
197 /* Size of the symbol. */
200 /* Offset in the section. */
203 /* Symbol table index of the symbol in the symbol table. */
206 /* Reference to name of the symbol. */
207 struct Ebl_Strent *strent;
211 /* Descriptor for section group. */
214 /* Entry in the section header string table. */
215 struct Ebl_Strent *strent;
217 /* The ELF section. */
221 struct AsmSym *signature;
224 struct AsmScn *members;
225 /* Number of members. */
232 struct AsmScnGrp *next;
234 /* Name of the section group. */
235 char name[flexarr_size];
239 /* Descriptor for disassembler. */
242 /* Handle for the backend library with the disassembler routine. */
245 /* ELF file containing all the data passed to the function. This
246 allows to look up symbols. */
249 /* Callback function to determine symbol names. */
250 DisasmGetSymCB_t symcb;
254 /* The default fill pattern: one zero byte. */
255 extern const struct FillPattern *__libasm_default_pattern
259 /* Ensure there are at least LEN bytes available in the output buffer
261 extern int __libasm_ensure_section_space (AsmScn_t *asmscn, size_t len)
264 /* Free all resources associated with the assembler context. */
265 extern void __libasm_finictx (AsmCtx_t *ctx) internal_function;
267 /* Set error code. */
268 extern void __libasm_seterrno (int err) internal_function;
270 /* Return handle for the named section. If it was not used before
272 extern AsmScn_t *__asm_newscn_internal (AsmCtx_t *ctx, const char *scnname,
273 GElf_Word type, GElf_Xword flags)
277 /* Internal aliases of the asm_addintXX functions. */
278 extern int __asm_addint8_internal (AsmScn_t *asmscn, int8_t num)
280 extern int __asm_addint16_internal (AsmScn_t *asmscn, int16_t num)
282 extern int __asm_addint32_internal (AsmScn_t *asmscn, int32_t num)
284 extern int __asm_addint64_internal (AsmScn_t *asmscn, int64_t num)
288 /* Produce disassembly output for given memory and output it using the
289 given callback functions. */
290 extern int __disasm_cb_internal (DisasmCtx_t *ctx, const uint8_t **startp,
291 const uint8_t *end, GElf_Addr addr,
292 const char *fmt, DisasmOutputCB_t outcb,
293 void *outcbarp, void *symcbarg)
297 /* Test whether given symbol is an internal symbol and if yes, whether
298 we should nevertheless emit it in the symbol table. */
299 // XXX The second part should probably be controlled by an option which
300 // isn't implemented yet
301 // XXX Also, the format will change with the backend.
302 #define asm_emit_symbol_p(name) (strncmp (name, ".L", 2) != 0)
304 #endif /* libasmP.h */