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