* 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-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
-*- 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
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];
%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
}
;
-wildcard_spec:
+wildcard_maybe_exclude:
wildcard_name
{
$$.name = $1;
$$.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 ')'
+ {
+ $$ = $3;
+ $$.sorted = by_none;
+ }
+ ;
+
+section_name_spec:
+ wildcard_maybe_exclude
+ | SORT_BY_NAME '(' wildcard_maybe_exclude ')'
{
- $$.name = $3;
+ $$ = $3;
+ $$.sorted = by_name;
+ }
+ | SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')'
+ {
+ $$ = $3;
$$.sorted = by_alignment;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
}
- | SORT_NONE '(' wildcard_name ')'
+ | SORT_NONE '(' wildcard_maybe_exclude ')'
{
- $$.name = $3;
+ $$ = $3;
$$.sorted = by_none;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
}
- | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
+ | SORT_BY_NAME '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
{
- $$.name = $5;
+ $$ = $5;
$$.sorted = by_name_alignment;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
}
- | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_name ')' ')'
+ | SORT_BY_NAME '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
{
- $$.name = $5;
+ $$ = $5;
$$.sorted = by_name;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
}
- | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_name ')' ')'
+ | SORT_BY_ALIGNMENT '(' SORT_BY_NAME '(' wildcard_maybe_exclude ')' ')'
{
- $$.name = $5;
+ $$ = $5;
$$.sorted = by_alignment_name;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
}
- | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_name ')' ')'
+ | SORT_BY_ALIGNMENT '(' SORT_BY_ALIGNMENT '(' wildcard_maybe_exclude ')' ')'
{
- $$.name = $5;
+ $$ = $5;
$$.sorted = by_alignment;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
}
- | SORT_BY_NAME '(' EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name ')'
+ | SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')'
{
- $$.name = $7;
- $$.sorted = by_name;
- $$.exclude_name_list = $5;
- $$.section_flag_list = NULL;
- }
- | SORT_BY_INIT_PRIORITY '(' wildcard_name ')'
- {
- $$.name = $3;
+ $$ = $3;
$$.sorted = by_init_priority;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
}
;
}
;
-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);
$$ = tmp;
}
|
- wildcard_spec
+ section_name_spec
{
struct wildcard_list *tmp;
tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
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;
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);
#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;
}
if (w->filenames_sorted)
- minfo ("SORT(");
+ minfo ("SORT_BY_NAME(");
if (w->filename != NULL)
minfo ("%s", w->filename);
else
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;
minfo ("%s", sec->spec.name);
else
minfo ("*");
- if (sec->spec.sorted)
- minfo (")");
+ for (;closing_paren > 0; closing_paren--)
+ minfo (")");
if (sec->next)
minfo (" ");
}
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;
}
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"
--- /dev/null
+# source: align2a.s
+# ld: -T align3.t
+# error: .*:4: syntax error
--- /dev/null
+SECTIONS
+{
+ .text : {
+ SORT_BY_ALIGNMENT (*) (.text .text.*)
+ }
+
+ .data : {
+ SORT_BY_ALIGNMENT (*) (.data .data.*)
+ }
+}
\ No newline at end of file
--- /dev/null
+# source: align2a.s
+# ld: -T align4.t
+# error: .*:4: syntax error
--- /dev/null
+SECTIONS
+{
+ .text : {
+ SORT_BY_INIT_PRIORITY (*) (.text .text.*)
+ }
+
+ .data : {
+ SORT_BY_INIT_PRIORITY (*) (.data .data.*)
+ }
+}
\ No newline at end of file
--- /dev/null
+# source: align2a.s
+# ld: -T align5.t
+# nm: -n
+
+#...
+.*foo
+#...
\ No newline at end of file
--- /dev/null
+SECTIONS
+{
+ .text : {
+ SORT_NONE (*) (.text .text.*)
+ }
+
+ .data : {
+ SORT_NONE (*) (.data .data.*)
+ foo = .;
+ }
+ /DISCARD/ : {*(*)}
+}
--- /dev/null
+#source: exclude-file-a.s
+#source: exclude-file-b.s
+#ld: -T exclude-file-5.t
+#map: exclude-file-5.map
+
--- /dev/null
+#...
+\.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
+
+#...
\ No newline at end of file
--- /dev/null
+SECTIONS
+{
+ .data : {
+ * (SORT_BY_NAME (EXCLUDE_FILE (*-b.o) .data))
+ * (SORT_BY_NAME (SORT_BY_NAME (EXCLUDE_FILE (*-a.o) .data.*)))
+ }
+
+ /DISCARD/ : {
+ * (*)
+ }
+}
--- /dev/null
+#source: exclude-file-a.s
+#source: exclude-file-b.s
+#ld: -T exclude-file-6.t
+#map: exclude-file-6.map
+
--- /dev/null
+#...
+\.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
+
+#...
\ No newline at end of file
--- /dev/null
+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/ : {
+ * (*)
+ }
+}
--- /dev/null
+#source: exclude-file-a.s
+#source: exclude-file-b.s
+#ld: -T exclude-file-7.t
+#map: exclude-file-7.map
+
--- /dev/null
+#...
+\.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
+
+#...
\ No newline at end of file
--- /dev/null
+SECTIONS
+{
+ .data : {
+ * (SORT_BY_INIT_PRIORITY (EXCLUDE_FILE (*-b.o) .data))
+ * (SORT_BY_ALIGNMENT (SORT_BY_ALIGNMENT (EXCLUDE_FILE (*-a.o) .data.*)))
+ }
+
+ /DISCARD/ : {
+ * (*)
+ }
+}