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.
This commit is contained in:
Andrew Burgess 2017-07-28 13:01:10 +01:00 committed by Nick Clifton
parent a808670465
commit 2b94abd48a
20 changed files with 250 additions and 66 deletions

View File

@ -1,3 +1,33 @@
2017-07-28 Andrew Burgess <andrew.burgess@embecosm.com>
* 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.
2017-07-27 Georg-Johann Lay <gjl@gcc.gnu.org>
PR ld/21849

View File

@ -1,5 +1,12 @@
-*- text -*-
* Tighten linker script grammar around file name specifiers to prevent the use
of SORT_BY_ALIGNMENT and SORT_BY_INIT_PRIORITY on filenames. These would
previously be accepted but had no effect.
* The EXCLUDE_FILE directive can now be placed within any SORT_* directive
within input section lists.
Changes in 2.29:
* Support for -z shstk in the x86 ELF linker to generate

View File

@ -48,8 +48,8 @@
static enum section_type sectype;
static lang_memory_region_type *region;
bfd_boolean ldgram_had_keep = FALSE;
char *ldgram_vers_current_lang = NULL;
static bfd_boolean ldgram_had_keep = FALSE;
static char *ldgram_vers_current_lang = NULL;
#define ERROR_NAME_MAX 20
static char *error_names[ERROR_NAME_MAX];
@ -92,13 +92,13 @@ static int error_index;
%type <etree> opt_exp_without_type opt_subalign opt_align
%type <fill> fill_opt fill_exp
%type <name_list> exclude_name_list
%type <wildcard_list> section_NAME_list
%type <wildcard_list> section_name_list
%type <flag_info_list> sect_flag_list
%type <flag_info> sect_flags
%type <name> memspec_opt casesymlist
%type <name> memspec_at_opt
%type <cname> wildcard_name
%type <wildcard> wildcard_spec
%type <wildcard> section_name_spec filename_spec wildcard_maybe_exclude
%token <bigint> INT
%token <name> NAME LNAME
%type <integer> length
@ -447,7 +447,7 @@ wildcard_name:
}
;
wildcard_spec:
wildcard_maybe_exclude:
wildcard_name
{
$$.name = $1;
@ -462,68 +462,63 @@ wildcard_spec:
$$.exclude_name_list = $3;
$$.section_flag_list = NULL;
}
| SORT_BY_NAME '(' wildcard_name ')'
;
filename_spec:
wildcard_maybe_exclude
| SORT_BY_NAME '(' wildcard_maybe_exclude ')'
{
$$.name = $3;
$$ = $3;
$$.sorted = by_name;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_BY_ALIGNMENT '(' wildcard_name ')'
| SORT_NONE '(' wildcard_maybe_exclude ')'
{
$$.name = $3;
$$.sorted = by_alignment;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_NONE '(' wildcard_name ')'
{
$$.name = $3;
$$ = $3;
$$.sorted = by_none;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
;
section_name_spec:
wildcard_maybe_exclude
| SORT_BY_NAME '(' wildcard_maybe_exclude ')'
{
$$.name = $5;
$$.sorted = by_name_alignment;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
{
$$.name = $5;
$$ = $3;
$$.sorted = by_name;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
| SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')'
{
$$.name = $5;
$$.sorted = by_alignment_name;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
{
$$.name = $5;
$$ = $3;
$$.sorted = by_alignment;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
| SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
| SORT_NONE '(' wildcard_maybe_exclude ')'
{
$$.name = $7;
$$ = $3;
$$.sorted = by_none;
}
| SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
{
$$ = $5;
$$.sorted = by_name_alignment;
}
| SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
{
$$ = $5;
$$.sorted = by_name;
$$.exclude_name_list = $5;
$$.section_flag_list = NULL;
}
| SORT_BY_INIT_PRIORITY '(' wildcard_name ')'
| SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
{
$$.name = $3;
$$ = $5;
$$.sorted = by_alignment_name;
}
| SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
{
$$ = $5;
$$.sorted = by_alignment;
}
| SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')'
{
$$ = $3;
$$.sorted = by_init_priority;
$$.exclude_name_list = NULL;
$$.section_flag_list = NULL;
}
;
@ -598,8 +593,8 @@ exclude_name_list:
}
;
section_NAME_list:
section_NAME_list opt_comma wildcard_spec
section_name_list:
section_name_list opt_comma section_name_spec
{
struct wildcard_list *tmp;
tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
@ -608,7 +603,7 @@ section_NAME_list:
$$ = tmp;
}
|
wildcard_spec
section_name_spec
{
struct wildcard_list *tmp;
tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
@ -637,11 +632,11 @@ input_section_spec_no_keep:
tmp.section_flag_list = $1;
lang_add_wild (&tmp, NULL, ldgram_had_keep);
}
| '[' section_NAME_list ']'
| '[' section_name_list ']'
{
lang_add_wild (NULL, $2, ldgram_had_keep);
}
| sect_flags '[' section_NAME_list ']'
| sect_flags '[' section_name_list ']'
{
struct wildcard_spec tmp;
tmp.name = NULL;
@ -650,11 +645,11 @@ input_section_spec_no_keep:
tmp.section_flag_list = $1;
lang_add_wild (&tmp, $3, ldgram_had_keep);
}
| wildcard_spec '(' section_NAME_list ')'
| filename_spec '(' section_name_list ')'
{
lang_add_wild (&$1, $3, ldgram_had_keep);
}
| sect_flags wildcard_spec '(' section_NAME_list ')'
| sect_flags filename_spec '(' section_name_list ')'
{
$2.section_flag_list = $1;
lang_add_wild (&$2, $4, ldgram_had_keep);

View File

@ -61,7 +61,6 @@ static struct obstack map_obstack;
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
static const char *entry_symbol_default = "start";
static bfd_boolean placed_commons = FALSE;
static bfd_boolean map_head_is_link_order = FALSE;
static lang_output_section_statement_type *default_common_section;
static bfd_boolean map_option_f;
@ -4414,7 +4413,7 @@ print_wild_statement (lang_wild_statement_type *w,
}
if (w->filenames_sorted)
minfo ("SORT(");
minfo ("SORT_BY_NAME(");
if (w->filename != NULL)
minfo ("%s", w->filename);
else
@ -4425,8 +4424,44 @@ print_wild_statement (lang_wild_statement_type *w,
minfo ("(");
for (sec = w->section_list; sec; sec = sec->next)
{
if (sec->spec.sorted)
minfo ("SORT(");
int closing_paren = 0;
switch (sec->spec.sorted)
{
case none:
break;
case by_name:
minfo ("SORT_BY_NAME(");
closing_paren = 1;
break;
case by_alignment:
minfo ("SORT_BY_ALIGNMENT(");
closing_paren = 1;
break;
case by_name_alignment:
minfo ("SORT_BY_NAME(SORT_BY_ALIGNMENT(");
closing_paren = 2;
break;
case by_alignment_name:
minfo ("SORT_BY_ALIGNMENT(SORT_BY_NAME(");
closing_paren = 2;
break;
case by_none:
minfo ("SORT_NONE(");
closing_paren = 1;
break;
case by_init_priority:
minfo ("SORT_BY_INIT_PRIORITY(");
closing_paren = 1;
break;
}
if (sec->spec.exclude_name_list != NULL)
{
name_list *tmp;
@ -4439,8 +4474,8 @@ print_wild_statement (lang_wild_statement_type *w,
minfo ("%s", sec->spec.name);
else
minfo ("*");
if (sec->spec.sorted)
minfo (")");
for (;closing_paren > 0; closing_paren--)
minfo (")");
if (sec->next)
minfo (" ");
}
@ -7238,9 +7273,6 @@ lang_add_wild (struct wildcard_spec *filespec,
curr != NULL;
section_list = curr, curr = next)
{
if (curr->spec.name != NULL && strcmp (curr->spec.name, "COMMON") == 0)
placed_commons = TRUE;
next = curr->next;
curr->next = section_list;
}

View File

@ -47,6 +47,9 @@ if ![ld_link $ld tmpdir/align "$LDFLAGS -T $srcdir/$subdir/align.t tmpdir/align.
if ![is_aout_format] {
run_dump_test align2a
run_dump_test align2b
run_dump_test align3
run_dump_test align4
run_dump_test align5
}
run_dump_test align2c
set LDFLAGS "$saved_LDFLAGS"

View File

@ -0,0 +1,3 @@
# source: align2a.s
# ld: -T align3.t
# error: .*:4: syntax error

View File

@ -0,0 +1,10 @@
SECTIONS
{
.text : {
SORT_BY_ALIGNMENT (*) (.text .text.*)
}
.data : {
SORT_BY_ALIGNMENT (*) (.data .data.*)
}
}

View File

@ -0,0 +1,3 @@
# source: align2a.s
# ld: -T align4.t
# error: .*:4: syntax error

View File

@ -0,0 +1,10 @@
SECTIONS
{
.text : {
SORT_BY_INIT_PRIORITY (*) (.text .text.*)
}
.data : {
SORT_BY_INIT_PRIORITY (*) (.data .data.*)
}
}

View File

@ -0,0 +1,7 @@
# source: align2a.s
# ld: -T align5.t
# nm: -n
#...
.*foo
#...

View File

@ -0,0 +1,12 @@
SECTIONS
{
.text : {
SORT_NONE (*) (.text .text.*)
}
.data : {
SORT_NONE (*) (.data .data.*)
foo = .;
}
/DISCARD/ : {*(*)}
}

View File

@ -0,0 +1,5 @@
#source: exclude-file-a.s
#source: exclude-file-b.s
#ld: -T exclude-file-5.t
#map: exclude-file-5.map

View File

@ -0,0 +1,8 @@
#...
\.data +0x[0-9a-f]+ +0x[0-9a-f]+
\*\(SORT_BY_NAME\(EXCLUDE_FILE\(\*-b\.o\) \.data\)\)
\.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o
\*\(SORT_BY_NAME\(EXCLUDE_FILE\(\*-a\.o\) \.data\.\*\)\)
\.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-b\.o
#...

View File

@ -0,0 +1,11 @@
SECTIONS
{
.data : {
* (SORT_BY_NAME (EXCLUDE_FILE (*-b.o) .data))
* (SORT_BY_NAME (SORT_BY_NAME (EXCLUDE_FILE (*-a.o) .data.*)))
}
/DISCARD/ : {
* (*)
}
}

View File

@ -0,0 +1,5 @@
#source: exclude-file-a.s
#source: exclude-file-b.s
#ld: -T exclude-file-6.t
#map: exclude-file-6.map

View File

@ -0,0 +1,8 @@
#...
\.data +0x[0-9a-f]+ +0x[0-9a-f]+
\*\(SORT_BY_ALIGNMENT\(SORT_BY_NAME\(EXCLUDE_FILE\(\*-b\.o\) \.data\)\)\)
\.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o
\*\(SORT_BY_NAME\(SORT_BY_ALIGNMENT\(EXCLUDE_FILE\(\*-a\.o\) \.data\.\*\)\)\)
\.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-b\.o
#...

View File

@ -0,0 +1,11 @@
SECTIONS
{
.data : {
* (SORT_BY_ALIGNMENT (SORT_BY_NAME (EXCLUDE_FILE (*-b.o) .data)))
* (SORT_BY_NAME (SORT_BY_ALIGNMENT (EXCLUDE_FILE (*-a.o) .data.*)))
}
/DISCARD/ : {
* (*)
}
}

View File

@ -0,0 +1,5 @@
#source: exclude-file-a.s
#source: exclude-file-b.s
#ld: -T exclude-file-7.t
#map: exclude-file-7.map

View File

@ -0,0 +1,8 @@
#...
\.data +0x[0-9a-f]+ +0x[0-9a-f]+
\*\(SORT_BY_INIT_PRIORITY\(EXCLUDE_FILE\(\*-b\.o\) \.data\)\)
\.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o
\*\(SORT_BY_ALIGNMENT\(EXCLUDE_FILE\(\*-a\.o\) \.data\.\*\)\)
\.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-b\.o
#...

View File

@ -0,0 +1,11 @@
SECTIONS
{
.data : {
* (SORT_BY_INIT_PRIORITY (EXCLUDE_FILE (*-b.o) .data))
* (SORT_BY_ALIGNMENT (SORT_BY_ALIGNMENT (EXCLUDE_FILE (*-a.o) .data.*)))
}
/DISCARD/ : {
* (*)
}
}