bfd/
[binutils.git] / include / plugin-api.h
blobf536d57d751f5bb98794b4d121f2da38539e574e
1 /* plugin-api.h -- External linker plugin API. */
3 /* Copyright 2008 Free Software Foundation, Inc.
4 Written by Cary Coutant <ccoutant@google.com>.
6 This file is part of binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 /* This file defines the interface for writing a linker plugin, which is
24 described at < http://gcc.gnu.org/wiki/whopr/driver >. */
26 #ifndef PLUGIN_API_H
27 #define PLUGIN_API_H
29 #include <stdint.h>
30 #include <sys/types.h>
32 #ifdef __cplusplus
33 extern "C"
35 #endif
37 /* Status code returned by most API routines. */
39 enum ld_plugin_status
41 LDPS_OK = 0,
42 LDPS_NO_SYMS, /* Attempt to get symbols that haven't been added. */
43 LDPS_BAD_HANDLE, /* No claimed object associated with given handle. */
44 LDPS_ERR
45 /* Additional Error codes TBD. */
48 /* The version of the API specification. */
50 enum ld_plugin_api_version
52 LD_PLUGIN_API_VERSION = 1
55 /* The type of output file being generated by the linker. */
57 enum ld_plugin_output_file_type
59 LDPO_REL,
60 LDPO_EXEC,
61 LDPO_DYN
64 /* An input file managed by the plugin library. */
66 struct ld_plugin_input_file
68 const char *name;
69 int fd;
70 off_t offset;
71 off_t filesize;
72 void *handle;
75 /* A symbol belonging to an input file managed by the plugin library. */
77 struct ld_plugin_symbol
79 char *name;
80 char *version;
81 int def;
82 int visibility;
83 uint64_t size;
84 char *comdat_key;
85 int resolution;
88 /* Whether the symbol is a definition, reference, or common, weak or not. */
90 enum ld_plugin_symbol_kind
92 LDPK_DEF,
93 LDPK_WEAKDEF,
94 LDPK_UNDEF,
95 LDPK_WEAKUNDEF,
96 LDPK_COMMON
99 /* The visibility of the symbol. */
101 enum ld_plugin_symbol_visibility
103 LDPV_DEFAULT,
104 LDPV_PROTECTED,
105 LDPV_INTERNAL,
106 LDPV_HIDDEN
109 /* How a symbol is resolved. */
111 enum ld_plugin_symbol_resolution
113 LDPR_UNKNOWN = 0,
114 LDPR_UNDEF,
115 LDPR_PREVAILING_DEF,
116 LDPR_PREVAILING_DEF_IRONLY,
117 LDPR_PREEMPTED_REG,
118 LDPR_PREEMPTED_IR,
119 LDPR_RESOLVED_IR,
120 LDPR_RESOLVED_EXEC,
121 LDPR_RESOLVED_DYN
124 /* The plugin library's "claim file" handler. */
126 typedef
127 enum ld_plugin_status
128 (*ld_plugin_claim_file_handler) (
129 const struct ld_plugin_input_file *file, int *claimed);
131 /* The plugin library's "all symbols read" handler. */
133 typedef
134 enum ld_plugin_status
135 (*ld_plugin_all_symbols_read_handler) (void);
137 /* The plugin library's cleanup handler. */
139 typedef
140 enum ld_plugin_status
141 (*ld_plugin_cleanup_handler) (void);
143 /* The linker's interface for registering the "claim file" handler. */
145 typedef
146 enum ld_plugin_status
147 (*ld_plugin_register_claim_file) (ld_plugin_claim_file_handler handler);
149 /* The linker's interface for registering the "all symbols read" handler. */
151 typedef
152 enum ld_plugin_status
153 (*ld_plugin_register_all_symbols_read) (
154 ld_plugin_all_symbols_read_handler handler);
156 /* The linker's interface for registering the cleanup handler. */
158 typedef
159 enum ld_plugin_status
160 (*ld_plugin_register_cleanup) (ld_plugin_cleanup_handler handler);
162 /* The linker's interface for adding symbols from a claimed input file. */
164 typedef
165 enum ld_plugin_status
166 (*ld_plugin_add_symbols) (void *handle, int nsyms,
167 const struct ld_plugin_symbol *syms);
169 /* The linker's interface for getting the input file information with
170 an open (possibly re-opened) file descriptor. */
172 typedef
173 enum ld_plugin_status
174 (*ld_plugin_get_input_file) (const void *handle,
175 struct ld_plugin_input_file *file);
177 /* The linker's interface for releasing the input file. */
179 typedef
180 enum ld_plugin_status
181 (*ld_plugin_release_input_file) (const void *handle);
183 /* The linker's interface for retrieving symbol resolution information. */
185 typedef
186 enum ld_plugin_status
187 (*ld_plugin_get_symbols) (const void *handle, int nsyms,
188 struct ld_plugin_symbol *syms);
190 /* The linker's interface for adding a compiled input file. */
192 typedef
193 enum ld_plugin_status
194 (*ld_plugin_add_input_file) (char *pathname);
196 /* The linker's interface for issuing a warning or error message. */
198 typedef
199 enum ld_plugin_status
200 (*ld_plugin_message) (int level, const char *format, ...);
202 enum ld_plugin_level
204 LDPL_INFO,
205 LDPL_WARNING,
206 LDPL_ERROR,
207 LDPL_FATAL
210 /* Values for the tv_tag field of the transfer vector. */
212 enum ld_plugin_tag
214 LDPT_NULL = 0,
215 LDPT_API_VERSION,
216 LDPT_GOLD_VERSION,
217 LDPT_LINKER_OUTPUT,
218 LDPT_OPTION,
219 LDPT_REGISTER_CLAIM_FILE_HOOK,
220 LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK,
221 LDPT_REGISTER_CLEANUP_HOOK,
222 LDPT_ADD_SYMBOLS,
223 LDPT_GET_SYMBOLS,
224 LDPT_ADD_INPUT_FILE,
225 LDPT_MESSAGE,
226 LDPT_GET_INPUT_FILE,
227 LDPT_RELEASE_INPUT_FILE
230 /* The plugin transfer vector. */
232 struct ld_plugin_tv
234 enum ld_plugin_tag tv_tag;
235 union
237 int tv_val;
238 const char *tv_string;
239 ld_plugin_register_claim_file tv_register_claim_file;
240 ld_plugin_register_all_symbols_read tv_register_all_symbols_read;
241 ld_plugin_register_cleanup tv_register_cleanup;
242 ld_plugin_add_symbols tv_add_symbols;
243 ld_plugin_get_symbols tv_get_symbols;
244 ld_plugin_add_input_file tv_add_input_file;
245 ld_plugin_message tv_message;
246 ld_plugin_get_input_file tv_get_input_file;
247 ld_plugin_release_input_file tv_release_input_file;
248 } tv_u;
251 /* The plugin library's "onload" entry point. */
253 typedef
254 enum ld_plugin_status
255 (*ld_plugin_onload) (struct ld_plugin_tv *tv);
257 #ifdef __cplusplus
259 #endif
261 #endif /* !defined(PLUGIN_API_H) */