PR gas/11973
[deliverable/binutils-gdb.git] / gold / script-c.h
CommitLineData
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
40namespace gold
41{
dbe717ef
ILT
42#endif
43
e5756efb
ILT
44/* A string value for the bison parser. */
45
46struct 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 58class Expression;
494e05f4 59typedef Expression* Expression_ptr;
e5756efb
ILT
60#else
61typedef void* Expression_ptr;
62#endif
63
1e5d2fb1
DK
64/* Script_section type. */
65enum Script_section_type
66{
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
74};
75
3802b2dd
ILT
76/* A constraint for whether to use a particular output section
77 definition. */
78
79enum Section_constraint
80{
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
89};
90
494e05f4
ILT
91/* The information we store for an output section header in the bison
92 parser. */
93
94struct Parser_output_section_header
95{
96 /* The address. This may be NULL. */
97 Expression_ptr address;
1e5d2fb1
DK
98 /* Section type. May be NULL string. */
99 enum Script_section_type section_type;
494e05f4
ILT
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;
3802b2dd
ILT
107 /* A constraint on this output section. */
108 enum Section_constraint constraint;
494e05f4
ILT
109};
110
494e05f4
ILT
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. */
114
115#ifdef __cplusplus
116typedef std::vector<std::string> String_list;
117typedef String_list* String_list_ptr;
118#else
119typedef void* String_list_ptr;
120#endif
121
1c4f3631
ILT
122/* The information we store for an output section trailer in the bison
123 parser. */
124
125struct Parser_output_section_trailer
126{
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;
132};
133
494e05f4
ILT
134/* The different sorts we can find in a linker script. */
135
136enum Sort_wildcard
137{
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
143};
144
145/* The information we build for a single wildcard specification. */
146
147struct Wildcard_section
148{
149 /* The wildcard spec itself. */
150 struct Parser_string name;
151 /* How the entries should be sorted. */
152 enum Sort_wildcard sort;
153};
154
155/* A vector of Wildcard_section entries. */
156
157#ifdef __cplusplus
158typedef std::vector<Wildcard_section> String_sort_list;
159typedef String_sort_list* String_sort_list_ptr;
160#else
161typedef void* String_sort_list_ptr;
162#endif
163
164/* A list of wildcard specifications, which may include EXCLUDE_FILE
165 clauses. */
166
167struct Wildcard_sections
168{
169 /* Wildcard specs. */
170 String_sort_list_ptr sections;
171 /* Exclusions. */
172 String_list_ptr exclude;
173};
174
175/* A complete input section specification. */
176
177struct Input_section_spec
178{
179 /* The file name. */
180 struct Wildcard_section file;
181 /* The list of sections. */
182 struct Wildcard_sections input_sections;
183};
184
1c4f3631
ILT
185/* Information for a program header. */
186
187struct Phdr_info
188{
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;
199};
200
494e05f4
ILT
201struct Version_dependency_list;
202struct Version_expression_list;
203struct Version_tree;
204
205#ifdef __cplusplus
206extern "C" {
207#endif
208
e5756efb
ILT
209/* The bison parser definitions. */
210
dbe717ef
ILT
211#include "yyscript.h"
212
213/* The bison parser function. */
214
215extern int
216yyparse(void* closure);
217
218/* Called by the bison parser skeleton to return the next token. */
219
220extern int
221yylex(YYSTYPE*, void* closure);
222
223/* Called by the bison parser skeleton to report an error. */
224
225extern void
226yyerror(void* closure, const char*);
227
afc06bb8
ILT
228/* Called by the bison parser to add an external symbol (a symbol in
229 an EXTERN declaration) to the link. */
230
231extern void
232script_add_extern(void* closure, const char*, size_t);
233
dbe717ef
ILT
234/* Called by the bison parser to add a file to the link. */
235
236extern void
e5756efb 237script_add_file(void* closure, const char*, size_t);
dbe717ef 238
e1df38aa
NC
239/* Called by the bison parser to add a library to the link. */
240
241extern void
242script_add_library(void* closure, const char*, size_t);
243
dbe717ef
ILT
244/* Called by the bison parser to start and stop a group. */
245
246extern void
247script_start_group(void* closure);
248extern void
249script_end_group(void* closure);
250
251/* Called by the bison parser to start and end an AS_NEEDED list. */
252
253extern void
254script_start_as_needed(void* closure);
255extern void
256script_end_as_needed(void* closure);
257
d391083d
ILT
258/* Called by the bison parser to set the entry symbol. */
259
260extern void
e5756efb 261script_set_entry(void* closure, const char*, size_t);
d391083d 262
0dfbdef4
ILT
263/* Called by the bison parser to set whether to define common symbols. */
264
265extern void
266script_set_common_allocation(void* closure, int);
267
195e7dc6 268/* Called by the bison parser to parse an OPTION. */
e5756efb
ILT
269
270extern void
271script_parse_option(void* closure, const char*, size_t);
272
15f8229b
ILT
273/* Called by the bison parser to handle OUTPUT_FORMAT. This return 0
274 if the parse should be aborted. */
275
276extern int
277script_check_output_format(void* closure, const char*, size_t,
278 const char*, size_t, const char*, size_t);
279
e6a307ba
ILT
280/* Called by the bison parser to handle TARGET. */
281extern void
282script_set_target(void* closure, const char*, size_t);
283
3802b2dd
ILT
284/* Called by the bison parser to handle SEARCH_DIR. */
285
286extern void
287script_add_search_dir(void* closure, const char*, size_t);
288
e5756efb
ILT
289/* Called by the bison parser to push the lexer into expression
290 mode. */
291
292extern void
293script_push_lex_into_expression_mode(void* closure);
294
09124467
ILT
295/* Called by the bison parser to push the lexer into version
296 mode. */
297
298extern void
299script_push_lex_into_version_mode(void* closure);
300
e5756efb
ILT
301/* Called by the bison parser to pop the lexer mode. */
302
303extern void
304script_pop_lex_mode(void* closure);
305
88a4108b
ILT
306/* Called by the bison parser to get the value of a symbol. This is
307 called for a reference to a symbol, but is not called for something
308 like "sym += 10". Uses of the special symbol "." can just call
309 script_exp_string. */
310
311extern Expression_ptr
312script_symbol(void* closure, const char*, size_t);
313
e5756efb
ILT
314/* Called by the bison parser to set a symbol to a value. PROVIDE is
315 non-zero if the symbol should be provided--only defined if there is
316 an undefined reference. HIDDEN is non-zero if the symbol should be
317 hidden. */
318
195e7dc6 319extern void
e5756efb
ILT
320script_set_symbol(void* closure, const char*, size_t, Expression_ptr,
321 int provide, int hidden);
322
494e05f4
ILT
323/* Called by the bison parser to add an assertion. */
324
325extern void
326script_add_assertion(void* closure, Expression_ptr, const char* message,
327 size_t messagelen);
328
329/* Called by the bison parser to start a SECTIONS clause. */
330
331extern void
332script_start_sections(void* closure);
333
334/* Called by the bison parser to finish a SECTIONS clause. */
335
336extern void
337script_finish_sections(void* closure);
338
339/* Called by the bison parser to start handling input section
340 specifications for an output section. */
341
342extern void
343script_start_output_section(void* closure, const char* name, size_t namelen,
344 const struct Parser_output_section_header*);
345
346/* Called by the bison parser when done handling input section
347 specifications for an output section. */
348
349extern void
350script_finish_output_section(void* closure,
351 const struct Parser_output_section_trailer*);
352
353/* Called by the bison parser to handle a data statement (LONG, BYTE,
354 etc.) in an output section. */
355
356extern void
357script_add_data(void* closure, int data_token, Expression_ptr val);
358
359/* Called by the bison parser to set the fill value in an output
360 section. */
361
362extern void
363script_add_fill(void* closure, Expression_ptr val);
364
365/* Called by the bison parser to add an input section specification to
366 an output section. The KEEP parameter is non-zero if this is
367 within a KEEP clause, meaning that the garbage collector should not
368 discard it. */
369
370extern void
371script_add_input_section(void* closure, const struct Input_section_spec*,
372 int keep);
373
374/* Create a new list of string and sort entries. */
375
376extern String_sort_list_ptr
377script_new_string_sort_list(const struct Wildcard_section*);
378
379/* Add an entry to a list of string and sort entries. */
380
381extern String_sort_list_ptr
382script_string_sort_list_add(String_sort_list_ptr,
383 const struct Wildcard_section*);
384
385/* Create a new list of strings. */
386
387extern String_list_ptr
388script_new_string_list(const char*, size_t);
389
390/* Add an element to a list of strings. */
391
392extern String_list_ptr
393script_string_list_push_back(String_list_ptr, const char*, size_t);
394
395/* Concatenate two string lists. */
396
397extern String_list_ptr
398script_string_list_append(String_list_ptr, String_list_ptr);
399
1c4f3631
ILT
400/* Define a new program header. */
401
402extern void
403script_add_phdr(void* closure, const char* name, size_t namelen,
404 unsigned int type, const struct Phdr_info*);
405
406/* Convert a program header string to a type. */
407
408extern unsigned int
409script_phdr_string_to_type(void* closure, const char*, size_t);
410
2d924fd9
ILT
411/* Handle DATA_SEGMENT_ALIGN and DATA_SEGMENT_RELRO_END. */
412
413extern void
414script_data_segment_align(void* closure);
415
416extern void
417script_data_segment_relro_end(void* closure);
418
3c12dcdb
DK
419/* Record the fact that a SEGMENT_START expression is seen. */
420
421extern void
422script_saw_segment_start_expression(void* closure);
423
e5756efb
ILT
424/* Called by the bison parser for expressions. */
425
426extern Expression_ptr
427script_exp_unary_minus(Expression_ptr);
428extern Expression_ptr
429script_exp_unary_logical_not(Expression_ptr);
430extern Expression_ptr
431script_exp_unary_bitwise_not(Expression_ptr);
432extern Expression_ptr
433script_exp_binary_mult(Expression_ptr, Expression_ptr);
434extern Expression_ptr
435script_exp_binary_div(Expression_ptr, Expression_ptr);
436extern Expression_ptr
437script_exp_binary_mod(Expression_ptr, Expression_ptr);
438extern Expression_ptr
439script_exp_binary_add(Expression_ptr, Expression_ptr);
440extern Expression_ptr
441script_exp_binary_sub(Expression_ptr, Expression_ptr);
442extern Expression_ptr
443script_exp_binary_lshift(Expression_ptr, Expression_ptr);
444extern Expression_ptr
445script_exp_binary_rshift(Expression_ptr, Expression_ptr);
446extern Expression_ptr
447script_exp_binary_eq(Expression_ptr, Expression_ptr);
448extern Expression_ptr
449script_exp_binary_ne(Expression_ptr, Expression_ptr);
450extern Expression_ptr
451script_exp_binary_le(Expression_ptr, Expression_ptr);
452extern Expression_ptr
453script_exp_binary_ge(Expression_ptr, Expression_ptr);
454extern Expression_ptr
455script_exp_binary_lt(Expression_ptr, Expression_ptr);
456extern Expression_ptr
457script_exp_binary_gt(Expression_ptr, Expression_ptr);
458extern Expression_ptr
459script_exp_binary_bitwise_and(Expression_ptr, Expression_ptr);
460extern Expression_ptr
461script_exp_binary_bitwise_xor(Expression_ptr, Expression_ptr);
462extern Expression_ptr
463script_exp_binary_bitwise_or(Expression_ptr, Expression_ptr);
464extern Expression_ptr
465script_exp_binary_logical_and(Expression_ptr, Expression_ptr);
466extern Expression_ptr
467script_exp_binary_logical_or(Expression_ptr, Expression_ptr);
468extern Expression_ptr
469script_exp_trinary_cond(Expression_ptr, Expression_ptr, Expression_ptr);
470extern Expression_ptr
471script_exp_integer(uint64_t);
472extern Expression_ptr
473script_exp_string(const char*, size_t);
474extern Expression_ptr
475script_exp_function_max(Expression_ptr, Expression_ptr);
476extern Expression_ptr
477script_exp_function_min(Expression_ptr, Expression_ptr);
478extern Expression_ptr
479script_exp_function_defined(const char*, size_t);
480extern Expression_ptr
494e05f4 481script_exp_function_sizeof_headers(void);
e5756efb
ILT
482extern Expression_ptr
483script_exp_function_alignof(const char*, size_t);
484extern Expression_ptr
485script_exp_function_sizeof(const char*, size_t);
486extern Expression_ptr
487script_exp_function_addr(const char*, size_t);
488extern Expression_ptr
489script_exp_function_loadaddr(const char*, size_t);
490extern Expression_ptr
491script_exp_function_origin(const char*, size_t);
492extern Expression_ptr
493script_exp_function_length(const char*, size_t);
494extern Expression_ptr
495script_exp_function_constant(const char*, size_t);
496extern Expression_ptr
497script_exp_function_absolute(Expression_ptr);
498extern Expression_ptr
499script_exp_function_align(Expression_ptr, Expression_ptr);
500extern Expression_ptr
501script_exp_function_data_segment_align(Expression_ptr, Expression_ptr);
502extern Expression_ptr
503script_exp_function_data_segment_relro_end(Expression_ptr, Expression_ptr);
504extern Expression_ptr
505script_exp_function_data_segment_end(Expression_ptr);
506extern Expression_ptr
507script_exp_function_segment_start(const char*, size_t, Expression_ptr);
508extern Expression_ptr
509script_exp_function_assert(Expression_ptr, const char*, size_t);
195e7dc6 510
09124467
ILT
511extern void
512script_register_vers_node(void* closure,
513 const char* tag,
514 int taglen,
ca09d69a
NC
515 struct Version_tree*,
516 struct Version_dependency_list*);
09124467 517
ca09d69a 518extern struct Version_dependency_list*
09124467 519script_add_vers_depend(void* closure,
ca09d69a
NC
520 struct Version_dependency_list* existing_dependencies,
521 const char* depend_to_add, int deplen);
09124467 522
ca09d69a 523extern struct Version_expression_list*
09124467 524script_new_vers_pattern(void* closure,
ca09d69a
NC
525 struct Version_expression_list*,
526 const char*, int, int);
10600224 527
ca09d69a
NC
528extern struct Version_expression_list*
529script_merge_expressions(struct Version_expression_list* a,
530 struct Version_expression_list* b);
09124467 531
ca09d69a 532extern struct Version_tree*
09124467 533script_new_vers_node(void* closure,
ca09d69a
NC
534 struct Version_expression_list* global,
535 struct Version_expression_list* local);
09124467
ILT
536
537extern void
538version_script_push_lang(void* closure, const char* lang, int langlen);
539
540extern void
541version_script_pop_lang(void* closure);
542
dbe717ef 543#ifdef __cplusplus
494e05f4
ILT
544} // End extern "C"
545#endif
546
547#ifdef __cplusplus
548} // End namespace gold.
dbe717ef
ILT
549#endif
550
551#endif /* !defined(GOLD_SCRIPT_C_H) */
This page took 0.249539 seconds and 4 git commands to generate.