OSDN Git Service

Merge lto branch into trunk.
[pf3gnuchains/gcc-fork.git] / include / plugin-api.h
1 /* plugin-api.h -- External linker plugin API.  */
2
3 /* Copyright 2009 Free Software Foundation, Inc.
4    Written by Cary Coutant <ccoutant@google.com>.
5
6    This file is part of binutils.
7
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.
12
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.
17
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.  */
22
23 /* This file defines the interface for writing a linker plugin, which is
24    described at < http://gcc.gnu.org/wiki/whopr/driver >.  */
25
26 #ifndef PLUGIN_API_H
27 #define PLUGIN_API_H
28
29 #include <stdint.h>
30 #include <sys/types.h>
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 /* Status code returned by most API routines.  */
38
39 enum ld_plugin_status
40 {
41   LDPS_OK = 0,
42   LDPS_NO_SYMS,         /* Attempt to get symbols that haven't been added. */
43   LDPS_ERR
44   /* Additional Error codes TBD.  */
45 };
46
47 /* The version of the API specification.  */
48
49 enum ld_plugin_api_version
50 {
51   LD_PLUGIN_API_VERSION = 1
52 };
53
54 /* The type of output file being generated by the linker.  */
55
56 enum ld_plugin_output_file_type
57 {
58   LDPO_REL,
59   LDPO_EXEC,
60   LDPO_DYN
61 };
62
63 /* An input file managed by the plugin library.  */
64
65 struct ld_plugin_input_file
66 {
67   const char *name;
68   int fd;
69   off_t offset;
70   off_t filesize;
71   void *handle;
72 };
73
74 /* A symbol belonging to an input file managed by the plugin library.  */
75
76 struct ld_plugin_symbol
77 {
78   char *name;
79   char *version;
80   int def;
81   int visibility;
82   uint64_t size;
83   char *comdat_key;
84   int resolution;
85 };
86
87 /* Whether the symbol is a definition, reference, or common, weak or not.  */
88
89 enum ld_plugin_symbol_kind
90 {
91   LDPK_DEF,
92   LDPK_WEAKDEF,
93   LDPK_UNDEF,
94   LDPK_WEAKUNDEF,
95   LDPK_COMMON
96 };
97
98 /* The visibility of the symbol.  */
99
100 enum ld_plugin_symbol_visibility
101 {
102   LDPV_DEFAULT,
103   LDPV_PROTECTED,
104   LDPV_INTERNAL,
105   LDPV_HIDDEN
106 };
107
108 /* How a symbol is resolved.  */
109
110 enum ld_plugin_symbol_resolution
111 {
112   LDPR_UNKNOWN = 0,
113
114   /* Symbol is still undefined at this point.  */
115   LDPR_UNDEF,
116
117   /* This is the prevailing definition of the symbol, with references from
118      regular object code.  */
119   LDPR_PREVAILING_DEF,
120
121   /* This is the prevailing definition of the symbol, with no
122      references from regular objects.  It is only referenced from IR
123      code.  */
124   LDPR_PREVAILING_DEF_IRONLY,
125
126   /* This definition was pre-empted by a definition in a regular
127      object file.  */
128   LDPR_PREEMPTED_REG,
129
130   /* This definition was pre-empted by a definition in another IR file.  */
131   LDPR_PREEMPTED_IR,
132
133   /* This symbol was resolved by a definition in another IR file.  */
134   LDPR_RESOLVED_IR,
135
136   /* This symbol was resolved by a definition in a regular object
137      linked into the main executable.  */
138   LDPR_RESOLVED_EXEC,
139
140   /* This symbol was resolved by a definition in a shared object.  */
141   LDPR_RESOLVED_DYN
142 };
143
144 /* The plugin library's "claim file" handler.  */
145
146 typedef
147 enum ld_plugin_status
148 (*ld_plugin_claim_file_handler) (
149   const struct ld_plugin_input_file *file, int *claimed);
150
151 /* The plugin library's "all symbols read" handler.  */
152
153 typedef
154 enum ld_plugin_status
155 (*ld_plugin_all_symbols_read_handler) (void);
156
157 /* The plugin library's cleanup handler.  */
158
159 typedef
160 enum ld_plugin_status
161 (*ld_plugin_cleanup_handler) (void);
162
163 /* The linker's interface for registering the "claim file" handler.  */
164
165 typedef
166 enum ld_plugin_status
167 (*ld_plugin_register_claim_file) (ld_plugin_claim_file_handler handler);
168
169 /* The linker's interface for registering the "all symbols read" handler.  */
170
171 typedef
172 enum ld_plugin_status
173 (*ld_plugin_register_all_symbols_read) (
174   ld_plugin_all_symbols_read_handler handler);
175
176 /* The linker's interface for registering the cleanup handler.  */
177
178 typedef
179 enum ld_plugin_status
180 (*ld_plugin_register_cleanup) (ld_plugin_cleanup_handler handler);
181
182 /* The linker's interface for adding symbols from a claimed input file.  */
183
184 typedef
185 enum ld_plugin_status
186 (*ld_plugin_add_symbols) (void *handle, int nsyms,
187                           const struct ld_plugin_symbol *syms);
188
189 /* The linker's interface for retrieving symbol resolution information.  */
190
191 typedef
192 enum ld_plugin_status
193 (*ld_plugin_get_symbols) (const void *handle, int nsyms,
194                           struct ld_plugin_symbol *syms);
195
196 /* The linker's interface for adding a compiled input file.  */
197
198 typedef
199 enum ld_plugin_status
200 (*ld_plugin_add_input_file) (char *pathname);
201
202 /* The linker's interface for issuing a warning or error message.  */
203
204 typedef
205 enum ld_plugin_status
206 (*ld_plugin_message) (int level, char *format, ...);
207
208 enum ld_plugin_level
209 {
210   LDPL_INFO,
211   LDPL_WARNING,
212   LDPL_ERROR,
213   LDPL_FATAL
214 };
215
216 /* Values for the tv_tag field of the transfer vector.  */
217
218 enum ld_plugin_tag
219 {
220   LDPT_NULL = 0,
221   LDPT_API_VERSION,
222   LDPT_GOLD_VERSION,
223   LDPT_LINKER_OUTPUT,
224   LDPT_OPTION,
225   LDPT_REGISTER_CLAIM_FILE_HOOK,
226   LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK,
227   LDPT_REGISTER_CLEANUP_HOOK,
228   LDPT_ADD_SYMBOLS,
229   LDPT_GET_SYMBOLS,
230   LDPT_ADD_INPUT_FILE,
231   LDPT_MESSAGE
232 };
233
234 /* The plugin transfer vector.  */
235
236 struct ld_plugin_tv
237 {
238   enum ld_plugin_tag tv_tag;
239   union
240   {
241     int tv_val;
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;
250   } tv_u;
251 };
252
253 /* The plugin library's "onload" entry point.  */
254
255 typedef
256 enum ld_plugin_status
257 (*ld_plugin_onload) (struct ld_plugin_tv *tv);
258
259 #ifdef __cplusplus
260 };
261 #endif
262
263 #endif /* !defined(PLUGIN_API_H) */