]>
Commit | Line | Data |
---|---|---|
dbe717ef ILT |
1 | /* script-c.h -- C interface for linker scripts in gold. */ |
2 | ||
e5756efb | 3 | /* Copyright 2006, 2007, 2008 Free Software Foundation, Inc. |
6cb15b7f ILT |
4 | Written by Ian Lance Taylor <iant@google.com>. |
5 | ||
6 | This file is part of gold. | |
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 | ||
dbe717ef ILT |
23 | /* This file exists so that both the bison parser and script.cc can |
24 | include it, so that they can communicate back and forth. */ | |
25 | ||
26 | #ifndef GOLD_SCRIPT_C_H | |
27 | #define GOLD_SCRIPT_C_H | |
28 | ||
29 | #ifdef __cplusplus | |
494e05f4 ILT |
30 | #include <vector> |
31 | #include <string> | |
32 | #endif | |
33 | ||
34 | #ifdef __cplusplus | |
35 | ||
36 | // For the C++ code we declare the various supporting structures in | |
37 | // the gold namespace. For the C code we declare it at the top level. | |
38 | // The namespace level should not affect the layout of the structure. | |
39 | ||
40 | namespace gold | |
41 | { | |
dbe717ef ILT |
42 | #endif |
43 | ||
e5756efb ILT |
44 | /* A string value for the bison parser. */ |
45 | ||
46 | struct Parser_string | |
47 | { | |
48 | const char* value; | |
49 | size_t length; | |
50 | }; | |
51 | ||
52 | /* The expression functions deal with pointers to Expression objects. | |
53 | Since the bison parser generates C code, this is a hack to keep the | |
54 | C++ code type safe. This hacks assumes that all pointers look | |
55 | alike. */ | |
56 | ||
57 | #ifdef __cplusplus | |
e5756efb | 58 | class Expression; |
494e05f4 | 59 | typedef Expression* Expression_ptr; |
e5756efb ILT |
60 | #else |
61 | typedef void* Expression_ptr; | |
62 | #endif | |
63 | ||
3802b2dd ILT |
64 | /* A constraint for whether to use a particular output section |
65 | definition. */ | |
66 | ||
67 | enum Section_constraint | |
68 | { | |
69 | /* No constraint. */ | |
70 | CONSTRAINT_NONE, | |
71 | /* Only if all input sections are read-only. */ | |
72 | CONSTRAINT_ONLY_IF_RO, | |
73 | /* Only if at least input section is writable. */ | |
74 | CONSTRAINT_ONLY_IF_RW, | |
75 | /* Special constraint. */ | |
76 | CONSTRAINT_SPECIAL | |
77 | }; | |
78 | ||
494e05f4 ILT |
79 | /* The information we store for an output section header in the bison |
80 | parser. */ | |
81 | ||
82 | struct Parser_output_section_header | |
83 | { | |
84 | /* The address. This may be NULL. */ | |
85 | Expression_ptr address; | |
86 | /* The load address, from the AT specifier. This may be NULL. */ | |
87 | Expression_ptr load_address; | |
88 | /* The alignment, from the ALIGN specifier. This may be NULL. */ | |
89 | Expression_ptr align; | |
90 | /* The input section alignment, from the SUBALIGN specifier. This | |
91 | may be NULL. */ | |
92 | Expression_ptr subalign; | |
3802b2dd ILT |
93 | /* A constraint on this output section. */ |
94 | enum Section_constraint constraint; | |
494e05f4 ILT |
95 | }; |
96 | ||
97 | /* The information we store for an output section trailer in the bison | |
98 | parser. */ | |
99 | ||
100 | struct Parser_output_section_trailer | |
101 | { | |
102 | /* The fill value. This may be NULL. */ | |
103 | Expression_ptr fill; | |
104 | }; | |
105 | ||
106 | /* We keep vectors of strings. In order to manage this in both C and | |
107 | C++, we use a pointer to a vector. This assumes that all pointers | |
108 | look the same. */ | |
109 | ||
110 | #ifdef __cplusplus | |
111 | typedef std::vector<std::string> String_list; | |
112 | typedef String_list* String_list_ptr; | |
113 | #else | |
114 | typedef void* String_list_ptr; | |
115 | #endif | |
116 | ||
117 | /* The different sorts we can find in a linker script. */ | |
118 | ||
119 | enum Sort_wildcard | |
120 | { | |
121 | SORT_WILDCARD_NONE, | |
122 | SORT_WILDCARD_BY_NAME, | |
123 | SORT_WILDCARD_BY_ALIGNMENT, | |
124 | SORT_WILDCARD_BY_NAME_BY_ALIGNMENT, | |
125 | SORT_WILDCARD_BY_ALIGNMENT_BY_NAME | |
126 | }; | |
127 | ||
128 | /* The information we build for a single wildcard specification. */ | |
129 | ||
130 | struct Wildcard_section | |
131 | { | |
132 | /* The wildcard spec itself. */ | |
133 | struct Parser_string name; | |
134 | /* How the entries should be sorted. */ | |
135 | enum Sort_wildcard sort; | |
136 | }; | |
137 | ||
138 | /* A vector of Wildcard_section entries. */ | |
139 | ||
140 | #ifdef __cplusplus | |
141 | typedef std::vector<Wildcard_section> String_sort_list; | |
142 | typedef String_sort_list* String_sort_list_ptr; | |
143 | #else | |
144 | typedef void* String_sort_list_ptr; | |
145 | #endif | |
146 | ||
147 | /* A list of wildcard specifications, which may include EXCLUDE_FILE | |
148 | clauses. */ | |
149 | ||
150 | struct Wildcard_sections | |
151 | { | |
152 | /* Wildcard specs. */ | |
153 | String_sort_list_ptr sections; | |
154 | /* Exclusions. */ | |
155 | String_list_ptr exclude; | |
156 | }; | |
157 | ||
158 | /* A complete input section specification. */ | |
159 | ||
160 | struct Input_section_spec | |
161 | { | |
162 | /* The file name. */ | |
163 | struct Wildcard_section file; | |
164 | /* The list of sections. */ | |
165 | struct Wildcard_sections input_sections; | |
166 | }; | |
167 | ||
168 | struct Version_dependency_list; | |
169 | struct Version_expression_list; | |
170 | struct Version_tree; | |
171 | ||
172 | #ifdef __cplusplus | |
173 | extern "C" { | |
174 | #endif | |
175 | ||
e5756efb ILT |
176 | /* The bison parser definitions. */ |
177 | ||
dbe717ef ILT |
178 | #include "yyscript.h" |
179 | ||
180 | /* The bison parser function. */ | |
181 | ||
182 | extern int | |
183 | yyparse(void* closure); | |
184 | ||
185 | /* Called by the bison parser skeleton to return the next token. */ | |
186 | ||
187 | extern int | |
188 | yylex(YYSTYPE*, void* closure); | |
189 | ||
190 | /* Called by the bison parser skeleton to report an error. */ | |
191 | ||
192 | extern void | |
193 | yyerror(void* closure, const char*); | |
194 | ||
195 | /* Called by the bison parser to add a file to the link. */ | |
196 | ||
197 | extern void | |
e5756efb | 198 | script_add_file(void* closure, const char*, size_t); |
dbe717ef ILT |
199 | |
200 | /* Called by the bison parser to start and stop a group. */ | |
201 | ||
202 | extern void | |
203 | script_start_group(void* closure); | |
204 | extern void | |
205 | script_end_group(void* closure); | |
206 | ||
207 | /* Called by the bison parser to start and end an AS_NEEDED list. */ | |
208 | ||
209 | extern void | |
210 | script_start_as_needed(void* closure); | |
211 | extern void | |
212 | script_end_as_needed(void* closure); | |
213 | ||
d391083d ILT |
214 | /* Called by the bison parser to set the entry symbol. */ |
215 | ||
216 | extern void | |
e5756efb | 217 | script_set_entry(void* closure, const char*, size_t); |
d391083d | 218 | |
195e7dc6 | 219 | /* Called by the bison parser to parse an OPTION. */ |
e5756efb ILT |
220 | |
221 | extern void | |
222 | script_parse_option(void* closure, const char*, size_t); | |
223 | ||
3802b2dd ILT |
224 | /* Called by the bison parser to handle SEARCH_DIR. */ |
225 | ||
226 | extern void | |
227 | script_add_search_dir(void* closure, const char*, size_t); | |
228 | ||
e5756efb ILT |
229 | /* Called by the bison parser to push the lexer into expression |
230 | mode. */ | |
231 | ||
232 | extern void | |
233 | script_push_lex_into_expression_mode(void* closure); | |
234 | ||
09124467 ILT |
235 | /* Called by the bison parser to push the lexer into version |
236 | mode. */ | |
237 | ||
238 | extern void | |
239 | script_push_lex_into_version_mode(void* closure); | |
240 | ||
e5756efb ILT |
241 | /* Called by the bison parser to pop the lexer mode. */ |
242 | ||
243 | extern void | |
244 | script_pop_lex_mode(void* closure); | |
245 | ||
246 | /* Called by the bison parser to set a symbol to a value. PROVIDE is | |
247 | non-zero if the symbol should be provided--only defined if there is | |
248 | an undefined reference. HIDDEN is non-zero if the symbol should be | |
249 | hidden. */ | |
250 | ||
195e7dc6 | 251 | extern void |
e5756efb ILT |
252 | script_set_symbol(void* closure, const char*, size_t, Expression_ptr, |
253 | int provide, int hidden); | |
254 | ||
494e05f4 ILT |
255 | /* Called by the bison parser to add an assertion. */ |
256 | ||
257 | extern void | |
258 | script_add_assertion(void* closure, Expression_ptr, const char* message, | |
259 | size_t messagelen); | |
260 | ||
261 | /* Called by the bison parser to start a SECTIONS clause. */ | |
262 | ||
263 | extern void | |
264 | script_start_sections(void* closure); | |
265 | ||
266 | /* Called by the bison parser to finish a SECTIONS clause. */ | |
267 | ||
268 | extern void | |
269 | script_finish_sections(void* closure); | |
270 | ||
271 | /* Called by the bison parser to start handling input section | |
272 | specifications for an output section. */ | |
273 | ||
274 | extern void | |
275 | script_start_output_section(void* closure, const char* name, size_t namelen, | |
276 | const struct Parser_output_section_header*); | |
277 | ||
278 | /* Called by the bison parser when done handling input section | |
279 | specifications for an output section. */ | |
280 | ||
281 | extern void | |
282 | script_finish_output_section(void* closure, | |
283 | const struct Parser_output_section_trailer*); | |
284 | ||
285 | /* Called by the bison parser to handle a data statement (LONG, BYTE, | |
286 | etc.) in an output section. */ | |
287 | ||
288 | extern void | |
289 | script_add_data(void* closure, int data_token, Expression_ptr val); | |
290 | ||
291 | /* Called by the bison parser to set the fill value in an output | |
292 | section. */ | |
293 | ||
294 | extern void | |
295 | script_add_fill(void* closure, Expression_ptr val); | |
296 | ||
297 | /* Called by the bison parser to add an input section specification to | |
298 | an output section. The KEEP parameter is non-zero if this is | |
299 | within a KEEP clause, meaning that the garbage collector should not | |
300 | discard it. */ | |
301 | ||
302 | extern void | |
303 | script_add_input_section(void* closure, const struct Input_section_spec*, | |
304 | int keep); | |
305 | ||
306 | /* Create a new list of string and sort entries. */ | |
307 | ||
308 | extern String_sort_list_ptr | |
309 | script_new_string_sort_list(const struct Wildcard_section*); | |
310 | ||
311 | /* Add an entry to a list of string and sort entries. */ | |
312 | ||
313 | extern String_sort_list_ptr | |
314 | script_string_sort_list_add(String_sort_list_ptr, | |
315 | const struct Wildcard_section*); | |
316 | ||
317 | /* Create a new list of strings. */ | |
318 | ||
319 | extern String_list_ptr | |
320 | script_new_string_list(const char*, size_t); | |
321 | ||
322 | /* Add an element to a list of strings. */ | |
323 | ||
324 | extern String_list_ptr | |
325 | script_string_list_push_back(String_list_ptr, const char*, size_t); | |
326 | ||
327 | /* Concatenate two string lists. */ | |
328 | ||
329 | extern String_list_ptr | |
330 | script_string_list_append(String_list_ptr, String_list_ptr); | |
331 | ||
e5756efb ILT |
332 | /* Called by the bison parser for expressions. */ |
333 | ||
334 | extern Expression_ptr | |
335 | script_exp_unary_minus(Expression_ptr); | |
336 | extern Expression_ptr | |
337 | script_exp_unary_logical_not(Expression_ptr); | |
338 | extern Expression_ptr | |
339 | script_exp_unary_bitwise_not(Expression_ptr); | |
340 | extern Expression_ptr | |
341 | script_exp_binary_mult(Expression_ptr, Expression_ptr); | |
342 | extern Expression_ptr | |
343 | script_exp_binary_div(Expression_ptr, Expression_ptr); | |
344 | extern Expression_ptr | |
345 | script_exp_binary_mod(Expression_ptr, Expression_ptr); | |
346 | extern Expression_ptr | |
347 | script_exp_binary_add(Expression_ptr, Expression_ptr); | |
348 | extern Expression_ptr | |
349 | script_exp_binary_sub(Expression_ptr, Expression_ptr); | |
350 | extern Expression_ptr | |
351 | script_exp_binary_lshift(Expression_ptr, Expression_ptr); | |
352 | extern Expression_ptr | |
353 | script_exp_binary_rshift(Expression_ptr, Expression_ptr); | |
354 | extern Expression_ptr | |
355 | script_exp_binary_eq(Expression_ptr, Expression_ptr); | |
356 | extern Expression_ptr | |
357 | script_exp_binary_ne(Expression_ptr, Expression_ptr); | |
358 | extern Expression_ptr | |
359 | script_exp_binary_le(Expression_ptr, Expression_ptr); | |
360 | extern Expression_ptr | |
361 | script_exp_binary_ge(Expression_ptr, Expression_ptr); | |
362 | extern Expression_ptr | |
363 | script_exp_binary_lt(Expression_ptr, Expression_ptr); | |
364 | extern Expression_ptr | |
365 | script_exp_binary_gt(Expression_ptr, Expression_ptr); | |
366 | extern Expression_ptr | |
367 | script_exp_binary_bitwise_and(Expression_ptr, Expression_ptr); | |
368 | extern Expression_ptr | |
369 | script_exp_binary_bitwise_xor(Expression_ptr, Expression_ptr); | |
370 | extern Expression_ptr | |
371 | script_exp_binary_bitwise_or(Expression_ptr, Expression_ptr); | |
372 | extern Expression_ptr | |
373 | script_exp_binary_logical_and(Expression_ptr, Expression_ptr); | |
374 | extern Expression_ptr | |
375 | script_exp_binary_logical_or(Expression_ptr, Expression_ptr); | |
376 | extern Expression_ptr | |
377 | script_exp_trinary_cond(Expression_ptr, Expression_ptr, Expression_ptr); | |
378 | extern Expression_ptr | |
379 | script_exp_integer(uint64_t); | |
380 | extern Expression_ptr | |
381 | script_exp_string(const char*, size_t); | |
382 | extern Expression_ptr | |
383 | script_exp_function_max(Expression_ptr, Expression_ptr); | |
384 | extern Expression_ptr | |
385 | script_exp_function_min(Expression_ptr, Expression_ptr); | |
386 | extern Expression_ptr | |
387 | script_exp_function_defined(const char*, size_t); | |
388 | extern Expression_ptr | |
494e05f4 | 389 | script_exp_function_sizeof_headers(void); |
e5756efb ILT |
390 | extern Expression_ptr |
391 | script_exp_function_alignof(const char*, size_t); | |
392 | extern Expression_ptr | |
393 | script_exp_function_sizeof(const char*, size_t); | |
394 | extern Expression_ptr | |
395 | script_exp_function_addr(const char*, size_t); | |
396 | extern Expression_ptr | |
397 | script_exp_function_loadaddr(const char*, size_t); | |
398 | extern Expression_ptr | |
399 | script_exp_function_origin(const char*, size_t); | |
400 | extern Expression_ptr | |
401 | script_exp_function_length(const char*, size_t); | |
402 | extern Expression_ptr | |
403 | script_exp_function_constant(const char*, size_t); | |
404 | extern Expression_ptr | |
405 | script_exp_function_absolute(Expression_ptr); | |
406 | extern Expression_ptr | |
407 | script_exp_function_align(Expression_ptr, Expression_ptr); | |
408 | extern Expression_ptr | |
409 | script_exp_function_data_segment_align(Expression_ptr, Expression_ptr); | |
410 | extern Expression_ptr | |
411 | script_exp_function_data_segment_relro_end(Expression_ptr, Expression_ptr); | |
412 | extern Expression_ptr | |
413 | script_exp_function_data_segment_end(Expression_ptr); | |
414 | extern Expression_ptr | |
415 | script_exp_function_segment_start(const char*, size_t, Expression_ptr); | |
416 | extern Expression_ptr | |
417 | script_exp_function_assert(Expression_ptr, const char*, size_t); | |
195e7dc6 | 418 | |
09124467 ILT |
419 | extern void |
420 | script_register_vers_node(void* closure, | |
421 | const char* tag, | |
422 | int taglen, | |
423 | struct Version_tree *, | |
424 | struct Version_dependency_list *); | |
425 | ||
426 | extern struct Version_dependency_list * | |
427 | script_add_vers_depend(void* closure, | |
428 | struct Version_dependency_list *existing_dependencies, | |
429 | const char *depend_to_add, int deplen); | |
430 | ||
431 | extern struct Version_expression_list * | |
432 | script_new_vers_pattern(void* closure, | |
433 | struct Version_expression_list *, | |
10600224 ILT |
434 | const char *, int, int); |
435 | ||
436 | extern struct Version_expression_list * | |
437 | script_merge_expressions(struct Version_expression_list *a, | |
438 | struct Version_expression_list *b); | |
09124467 ILT |
439 | |
440 | extern struct Version_tree * | |
441 | script_new_vers_node(void* closure, | |
442 | struct Version_expression_list *global, | |
443 | struct Version_expression_list *local); | |
444 | ||
445 | extern void | |
446 | version_script_push_lang(void* closure, const char* lang, int langlen); | |
447 | ||
448 | extern void | |
449 | version_script_pop_lang(void* closure); | |
450 | ||
dbe717ef | 451 | #ifdef __cplusplus |
494e05f4 ILT |
452 | } // End extern "C" |
453 | #endif | |
454 | ||
455 | #ifdef __cplusplus | |
456 | } // End namespace gold. | |
dbe717ef ILT |
457 | #endif |
458 | ||
459 | #endif /* !defined(GOLD_SCRIPT_C_H) */ |