1 /* plugin-api.h -- External linker plugin API. */
3 /* Copyright 2009 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 >. */
30 #include <sys/types.h>
37 /* Status code returned by most API routines. */
42 LDPS_NO_SYMS, /* Attempt to get symbols that haven't been added. */
44 /* Additional Error codes TBD. */
47 /* The version of the API specification. */
49 enum ld_plugin_api_version
51 LD_PLUGIN_API_VERSION = 1
54 /* The type of output file being generated by the linker. */
56 enum ld_plugin_output_file_type
63 /* An input file managed by the plugin library. */
65 struct ld_plugin_input_file
74 /* A symbol belonging to an input file managed by the plugin library. */
76 struct ld_plugin_symbol
87 /* Whether the symbol is a definition, reference, or common, weak or not. */
89 enum ld_plugin_symbol_kind
98 /* The visibility of the symbol. */
100 enum ld_plugin_symbol_visibility
108 /* How a symbol is resolved. */
110 enum ld_plugin_symbol_resolution
114 /* Symbol is still undefined at this point. */
117 /* This is the prevailing definition of the symbol, with references from
118 regular object code. */
121 /* This is the prevailing definition of the symbol, with no
122 references from regular objects. It is only referenced from IR
124 LDPR_PREVAILING_DEF_IRONLY,
126 /* This definition was pre-empted by a definition in a regular
130 /* This definition was pre-empted by a definition in another IR file. */
133 /* This symbol was resolved by a definition in another IR file. */
136 /* This symbol was resolved by a definition in a regular object
137 linked into the main executable. */
140 /* This symbol was resolved by a definition in a shared object. */
144 /* The plugin library's "claim file" handler. */
147 enum ld_plugin_status
148 (*ld_plugin_claim_file_handler) (
149 const struct ld_plugin_input_file *file, int *claimed);
151 /* The plugin library's "all symbols read" handler. */
154 enum ld_plugin_status
155 (*ld_plugin_all_symbols_read_handler) (void);
157 /* The plugin library's cleanup handler. */
160 enum ld_plugin_status
161 (*ld_plugin_cleanup_handler) (void);
163 /* The linker's interface for registering the "claim file" handler. */
166 enum ld_plugin_status
167 (*ld_plugin_register_claim_file) (ld_plugin_claim_file_handler handler);
169 /* The linker's interface for registering the "all symbols read" handler. */
172 enum ld_plugin_status
173 (*ld_plugin_register_all_symbols_read) (
174 ld_plugin_all_symbols_read_handler handler);
176 /* The linker's interface for registering the cleanup handler. */
179 enum ld_plugin_status
180 (*ld_plugin_register_cleanup) (ld_plugin_cleanup_handler handler);
182 /* The linker's interface for adding symbols from a claimed input file. */
185 enum ld_plugin_status
186 (*ld_plugin_add_symbols) (void *handle, int nsyms,
187 const struct ld_plugin_symbol *syms);
189 /* The linker's interface for retrieving symbol resolution information. */
192 enum ld_plugin_status
193 (*ld_plugin_get_symbols) (const void *handle, int nsyms,
194 struct ld_plugin_symbol *syms);
196 /* The linker's interface for adding a compiled input file. */
199 enum ld_plugin_status
200 (*ld_plugin_add_input_file) (char *pathname);
202 /* The linker's interface for issuing a warning or error message. */
205 enum ld_plugin_status
206 (*ld_plugin_message) (int level, char *format, ...);
216 /* Values for the tv_tag field of the transfer vector. */
225 LDPT_REGISTER_CLAIM_FILE_HOOK,
226 LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK,
227 LDPT_REGISTER_CLEANUP_HOOK,
234 /* The plugin transfer vector. */
238 enum ld_plugin_tag tv_tag;
242 const char *tv_string;
243 ld_plugin_register_claim_file tv_register_claim_file;
244 ld_plugin_register_all_symbols_read tv_register_all_symbols_read;
245 ld_plugin_register_cleanup tv_register_cleanup;
246 ld_plugin_add_symbols tv_add_symbols;
247 ld_plugin_get_symbols tv_get_symbols;
248 ld_plugin_add_input_file tv_add_input_file;
249 ld_plugin_message tv_message;
253 /* The plugin library's "onload" entry point. */
256 enum ld_plugin_status
257 (*ld_plugin_onload) (struct ld_plugin_tv *tv);
263 #endif /* !defined(PLUGIN_API_H) */