revert erroneous commit
[binutils.git] / gold / script-c.h
blob77b4aa410b54b5b94f395c2269f5e5c18942e171
1 /* script-c.h -- C interface for linker scripts in gold. */
3 /* Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <iant@google.com>.
6 This file is part of gold.
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 exists so that both the bison parser and script.cc can
24 include it, so that they can communicate back and forth. */
26 #ifndef GOLD_SCRIPT_C_H
27 #define GOLD_SCRIPT_C_H
29 #ifdef __cplusplus
30 #include <vector>
31 #include <string>
32 #endif
34 #ifdef __cplusplus
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.
40 namespace gold
42 #endif
44 /* A string value for the bison parser. */
46 struct Parser_string
48 const char* value;
49 size_t length;
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. */
57 #ifdef __cplusplus
58 class Expression;
59 typedef Expression* Expression_ptr;
60 #else
61 typedef void* Expression_ptr;
62 #endif
64 /* Script_section type. */
65 enum Script_section_type
67 /* No section type. */
68 SCRIPT_SECTION_TYPE_NONE,
69 SCRIPT_SECTION_TYPE_NOLOAD,
70 SCRIPT_SECTION_TYPE_DSECT,
71 SCRIPT_SECTION_TYPE_COPY,
72 SCRIPT_SECTION_TYPE_INFO,
73 SCRIPT_SECTION_TYPE_OVERLAY
76 /* A constraint for whether to use a particular output section
77 definition. */
79 enum Section_constraint
81 /* No constraint. */
82 CONSTRAINT_NONE,
83 /* Only if all input sections are read-only. */
84 CONSTRAINT_ONLY_IF_RO,
85 /* Only if at least input section is writable. */
86 CONSTRAINT_ONLY_IF_RW,
87 /* Special constraint. */
88 CONSTRAINT_SPECIAL
91 /* The information we store for an output section header in the bison
92 parser. */
94 struct Parser_output_section_header
96 /* The address. This may be NULL. */
97 Expression_ptr address;
98 /* Section type. May be NULL string. */
99 enum Script_section_type section_type;
100 /* The load address, from the AT specifier. This may be NULL. */
101 Expression_ptr load_address;
102 /* The alignment, from the ALIGN specifier. This may be NULL. */
103 Expression_ptr align;
104 /* The input section alignment, from the SUBALIGN specifier. This
105 may be NULL. */
106 Expression_ptr subalign;
107 /* A constraint on this output section. */
108 enum Section_constraint constraint;
111 /* We keep vectors of strings. In order to manage this in both C and
112 C++, we use a pointer to a vector. This assumes that all pointers
113 look the same. */
115 #ifdef __cplusplus
116 typedef std::vector<std::string> String_list;
117 typedef String_list* String_list_ptr;
118 #else
119 typedef void* String_list_ptr;
120 #endif
122 /* The information we store for an output section trailer in the bison
123 parser. */
125 struct Parser_output_section_trailer
127 /* The fill value. This may be NULL. */
128 Expression_ptr fill;
129 /* The program segments this section should go into. This may be
130 NULL. */
131 String_list_ptr phdrs;
134 /* The different sorts we can find in a linker script. */
136 enum Sort_wildcard
138 SORT_WILDCARD_NONE,
139 SORT_WILDCARD_BY_NAME,
140 SORT_WILDCARD_BY_ALIGNMENT,
141 SORT_WILDCARD_BY_NAME_BY_ALIGNMENT,
142 SORT_WILDCARD_BY_ALIGNMENT_BY_NAME
145 /* The information we build for a single wildcard specification. */
147 struct Wildcard_section
149 /* The wildcard spec itself. */
150 struct Parser_string name;
151 /* How the entries should be sorted. */
152 enum Sort_wildcard sort;
155 /* A vector of Wildcard_section entries. */
157 #ifdef __cplusplus
158 typedef std::vector<Wildcard_section> String_sort_list;
159 typedef String_sort_list* String_sort_list_ptr;
160 #else
161 typedef void* String_sort_list_ptr;
162 #endif
164 /* A list of wildcard specifications, which may include EXCLUDE_FILE
165 clauses. */
167 struct Wildcard_sections
169 /* Wildcard specs. */
170 String_sort_list_ptr sections;
171 /* Exclusions. */
172 String_list_ptr exclude;
175 /* A complete input section specification. */
177 struct Input_section_spec
179 /* The file name. */
180 struct Wildcard_section file;
181 /* The list of sections. */
182 struct Wildcard_sections input_sections;
185 /* Information for a program header. */
187 struct Phdr_info
189 /* A boolean value: whether to include the file header. */
190 int includes_filehdr;
191 /* A boolean value: whether to include the program headers. */
192 int includes_phdrs;
193 /* A boolean value: whether the flags field is valid. */
194 int is_flags_valid;
195 /* The value to use for the flags. */
196 unsigned int flags;
197 /* The load address. */
198 Expression_ptr load_address;
201 struct Version_dependency_list;
202 struct Version_expression_list;
203 struct Version_tree;
205 #ifdef __cplusplus
206 extern "C" {
207 #endif
209 /* The bison parser definitions. */
211 #include "yyscript.h"
213 /* The bison parser function. */
215 extern int
216 yyparse(void* closure);
218 /* Called by the bison parser skeleton to return the next token. */
220 extern int
221 yylex(YYSTYPE*, void* closure);
223 /* Called by the bison parser skeleton to report an error. */
225 extern void
226 yyerror(void* closure, const char*);
228 /* Called by the bison parser to add an external symbol (a symbol in
229 an EXTERN declaration) to the link. */
231 extern void
232 script_add_extern(void* closure, const char*, size_t);
234 /* Called by the bison parser to add a file to the link. */
236 extern void
237 script_add_file(void* closure, const char*, size_t);
239 /* Called by the bison parser to start and stop a group. */
241 extern void
242 script_start_group(void* closure);
243 extern void
244 script_end_group(void* closure);
246 /* Called by the bison parser to start and end an AS_NEEDED list. */
248 extern void
249 script_start_as_needed(void* closure);
250 extern void
251 script_end_as_needed(void* closure);
253 /* Called by the bison parser to set the entry symbol. */
255 extern void
256 script_set_entry(void* closure, const char*, size_t);
258 /* Called by the bison parser to set whether to define common symbols. */
260 extern void
261 script_set_common_allocation(void* closure, int);
263 /* Called by the bison parser to parse an OPTION. */
265 extern void
266 script_parse_option(void* closure, const char*, size_t);
268 /* Called by the bison parser to handle OUTPUT_FORMAT. This return 0
269 if the parse should be aborted. */
271 extern int
272 script_check_output_format(void* closure, const char*, size_t,
273 const char*, size_t, const char*, size_t);
275 /* Called by the bison parser to handle TARGET. */
276 extern void
277 script_set_target(void* closure, const char*, size_t);
279 /* Called by the bison parser to handle SEARCH_DIR. */
281 extern void
282 script_add_search_dir(void* closure, const char*, size_t);
284 /* Called by the bison parser to push the lexer into expression
285 mode. */
287 extern void
288 script_push_lex_into_expression_mode(void* closure);
290 /* Called by the bison parser to push the lexer into version
291 mode. */
293 extern void
294 script_push_lex_into_version_mode(void* closure);
296 /* Called by the bison parser to pop the lexer mode. */
298 extern void
299 script_pop_lex_mode(void* closure);
301 /* Called by the bison parser to set a symbol to a value. PROVIDE is
302 non-zero if the symbol should be provided--only defined if there is
303 an undefined reference. HIDDEN is non-zero if the symbol should be
304 hidden. */
306 extern void
307 script_set_symbol(void* closure, const char*, size_t, Expression_ptr,
308 int provide, int hidden);
310 /* Called by the bison parser to add an assertion. */
312 extern void
313 script_add_assertion(void* closure, Expression_ptr, const char* message,
314 size_t messagelen);
316 /* Called by the bison parser to start a SECTIONS clause. */
318 extern void
319 script_start_sections(void* closure);
321 /* Called by the bison parser to finish a SECTIONS clause. */
323 extern void
324 script_finish_sections(void* closure);
326 /* Called by the bison parser to start handling input section
327 specifications for an output section. */
329 extern void
330 script_start_output_section(void* closure, const char* name, size_t namelen,
331 const struct Parser_output_section_header*);
333 /* Called by the bison parser when done handling input section
334 specifications for an output section. */
336 extern void
337 script_finish_output_section(void* closure,
338 const struct Parser_output_section_trailer*);
340 /* Called by the bison parser to handle a data statement (LONG, BYTE,
341 etc.) in an output section. */
343 extern void
344 script_add_data(void* closure, int data_token, Expression_ptr val);
346 /* Called by the bison parser to set the fill value in an output
347 section. */
349 extern void
350 script_add_fill(void* closure, Expression_ptr val);
352 /* Called by the bison parser to add an input section specification to
353 an output section. The KEEP parameter is non-zero if this is
354 within a KEEP clause, meaning that the garbage collector should not
355 discard it. */
357 extern void
358 script_add_input_section(void* closure, const struct Input_section_spec*,
359 int keep);
361 /* Create a new list of string and sort entries. */
363 extern String_sort_list_ptr
364 script_new_string_sort_list(const struct Wildcard_section*);
366 /* Add an entry to a list of string and sort entries. */
368 extern String_sort_list_ptr
369 script_string_sort_list_add(String_sort_list_ptr,
370 const struct Wildcard_section*);
372 /* Create a new list of strings. */
374 extern String_list_ptr
375 script_new_string_list(const char*, size_t);
377 /* Add an element to a list of strings. */
379 extern String_list_ptr
380 script_string_list_push_back(String_list_ptr, const char*, size_t);
382 /* Concatenate two string lists. */
384 extern String_list_ptr
385 script_string_list_append(String_list_ptr, String_list_ptr);
387 /* Define a new program header. */
389 extern void
390 script_add_phdr(void* closure, const char* name, size_t namelen,
391 unsigned int type, const struct Phdr_info*);
393 /* Convert a program header string to a type. */
395 extern unsigned int
396 script_phdr_string_to_type(void* closure, const char*, size_t);
398 /* Handle DATA_SEGMENT_ALIGN and DATA_SEGMENT_RELRO_END. */
400 extern void
401 script_data_segment_align(void* closure);
403 extern void
404 script_data_segment_relro_end(void* closure);
406 /* Record the fact that a SEGMENT_START expression is seen. */
408 extern void
409 script_saw_segment_start_expression(void* closure);
411 /* Called by the bison parser for expressions. */
413 extern Expression_ptr
414 script_exp_unary_minus(Expression_ptr);
415 extern Expression_ptr
416 script_exp_unary_logical_not(Expression_ptr);
417 extern Expression_ptr
418 script_exp_unary_bitwise_not(Expression_ptr);
419 extern Expression_ptr
420 script_exp_binary_mult(Expression_ptr, Expression_ptr);
421 extern Expression_ptr
422 script_exp_binary_div(Expression_ptr, Expression_ptr);
423 extern Expression_ptr
424 script_exp_binary_mod(Expression_ptr, Expression_ptr);
425 extern Expression_ptr
426 script_exp_binary_add(Expression_ptr, Expression_ptr);
427 extern Expression_ptr
428 script_exp_binary_sub(Expression_ptr, Expression_ptr);
429 extern Expression_ptr
430 script_exp_binary_lshift(Expression_ptr, Expression_ptr);
431 extern Expression_ptr
432 script_exp_binary_rshift(Expression_ptr, Expression_ptr);
433 extern Expression_ptr
434 script_exp_binary_eq(Expression_ptr, Expression_ptr);
435 extern Expression_ptr
436 script_exp_binary_ne(Expression_ptr, Expression_ptr);
437 extern Expression_ptr
438 script_exp_binary_le(Expression_ptr, Expression_ptr);
439 extern Expression_ptr
440 script_exp_binary_ge(Expression_ptr, Expression_ptr);
441 extern Expression_ptr
442 script_exp_binary_lt(Expression_ptr, Expression_ptr);
443 extern Expression_ptr
444 script_exp_binary_gt(Expression_ptr, Expression_ptr);
445 extern Expression_ptr
446 script_exp_binary_bitwise_and(Expression_ptr, Expression_ptr);
447 extern Expression_ptr
448 script_exp_binary_bitwise_xor(Expression_ptr, Expression_ptr);
449 extern Expression_ptr
450 script_exp_binary_bitwise_or(Expression_ptr, Expression_ptr);
451 extern Expression_ptr
452 script_exp_binary_logical_and(Expression_ptr, Expression_ptr);
453 extern Expression_ptr
454 script_exp_binary_logical_or(Expression_ptr, Expression_ptr);
455 extern Expression_ptr
456 script_exp_trinary_cond(Expression_ptr, Expression_ptr, Expression_ptr);
457 extern Expression_ptr
458 script_exp_integer(uint64_t);
459 extern Expression_ptr
460 script_exp_string(const char*, size_t);
461 extern Expression_ptr
462 script_exp_function_max(Expression_ptr, Expression_ptr);
463 extern Expression_ptr
464 script_exp_function_min(Expression_ptr, Expression_ptr);
465 extern Expression_ptr
466 script_exp_function_defined(const char*, size_t);
467 extern Expression_ptr
468 script_exp_function_sizeof_headers(void);
469 extern Expression_ptr
470 script_exp_function_alignof(const char*, size_t);
471 extern Expression_ptr
472 script_exp_function_sizeof(const char*, size_t);
473 extern Expression_ptr
474 script_exp_function_addr(const char*, size_t);
475 extern Expression_ptr
476 script_exp_function_loadaddr(const char*, size_t);
477 extern Expression_ptr
478 script_exp_function_origin(const char*, size_t);
479 extern Expression_ptr
480 script_exp_function_length(const char*, size_t);
481 extern Expression_ptr
482 script_exp_function_constant(const char*, size_t);
483 extern Expression_ptr
484 script_exp_function_absolute(Expression_ptr);
485 extern Expression_ptr
486 script_exp_function_align(Expression_ptr, Expression_ptr);
487 extern Expression_ptr
488 script_exp_function_data_segment_align(Expression_ptr, Expression_ptr);
489 extern Expression_ptr
490 script_exp_function_data_segment_relro_end(Expression_ptr, Expression_ptr);
491 extern Expression_ptr
492 script_exp_function_data_segment_end(Expression_ptr);
493 extern Expression_ptr
494 script_exp_function_segment_start(const char*, size_t, Expression_ptr);
495 extern Expression_ptr
496 script_exp_function_assert(Expression_ptr, const char*, size_t);
498 extern void
499 script_register_vers_node(void* closure,
500 const char* tag,
501 int taglen,
502 struct Version_tree *,
503 struct Version_dependency_list *);
505 extern struct Version_dependency_list *
506 script_add_vers_depend(void* closure,
507 struct Version_dependency_list *existing_dependencies,
508 const char *depend_to_add, int deplen);
510 extern struct Version_expression_list *
511 script_new_vers_pattern(void* closure,
512 struct Version_expression_list *,
513 const char *, int, int);
515 extern struct Version_expression_list *
516 script_merge_expressions(struct Version_expression_list *a,
517 struct Version_expression_list *b);
519 extern struct Version_tree *
520 script_new_vers_node(void* closure,
521 struct Version_expression_list *global,
522 struct Version_expression_list *local);
524 extern void
525 version_script_push_lang(void* closure, const char* lang, int langlen);
527 extern void
528 version_script_pop_lang(void* closure);
530 #ifdef __cplusplus
531 } // End extern "C"
532 #endif
534 #ifdef __cplusplus
535 } // End namespace gold.
536 #endif
538 #endif /* !defined(GOLD_SCRIPT_C_H) */