WIP MachO binutils port assisted by AI I may consider upstreaming this in the future.
0

Configure Feed

Select the types of activity you want to include in your feed.

Make some improvements to how SORT_* specifiers and EXCLUDE_FILE specifiers are handled in the linker script grammar.

* ldgram.y (ldgram_had_keep): Make static.
(ldgram_vers_current_lang): Likewise.
(filename_spec): New rule.
(input_section_spec_no_keep): Use filename_spec.
(wildcard_maybe_exclude): New rule.
(wildcard_spec): Rename to...
(section_name_spec): ...this.
(section_NAME_list): Rename to...
(section_name_list): ...this.
(section_name_spec): Simplifiy and use wildcard_maybe_exclude.
* ldlang.c (placed_commons): Delete.
(lang_add_wild): No longer set placed_commons.
(print_wild_statement): Use full names for SORT specifiers.
* testsuite/ld-scripts/align.exp: Run new tests.
* testsuite/ld-scripts/align3.d: New file.
* testsuite/ld-scripts/align3.t: New file.
* testsuite/ld-scripts/align4.d: New file.
* testsuite/ld-scripts/align4.t: New file.
* testsuite/ld-scripts/align5.d: New file.
* testsuite/ld-scripts/align5.t: New file.
* testsuite/ld-scripts/exclude-file-5.d: New file.
* testsuite/ld-scripts/exclude-file-5.map: New file.
* testsuite/ld-scripts/exclude-file-5.t: New file.
* testsuite/ld-scripts/exclude-file-6.d: New file.
* testsuite/ld-scripts/exclude-file-6.map: New file.
* testsuite/ld-scripts/exclude-file-6.t: New file.
* NEWS: Mention the changes.

authored by

Andrew Burgess and committed by
Nick Clifton
(Jul 28, 2017, 1:01 PM +0100) 2b94abd4 a8086704

+244 -60
+30
ld/ChangeLog
··· 1 + 2017-07-28 Andrew Burgess <andrew.burgess@embecosm.com> 2 + 3 + * ldgram.y (ldgram_had_keep): Make static. 4 + (ldgram_vers_current_lang): Likewise. 5 + (filename_spec): New rule. 6 + (input_section_spec_no_keep): Use filename_spec. 7 + (wildcard_maybe_exclude): New rule. 8 + (wildcard_spec): Rename to... 9 + (section_name_spec): ...this. 10 + (section_NAME_list): Rename to... 11 + (section_name_list): ...this. 12 + (section_name_spec): Simplifiy and use wildcard_maybe_exclude. 13 + * ldlang.c (placed_commons): Delete. 14 + (lang_add_wild): No longer set placed_commons. 15 + (print_wild_statement): Use full names for SORT specifiers. 16 + * testsuite/ld-scripts/align.exp: Run new tests. 17 + * testsuite/ld-scripts/align3.d: New file. 18 + * testsuite/ld-scripts/align3.t: New file. 19 + * testsuite/ld-scripts/align4.d: New file. 20 + * testsuite/ld-scripts/align4.t: New file. 21 + * testsuite/ld-scripts/align5.d: New file. 22 + * testsuite/ld-scripts/align5.t: New file. 23 + * testsuite/ld-scripts/exclude-file-5.d: New file. 24 + * testsuite/ld-scripts/exclude-file-5.map: New file. 25 + * testsuite/ld-scripts/exclude-file-5.t: New file. 26 + * testsuite/ld-scripts/exclude-file-6.d: New file. 27 + * testsuite/ld-scripts/exclude-file-6.map: New file. 28 + * testsuite/ld-scripts/exclude-file-6.t: New file. 29 + * NEWS: Mention the changes. 30 + 1 31 2017-07-27 Georg-Johann Lay <gjl@gcc.gnu.org> 2 32 3 33 PR ld/21849
+7
ld/NEWS
··· 1 1 -*- text -*- 2 2 3 + * Tighten linker script grammar around file name specifiers to prevent the use 4 + of SORT_BY_ALIGNMENT and SORT_BY_INIT_PRIORITY on filenames. These would 5 + previously be accepted but had no effect. 6 + 7 + * The EXCLUDE_FILE directive can now be placed within any SORT_* directive 8 + within input section lists. 9 + 3 10 Changes in 2.29: 4 11 5 12 * Support for -z shstk in the x86 ELF linker to generate
+46 -51
ld/ldgram.y
··· 48 48 static enum section_type sectype; 49 49 static lang_memory_region_type *region; 50 50 51 - bfd_boolean ldgram_had_keep = FALSE; 52 - char *ldgram_vers_current_lang = NULL; 51 + static bfd_boolean ldgram_had_keep = FALSE; 52 + static char *ldgram_vers_current_lang = NULL; 53 53 54 54 #define ERROR_NAME_MAX 20 55 55 static char *error_names[ERROR_NAME_MAX]; ··· 92 92 %type <etree> opt_exp_without_type opt_subalign opt_align 93 93 %type <fill> fill_opt fill_exp 94 94 %type <name_list> exclude_name_list 95 - %type <wildcard_list> section_NAME_list 95 + %type <wildcard_list> section_name_list 96 96 %type <flag_info_list> sect_flag_list 97 97 %type <flag_info> sect_flags 98 98 %type <name> memspec_opt casesymlist 99 99 %type <name> memspec_at_opt 100 100 %type <cname> wildcard_name 101 - %type <wildcard> wildcard_spec 101 + %type <wildcard> section_name_spec filename_spec wildcard_maybe_exclude 102 102 %token <bigint> INT 103 103 %token <name> NAME LNAME 104 104 %type <integer> length ··· 447 447 } 448 448 ; 449 449 450 - wildcard_spec: 450 + wildcard_maybe_exclude: 451 451 wildcard_name 452 452 { 453 453 $$.name = $1; ··· 462 462 $$.exclude_name_list = $3; 463 463 $$.section_flag_list = NULL; 464 464 } 465 - | SORT_BY_NAME '(' wildcard_name ')' 465 + ; 466 + 467 + filename_spec: 468 + wildcard_maybe_exclude 469 + | SORT_BY_NAME '(' wildcard_maybe_exclude ')' 470 + { 471 + $$ = $3; 472 + $$.sorted = by_name; 473 + } 474 + | SORT_NONE '(' wildcard_maybe_exclude ')' 475 + { 476 + $$ = $3; 477 + $$.sorted = by_none; 478 + } 479 + ; 480 + 481 + section_name_spec: 482 + wildcard_maybe_exclude 483 + | SORT_BY_NAME '(' wildcard_maybe_exclude ')' 466 484 { 467 - $$.name = $3; 485 + $$ = $3; 468 486 $$.sorted = by_name; 469 - $$.exclude_name_list = NULL; 470 - $$.section_flag_list = NULL; 471 487 } 472 - | SORT_BY_ALIGNMENT '(' wildcard_name ')' 488 + | SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' 473 489 { 474 - $$.name = $3; 490 + $$ = $3; 475 491 $$.sorted = by_alignment; 476 - $$.exclude_name_list = NULL; 477 - $$.section_flag_list = NULL; 478 492 } 479 - | SORT_NONE '(' wildcard_name ')' 493 + | SORT_NONE '(' wildcard_maybe_exclude ')' 480 494 { 481 - $$.name = $3; 495 + $$ = $3; 482 496 $$.sorted = by_none; 483 - $$.exclude_name_list = NULL; 484 - $$.section_flag_list = NULL; 485 497 } 486 - | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')' 498 + | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')' 487 499 { 488 - $$.name = $5; 500 + $$ = $5; 489 501 $$.sorted = by_name_alignment; 490 - $$.exclude_name_list = NULL; 491 - $$.section_flag_list = NULL; 492 502 } 493 - | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')' 503 + | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')' 494 504 { 495 - $$.name = $5; 505 + $$ = $5; 496 506 $$.sorted = by_name; 497 - $$.exclude_name_list = NULL; 498 - $$.section_flag_list = NULL; 499 507 } 500 - | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')' 508 + | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')' 501 509 { 502 - $$.name = $5; 510 + $$ = $5; 503 511 $$.sorted = by_alignment_name; 504 - $$.exclude_name_list = NULL; 505 - $$.section_flag_list = NULL; 506 512 } 507 - | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')' 513 + | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')' 508 514 { 509 - $$.name = $5; 515 + $$ = $5; 510 516 $$.sorted = by_alignment; 511 - $$.exclude_name_list = NULL; 512 - $$.section_flag_list = NULL; 513 517 } 514 - | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')' 515 - { 516 - $$.name = $7; 517 - $$.sorted = by_name; 518 - $$.exclude_name_list = $5; 519 - $$.section_flag_list = NULL; 520 - } 521 - | SORT_BY_INIT_PRIORITY '(' wildcard_name ')' 518 + | SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')' 522 519 { 523 - $$.name = $3; 520 + $$ = $3; 524 521 $$.sorted = by_init_priority; 525 - $$.exclude_name_list = NULL; 526 - $$.section_flag_list = NULL; 527 522 } 528 523 ; 529 524 ··· 598 593 } 599 594 ; 600 595 601 - section_NAME_list: 602 - section_NAME_list opt_comma wildcard_spec 596 + section_name_list: 597 + section_name_list opt_comma section_name_spec 603 598 { 604 599 struct wildcard_list *tmp; 605 600 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); ··· 608 603 $$ = tmp; 609 604 } 610 605 | 611 - wildcard_spec 606 + section_name_spec 612 607 { 613 608 struct wildcard_list *tmp; 614 609 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); ··· 637 632 tmp.section_flag_list = $1; 638 633 lang_add_wild (&tmp, NULL, ldgram_had_keep); 639 634 } 640 - | '[' section_NAME_list ']' 635 + | '[' section_name_list ']' 641 636 { 642 637 lang_add_wild (NULL, $2, ldgram_had_keep); 643 638 } 644 - | sect_flags '[' section_NAME_list ']' 639 + | sect_flags '[' section_name_list ']' 645 640 { 646 641 struct wildcard_spec tmp; 647 642 tmp.name = NULL; ··· 650 645 tmp.section_flag_list = $1; 651 646 lang_add_wild (&tmp, $3, ldgram_had_keep); 652 647 } 653 - | wildcard_spec '(' section_NAME_list ')' 648 + | filename_spec '(' section_name_list ')' 654 649 { 655 650 lang_add_wild (&$1, $3, ldgram_had_keep); 656 651 } 657 - | sect_flags wildcard_spec '(' section_NAME_list ')' 652 + | sect_flags filename_spec '(' section_name_list ')' 658 653 { 659 654 $2.section_flag_list = $1; 660 655 lang_add_wild (&$2, $4, ldgram_had_keep);
+41 -9
ld/ldlang.c
··· 61 61 #define obstack_chunk_alloc xmalloc 62 62 #define obstack_chunk_free free 63 63 static const char *entry_symbol_default = "start"; 64 - static bfd_boolean placed_commons = FALSE; 65 64 static bfd_boolean map_head_is_link_order = FALSE; 66 65 static lang_output_section_statement_type *default_common_section; 67 66 static bfd_boolean map_option_f; ··· 4414 4413 } 4415 4414 4416 4415 if (w->filenames_sorted) 4417 - minfo ("SORT("); 4416 + minfo ("SORT_BY_NAME("); 4418 4417 if (w->filename != NULL) 4419 4418 minfo ("%s", w->filename); 4420 4419 else ··· 4425 4424 minfo ("("); 4426 4425 for (sec = w->section_list; sec; sec = sec->next) 4427 4426 { 4428 - if (sec->spec.sorted) 4429 - minfo ("SORT("); 4427 + int closing_paren = 0; 4428 + 4429 + switch (sec->spec.sorted) 4430 + { 4431 + case none: 4432 + break; 4433 + 4434 + case by_name: 4435 + minfo ("SORT_BY_NAME("); 4436 + closing_paren = 1; 4437 + break; 4438 + 4439 + case by_alignment: 4440 + minfo ("SORT_BY_ALIGNMENT("); 4441 + closing_paren = 1; 4442 + break; 4443 + 4444 + case by_name_alignment: 4445 + minfo ("SORT_BY_NAME(SORT_BY_ALIGNMENT("); 4446 + closing_paren = 2; 4447 + break; 4448 + 4449 + case by_alignment_name: 4450 + minfo ("SORT_BY_ALIGNMENT(SORT_BY_NAME("); 4451 + closing_paren = 2; 4452 + break; 4453 + 4454 + case by_none: 4455 + minfo ("SORT_NONE("); 4456 + closing_paren = 1; 4457 + break; 4458 + 4459 + case by_init_priority: 4460 + minfo ("SORT_BY_INIT_PRIORITY("); 4461 + closing_paren = 1; 4462 + break; 4463 + } 4464 + 4430 4465 if (sec->spec.exclude_name_list != NULL) 4431 4466 { 4432 4467 name_list *tmp; ··· 4439 4474 minfo ("%s", sec->spec.name); 4440 4475 else 4441 4476 minfo ("*"); 4442 - if (sec->spec.sorted) 4443 - minfo (")"); 4477 + for (;closing_paren > 0; closing_paren--) 4478 + minfo (")"); 4444 4479 if (sec->next) 4445 4480 minfo (" "); 4446 4481 } ··· 7238 7273 curr != NULL; 7239 7274 section_list = curr, curr = next) 7240 7275 { 7241 - if (curr->spec.name != NULL && strcmp (curr->spec.name, "COMMON") == 0) 7242 - placed_commons = TRUE; 7243 - 7244 7276 next = curr->next; 7245 7277 curr->next = section_list; 7246 7278 }
+3
ld/testsuite/ld-scripts/align.exp
··· 47 47 if ![is_aout_format] { 48 48 run_dump_test align2a 49 49 run_dump_test align2b 50 + run_dump_test align3 51 + run_dump_test align4 52 + run_dump_test align5 50 53 } 51 54 run_dump_test align2c 52 55 set LDFLAGS "$saved_LDFLAGS"
+3
ld/testsuite/ld-scripts/align3.d
··· 1 + # source: align2a.s 2 + # ld: -T align3.t 3 + # error: .*:4: syntax error
+10
ld/testsuite/ld-scripts/align3.t
··· 1 + SECTIONS 2 + { 3 + .text : { 4 + SORT_BY_ALIGNMENT (*) (.text .text.*) 5 + } 6 + 7 + .data : { 8 + SORT_BY_ALIGNMENT (*) (.data .data.*) 9 + } 10 + }
+3
ld/testsuite/ld-scripts/align4.d
··· 1 + # source: align2a.s 2 + # ld: -T align4.t 3 + # error: .*:4: syntax error
+10
ld/testsuite/ld-scripts/align4.t
··· 1 + SECTIONS 2 + { 3 + .text : { 4 + SORT_BY_INIT_PRIORITY (*) (.text .text.*) 5 + } 6 + 7 + .data : { 8 + SORT_BY_INIT_PRIORITY (*) (.data .data.*) 9 + } 10 + }
+7
ld/testsuite/ld-scripts/align5.d
··· 1 + # source: align2a.s 2 + # ld: -T align5.t 3 + # nm: -n 4 + 5 + #... 6 + .*foo 7 + #...
+12
ld/testsuite/ld-scripts/align5.t
··· 1 + SECTIONS 2 + { 3 + .text : { 4 + SORT_NONE (*) (.text .text.*) 5 + } 6 + 7 + .data : { 8 + SORT_NONE (*) (.data .data.*) 9 + foo = .; 10 + } 11 + /DISCARD/ : {*(*)} 12 + }
+5
ld/testsuite/ld-scripts/exclude-file-5.d
··· 1 + #source: exclude-file-a.s 2 + #source: exclude-file-b.s 3 + #ld: -T exclude-file-5.t 4 + #map: exclude-file-5.map 5 +
+8
ld/testsuite/ld-scripts/exclude-file-5.map
··· 1 + #... 2 + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ 3 + \*\(SORT_BY_NAME\(EXCLUDE_FILE\(\*-b\.o\) \.data\)\) 4 + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o 5 + \*\(SORT_BY_NAME\(EXCLUDE_FILE\(\*-a\.o\) \.data\.\*\)\) 6 + \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-b\.o 7 + 8 + #...
+11
ld/testsuite/ld-scripts/exclude-file-5.t
··· 1 + SECTIONS 2 + { 3 + .data : { 4 + * (SORT_BY_NAME (EXCLUDE_FILE (*-b.o) .data)) 5 + * (SORT_BY_NAME (SORT_BY_NAME (EXCLUDE_FILE (*-a.o) .data.*))) 6 + } 7 + 8 + /DISCARD/ : { 9 + * (*) 10 + } 11 + }
+5
ld/testsuite/ld-scripts/exclude-file-6.d
··· 1 + #source: exclude-file-a.s 2 + #source: exclude-file-b.s 3 + #ld: -T exclude-file-6.t 4 + #map: exclude-file-6.map 5 +
+8
ld/testsuite/ld-scripts/exclude-file-6.map
··· 1 + #... 2 + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ 3 + \*\(SORT_BY_ALIGNMENT\(SORT_BY_NAME\(EXCLUDE_FILE\(\*-b\.o\) \.data\)\)\) 4 + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o 5 + \*\(SORT_BY_NAME\(SORT_BY_ALIGNMENT\(EXCLUDE_FILE\(\*-a\.o\) \.data\.\*\)\)\) 6 + \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-b\.o 7 + 8 + #...
+11
ld/testsuite/ld-scripts/exclude-file-6.t
··· 1 + SECTIONS 2 + { 3 + .data : { 4 + * (SORT_BY_ALIGNMENT (SORT_BY_NAME (EXCLUDE_FILE (*-b.o) .data))) 5 + * (SORT_BY_NAME (SORT_BY_ALIGNMENT (EXCLUDE_FILE (*-a.o) .data.*))) 6 + } 7 + 8 + /DISCARD/ : { 9 + * (*) 10 + } 11 + }
+5
ld/testsuite/ld-scripts/exclude-file-7.d
··· 1 + #source: exclude-file-a.s 2 + #source: exclude-file-b.s 3 + #ld: -T exclude-file-7.t 4 + #map: exclude-file-7.map 5 +
+8
ld/testsuite/ld-scripts/exclude-file-7.map
··· 1 + #... 2 + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ 3 + \*\(SORT_BY_INIT_PRIORITY\(EXCLUDE_FILE\(\*-b\.o\) \.data\)\) 4 + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o 5 + \*\(SORT_BY_ALIGNMENT\(EXCLUDE_FILE\(\*-a\.o\) \.data\.\*\)\) 6 + \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-b\.o 7 + 8 + #...
+11
ld/testsuite/ld-scripts/exclude-file-7.t
··· 1 + SECTIONS 2 + { 3 + .data : { 4 + * (SORT_BY_INIT_PRIORITY (EXCLUDE_FILE (*-b.o) .data)) 5 + * (SORT_BY_ALIGNMENT (SORT_BY_ALIGNMENT (EXCLUDE_FILE (*-a.o) .data.*))) 6 + } 7 + 8 + /DISCARD/ : { 9 + * (*) 10 + } 11 + }