Commit | Line | Data |
---|---|---|
8e5a525c | 1 | /* A YACC grammar to parse a superset of the AT&T linker scripting language. |
82704155 | 2 | Copyright (C) 1991-2019 Free Software Foundation, Inc. |
252b5132 RH |
3 | Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com). |
4 | ||
f96b4a7b | 5 | This file is part of the GNU Binutils. |
252b5132 | 6 | |
3ec57632 NC |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
f96b4a7b | 9 | the Free Software Foundation; either version 3 of the License, or |
3ec57632 | 10 | (at your option) any later version. |
252b5132 | 11 | |
3ec57632 NC |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
252b5132 | 16 | |
3ec57632 NC |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
f96b4a7b NC |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | MA 02110-1301, USA. */ | |
252b5132 RH |
21 | |
22 | %{ | |
23 | /* | |
24 | ||
25 | */ | |
26 | ||
27 | #define DONTDECLARE_MALLOC | |
28 | ||
252b5132 | 29 | #include "sysdep.h" |
3db64b00 | 30 | #include "bfd.h" |
252b5132 | 31 | #include "bfdlink.h" |
1ff6de03 | 32 | #include "ctf-api.h" |
d038301c | 33 | #include "ld.h" |
252b5132 RH |
34 | #include "ldexp.h" |
35 | #include "ldver.h" | |
36 | #include "ldlang.h" | |
252b5132 | 37 | #include "ldfile.h" |
b71e2778 | 38 | #include "ldemul.h" |
252b5132 RH |
39 | #include "ldmisc.h" |
40 | #include "ldmain.h" | |
41 | #include "mri.h" | |
42 | #include "ldctor.h" | |
43 | #include "ldlex.h" | |
44 | ||
45 | #ifndef YYDEBUG | |
46 | #define YYDEBUG 1 | |
47 | #endif | |
48 | ||
49 | static enum section_type sectype; | |
279e75dc | 50 | static lang_memory_region_type *region; |
252b5132 | 51 | |
2b94abd4 AB |
52 | static bfd_boolean ldgram_had_keep = FALSE; |
53 | static char *ldgram_vers_current_lang = NULL; | |
252b5132 RH |
54 | |
55 | #define ERROR_NAME_MAX 20 | |
56 | static char *error_names[ERROR_NAME_MAX]; | |
57 | static int error_index; | |
58 | #define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++; | |
59 | #define POP_ERROR() error_index--; | |
60 | %} | |
61 | %union { | |
62 | bfd_vma integer; | |
2c382fb6 AM |
63 | struct big_int |
64 | { | |
65 | bfd_vma integer; | |
66 | char *str; | |
67 | } bigint; | |
68 | fill_type *fill; | |
252b5132 RH |
69 | char *name; |
70 | const char *cname; | |
71 | struct wildcard_spec wildcard; | |
b6bf44ba | 72 | struct wildcard_list *wildcard_list; |
18625d54 | 73 | struct name_list *name_list; |
ae17ab41 CM |
74 | struct flag_info_list *flag_info_list; |
75 | struct flag_info *flag_info; | |
252b5132 RH |
76 | int token; |
77 | union etree_union *etree; | |
78 | struct phdr_info | |
79 | { | |
b34976b6 AM |
80 | bfd_boolean filehdr; |
81 | bfd_boolean phdrs; | |
252b5132 RH |
82 | union etree_union *at; |
83 | union etree_union *flags; | |
84 | } phdr; | |
85 | struct lang_nocrossref *nocrossref; | |
86 | struct lang_output_section_phdr_list *section_phdr; | |
87 | struct bfd_elf_version_deps *deflist; | |
88 | struct bfd_elf_version_expr *versyms; | |
89 | struct bfd_elf_version_tree *versnode; | |
90 | } | |
91 | ||
92 | %type <etree> exp opt_exp_with_type mustbe_exp opt_at phdr_type phdr_val | |
bbf115d3 | 93 | %type <etree> opt_exp_without_type opt_subalign opt_align |
2c382fb6 | 94 | %type <fill> fill_opt fill_exp |
18625d54 | 95 | %type <name_list> exclude_name_list |
2b94abd4 | 96 | %type <wildcard_list> section_name_list |
ae17ab41 CM |
97 | %type <flag_info_list> sect_flag_list |
98 | %type <flag_info> sect_flags | |
252b5132 | 99 | %type <name> memspec_opt casesymlist |
562d3460 | 100 | %type <name> memspec_at_opt |
252b5132 | 101 | %type <cname> wildcard_name |
2b94abd4 | 102 | %type <wildcard> section_name_spec filename_spec wildcard_maybe_exclude |
d038301c | 103 | %token <bigint> INT |
252b5132 RH |
104 | %token <name> NAME LNAME |
105 | %type <integer> length | |
106 | %type <phdr> phdr_qualifiers | |
107 | %type <nocrossref> nocrossref_list | |
108 | %type <section_phdr> phdr_opt | |
109 | %type <integer> opt_nocrossrefs | |
110 | ||
d038301c | 111 | %right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ |
252b5132 RH |
112 | %right <token> '?' ':' |
113 | %left <token> OROR | |
114 | %left <token> ANDAND | |
115 | %left <token> '|' | |
116 | %left <token> '^' | |
117 | %left <token> '&' | |
118 | %left <token> EQ NE | |
119 | %left <token> '<' '>' LE GE | |
120 | %left <token> LSHIFT RSHIFT | |
121 | ||
122 | %left <token> '+' '-' | |
123 | %left <token> '*' '/' '%' | |
124 | ||
125 | %right UNARY | |
d038301c | 126 | %token END |
252b5132 RH |
127 | %left <token> '(' |
128 | %token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE | |
53d25da6 AM |
129 | %token SECTIONS PHDRS INSERT_K AFTER BEFORE |
130 | %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END | |
eda680f8 | 131 | %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE |
02ecc8e9 | 132 | %token SORT_BY_INIT_PRIORITY |
252b5132 RH |
133 | %token '{' '}' |
134 | %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH | |
7bdf4127 | 135 | %token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION |
ba916c8a | 136 | %token SEGMENT_START |
252b5132 | 137 | %token INCLUDE |
ed9ef263 | 138 | %token MEMORY |
4a93e180 | 139 | %token REGION_ALIAS |
01554a74 | 140 | %token LD_FEATURE |
252b5132 | 141 | %token NOLOAD DSECT COPY INFO OVERLAY |
ed9ef263 | 142 | %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY |
252b5132 | 143 | %token <integer> NEXT |
5d41b3ef | 144 | %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K |
cdf96953 | 145 | %token STARTUP HLL SYSLIB FLOAT NOFLOAT NOCROSSREFS NOCROSSREFS_TO |
252b5132 RH |
146 | %token ORIGIN FILL |
147 | %token LENGTH CREATE_OBJECT_SYMBOLS INPUT GROUP OUTPUT CONSTRUCTORS | |
eb8476a6 | 148 | %token ALIGNMOD AT SUBALIGN HIDDEN PROVIDE PROVIDE_HIDDEN AS_NEEDED |
1eec346e | 149 | %type <token> assign_op atype attributes_opt sect_constraint opt_align_with_input |
252b5132 RH |
150 | %type <name> filename |
151 | %token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD ASSERT_K | |
2e53f7d6 | 152 | %token LOG2CEIL FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE REL |
252b5132 RH |
153 | %token INPUT_SCRIPT INPUT_MRI_SCRIPT INPUT_DEFSYM CASE EXTERN START |
154 | %token <name> VERS_TAG VERS_IDENTIFIER | |
155 | %token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT | |
1eec346e | 156 | %token KEEP ONLY_IF_RO ONLY_IF_RW SPECIAL INPUT_SECTION_FLAGS ALIGN_WITH_INPUT |
252b5132 | 157 | %token EXCLUDE_FILE |
24718e3b | 158 | %token CONSTANT |
252b5132 RH |
159 | %type <versyms> vers_defns |
160 | %type <versnode> vers_tag | |
161 | %type <deflist> verdep | |
55255dae | 162 | %token INPUT_DYNAMIC_LIST |
252b5132 RH |
163 | |
164 | %% | |
165 | ||
d038301c | 166 | file: |
252b5132 RH |
167 | INPUT_SCRIPT script_file |
168 | | INPUT_MRI_SCRIPT mri_script_file | |
169 | | INPUT_VERSION_SCRIPT version_script_file | |
55255dae | 170 | | INPUT_DYNAMIC_LIST dynamic_list_file |
252b5132 RH |
171 | | INPUT_DEFSYM defsym_expr |
172 | ; | |
173 | ||
174 | ||
175 | filename: NAME; | |
176 | ||
177 | ||
178 | defsym_expr: | |
179 | { ldlex_defsym(); } | |
180 | NAME '=' exp | |
181 | { | |
182 | ldlex_popstate(); | |
2e57b2af | 183 | lang_add_assignment (exp_defsym ($2, $4)); |
252b5132 | 184 | } |
944cd72c | 185 | ; |
252b5132 | 186 | |
d038301c | 187 | /* SYNTAX WITHIN AN MRI SCRIPT FILE */ |
252b5132 RH |
188 | mri_script_file: |
189 | { | |
190 | ldlex_mri_script (); | |
191 | PUSH_ERROR (_("MRI style script")); | |
192 | } | |
193 | mri_script_lines | |
194 | { | |
195 | ldlex_popstate (); | |
196 | mri_draw_tree (); | |
197 | POP_ERROR (); | |
198 | } | |
199 | ; | |
200 | ||
201 | mri_script_lines: | |
202 | mri_script_lines mri_script_command NEWLINE | |
6c19b93b | 203 | | |
252b5132 RH |
204 | ; |
205 | ||
206 | mri_script_command: | |
d038301c | 207 | CHIP exp |
252b5132 | 208 | | CHIP exp ',' exp |
6c19b93b | 209 | | NAME { |
df5f2391 | 210 | einfo(_("%F%P: unrecognised keyword in MRI style script '%s'\n"),$1); |
252b5132 | 211 | } |
6c19b93b | 212 | | LIST { |
252b5132 RH |
213 | config.map_filename = "-"; |
214 | } | |
6c19b93b AM |
215 | | ORDER ordernamelist |
216 | | ENDWORD | |
217 | | PUBLIC NAME '=' exp | |
218 | { mri_public($2, $4); } | |
219 | | PUBLIC NAME ',' exp | |
220 | { mri_public($2, $4); } | |
221 | | PUBLIC NAME exp | |
222 | { mri_public($2, $3); } | |
223 | | FORMAT NAME | |
252b5132 RH |
224 | { mri_format($2); } |
225 | | SECT NAME ',' exp | |
226 | { mri_output_section($2, $4);} | |
227 | | SECT NAME exp | |
228 | { mri_output_section($2, $3);} | |
229 | | SECT NAME '=' exp | |
230 | { mri_output_section($2, $4);} | |
231 | | ALIGN_K NAME '=' exp | |
232 | { mri_align($2,$4); } | |
233 | | ALIGN_K NAME ',' exp | |
234 | { mri_align($2,$4); } | |
235 | | ALIGNMOD NAME '=' exp | |
236 | { mri_alignmod($2,$4); } | |
237 | | ALIGNMOD NAME ',' exp | |
238 | { mri_alignmod($2,$4); } | |
239 | | ABSOLUTE mri_abs_name_list | |
240 | | LOAD mri_load_name_list | |
6c19b93b | 241 | | NAMEWORD NAME |
d038301c | 242 | { mri_name($2); } |
252b5132 RH |
243 | | ALIAS NAME ',' NAME |
244 | { mri_alias($2,$4,0);} | |
245 | | ALIAS NAME ',' INT | |
2c382fb6 | 246 | { mri_alias ($2, 0, (int) $4.integer); } |
6c19b93b | 247 | | BASE exp |
252b5132 | 248 | { mri_base($2); } |
2c382fb6 AM |
249 | | TRUNCATE INT |
250 | { mri_truncate ((unsigned int) $2.integer); } | |
252b5132 RH |
251 | | CASE casesymlist |
252 | | EXTERN extern_name_list | |
253 | | INCLUDE filename | |
b47c4208 AM |
254 | { ldlex_script (); ldfile_open_command_file($2); } |
255 | mri_script_lines END | |
256 | { ldlex_popstate (); } | |
252b5132 | 257 | | START NAME |
b34976b6 | 258 | { lang_add_entry ($2, FALSE); } |
6c19b93b | 259 | | |
252b5132 RH |
260 | ; |
261 | ||
262 | ordernamelist: | |
6c19b93b AM |
263 | ordernamelist ',' NAME { mri_order($3); } |
264 | | ordernamelist NAME { mri_order($2); } | |
265 | | | |
252b5132 RH |
266 | ; |
267 | ||
268 | mri_load_name_list: | |
269 | NAME | |
270 | { mri_load($1); } | |
271 | | mri_load_name_list ',' NAME { mri_load($3); } | |
272 | ; | |
273 | ||
274 | mri_abs_name_list: | |
6c19b93b AM |
275 | NAME |
276 | { mri_only_load($1); } | |
252b5132 | 277 | | mri_abs_name_list ',' NAME |
6c19b93b | 278 | { mri_only_load($3); } |
252b5132 RH |
279 | ; |
280 | ||
281 | casesymlist: | |
282 | /* empty */ { $$ = NULL; } | |
283 | | NAME | |
284 | | casesymlist ',' NAME | |
285 | ; | |
286 | ||
8545d1a9 | 287 | /* Parsed as expressions so that commas separate entries */ |
252b5132 | 288 | extern_name_list: |
8545d1a9 NS |
289 | { ldlex_expression (); } |
290 | extern_name_list_body | |
291 | { ldlex_popstate (); } | |
292 | ||
293 | extern_name_list_body: | |
252b5132 | 294 | NAME |
24898b70 | 295 | { ldlang_add_undef ($1, FALSE); } |
8545d1a9 | 296 | | extern_name_list_body NAME |
24898b70 | 297 | { ldlang_add_undef ($2, FALSE); } |
8545d1a9 | 298 | | extern_name_list_body ',' NAME |
24898b70 | 299 | { ldlang_add_undef ($3, FALSE); } |
252b5132 RH |
300 | ; |
301 | ||
302 | script_file: | |
8545d1a9 NS |
303 | { ldlex_both(); } |
304 | ifile_list | |
305 | { ldlex_popstate(); } | |
6c19b93b | 306 | ; |
252b5132 | 307 | |
252b5132 | 308 | ifile_list: |
8545d1a9 | 309 | ifile_list ifile_p1 |
6c19b93b | 310 | | |
252b5132 RH |
311 | ; |
312 | ||
313 | ||
252b5132 RH |
314 | ifile_p1: |
315 | memory | |
316 | | sections | |
317 | | phdrs | |
318 | | startup | |
319 | | high_level_library | |
320 | | low_level_library | |
321 | | floating_point_support | |
322 | | statement_anywhere | |
323 | | version | |
6c19b93b | 324 | | ';' |
252b5132 RH |
325 | | TARGET_K '(' NAME ')' |
326 | { lang_add_target($3); } | |
327 | | SEARCH_DIR '(' filename ')' | |
b34976b6 | 328 | { ldfile_add_library_path ($3, FALSE); } |
252b5132 RH |
329 | | OUTPUT '(' filename ')' |
330 | { lang_add_output($3, 1); } | |
6c19b93b | 331 | | OUTPUT_FORMAT '(' NAME ')' |
252b5132 RH |
332 | { lang_add_output_format ($3, (char *) NULL, |
333 | (char *) NULL, 1); } | |
334 | | OUTPUT_FORMAT '(' NAME ',' NAME ',' NAME ')' | |
335 | { lang_add_output_format ($3, $5, $7, 1); } | |
6c19b93b | 336 | | OUTPUT_ARCH '(' NAME ')' |
5e2f1575 | 337 | { ldfile_set_output_arch ($3, bfd_arch_unknown); } |
252b5132 | 338 | | FORCE_COMMON_ALLOCATION |
b34976b6 | 339 | { command_line.force_common_definition = TRUE ; } |
7bdf4127 AB |
340 | | FORCE_GROUP_ALLOCATION |
341 | { command_line.force_group_allocation = TRUE ; } | |
4818e05f | 342 | | INHIBIT_COMMON_ALLOCATION |
a4819f54 | 343 | { link_info.inhibit_common_definition = TRUE ; } |
252b5132 RH |
344 | | INPUT '(' input_list ')' |
345 | | GROUP | |
346 | { lang_enter_group (); } | |
347 | '(' input_list ')' | |
348 | { lang_leave_group (); } | |
6c19b93b | 349 | | MAP '(' filename ')' |
252b5132 | 350 | { lang_add_map($3); } |
d038301c | 351 | | INCLUDE filename |
b47c4208 AM |
352 | { ldlex_script (); ldfile_open_command_file($2); } |
353 | ifile_list END | |
354 | { ldlex_popstate (); } | |
252b5132 RH |
355 | | NOCROSSREFS '(' nocrossref_list ')' |
356 | { | |
357 | lang_add_nocrossref ($3); | |
358 | } | |
cdf96953 MF |
359 | | NOCROSSREFS_TO '(' nocrossref_list ')' |
360 | { | |
361 | lang_add_nocrossref_to ($3); | |
362 | } | |
252b5132 | 363 | | EXTERN '(' extern_name_list ')' |
53d25da6 AM |
364 | | INSERT_K AFTER NAME |
365 | { lang_add_insert ($3, 0); } | |
366 | | INSERT_K BEFORE NAME | |
367 | { lang_add_insert ($3, 1); } | |
4a93e180 NC |
368 | | REGION_ALIAS '(' NAME ',' NAME ')' |
369 | { lang_memory_region_alias ($3, $5); } | |
01554a74 AM |
370 | | LD_FEATURE '(' NAME ')' |
371 | { lang_ld_feature ($3); } | |
252b5132 RH |
372 | ; |
373 | ||
374 | input_list: | |
eeed9cc7 HPN |
375 | { ldlex_inputlist(); } |
376 | input_list1 | |
377 | { ldlex_popstate(); } | |
378 | ||
379 | input_list1: | |
252b5132 RH |
380 | NAME |
381 | { lang_add_input_file($1,lang_input_file_is_search_file_enum, | |
382 | (char *)NULL); } | |
eeed9cc7 | 383 | | input_list1 ',' NAME |
252b5132 RH |
384 | { lang_add_input_file($3,lang_input_file_is_search_file_enum, |
385 | (char *)NULL); } | |
eeed9cc7 | 386 | | input_list1 NAME |
252b5132 RH |
387 | { lang_add_input_file($2,lang_input_file_is_search_file_enum, |
388 | (char *)NULL); } | |
389 | | LNAME | |
390 | { lang_add_input_file($1,lang_input_file_is_l_enum, | |
391 | (char *)NULL); } | |
eeed9cc7 | 392 | | input_list1 ',' LNAME |
252b5132 RH |
393 | { lang_add_input_file($3,lang_input_file_is_l_enum, |
394 | (char *)NULL); } | |
eeed9cc7 | 395 | | input_list1 LNAME |
252b5132 RH |
396 | { lang_add_input_file($2,lang_input_file_is_l_enum, |
397 | (char *)NULL); } | |
b717d30e | 398 | | AS_NEEDED '(' |
66be1055 AM |
399 | { $<integer>$ = input_flags.add_DT_NEEDED_for_regular; |
400 | input_flags.add_DT_NEEDED_for_regular = TRUE; } | |
eeed9cc7 | 401 | input_list1 ')' |
66be1055 | 402 | { input_flags.add_DT_NEEDED_for_regular = $<integer>3; } |
eeed9cc7 | 403 | | input_list1 ',' AS_NEEDED '(' |
66be1055 AM |
404 | { $<integer>$ = input_flags.add_DT_NEEDED_for_regular; |
405 | input_flags.add_DT_NEEDED_for_regular = TRUE; } | |
eeed9cc7 | 406 | input_list1 ')' |
66be1055 | 407 | { input_flags.add_DT_NEEDED_for_regular = $<integer>5; } |
eeed9cc7 | 408 | | input_list1 AS_NEEDED '(' |
66be1055 AM |
409 | { $<integer>$ = input_flags.add_DT_NEEDED_for_regular; |
410 | input_flags.add_DT_NEEDED_for_regular = TRUE; } | |
eeed9cc7 | 411 | input_list1 ')' |
66be1055 | 412 | { input_flags.add_DT_NEEDED_for_regular = $<integer>4; } |
252b5132 RH |
413 | ; |
414 | ||
415 | sections: | |
416 | SECTIONS '{' sec_or_group_p1 '}' | |
417 | ; | |
418 | ||
419 | sec_or_group_p1: | |
420 | sec_or_group_p1 section | |
421 | | sec_or_group_p1 statement_anywhere | |
422 | | | |
423 | ; | |
424 | ||
425 | statement_anywhere: | |
426 | ENTRY '(' NAME ')' | |
b34976b6 | 427 | { lang_add_entry ($3, FALSE); } |
252b5132 | 428 | | assignment end |
b6ca8815 NS |
429 | | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' |
430 | { ldlex_popstate (); | |
431 | lang_add_assignment (exp_assert ($4, $6)); } | |
252b5132 RH |
432 | ; |
433 | ||
434 | /* The '*' and '?' cases are there because the lexer returns them as | |
435 | separate tokens rather than as NAME. */ | |
436 | wildcard_name: | |
437 | NAME | |
438 | { | |
439 | $$ = $1; | |
440 | } | |
441 | | '*' | |
442 | { | |
443 | $$ = "*"; | |
444 | } | |
445 | | '?' | |
446 | { | |
447 | $$ = "?"; | |
448 | } | |
449 | ; | |
450 | ||
2b94abd4 | 451 | wildcard_maybe_exclude: |
252b5132 RH |
452 | wildcard_name |
453 | { | |
454 | $$.name = $1; | |
bcaa7b3e | 455 | $$.sorted = none; |
18625d54 | 456 | $$.exclude_name_list = NULL; |
ae17ab41 | 457 | $$.section_flag_list = NULL; |
252b5132 | 458 | } |
6c19b93b | 459 | | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name |
252b5132 RH |
460 | { |
461 | $$.name = $5; | |
bcaa7b3e | 462 | $$.sorted = none; |
18625d54 | 463 | $$.exclude_name_list = $3; |
ae17ab41 | 464 | $$.section_flag_list = NULL; |
252b5132 | 465 | } |
2b94abd4 AB |
466 | ; |
467 | ||
468 | filename_spec: | |
469 | wildcard_maybe_exclude | |
470 | | SORT_BY_NAME '(' wildcard_maybe_exclude ')' | |
252b5132 | 471 | { |
2b94abd4 | 472 | $$ = $3; |
bcaa7b3e | 473 | $$.sorted = by_name; |
252b5132 | 474 | } |
2b94abd4 AB |
475 | | SORT_NONE '(' wildcard_maybe_exclude ')' |
476 | { | |
477 | $$ = $3; | |
478 | $$.sorted = by_none; | |
479 | } | |
480 | ; | |
481 | ||
482 | section_name_spec: | |
483 | wildcard_maybe_exclude | |
484 | | SORT_BY_NAME '(' wildcard_maybe_exclude ')' | |
bcaa7b3e | 485 | { |
2b94abd4 AB |
486 | $$ = $3; |
487 | $$.sorted = by_name; | |
488 | } | |
489 | | SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' | |
490 | { | |
491 | $$ = $3; | |
bcaa7b3e | 492 | $$.sorted = by_alignment; |
bcaa7b3e | 493 | } |
2b94abd4 | 494 | | SORT_NONE '(' wildcard_maybe_exclude ')' |
eda680f8 | 495 | { |
2b94abd4 | 496 | $$ = $3; |
eda680f8 | 497 | $$.sorted = by_none; |
eda680f8 | 498 | } |
2b94abd4 | 499 | | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')' |
bcaa7b3e | 500 | { |
2b94abd4 | 501 | $$ = $5; |
bcaa7b3e | 502 | $$.sorted = by_name_alignment; |
bcaa7b3e | 503 | } |
2b94abd4 | 504 | | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')' |
bcaa7b3e | 505 | { |
2b94abd4 | 506 | $$ = $5; |
bcaa7b3e | 507 | $$.sorted = by_name; |
bcaa7b3e | 508 | } |
2b94abd4 | 509 | | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')' |
bcaa7b3e | 510 | { |
2b94abd4 | 511 | $$ = $5; |
bcaa7b3e | 512 | $$.sorted = by_alignment_name; |
bcaa7b3e | 513 | } |
2b94abd4 | 514 | | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')' |
bcaa7b3e | 515 | { |
2b94abd4 | 516 | $$ = $5; |
bcaa7b3e | 517 | $$.sorted = by_alignment; |
252b5132 | 518 | } |
2b94abd4 | 519 | | SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')' |
02ecc8e9 | 520 | { |
2b94abd4 | 521 | $$ = $3; |
02ecc8e9 | 522 | $$.sorted = by_init_priority; |
ae17ab41 CM |
523 | } |
524 | ; | |
525 | ||
526 | sect_flag_list: NAME | |
527 | { | |
528 | struct flag_info_list *n; | |
529 | n = ((struct flag_info_list *) xmalloc (sizeof *n)); | |
530 | if ($1[0] == '!') | |
531 | { | |
532 | n->with = without_flags; | |
533 | n->name = &$1[1]; | |
534 | } | |
535 | else | |
536 | { | |
537 | n->with = with_flags; | |
538 | n->name = $1; | |
539 | } | |
540 | n->valid = FALSE; | |
541 | n->next = NULL; | |
542 | $$ = n; | |
543 | } | |
544 | | sect_flag_list '&' NAME | |
545 | { | |
546 | struct flag_info_list *n; | |
547 | n = ((struct flag_info_list *) xmalloc (sizeof *n)); | |
548 | if ($3[0] == '!') | |
549 | { | |
550 | n->with = without_flags; | |
551 | n->name = &$3[1]; | |
552 | } | |
553 | else | |
554 | { | |
555 | n->with = with_flags; | |
556 | n->name = $3; | |
557 | } | |
558 | n->valid = FALSE; | |
559 | n->next = $1; | |
560 | $$ = n; | |
561 | } | |
562 | ; | |
563 | ||
564 | sect_flags: | |
565 | INPUT_SECTION_FLAGS '(' sect_flag_list ')' | |
566 | { | |
567 | struct flag_info *n; | |
568 | n = ((struct flag_info *) xmalloc (sizeof *n)); | |
569 | n->flag_list = $3; | |
570 | n->flags_initialized = FALSE; | |
571 | n->not_with_flags = 0; | |
572 | n->only_with_flags = 0; | |
573 | $$ = n; | |
02ecc8e9 | 574 | } |
252b5132 RH |
575 | ; |
576 | ||
18625d54 | 577 | exclude_name_list: |
765b7cbe | 578 | exclude_name_list wildcard_name |
18625d54 CM |
579 | { |
580 | struct name_list *tmp; | |
581 | tmp = (struct name_list *) xmalloc (sizeof *tmp); | |
765b7cbe | 582 | tmp->name = $2; |
18625d54 | 583 | tmp->next = $1; |
d038301c | 584 | $$ = tmp; |
18625d54 CM |
585 | } |
586 | | | |
587 | wildcard_name | |
588 | { | |
589 | struct name_list *tmp; | |
590 | tmp = (struct name_list *) xmalloc (sizeof *tmp); | |
591 | tmp->name = $1; | |
592 | tmp->next = NULL; | |
593 | $$ = tmp; | |
594 | } | |
595 | ; | |
596 | ||
2b94abd4 AB |
597 | section_name_list: |
598 | section_name_list opt_comma section_name_spec | |
252b5132 | 599 | { |
b6bf44ba AM |
600 | struct wildcard_list *tmp; |
601 | tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); | |
602 | tmp->next = $1; | |
603 | tmp->spec = $3; | |
604 | $$ = tmp; | |
252b5132 | 605 | } |
b6bf44ba | 606 | | |
2b94abd4 | 607 | section_name_spec |
252b5132 | 608 | { |
b6bf44ba AM |
609 | struct wildcard_list *tmp; |
610 | tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); | |
611 | tmp->next = NULL; | |
612 | tmp->spec = $1; | |
613 | $$ = tmp; | |
252b5132 RH |
614 | } |
615 | ; | |
616 | ||
617 | input_section_spec_no_keep: | |
618 | NAME | |
619 | { | |
b6bf44ba AM |
620 | struct wildcard_spec tmp; |
621 | tmp.name = $1; | |
622 | tmp.exclude_name_list = NULL; | |
bcaa7b3e | 623 | tmp.sorted = none; |
ae17ab41 CM |
624 | tmp.section_flag_list = NULL; |
625 | lang_add_wild (&tmp, NULL, ldgram_had_keep); | |
626 | } | |
627 | | sect_flags NAME | |
628 | { | |
629 | struct wildcard_spec tmp; | |
630 | tmp.name = $2; | |
631 | tmp.exclude_name_list = NULL; | |
632 | tmp.sorted = none; | |
633 | tmp.section_flag_list = $1; | |
b6bf44ba | 634 | lang_add_wild (&tmp, NULL, ldgram_had_keep); |
252b5132 | 635 | } |
6c19b93b | 636 | | '[' section_name_list ']' |
252b5132 | 637 | { |
b6bf44ba | 638 | lang_add_wild (NULL, $2, ldgram_had_keep); |
252b5132 | 639 | } |
6c19b93b | 640 | | sect_flags '[' section_name_list ']' |
ae17ab41 CM |
641 | { |
642 | struct wildcard_spec tmp; | |
643 | tmp.name = NULL; | |
644 | tmp.exclude_name_list = NULL; | |
645 | tmp.sorted = none; | |
646 | tmp.section_flag_list = $1; | |
09f6ed34 | 647 | lang_add_wild (&tmp, $3, ldgram_had_keep); |
ae17ab41 | 648 | } |
2b94abd4 | 649 | | filename_spec '(' section_name_list ')' |
252b5132 | 650 | { |
b6bf44ba | 651 | lang_add_wild (&$1, $3, ldgram_had_keep); |
252b5132 | 652 | } |
2b94abd4 | 653 | | sect_flags filename_spec '(' section_name_list ')' |
ae17ab41 CM |
654 | { |
655 | $2.section_flag_list = $1; | |
656 | lang_add_wild (&$2, $4, ldgram_had_keep); | |
657 | } | |
252b5132 RH |
658 | ; |
659 | ||
660 | input_section_spec: | |
661 | input_section_spec_no_keep | |
662 | | KEEP '(' | |
b34976b6 | 663 | { ldgram_had_keep = TRUE; } |
252b5132 | 664 | input_section_spec_no_keep ')' |
b34976b6 | 665 | { ldgram_had_keep = FALSE; } |
252b5132 RH |
666 | ; |
667 | ||
668 | statement: | |
6c19b93b | 669 | assignment end |
252b5132 RH |
670 | | CREATE_OBJECT_SYMBOLS |
671 | { | |
6c19b93b AM |
672 | lang_add_attribute(lang_object_symbols_statement_enum); |
673 | } | |
674 | | ';' | |
675 | | CONSTRUCTORS | |
252b5132 | 676 | { |
d038301c RM |
677 | |
678 | lang_add_attribute(lang_constructors_statement_enum); | |
252b5132 | 679 | } |
bcaa7b3e | 680 | | SORT_BY_NAME '(' CONSTRUCTORS ')' |
252b5132 | 681 | { |
b34976b6 | 682 | constructors_sorted = TRUE; |
252b5132 RH |
683 | lang_add_attribute (lang_constructors_statement_enum); |
684 | } | |
685 | | input_section_spec | |
6c19b93b AM |
686 | | length '(' mustbe_exp ')' |
687 | { | |
688 | lang_add_data ((int) $1, $3); | |
689 | } | |
d038301c | 690 | |
2c382fb6 | 691 | | FILL '(' fill_exp ')' |
6c19b93b AM |
692 | { |
693 | lang_add_fill ($3); | |
694 | } | |
8545d1a9 NS |
695 | | ASSERT_K {ldlex_expression ();} '(' exp ',' NAME ')' end |
696 | { ldlex_popstate (); | |
697 | lang_add_assignment (exp_assert ($4, $6)); } | |
4006703d NS |
698 | | INCLUDE filename |
699 | { ldlex_script (); ldfile_open_command_file($2); } | |
700 | statement_list_opt END | |
701 | { ldlex_popstate (); } | |
252b5132 RH |
702 | ; |
703 | ||
704 | statement_list: | |
705 | statement_list statement | |
6c19b93b | 706 | | statement |
252b5132 | 707 | ; |
d038301c | 708 | |
252b5132 RH |
709 | statement_list_opt: |
710 | /* empty */ | |
711 | | statement_list | |
712 | ; | |
713 | ||
714 | length: | |
715 | QUAD | |
716 | { $$ = $1; } | |
717 | | SQUAD | |
718 | { $$ = $1; } | |
719 | | LONG | |
720 | { $$ = $1; } | |
6c19b93b | 721 | | SHORT |
252b5132 RH |
722 | { $$ = $1; } |
723 | | BYTE | |
724 | { $$ = $1; } | |
725 | ; | |
726 | ||
2c382fb6 AM |
727 | fill_exp: |
728 | mustbe_exp | |
252b5132 | 729 | { |
e9ee469a | 730 | $$ = exp_get_fill ($1, 0, "fill value"); |
252b5132 | 731 | } |
252b5132 RH |
732 | ; |
733 | ||
2c382fb6 AM |
734 | fill_opt: |
735 | '=' fill_exp | |
736 | { $$ = $2; } | |
6c19b93b | 737 | | { $$ = (fill_type *) 0; } |
2c382fb6 | 738 | ; |
252b5132 RH |
739 | |
740 | assign_op: | |
741 | PLUSEQ | |
742 | { $$ = '+'; } | |
743 | | MINUSEQ | |
744 | { $$ = '-'; } | |
6c19b93b | 745 | | MULTEQ |
252b5132 | 746 | { $$ = '*'; } |
6c19b93b | 747 | | DIVEQ |
252b5132 | 748 | { $$ = '/'; } |
6c19b93b | 749 | | LSHIFTEQ |
252b5132 | 750 | { $$ = LSHIFT; } |
6c19b93b | 751 | | RSHIFTEQ |
252b5132 | 752 | { $$ = RSHIFT; } |
6c19b93b | 753 | | ANDEQ |
252b5132 | 754 | { $$ = '&'; } |
6c19b93b | 755 | | OREQ |
252b5132 RH |
756 | { $$ = '|'; } |
757 | ||
758 | ; | |
759 | ||
760 | end: ';' | ',' | |
761 | ; | |
762 | ||
763 | ||
764 | assignment: | |
765 | NAME '=' mustbe_exp | |
766 | { | |
eb8476a6 | 767 | lang_add_assignment (exp_assign ($1, $3, FALSE)); |
252b5132 RH |
768 | } |
769 | | NAME assign_op mustbe_exp | |
770 | { | |
2e57b2af AM |
771 | lang_add_assignment (exp_assign ($1, |
772 | exp_binop ($2, | |
773 | exp_nameop (NAME, | |
774 | $1), | |
eb8476a6 MR |
775 | $3), FALSE)); |
776 | } | |
777 | | HIDDEN '(' NAME '=' mustbe_exp ')' | |
778 | { | |
779 | lang_add_assignment (exp_assign ($3, $5, TRUE)); | |
252b5132 RH |
780 | } |
781 | | PROVIDE '(' NAME '=' mustbe_exp ')' | |
782 | { | |
7af8e998 L |
783 | lang_add_assignment (exp_provide ($3, $5, FALSE)); |
784 | } | |
785 | | PROVIDE_HIDDEN '(' NAME '=' mustbe_exp ')' | |
786 | { | |
787 | lang_add_assignment (exp_provide ($3, $5, TRUE)); | |
252b5132 RH |
788 | } |
789 | ; | |
790 | ||
791 | ||
792 | opt_comma: | |
793 | ',' | ; | |
794 | ||
795 | ||
796 | memory: | |
4006703d | 797 | MEMORY '{' memory_spec_list_opt '}' |
252b5132 RH |
798 | ; |
799 | ||
4006703d NS |
800 | memory_spec_list_opt: memory_spec_list | ; |
801 | ||
252b5132 | 802 | memory_spec_list: |
4006703d NS |
803 | memory_spec_list opt_comma memory_spec |
804 | | memory_spec | |
252b5132 RH |
805 | ; |
806 | ||
807 | ||
6c19b93b | 808 | memory_spec: NAME |
a747ee4d | 809 | { region = lang_memory_region_lookup ($1, TRUE); } |
252b5132 RH |
810 | attributes_opt ':' |
811 | origin_spec opt_comma length_spec | |
2d801b0f | 812 | {} |
4006703d NS |
813 | | INCLUDE filename |
814 | { ldlex_script (); ldfile_open_command_file($2); } | |
815 | memory_spec_list_opt END | |
816 | { ldlex_popstate (); } | |
74459f0e TW |
817 | ; |
818 | ||
819 | origin_spec: | |
252b5132 | 820 | ORIGIN '=' mustbe_exp |
e9ee469a | 821 | { |
cc9ad334 | 822 | region->origin_exp = $3; |
e9ee469a | 823 | } |
252b5132 RH |
824 | ; |
825 | ||
826 | length_spec: | |
6c19b93b | 827 | LENGTH '=' mustbe_exp |
e9ee469a | 828 | { |
cc9ad334 | 829 | region->length_exp = $3; |
252b5132 | 830 | } |
aa8804e4 | 831 | ; |
252b5132 RH |
832 | |
833 | attributes_opt: | |
aa8804e4 ILT |
834 | /* empty */ |
835 | { /* dummy action to avoid bison 1.25 error message */ } | |
836 | | '(' attributes_list ')' | |
837 | ; | |
838 | ||
839 | attributes_list: | |
840 | attributes_string | |
841 | | attributes_list attributes_string | |
842 | ; | |
843 | ||
844 | attributes_string: | |
845 | NAME | |
846 | { lang_set_flags (region, $1, 0); } | |
847 | | '!' NAME | |
848 | { lang_set_flags (region, $2, 1); } | |
252b5132 RH |
849 | ; |
850 | ||
851 | startup: | |
852 | STARTUP '(' filename ')' | |
853 | { lang_startup($3); } | |
854 | ; | |
855 | ||
856 | high_level_library: | |
857 | HLL '(' high_level_library_NAME_list ')' | |
858 | | HLL '(' ')' | |
859 | { ldemul_hll((char *)NULL); } | |
860 | ; | |
861 | ||
862 | high_level_library_NAME_list: | |
863 | high_level_library_NAME_list opt_comma filename | |
864 | { ldemul_hll($3); } | |
865 | | filename | |
866 | { ldemul_hll($1); } | |
867 | ||
868 | ; | |
869 | ||
870 | low_level_library: | |
871 | SYSLIB '(' low_level_library_NAME_list ')' | |
872 | ; low_level_library_NAME_list: | |
873 | low_level_library_NAME_list opt_comma filename | |
874 | { ldemul_syslib($3); } | |
875 | | | |
876 | ; | |
877 | ||
878 | floating_point_support: | |
879 | FLOAT | |
b34976b6 | 880 | { lang_float(TRUE); } |
252b5132 | 881 | | NOFLOAT |
b34976b6 | 882 | { lang_float(FALSE); } |
252b5132 | 883 | ; |
d038301c | 884 | |
252b5132 RH |
885 | nocrossref_list: |
886 | /* empty */ | |
887 | { | |
888 | $$ = NULL; | |
889 | } | |
890 | | NAME nocrossref_list | |
891 | { | |
892 | struct lang_nocrossref *n; | |
893 | ||
894 | n = (struct lang_nocrossref *) xmalloc (sizeof *n); | |
895 | n->name = $1; | |
896 | n->next = $2; | |
897 | $$ = n; | |
898 | } | |
899 | | NAME ',' nocrossref_list | |
900 | { | |
901 | struct lang_nocrossref *n; | |
902 | ||
903 | n = (struct lang_nocrossref *) xmalloc (sizeof *n); | |
904 | n->name = $1; | |
905 | n->next = $3; | |
906 | $$ = n; | |
907 | } | |
908 | ; | |
909 | ||
3ec57632 | 910 | mustbe_exp: { ldlex_expression (); } |
252b5132 | 911 | exp |
3ec57632 | 912 | { ldlex_popstate (); $$=$2;} |
252b5132 RH |
913 | ; |
914 | ||
915 | exp : | |
916 | '-' exp %prec UNARY | |
3ec57632 | 917 | { $$ = exp_unop ('-', $2); } |
252b5132 RH |
918 | | '(' exp ')' |
919 | { $$ = $2; } | |
920 | | NEXT '(' exp ')' %prec UNARY | |
3ec57632 | 921 | { $$ = exp_unop ((int) $1,$3); } |
252b5132 | 922 | | '!' exp %prec UNARY |
3ec57632 | 923 | { $$ = exp_unop ('!', $2); } |
252b5132 RH |
924 | | '+' exp %prec UNARY |
925 | { $$ = $2; } | |
926 | | '~' exp %prec UNARY | |
3ec57632 | 927 | { $$ = exp_unop ('~', $2);} |
252b5132 RH |
928 | |
929 | | exp '*' exp | |
3ec57632 | 930 | { $$ = exp_binop ('*', $1, $3); } |
252b5132 | 931 | | exp '/' exp |
3ec57632 | 932 | { $$ = exp_binop ('/', $1, $3); } |
252b5132 | 933 | | exp '%' exp |
3ec57632 | 934 | { $$ = exp_binop ('%', $1, $3); } |
252b5132 | 935 | | exp '+' exp |
3ec57632 | 936 | { $$ = exp_binop ('+', $1, $3); } |
252b5132 | 937 | | exp '-' exp |
3ec57632 | 938 | { $$ = exp_binop ('-' , $1, $3); } |
252b5132 | 939 | | exp LSHIFT exp |
3ec57632 | 940 | { $$ = exp_binop (LSHIFT , $1, $3); } |
252b5132 | 941 | | exp RSHIFT exp |
3ec57632 | 942 | { $$ = exp_binop (RSHIFT , $1, $3); } |
252b5132 | 943 | | exp EQ exp |
3ec57632 | 944 | { $$ = exp_binop (EQ , $1, $3); } |
252b5132 | 945 | | exp NE exp |
3ec57632 | 946 | { $$ = exp_binop (NE , $1, $3); } |
252b5132 | 947 | | exp LE exp |
3ec57632 | 948 | { $$ = exp_binop (LE , $1, $3); } |
6c19b93b | 949 | | exp GE exp |
3ec57632 | 950 | { $$ = exp_binop (GE , $1, $3); } |
252b5132 | 951 | | exp '<' exp |
3ec57632 | 952 | { $$ = exp_binop ('<' , $1, $3); } |
252b5132 | 953 | | exp '>' exp |
3ec57632 | 954 | { $$ = exp_binop ('>' , $1, $3); } |
252b5132 | 955 | | exp '&' exp |
3ec57632 | 956 | { $$ = exp_binop ('&' , $1, $3); } |
252b5132 | 957 | | exp '^' exp |
3ec57632 | 958 | { $$ = exp_binop ('^' , $1, $3); } |
252b5132 | 959 | | exp '|' exp |
3ec57632 | 960 | { $$ = exp_binop ('|' , $1, $3); } |
252b5132 | 961 | | exp '?' exp ':' exp |
3ec57632 | 962 | { $$ = exp_trinop ('?' , $1, $3, $5); } |
252b5132 | 963 | | exp ANDAND exp |
3ec57632 | 964 | { $$ = exp_binop (ANDAND , $1, $3); } |
252b5132 | 965 | | exp OROR exp |
3ec57632 | 966 | { $$ = exp_binop (OROR , $1, $3); } |
252b5132 | 967 | | DEFINED '(' NAME ')' |
3ec57632 | 968 | { $$ = exp_nameop (DEFINED, $3); } |
252b5132 | 969 | | INT |
2c382fb6 | 970 | { $$ = exp_bigintop ($1.integer, $1.str); } |
6c19b93b | 971 | | SIZEOF_HEADERS |
3ec57632 | 972 | { $$ = exp_nameop (SIZEOF_HEADERS,0); } |
252b5132 | 973 | |
5d41b3ef NS |
974 | | ALIGNOF '(' NAME ')' |
975 | { $$ = exp_nameop (ALIGNOF,$3); } | |
252b5132 | 976 | | SIZEOF '(' NAME ')' |
3ec57632 | 977 | { $$ = exp_nameop (SIZEOF,$3); } |
252b5132 | 978 | | ADDR '(' NAME ')' |
3ec57632 | 979 | { $$ = exp_nameop (ADDR,$3); } |
252b5132 | 980 | | LOADADDR '(' NAME ')' |
3ec57632 | 981 | { $$ = exp_nameop (LOADADDR,$3); } |
24718e3b L |
982 | | CONSTANT '(' NAME ')' |
983 | { $$ = exp_nameop (CONSTANT,$3); } | |
252b5132 | 984 | | ABSOLUTE '(' exp ')' |
3ec57632 | 985 | { $$ = exp_unop (ABSOLUTE, $3); } |
252b5132 | 986 | | ALIGN_K '(' exp ')' |
3ec57632 | 987 | { $$ = exp_unop (ALIGN_K,$3); } |
876f4090 | 988 | | ALIGN_K '(' exp ',' exp ')' |
3ec57632 | 989 | { $$ = exp_binop (ALIGN_K,$3,$5); } |
2d20f7bf JJ |
990 | | DATA_SEGMENT_ALIGN '(' exp ',' exp ')' |
991 | { $$ = exp_binop (DATA_SEGMENT_ALIGN, $3, $5); } | |
a4f5ad88 JJ |
992 | | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')' |
993 | { $$ = exp_binop (DATA_SEGMENT_RELRO_END, $5, $3); } | |
2d20f7bf | 994 | | DATA_SEGMENT_END '(' exp ')' |
3ec57632 | 995 | { $$ = exp_unop (DATA_SEGMENT_END, $3); } |
6c19b93b AM |
996 | | SEGMENT_START '(' NAME ',' exp ')' |
997 | { /* The operands to the expression node are | |
ba916c8a MM |
998 | placed in the opposite order from the way |
999 | in which they appear in the script as | |
1000 | that allows us to reuse more code in | |
1001 | fold_binary. */ | |
1002 | $$ = exp_binop (SEGMENT_START, | |
1003 | $5, | |
1004 | exp_nameop (NAME, $3)); } | |
252b5132 | 1005 | | BLOCK '(' exp ')' |
3ec57632 | 1006 | { $$ = exp_unop (ALIGN_K,$3); } |
252b5132 | 1007 | | NAME |
3ec57632 | 1008 | { $$ = exp_nameop (NAME,$1); } |
252b5132 RH |
1009 | | MAX_K '(' exp ',' exp ')' |
1010 | { $$ = exp_binop (MAX_K, $3, $5 ); } | |
1011 | | MIN_K '(' exp ',' exp ')' | |
1012 | { $$ = exp_binop (MIN_K, $3, $5 ); } | |
1013 | | ASSERT_K '(' exp ',' NAME ')' | |
1014 | { $$ = exp_assert ($3, $5); } | |
3ec57632 NC |
1015 | | ORIGIN '(' NAME ')' |
1016 | { $$ = exp_nameop (ORIGIN, $3); } | |
1017 | | LENGTH '(' NAME ')' | |
1018 | { $$ = exp_nameop (LENGTH, $3); } | |
2e53f7d6 NC |
1019 | | LOG2CEIL '(' exp ')' |
1020 | { $$ = exp_unop (LOG2CEIL, $3); } | |
252b5132 RH |
1021 | ; |
1022 | ||
1023 | ||
562d3460 | 1024 | memspec_at_opt: |
6c19b93b AM |
1025 | AT '>' NAME { $$ = $3; } |
1026 | | { $$ = 0; } | |
1027 | ; | |
562d3460 | 1028 | |
252b5132 RH |
1029 | opt_at: |
1030 | AT '(' exp ')' { $$ = $3; } | |
1031 | | { $$ = 0; } | |
1032 | ; | |
1033 | ||
bbf115d3 L |
1034 | opt_align: |
1035 | ALIGN_K '(' exp ')' { $$ = $3; } | |
1036 | | { $$ = 0; } | |
1037 | ; | |
1038 | ||
1eec346e NC |
1039 | opt_align_with_input: |
1040 | ALIGN_WITH_INPUT { $$ = ALIGN_WITH_INPUT; } | |
1041 | | { $$ = 0; } | |
1042 | ; | |
1043 | ||
7e7d5768 AM |
1044 | opt_subalign: |
1045 | SUBALIGN '(' exp ')' { $$ = $3; } | |
1046 | | { $$ = 0; } | |
1047 | ; | |
1048 | ||
0841712e JJ |
1049 | sect_constraint: |
1050 | ONLY_IF_RO { $$ = ONLY_IF_RO; } | |
1051 | | ONLY_IF_RW { $$ = ONLY_IF_RW; } | |
0cf7d72c | 1052 | | SPECIAL { $$ = SPECIAL; } |
0841712e JJ |
1053 | | { $$ = 0; } |
1054 | ; | |
1055 | ||
6c19b93b | 1056 | section: NAME { ldlex_expression(); } |
d038301c | 1057 | opt_exp_with_type |
7e7d5768 | 1058 | opt_at |
bbf115d3 | 1059 | opt_align |
1eec346e | 1060 | opt_align_with_input |
7e7d5768 | 1061 | opt_subalign { ldlex_popstate (); ldlex_script (); } |
0841712e | 1062 | sect_constraint |
252b5132 RH |
1063 | '{' |
1064 | { | |
1065 | lang_enter_output_section_statement($1, $3, | |
1066 | sectype, | |
1eec346e | 1067 | $5, $7, $4, $9, $6); |
252b5132 | 1068 | } |
d038301c | 1069 | statement_list_opt |
6c19b93b | 1070 | '}' { ldlex_popstate (); ldlex_expression (); } |
562d3460 | 1071 | memspec_opt memspec_at_opt phdr_opt fill_opt |
252b5132 RH |
1072 | { |
1073 | ldlex_popstate (); | |
1eec346e | 1074 | lang_leave_output_section_statement ($18, $15, $17, $16); |
252b5132 RH |
1075 | } |
1076 | opt_comma | |
2d801b0f | 1077 | {} |
252b5132 RH |
1078 | | OVERLAY |
1079 | { ldlex_expression (); } | |
7e7d5768 | 1080 | opt_exp_without_type opt_nocrossrefs opt_at opt_subalign |
252b5132 | 1081 | { ldlex_popstate (); ldlex_script (); } |
d038301c | 1082 | '{' |
252b5132 | 1083 | { |
7e7d5768 | 1084 | lang_enter_overlay ($3, $6); |
252b5132 RH |
1085 | } |
1086 | overlay_section | |
1087 | '}' | |
1088 | { ldlex_popstate (); ldlex_expression (); } | |
562d3460 | 1089 | memspec_opt memspec_at_opt phdr_opt fill_opt |
252b5132 RH |
1090 | { |
1091 | ldlex_popstate (); | |
9f88b410 | 1092 | lang_leave_overlay ($5, (int) $4, |
7e7d5768 | 1093 | $16, $13, $15, $14); |
252b5132 RH |
1094 | } |
1095 | opt_comma | |
1096 | | /* The GROUP case is just enough to support the gcc | |
1097 | svr3.ifile script. It is not intended to be full | |
1098 | support. I'm not even sure what GROUP is supposed | |
1099 | to mean. */ | |
1100 | GROUP { ldlex_expression (); } | |
1101 | opt_exp_with_type | |
1102 | { | |
1103 | ldlex_popstate (); | |
eb8476a6 | 1104 | lang_add_assignment (exp_assign (".", $3, FALSE)); |
252b5132 RH |
1105 | } |
1106 | '{' sec_or_group_p1 '}' | |
4006703d NS |
1107 | | INCLUDE filename |
1108 | { ldlex_script (); ldfile_open_command_file($2); } | |
1109 | sec_or_group_p1 END | |
1110 | { ldlex_popstate (); } | |
252b5132 RH |
1111 | ; |
1112 | ||
1113 | type: | |
1114 | NOLOAD { sectype = noload_section; } | |
02a38f92 AM |
1115 | | DSECT { sectype = noalloc_section; } |
1116 | | COPY { sectype = noalloc_section; } | |
1117 | | INFO { sectype = noalloc_section; } | |
1118 | | OVERLAY { sectype = noalloc_section; } | |
252b5132 RH |
1119 | ; |
1120 | ||
1121 | atype: | |
6c19b93b AM |
1122 | '(' type ')' |
1123 | | /* EMPTY */ { sectype = normal_section; } | |
1124 | | '(' ')' { sectype = normal_section; } | |
252b5132 RH |
1125 | ; |
1126 | ||
1127 | opt_exp_with_type: | |
1128 | exp atype ':' { $$ = $1; } | |
1129 | | atype ':' { $$ = (etree_type *)NULL; } | |
1130 | | /* The BIND cases are to support the gcc svr3.ifile | |
1131 | script. They aren't intended to implement full | |
1132 | support for the BIND keyword. I'm not even sure | |
1133 | what BIND is supposed to mean. */ | |
1134 | BIND '(' exp ')' atype ':' { $$ = $3; } | |
1135 | | BIND '(' exp ')' BLOCK '(' exp ')' atype ':' | |
1136 | { $$ = $3; } | |
1137 | ; | |
1138 | ||
1139 | opt_exp_without_type: | |
1140 | exp ':' { $$ = $1; } | |
1141 | | ':' { $$ = (etree_type *) NULL; } | |
1142 | ; | |
1143 | ||
1144 | opt_nocrossrefs: | |
1145 | /* empty */ | |
1146 | { $$ = 0; } | |
1147 | | NOCROSSREFS | |
1148 | { $$ = 1; } | |
1149 | ; | |
1150 | ||
1151 | memspec_opt: | |
1152 | '>' NAME | |
1153 | { $$ = $2; } | |
a747ee4d | 1154 | | { $$ = DEFAULT_MEMORY_REGION; } |
252b5132 RH |
1155 | ; |
1156 | ||
1157 | phdr_opt: | |
1158 | /* empty */ | |
1159 | { | |
1160 | $$ = NULL; | |
1161 | } | |
1162 | | phdr_opt ':' NAME | |
1163 | { | |
1164 | struct lang_output_section_phdr_list *n; | |
1165 | ||
1166 | n = ((struct lang_output_section_phdr_list *) | |
1167 | xmalloc (sizeof *n)); | |
1168 | n->name = $3; | |
b34976b6 | 1169 | n->used = FALSE; |
252b5132 RH |
1170 | n->next = $1; |
1171 | $$ = n; | |
1172 | } | |
1173 | ; | |
1174 | ||
1175 | overlay_section: | |
1176 | /* empty */ | |
1177 | | overlay_section | |
1178 | NAME | |
1179 | { | |
1180 | ldlex_script (); | |
1181 | lang_enter_overlay_section ($2); | |
1182 | } | |
1183 | '{' statement_list_opt '}' | |
1184 | { ldlex_popstate (); ldlex_expression (); } | |
1185 | phdr_opt fill_opt | |
1186 | { | |
1187 | ldlex_popstate (); | |
1188 | lang_leave_overlay_section ($9, $8); | |
1189 | } | |
1190 | opt_comma | |
1191 | ; | |
1192 | ||
1193 | phdrs: | |
1194 | PHDRS '{' phdr_list '}' | |
1195 | ; | |
1196 | ||
1197 | phdr_list: | |
1198 | /* empty */ | |
1199 | | phdr_list phdr | |
1200 | ; | |
1201 | ||
1202 | phdr: | |
1203 | NAME { ldlex_expression (); } | |
1204 | phdr_type phdr_qualifiers { ldlex_popstate (); } | |
1205 | ';' | |
1206 | { | |
1207 | lang_new_phdr ($1, $3, $4.filehdr, $4.phdrs, $4.at, | |
1208 | $4.flags); | |
1209 | } | |
1210 | ; | |
1211 | ||
1212 | phdr_type: | |
1213 | exp | |
1214 | { | |
1215 | $$ = $1; | |
1216 | ||
1217 | if ($1->type.node_class == etree_name | |
1218 | && $1->type.node_code == NAME) | |
1219 | { | |
1220 | const char *s; | |
1221 | unsigned int i; | |
1222 | static const char * const phdr_types[] = | |
1223 | { | |
1224 | "PT_NULL", "PT_LOAD", "PT_DYNAMIC", | |
1225 | "PT_INTERP", "PT_NOTE", "PT_SHLIB", | |
d038301c | 1226 | "PT_PHDR", "PT_TLS" |
252b5132 RH |
1227 | }; |
1228 | ||
1229 | s = $1->name.name; | |
1230 | for (i = 0; | |
1231 | i < sizeof phdr_types / sizeof phdr_types[0]; | |
1232 | i++) | |
1233 | if (strcmp (s, phdr_types[i]) == 0) | |
1234 | { | |
1235 | $$ = exp_intop (i); | |
1236 | break; | |
1237 | } | |
d038301c RM |
1238 | if (i == sizeof phdr_types / sizeof phdr_types[0]) |
1239 | { | |
1240 | if (strcmp (s, "PT_GNU_EH_FRAME") == 0) | |
1241 | $$ = exp_intop (0x6474e550); | |
9ee5e499 JJ |
1242 | else if (strcmp (s, "PT_GNU_STACK") == 0) |
1243 | $$ = exp_intop (0x6474e551); | |
d038301c RM |
1244 | else |
1245 | { | |
1246 | einfo (_("\ | |
c1c8c1ef | 1247 | %X%P:%pS: unknown phdr type `%s' (try integer literal)\n"), |
dab69f68 | 1248 | NULL, s); |
d038301c RM |
1249 | $$ = exp_intop (0); |
1250 | } | |
1251 | } | |
252b5132 RH |
1252 | } |
1253 | } | |
1254 | ; | |
1255 | ||
1256 | phdr_qualifiers: | |
1257 | /* empty */ | |
1258 | { | |
1259 | memset (&$$, 0, sizeof (struct phdr_info)); | |
1260 | } | |
1261 | | NAME phdr_val phdr_qualifiers | |
1262 | { | |
1263 | $$ = $3; | |
1264 | if (strcmp ($1, "FILEHDR") == 0 && $2 == NULL) | |
b34976b6 | 1265 | $$.filehdr = TRUE; |
252b5132 | 1266 | else if (strcmp ($1, "PHDRS") == 0 && $2 == NULL) |
b34976b6 | 1267 | $$.phdrs = TRUE; |
252b5132 RH |
1268 | else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL) |
1269 | $$.flags = $2; | |
1270 | else | |
c1c8c1ef | 1271 | einfo (_("%X%P:%pS: PHDRS syntax error at `%s'\n"), |
dab69f68 | 1272 | NULL, $1); |
252b5132 RH |
1273 | } |
1274 | | AT '(' exp ')' phdr_qualifiers | |
1275 | { | |
1276 | $$ = $5; | |
1277 | $$.at = $3; | |
1278 | } | |
1279 | ; | |
1280 | ||
1281 | phdr_val: | |
1282 | /* empty */ | |
1283 | { | |
1284 | $$ = NULL; | |
1285 | } | |
1286 | | '(' exp ')' | |
1287 | { | |
1288 | $$ = $2; | |
1289 | } | |
1290 | ; | |
1291 | ||
55255dae L |
1292 | dynamic_list_file: |
1293 | { | |
1294 | ldlex_version_file (); | |
1295 | PUSH_ERROR (_("dynamic list")); | |
1296 | } | |
1297 | dynamic_list_nodes | |
1298 | { | |
1299 | ldlex_popstate (); | |
1300 | POP_ERROR (); | |
1301 | } | |
1302 | ; | |
1303 | ||
1304 | dynamic_list_nodes: | |
1305 | dynamic_list_node | |
1306 | | dynamic_list_nodes dynamic_list_node | |
1307 | ; | |
1308 | ||
1309 | dynamic_list_node: | |
1310 | '{' dynamic_list_tag '}' ';' | |
1311 | ; | |
1312 | ||
1313 | dynamic_list_tag: | |
1314 | vers_defns ';' | |
1315 | { | |
1316 | lang_append_dynamic_list ($1); | |
1317 | } | |
1318 | ; | |
1319 | ||
252b5132 RH |
1320 | /* This syntax is used within an external version script file. */ |
1321 | ||
1322 | version_script_file: | |
1323 | { | |
1324 | ldlex_version_file (); | |
1325 | PUSH_ERROR (_("VERSION script")); | |
1326 | } | |
1327 | vers_nodes | |
1328 | { | |
1329 | ldlex_popstate (); | |
1330 | POP_ERROR (); | |
1331 | } | |
1332 | ; | |
1333 | ||
1334 | /* This is used within a normal linker script file. */ | |
1335 | ||
1336 | version: | |
1337 | { | |
1338 | ldlex_version_script (); | |
1339 | } | |
1340 | VERSIONK '{' vers_nodes '}' | |
1341 | { | |
1342 | ldlex_popstate (); | |
1343 | } | |
1344 | ; | |
1345 | ||
1346 | vers_nodes: | |
1347 | vers_node | |
1348 | | vers_nodes vers_node | |
1349 | ; | |
1350 | ||
1351 | vers_node: | |
6b9b879a JJ |
1352 | '{' vers_tag '}' ';' |
1353 | { | |
1354 | lang_register_vers_node (NULL, $2, NULL); | |
1355 | } | |
1356 | | VERS_TAG '{' vers_tag '}' ';' | |
252b5132 RH |
1357 | { |
1358 | lang_register_vers_node ($1, $3, NULL); | |
1359 | } | |
1360 | | VERS_TAG '{' vers_tag '}' verdep ';' | |
1361 | { | |
1362 | lang_register_vers_node ($1, $3, $5); | |
1363 | } | |
1364 | ; | |
1365 | ||
1366 | verdep: | |
1367 | VERS_TAG | |
1368 | { | |
1369 | $$ = lang_add_vers_depend (NULL, $1); | |
1370 | } | |
1371 | | verdep VERS_TAG | |
1372 | { | |
1373 | $$ = lang_add_vers_depend ($1, $2); | |
1374 | } | |
1375 | ; | |
1376 | ||
1377 | vers_tag: | |
1378 | /* empty */ | |
1379 | { | |
1380 | $$ = lang_new_vers_node (NULL, NULL); | |
1381 | } | |
1382 | | vers_defns ';' | |
1383 | { | |
1384 | $$ = lang_new_vers_node ($1, NULL); | |
1385 | } | |
1386 | | GLOBAL ':' vers_defns ';' | |
1387 | { | |
1388 | $$ = lang_new_vers_node ($3, NULL); | |
1389 | } | |
1390 | | LOCAL ':' vers_defns ';' | |
1391 | { | |
1392 | $$ = lang_new_vers_node (NULL, $3); | |
1393 | } | |
1394 | | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';' | |
1395 | { | |
1396 | $$ = lang_new_vers_node ($3, $7); | |
1397 | } | |
1398 | ; | |
1399 | ||
1400 | vers_defns: | |
1401 | VERS_IDENTIFIER | |
1402 | { | |
86043bbb MM |
1403 | $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, FALSE); |
1404 | } | |
6c19b93b | 1405 | | NAME |
86043bbb MM |
1406 | { |
1407 | $$ = lang_new_vers_pattern (NULL, $1, ldgram_vers_current_lang, TRUE); | |
252b5132 RH |
1408 | } |
1409 | | vers_defns ';' VERS_IDENTIFIER | |
1410 | { | |
86043bbb MM |
1411 | $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, FALSE); |
1412 | } | |
1413 | | vers_defns ';' NAME | |
1414 | { | |
1415 | $$ = lang_new_vers_pattern ($1, $3, ldgram_vers_current_lang, TRUE); | |
252b5132 | 1416 | } |
8e23b15d AM |
1417 | | vers_defns ';' EXTERN NAME '{' |
1418 | { | |
1419 | $<name>$ = ldgram_vers_current_lang; | |
1420 | ldgram_vers_current_lang = $4; | |
1421 | } | |
1422 | vers_defns opt_semicolon '}' | |
1423 | { | |
96f8ade5 JJ |
1424 | struct bfd_elf_version_expr *pat; |
1425 | for (pat = $7; pat->next != NULL; pat = pat->next); | |
1426 | pat->next = $1; | |
8e23b15d AM |
1427 | $$ = $7; |
1428 | ldgram_vers_current_lang = $<name>6; | |
1429 | } | |
252b5132 RH |
1430 | | EXTERN NAME '{' |
1431 | { | |
1432 | $<name>$ = ldgram_vers_current_lang; | |
1433 | ldgram_vers_current_lang = $2; | |
1434 | } | |
8e23b15d | 1435 | vers_defns opt_semicolon '}' |
252b5132 | 1436 | { |
e06cae36 | 1437 | $$ = $5; |
252b5132 RH |
1438 | ldgram_vers_current_lang = $<name>4; |
1439 | } | |
96f8ade5 JJ |
1440 | | GLOBAL |
1441 | { | |
86043bbb | 1442 | $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1443 | } |
1444 | | vers_defns ';' GLOBAL | |
1445 | { | |
86043bbb | 1446 | $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1447 | } |
1448 | | LOCAL | |
1449 | { | |
86043bbb | 1450 | $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1451 | } |
1452 | | vers_defns ';' LOCAL | |
1453 | { | |
86043bbb | 1454 | $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1455 | } |
1456 | | EXTERN | |
1457 | { | |
86043bbb | 1458 | $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang, FALSE); |
96f8ade5 JJ |
1459 | } |
1460 | | vers_defns ';' EXTERN | |
1461 | { | |
86043bbb | 1462 | $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang, FALSE); |
96f8ade5 | 1463 | } |
252b5132 RH |
1464 | ; |
1465 | ||
8e23b15d AM |
1466 | opt_semicolon: |
1467 | /* empty */ | |
1468 | | ';' | |
1469 | ; | |
1470 | ||
252b5132 RH |
1471 | %% |
1472 | void | |
d038301c | 1473 | yyerror(arg) |
252b5132 | 1474 | const char *arg; |
d038301c | 1475 | { |
252b5132 RH |
1476 | if (ldfile_assumed_script) |
1477 | einfo (_("%P:%s: file format not recognized; treating as linker script\n"), | |
dab69f68 | 1478 | ldlex_filename ()); |
252b5132 | 1479 | if (error_index > 0 && error_index < ERROR_NAME_MAX) |
df5f2391 | 1480 | einfo ("%F%P:%pS: %s in %s\n", NULL, arg, error_names[error_index - 1]); |
252b5132 | 1481 | else |
df5f2391 | 1482 | einfo ("%F%P:%pS: %s\n", NULL, arg); |
252b5132 | 1483 | } |