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