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