blob: 6daf221ea5dac9e5bc53efc8b3681ad046d3f85c [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Interface for libasm.
Ulrich Dreppera38998e2005-08-03 02:05:39 +00002 Copyright (C) 2002, 2005 Red Hat, Inc.
Ulrich Drepper361df7d2006-04-04 21:38:57 +00003 This file is part of Red Hat elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004
Ulrich Drepper361df7d2006-04-04 21:38:57 +00005 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.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00008
Ulrich Drepper361df7d2006-04-04 21:38:57 +00009 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.
13
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,
Ulrich Drepper1e9ef502006-04-04 22:29:06 +000016 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000017
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>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000025
26#ifndef _LIBASM_H
27#define _LIBASM_H 1
28
29#include <stdbool.h>
30#include <stdint.h>
31
Ulrich Dreppera38998e2005-08-03 02:05:39 +000032#include <libebl.h>
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000033
34
35/* Opaque type for the assembler context descriptor. */
36typedef struct AsmCtx AsmCtx_t;
37
38/* Opaque type for a section. */
39typedef struct AsmScn AsmScn_t;
40
41/* Opaque type for a section group. */
42typedef struct AsmScnGrp AsmScnGrp_t;
43
44/* Opaque type for a symbol. */
45typedef struct AsmSym AsmSym_t;
46
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/* Create output file and return descriptor for assembler context. If
53 TEXTP is true the output is an assembler format text file.
54 Otherwise an object file is created. The MACHINE parameter
55 corresponds to an EM_ constant from <elf.h>, KLASS specifies the
56 class (32- or 64-bit), and DATA specifies the byte order (little or
57 big endian). */
Ulrich Dreppera38998e2005-08-03 02:05:39 +000058extern AsmCtx_t *asm_begin (const char *fname, Ebl *ebl, bool textp);
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000059
60/* Abort the operation on the assembler context and free all resources. */
61extern int asm_abort (AsmCtx_t *ctx);
62
63/* Finalize output file and free all resources. */
64extern int asm_end (AsmCtx_t *ctx);
65
66
67/* Return handle for the named section. If it was not used before
68 create it. */
69extern AsmScn_t *asm_newscn (AsmCtx_t *ctx, const char *scnname,
70 GElf_Word type, GElf_Xword flags);
71
72
73/* Similar to 'asm_newscn', but make it part of section group GRP. */
74extern AsmScn_t *asm_newscn_ingrp (AsmCtx_t *ctx, const char *scnname,
75 GElf_Word type, GElf_Xword flags,
76 AsmScnGrp_t *grp);
77
78/* Create new subsection NR in the given section. */
79extern AsmScn_t *asm_newsubscn (AsmScn_t *asmscn, unsigned int nr);
80
81
82/* Return handle for new section group. The signature symbol can be
83 set later. */
84extern AsmScnGrp_t *asm_newscngrp (AsmCtx_t *ctx, const char *grpname,
85 AsmSym_t *signature, Elf32_Word flags);
86
87/* Set or overwrite signature symbol for group. */
88extern int asm_scngrp_newsignature (AsmScnGrp_t *grp, AsmSym_t *signature);
89
90
91/* Add zero terminated string STR of size LEN to (sub)section ASMSCN. */
92extern int asm_addstrz (AsmScn_t *asmscn, const char *str, size_t len);
93
94/* Add 8-bit signed integer NUM to (sub)section ASMSCN. */
95extern int asm_addint8 (AsmScn_t *asmscn, int8_t num);
96
97/* Add 8-bit unsigned integer NUM to (sub)section ASMSCN. */
98extern int asm_adduint8 (AsmScn_t *asmscn, uint8_t num);
99
100/* Add 16-bit signed integer NUM to (sub)section ASMSCN. */
101extern int asm_addint16 (AsmScn_t *asmscn, int16_t num);
102
103/* Add 16-bit unsigned integer NUM to (sub)section ASMSCN. */
104extern int asm_adduint16 (AsmScn_t *asmscn, uint16_t num);
105
106/* Add 32-bit signed integer NUM to (sub)section ASMSCN. */
107extern int asm_addint32 (AsmScn_t *asmscn, int32_t num);
108
109/* Add 32-bit unsigned integer NUM to (sub)section ASMSCN. */
110extern int asm_adduint32 (AsmScn_t *asmscn, uint32_t num);
111
112/* Add 64-bit signed integer NUM to (sub)section ASMSCN. */
113extern int asm_addint64 (AsmScn_t *asmscn, int64_t num);
114
115/* Add 64-bit unsigned integer NUM to (sub)section ASMSCN. */
116extern int asm_adduint64 (AsmScn_t *asmscn, uint64_t num);
117
118
119/* Add signed little endian base 128 integer NUM to (sub)section ASMSCN. */
120extern int asm_addsleb128 (AsmScn_t *asmscn, int32_t num);
121
122/* Add unsigned little endian base 128 integer NUM to (sub)section ASMSCN. */
123extern int asm_adduleb128 (AsmScn_t *asmscn, uint32_t num);
124
125
126/* Define new symbol NAME for current position in given section ASMSCN. */
127extern AsmSym_t *asm_newsym (AsmScn_t *asmscn, const char *name,
128 GElf_Xword size, int type, int binding);
129
130
131/* Define new common symbol NAME with given SIZE and alignment. */
132extern AsmSym_t *asm_newcomsym (AsmCtx_t *ctx, const char *name,
133 GElf_Xword size, GElf_Addr align);
134
135/* Define new common symbol NAME with given SIZE, VALUE, TYPE, and BINDING. */
136extern AsmSym_t *asm_newabssym (AsmCtx_t *ctx, const char *name,
137 GElf_Xword size, GElf_Addr value,
138 int type, int binding);
139
140
141/* Align (sub)section offset according to VALUE. */
142extern int asm_align (AsmScn_t *asmscn, GElf_Word value);
143
144/* Set the byte pattern used to fill gaps created by alignment. */
145extern int asm_fill (AsmScn_t *asmscn, void *bytes, size_t len);
146
147
148/* Return ELF descriptor created for the output file of the given context. */
149extern Elf *asm_getelf (AsmCtx_t *ctx);
150
151
152/* Return error code of last failing function call. This value is kept
153 separately for each thread. */
154extern int asm_errno (void);
155
156/* Return error string for ERROR. If ERROR is zero, return error string
157 for most recent error or NULL is none occurred. If ERROR is -1 the
158 behaviour is similar to the last case except that not NULL but a legal
159 string is returned. */
160extern const char *asm_errmsg (int __error);
161
162#ifdef __cplusplus
163}
164#endif
165
166#endif /* libasm.h */