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