1 /* yyscript.y -- linker script grammar for gold. */
3 /* Copyright (C) 2006-2024 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 is a bison grammar to parse a subset of the original GNU ld
24 linker script language. */
29 #include "diagnostics.h"
38 DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE
42 /* We need to use a pure parser because we might be multi-threaded.
43 We pass some arguments through the parser to the lexer. */
47 %parse
-param
{void* closure
}
48 %lex
-param
{void* closure
}
50 /* Since we require bison anyhow, we take advantage of it. */
54 /* The values associated with tokens. */
58 struct Parser_string
string;
63 /* An output section header. */
64 struct Parser_output_section_header output_section_header
;
65 /* An output section trailer. */
66 struct Parser_output_section_trailer output_section_trailer
;
67 /* A section constraint. */
68 enum Section_constraint constraint
;
69 /* A complete input section specification. */
70 struct Input_section_spec input_section_spec
;
71 /* A list of wildcard specifications, with exclusions. */
72 struct Wildcard_sections wildcard_sections
;
73 /* A single wildcard specification. */
74 struct Wildcard_section wildcard_section
;
75 /* A list of strings. */
76 String_list_ptr string_list
;
77 /* Information for a program header. */
78 struct Phdr_info phdr_info
;
79 /* Used for version scripts and within VERSION {}. */
80 struct Version_dependency_list
* deplist
;
81 struct Version_expression_list
* versyms
;
82 struct Version_tree
* versnode
;
83 enum Script_section_type section_type
;
86 /* Operators, including a precedence table for expressions. */
88 %right PLUSEQ MINUSEQ MULTEQ DIVEQ
'=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
101 /* A fake operator used to indicate unary operator precedence. */
106 %token
<string> STRING
107 %token
<string> QUOTED_STRING
108 %token
<integer
> INTEGER
110 /* Keywords. This list is taken from ldgram.y and ldlex.l in the old
111 GNU linker, with the keywords which only appear in MRI mode
112 removed. Not all these keywords are actually used in this grammar.
113 In most cases the keyword is recognized as the token name in upper
114 case. The comments indicate where this is not the case. */
118 %token ALIGN_K
/* ALIGN */
120 %token ASSERT_K
/* ASSERT */
129 %token CREATE_OBJECT_SYMBOLS
130 %token DATA_SEGMENT_ALIGN
131 %token DATA_SEGMENT_END
132 %token DATA_SEGMENT_RELRO_END
140 %token FORCE_COMMON_ALLOCATION
141 %token GLOBAL
/* global */
146 %token INHIBIT_COMMON_ALLOCATION
151 %token LENGTH
/* LENGTH, l, len */
153 %token LOCAL
/* local */
156 %token MAX_K
/* MAX */
158 %token MIN_K
/* MIN */
166 %token ORIGIN
/* ORIGIN, o, org */
173 %token PROVIDE_HIDDEN
180 %token SIZEOF_HEADERS
/* SIZEOF_HEADERS, sizeof_headers */
181 %token SORT_BY_ALIGNMENT
182 %token SORT_BY_INIT_PRIORITY
189 %token TARGET_K
/* TARGET */
191 %token VERSIONK
/* VERSION */
193 /* Keywords, part 2. These are keywords that are unique to gold,
194 and not present in the old GNU linker. As before, unless the
195 comments say otherwise, the keyword is recognized as the token
196 name in upper case. */
200 /* Special tokens used to tell the grammar what type of tokens we are
201 parsing. The token stream always begins with one of these tokens.
202 We do this because version scripts can appear embedded within
203 linker scripts, and because --defsym uses the expression
205 %token PARSING_LINKER_SCRIPT
206 %token PARSING_VERSION_SCRIPT
207 %token PARSING_DEFSYM
208 %token PARSING_DYNAMIC_LIST
209 %token PARSING_SECTIONS_BLOCK
210 %token PARSING_SECTION_COMMANDS
211 %token PARSING_MEMORY_DEF
213 /* Non-terminal types, where needed. */
215 %type
<expr
> parse_exp exp
216 %type
<expr
> opt_at opt_align opt_subalign opt_fill
217 %type
<output_section_header
> section_header opt_address_and_section_type
218 %type
<section_type
> section_type
219 %type
<output_section_trailer
> section_trailer
220 %type
<constraint
> opt_constraint
221 %type
<string_list
> opt_phdr
222 %type
<integer
> data_length
223 %type
<input_section_spec
> input_section_no_keep
224 %type
<wildcard_sections
> wildcard_sections
225 %type
<wildcard_section
> wildcard_file wildcard_section
226 %type
<string_list
> exclude_names
227 %type
<string> wildcard_name
228 %type
<integer
> phdr_type memory_attr
229 %type
<phdr_info
> phdr_info
230 %type
<versyms
> vers_defns
231 %type
<versnode
> vers_tag
232 %type
<deplist
> verdep
233 %type
<string> string
237 /* Read the special token to see what to read next. */
239 PARSING_LINKER_SCRIPT linker_script
240 | PARSING_VERSION_SCRIPT version_script
241 | PARSING_DEFSYM defsym_expr
242 | PARSING_DYNAMIC_LIST dynamic_list_expr
243 | PARSING_SECTIONS_BLOCK sections_block
244 | PARSING_SECTION_COMMANDS section_cmds
245 | PARSING_MEMORY_DEF memory_defs
248 /* A file contains a list of commands. */
250 linker_script file_cmd
254 /* A command which may appear at top level of a linker script. */
256 EXTERN
'(' extern_name_list
')'
257 | FORCE_COMMON_ALLOCATION
258 { script_set_common_allocation
(closure
, 1); }
260 { script_start_group
(closure
); }
262 { script_end_group
(closure
); }
263 | INHIBIT_COMMON_ALLOCATION
264 { script_set_common_allocation
(closure
, 0); }
265 | INPUT
'(' input_list
')'
266 | MEMORY
'{' memory_defs
'}'
267 | OPTION
'(' string ')'
268 { script_parse_option
(closure
, $3.value
, $3.length
); }
269 | OUTPUT_FORMAT
'(' string ')'
271 if
(!script_check_output_format
(closure
, $3.value
, $3.length
,
275 | OUTPUT_FORMAT
'(' string ',' string ',' string ')'
277 if
(!script_check_output_format
(closure
, $3.value
, $3.length
,
279 $7.value
, $7.length
))
282 | PHDRS
'{' phdrs_defs
'}'
283 | SEARCH_DIR
'(' string ')'
284 { script_add_search_dir
(closure
, $3.value
, $3.length
); }
286 { script_start_sections
(closure
); }
288 { script_finish_sections
(closure
); }
289 | TARGET_K
'(' string ')'
290 { script_set_target
(closure
, $3.value
, $3.length
); }
292 { script_push_lex_into_version_mode
(closure
); }
294 { script_pop_lex_mode
(closure
); }
295 | ENTRY
'(' string ')'
296 { script_set_entry
(closure
, $3.value
, $3.length
); }
298 | ASSERT_K
'(' parse_exp
',' string ')'
299 { script_add_assertion
(closure
, $3, $5.value
, $5.length
); }
301 { script_include_directive
(PARSING_LINKER_SCRIPT
, closure
,
302 $2.value
, $2.length
); }
307 /* Top level commands which we ignore. The GNU linker uses these to
308 select the output format, but we don't offer a choice. Ignoring
309 these is more-or-less OK since most scripts simply explicitly
310 choose the default. */
312 OUTPUT_ARCH
'(' string ')'
315 /* A list of external undefined symbols. We put the lexer into
316 expression mode so that commas separate names; this is what the GNU
320 { script_push_lex_into_expression_mode
(closure
); }
321 extern_name_list_body
322 { script_pop_lex_mode
(closure
); }
325 extern_name_list_body:
327 { script_add_extern
(closure
, $1.value
, $1.length
); }
328 | extern_name_list_body
string
329 { script_add_extern
(closure
, $2.value
, $2.length
); }
330 | extern_name_list_body
',' string
331 { script_add_extern
(closure
, $3.value
, $3.length
); }
334 /* A list of input file names. */
337 | input_list opt_comma input_list_element
340 /* An input file name. */
343 { script_add_file
(closure
, $1.value
, $1.length
); }
345 { script_add_library
(closure
, $2.value
, $2.length
); }
347 { script_start_as_needed
(closure
); }
349 { script_end_as_needed
(closure
); }
352 /* Commands in a SECTIONS block. */
354 sections_block section_block_cmd
358 /* A command which may appear within a SECTIONS block. */
361 { script_set_entry
(closure
, $3.value
, $3.length
); }
363 | ASSERT_K
'(' parse_exp
',' string ')'
364 { script_add_assertion
(closure
, $3, $5.value
, $5.length
); }
366 { script_include_directive
(PARSING_SECTIONS_BLOCK
, closure
,
367 $2.value
, $2.length
); }
368 |
string section_header
369 { script_start_output_section
(closure
, $1.value
, $1.length
, &$2); }
370 '{' section_cmds
'}' section_trailer
371 { script_finish_output_section
(closure
, &$7); }
374 /* The header of an output section in a SECTIONS block--everything
377 { script_push_lex_into_expression_mode
(closure
); }
378 opt_address_and_section_type opt_at opt_align opt_subalign
379 { script_pop_lex_mode
(closure
); }
382 $$.address
= $2.address
;
383 $$.section_type
= $2.section_type
;
384 $$.load_address
= $3;
391 /* The optional address followed by the optional section type. This
392 is a separate nonterminal to avoid a shift/reduce conflict on
393 '(' in section_header. */
395 opt_address_and_section_type:
399 $$.section_type
= SCRIPT_SECTION_TYPE_NONE
;
404 $$.section_type
= SCRIPT_SECTION_TYPE_NONE
;
409 $$.section_type
= SCRIPT_SECTION_TYPE_NONE
;
414 $$.section_type
= SCRIPT_SECTION_TYPE_NONE
;
416 |
'(' section_type
')' ':'
419 $$.section_type
= $2;
421 | exp
'(' section_type
')' ':'
424 $$.section_type
= $3;
428 /* We only support NOLOAD. */
431 { $$
= SCRIPT_SECTION_TYPE_NOLOAD
; }
434 yyerror(closure
, "DSECT section type is unsupported");
435 $$
= SCRIPT_SECTION_TYPE_DSECT
;
439 yyerror(closure
, "COPY section type is unsupported");
440 $$
= SCRIPT_SECTION_TYPE_COPY
;
444 yyerror(closure
, "INFO section type is unsupported");
445 $$
= SCRIPT_SECTION_TYPE_INFO
;
449 yyerror(closure
, "OVERLAY section type is unsupported");
450 $$
= SCRIPT_SECTION_TYPE_OVERLAY
;
454 /* The address at which an output section should be loaded. */
462 /* The alignment of an output section. */
466 | ALIGN_K
'(' exp
')'
470 /* The input section alignment within an output section. */
474 | SUBALIGN
'(' exp
')'
478 /* A section constraint. */
481 { $$
= CONSTRAINT_NONE
; }
483 { $$
= CONSTRAINT_ONLY_IF_RO
; }
485 { $$
= CONSTRAINT_ONLY_IF_RW
; }
487 { $$
= CONSTRAINT_SPECIAL
; }
490 /* The trailer of an output section in a SECTIONS block. */
492 opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
499 /* A memory specification for an output section. */
502 { script_set_section_region
(closure
, $2.value
, $2.length
, 1); }
506 /* A memory specification for where to load an output section. */
509 { script_set_section_region
(closure
, $3.value
, $3.length
, 0); }
513 /* The program segment an output section should go into. */
516 { $$
= script_string_list_push_back
($1, $3.value
, $3.length
); }
521 /* The value to use to fill an output section. FIXME: This does not
522 handle a string of arbitrary length. */
530 /* Commands which may appear within the description of an output
531 section in a SECTIONS block. */
534 | section_cmds section_cmd
537 /* A command which may appear within the description of an output
538 section in a SECTIONS block. */
542 | data_length
'(' parse_exp
')'
543 { script_add_data
(closure
, $1, $3); }
544 | ASSERT_K
'(' parse_exp
',' string ')'
545 { script_add_assertion
(closure
, $3, $5.value
, $5.length
); }
546 | FILL
'(' parse_exp
')'
547 { script_add_fill
(closure
, $3); }
550 /* The GNU linker uses CONSTRUCTORS for the a.out object
551 file format. It does nothing when using ELF. Since
552 some ELF linker scripts use it although it does
553 nothing, we accept it and ignore it. */
555 | SORT_BY_NAME
'(' CONSTRUCTORS
')'
557 { script_include_directive
(PARSING_SECTION_COMMANDS
, closure
,
558 $2.value
, $2.length
); }
562 /* The length of data which may appear within the description of an
563 output section in a SECTIONS block. */
577 /* An input section specification. This may appear within the
578 description of an output section in a SECTIONS block. */
580 input_section_no_keep
581 { script_add_input_section
(closure
, &$1, 0); }
582 | KEEP
'(' input_section_no_keep
')'
583 { script_add_input_section
(closure
, &$3, 1); }
586 /* An input section specification within a KEEP clause. */
587 input_section_no_keep:
591 $$.file.sort
= SORT_WILDCARD_NONE
;
592 $$.input_sections.sections
= NULL
;
593 $$.input_sections.exclude
= NULL
;
595 | wildcard_file
'(' wildcard_sections
')'
598 $$.input_sections
= $3;
602 /* A wildcard file specification. */
607 $$.sort
= SORT_WILDCARD_NONE
;
609 | SORT_BY_NAME
'(' wildcard_name
')'
612 $$.sort
= SORT_WILDCARD_BY_NAME
;
616 /* A list of wild card section specifications. */
618 wildcard_sections opt_comma wildcard_section
620 $$.sections
= script_string_sort_list_add
($1.sections
, &$3);
621 $$.exclude
= $1.exclude
;
625 $$.sections
= script_new_string_sort_list
(&$1);
628 | wildcard_sections opt_comma EXCLUDE_FILE
'(' exclude_names
')'
630 $$.sections
= $1.sections
;
631 $$.exclude
= script_string_list_append
($1.exclude
, $5);
633 | EXCLUDE_FILE
'(' exclude_names
')'
640 /* A single wild card specification. */
645 $$.sort
= SORT_WILDCARD_NONE
;
647 | SORT_BY_NAME
'(' wildcard_section
')'
652 case SORT_WILDCARD_NONE
:
653 $$.sort
= SORT_WILDCARD_BY_NAME
;
655 case SORT_WILDCARD_BY_NAME
:
656 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT
:
658 case SORT_WILDCARD_BY_ALIGNMENT
:
659 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME
:
660 $$.sort
= SORT_WILDCARD_BY_NAME_BY_ALIGNMENT
;
666 | SORT_BY_ALIGNMENT
'(' wildcard_section
')'
671 case SORT_WILDCARD_NONE
:
672 $$.sort
= SORT_WILDCARD_BY_ALIGNMENT
;
674 case SORT_WILDCARD_BY_ALIGNMENT
:
675 case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME
:
677 case SORT_WILDCARD_BY_NAME
:
678 case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT
:
679 $$.sort
= SORT_WILDCARD_BY_ALIGNMENT_BY_NAME
;
685 | SORT_BY_INIT_PRIORITY
'(' wildcard_name
')'
688 $$.sort
= SORT_WILDCARD_BY_INIT_PRIORITY
;
692 /* A list of file names to exclude. */
694 exclude_names opt_comma wildcard_name
695 { $$
= script_string_list_push_back
($1, $3.value
, $3.length
); }
697 { $$
= script_new_string_list
($1.value
, $1.length
); }
700 /* A single wildcard name. We recognize '*' and '?' specially since
701 they are expression tokens. */
717 /* A list of MEMORY definitions. */
719 memory_defs opt_comma memory_def
723 /* A single MEMORY definition. */
725 string memory_attr
':' memory_origin
'=' parse_exp opt_comma memory_length
'=' parse_exp
726 { script_add_memory
(closure
, $1.value
, $1.length
, $2, $6, $10); }
729 { script_include_directive
(PARSING_MEMORY_DEF
, closure
,
730 $2.value
, $2.length
); }
734 /* The (optional) attributes of a MEMORY region. */
737 { $$
= script_parse_memory_attr
(closure
, $2.value
, $2.length
, 0); }
738 |
/* Inverted attributes. */
740 { $$
= script_parse_memory_attr
(closure
, $3.value
, $3.length
, 1); }
761 /* A list of program header definitions. */
767 /* A program header definition. */
769 string phdr_type phdr_info
';'
770 { script_add_phdr
(closure
, $1.value
, $1.length
, $2, &$3); }
773 /* A program header type. The GNU linker accepts a general expression
774 here, but that would be a pain because we would have to dig into
775 the expression structure. It's unlikely that anybody uses anything
776 other than a string or a number here, so that is all we expect. */
779 { $$
= script_phdr_string_to_type
(closure
, $1.value
, $1.length
); }
784 /* Additional information for a program header. */
787 { memset
(&$$
, 0, sizeof
(struct Phdr_info
)); }
791 if
($1.length
== 7 && strncmp
($1.value
, "FILEHDR", 7) == 0)
792 $$.includes_filehdr
= 1;
794 yyerror(closure
, "PHDRS syntax error");
799 $$.includes_phdrs
= 1;
801 |
string '(' INTEGER
')' phdr_info
804 if
($1.length
== 5 && strncmp
($1.value
, "FLAGS", 5) == 0)
806 $$.is_flags_valid
= 1;
810 yyerror(closure
, "PHDRS syntax error");
812 | AT
'(' parse_exp
')' phdr_info
815 $$.load_address
= $3;
819 /* Set a symbol to a value. */
822 { script_set_symbol
(closure
, $1.value
, $1.length
, $3, 0, 0); }
823 |
string PLUSEQ parse_exp
825 Expression_ptr s
= script_exp_string
($1.value
, $1.length
);
826 Expression_ptr e
= script_exp_binary_add
(s
, $3);
827 script_set_symbol
(closure
, $1.value
, $1.length
, e
, 0, 0);
829 |
string MINUSEQ parse_exp
831 Expression_ptr s
= script_exp_string
($1.value
, $1.length
);
832 Expression_ptr e
= script_exp_binary_sub
(s
, $3);
833 script_set_symbol
(closure
, $1.value
, $1.length
, e
, 0, 0);
835 |
string MULTEQ parse_exp
837 Expression_ptr s
= script_exp_string
($1.value
, $1.length
);
838 Expression_ptr e
= script_exp_binary_mult
(s
, $3);
839 script_set_symbol
(closure
, $1.value
, $1.length
, e
, 0, 0);
841 |
string DIVEQ parse_exp
843 Expression_ptr s
= script_exp_string
($1.value
, $1.length
);
844 Expression_ptr e
= script_exp_binary_div
(s
, $3);
845 script_set_symbol
(closure
, $1.value
, $1.length
, e
, 0, 0);
847 |
string LSHIFTEQ parse_exp
849 Expression_ptr s
= script_exp_string
($1.value
, $1.length
);
850 Expression_ptr e
= script_exp_binary_lshift
(s
, $3);
851 script_set_symbol
(closure
, $1.value
, $1.length
, e
, 0, 0);
853 |
string RSHIFTEQ parse_exp
855 Expression_ptr s
= script_exp_string
($1.value
, $1.length
);
856 Expression_ptr e
= script_exp_binary_rshift
(s
, $3);
857 script_set_symbol
(closure
, $1.value
, $1.length
, e
, 0, 0);
859 |
string ANDEQ parse_exp
861 Expression_ptr s
= script_exp_string
($1.value
, $1.length
);
862 Expression_ptr e
= script_exp_binary_bitwise_and
(s
, $3);
863 script_set_symbol
(closure
, $1.value
, $1.length
, e
, 0, 0);
865 |
string OREQ parse_exp
867 Expression_ptr s
= script_exp_string
($1.value
, $1.length
);
868 Expression_ptr e
= script_exp_binary_bitwise_or
(s
, $3);
869 script_set_symbol
(closure
, $1.value
, $1.length
, e
, 0, 0);
871 | HIDDEN
'(' string '=' parse_exp
')'
872 { script_set_symbol
(closure
, $3.value
, $3.length
, $5, 0, 1); }
873 | PROVIDE
'(' string '=' parse_exp
')'
874 { script_set_symbol
(closure
, $3.value
, $3.length
, $5, 1, 0); }
875 | PROVIDE_HIDDEN
'(' string '=' parse_exp
')'
876 { script_set_symbol
(closure
, $3.value
, $3.length
, $5, 1, 1); }
879 /* Parse an expression, putting the lexer into the right mode. */
881 { script_push_lex_into_expression_mode
(closure
); }
884 script_pop_lex_mode
(closure
);
893 |
'-' exp %prec UNARY
894 { $$
= script_exp_unary_minus
($2); }
895 |
'!' exp %prec UNARY
896 { $$
= script_exp_unary_logical_not
($2); }
897 |
'~' exp %prec UNARY
898 { $$
= script_exp_unary_bitwise_not
($2); }
899 |
'+' exp %prec UNARY
902 { $$
= script_exp_binary_mult
($1, $3); }
904 { $$
= script_exp_binary_div
($1, $3); }
906 { $$
= script_exp_binary_mod
($1, $3); }
908 { $$
= script_exp_binary_add
($1, $3); }
910 { $$
= script_exp_binary_sub
($1, $3); }
912 { $$
= script_exp_binary_lshift
($1, $3); }
914 { $$
= script_exp_binary_rshift
($1, $3); }
916 { $$
= script_exp_binary_eq
($1, $3); }
918 { $$
= script_exp_binary_ne
($1, $3); }
920 { $$
= script_exp_binary_le
($1, $3); }
922 { $$
= script_exp_binary_ge
($1, $3); }
924 { $$
= script_exp_binary_lt
($1, $3); }
926 { $$
= script_exp_binary_gt
($1, $3); }
928 { $$
= script_exp_binary_bitwise_and
($1, $3); }
930 { $$
= script_exp_binary_bitwise_xor
($1, $3); }
932 { $$
= script_exp_binary_bitwise_or
($1, $3); }
934 { $$
= script_exp_binary_logical_and
($1, $3); }
936 { $$
= script_exp_binary_logical_or
($1, $3); }
937 | exp
'?' exp
':' exp
938 { $$
= script_exp_trinary_cond
($1, $3, $5); }
940 { $$
= script_exp_integer
($1); }
942 { $$
= script_symbol
(closure
, $1.value
, $1.length
); }
943 | MAX_K
'(' exp
',' exp
')'
944 { $$
= script_exp_function_max
($3, $5); }
945 | MIN_K
'(' exp
',' exp
')'
946 { $$
= script_exp_function_min
($3, $5); }
947 | DEFINED
'(' string ')'
948 { $$
= script_exp_function_defined
($3.value
, $3.length
); }
950 { $$
= script_exp_function_sizeof_headers
(); }
951 | ALIGNOF
'(' string ')'
952 { $$
= script_exp_function_alignof
($3.value
, $3.length
); }
953 | SIZEOF
'(' string ')'
954 { $$
= script_exp_function_sizeof
($3.value
, $3.length
); }
955 | ADDR
'(' string ')'
956 { $$
= script_exp_function_addr
($3.value
, $3.length
); }
957 | LOADADDR
'(' string ')'
958 { $$
= script_exp_function_loadaddr
($3.value
, $3.length
); }
959 | ORIGIN
'(' string ')'
960 { $$
= script_exp_function_origin
(closure
, $3.value
, $3.length
); }
961 | LENGTH
'(' string ')'
962 { $$
= script_exp_function_length
(closure
, $3.value
, $3.length
); }
963 | CONSTANT
'(' string ')'
964 { $$
= script_exp_function_constant
($3.value
, $3.length
); }
965 | ABSOLUTE
'(' exp
')'
966 { $$
= script_exp_function_absolute
($3); }
967 | ALIGN_K
'(' exp
')'
968 { $$
= script_exp_function_align
(script_exp_string
(".", 1), $3); }
969 | ALIGN_K
'(' exp
',' exp
')'
970 { $$
= script_exp_function_align
($3, $5); }
972 { $$
= script_exp_function_align
(script_exp_string
(".", 1), $3); }
973 | DATA_SEGMENT_ALIGN
'(' exp
',' exp
')'
975 script_data_segment_align
(closure
);
976 $$
= script_exp_function_data_segment_align
($3, $5);
978 | DATA_SEGMENT_RELRO_END
'(' exp
',' exp
')'
980 script_data_segment_relro_end
(closure
);
981 $$
= script_exp_function_data_segment_relro_end
($3, $5);
983 | DATA_SEGMENT_END
'(' exp
')'
984 { $$
= script_exp_function_data_segment_end
($3); }
985 | SEGMENT_START
'(' string ',' exp
')'
987 $$
= script_exp_function_segment_start
($3.value
, $3.length
, $5);
988 /* We need to take note of any SEGMENT_START expressions
989 because they change the behaviour of -Ttext, -Tdata and
991 script_saw_segment_start_expression
(closure
);
993 | ASSERT_K
'(' exp
',' string ')'
994 { $$
= script_exp_function_assert
($3, $5.value
, $5.length
); }
997 /* Handle the --defsym option. */
1000 { script_set_symbol
(closure
, $1.value
, $1.length
, $3, 0, 0); }
1003 /* Handle the --dynamic-list option. A dynamic list has the format
1004 { sym1; sym2; extern "C++" { namespace::sym3 }; };
1005 We store the symbol we see in the "local" list; that is where
1006 Command_line::in_dynamic_list() will look to do its check.
1007 TODO(csilvers): More than one of these brace-lists can appear, and
1008 should just be merged and treated as a single list. */
1009 dynamic_list_expr: dynamic_list_nodes
;
1013 | dynamic_list_nodes dynamic_list_node
1017 '{' vers_defns
';' '}' ';'
1018 { script_new_vers_node
(closure
, NULL
, $2); }
1021 /* A version script. */
1028 | vers_nodes vers_node
1032 '{' vers_tag
'}' ';'
1034 script_register_vers_node
(closure
, NULL
, 0, $2, NULL
);
1036 |
string '{' vers_tag
'}' ';'
1038 script_register_vers_node
(closure
, $1.value
, $1.length
, $3,
1041 |
string '{' vers_tag
'}' verdep
';'
1043 script_register_vers_node
(closure
, $1.value
, $1.length
, $3, $5);
1050 $$
= script_add_vers_depend
(closure
, NULL
, $1.value
, $1.length
);
1054 $$
= script_add_vers_depend
(closure
, $1, $2.value
, $2.length
);
1060 { $$
= script_new_vers_node
(closure
, NULL
, NULL
); }
1062 { $$
= script_new_vers_node
(closure
, $1, NULL
); }
1063 | GLOBAL
':' vers_defns
';'
1064 { $$
= script_new_vers_node
(closure
, $3, NULL
); }
1065 | LOCAL
':' vers_defns
';'
1066 { $$
= script_new_vers_node
(closure
, NULL
, $3); }
1067 | GLOBAL
':' vers_defns
';' LOCAL
':' vers_defns
';'
1068 { $$
= script_new_vers_node
(closure
, $3, $7); }
1071 /* Here is one of the rare places we care about the distinction
1072 between STRING and QUOTED_STRING. For QUOTED_STRING, we do exact
1073 matching on the pattern, so we pass in true for the exact_match
1074 parameter. For STRING, we do glob matching and pass in false. */
1078 $$
= script_new_vers_pattern
(closure
, NULL
, $1.value
,
1083 $$
= script_new_vers_pattern
(closure
, NULL
, $1.value
,
1086 | vers_defns
';' STRING
1088 $$
= script_new_vers_pattern
(closure
, $1, $3.value
,
1091 | vers_defns
';' QUOTED_STRING
1093 $$
= script_new_vers_pattern
(closure
, $1, $3.value
,
1096 |
/* Push string on the language stack. */
1098 { version_script_push_lang
(closure
, $2.value
, $2.length
); }
1099 vers_defns opt_semicolon
'}'
1102 version_script_pop_lang
(closure
);
1104 |
/* Push string on the language stack. This is more complicated
1105 than the other cases because we need to merge the linked-list
1106 state from the pre-EXTERN defns and the post-EXTERN defns. */
1107 vers_defns
';' EXTERN
string '{'
1108 { version_script_push_lang
(closure
, $4.value
, $4.length
); }
1109 vers_defns opt_semicolon
'}'
1111 $$
= script_merge_expressions
($1, $7);
1112 version_script_pop_lang
(closure
);
1114 | EXTERN
// "extern" as a symbol name
1116 $$
= script_new_vers_pattern
(closure
, NULL
, "extern",
1117 sizeof
("extern") - 1, 1);
1119 | vers_defns
';' EXTERN
1121 $$
= script_new_vers_pattern
(closure
, $1, "extern",
1122 sizeof
("extern") - 1, 1);
1126 /* A string can be either a STRING or a QUOTED_STRING. Almost all the
1127 time we don't care, and we use this rule. */
1135 /* Some statements require a terminator, which may be a semicolon or a
1142 /* An optional semicolon. */
1148 /* An optional comma. */