diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2016-09-20 14:21:05 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2016-11-04 12:04:11 +0000 |
commit | 8f1732fc2a11dc2dbece0800d4ed6f011590d3ad (patch) | |
tree | acc377f4e67f75cfa0b0add266c83e79486aa4a3 /ld/testsuite/ld-scripts | |
parent | 88bd15396002102beedf49c87adee7b16c2bb409 (diff) | |
download | gdb-8f1732fc2a11dc2dbece0800d4ed6f011590d3ad.zip gdb-8f1732fc2a11dc2dbece0800d4ed6f011590d3ad.tar.gz gdb-8f1732fc2a11dc2dbece0800d4ed6f011590d3ad.tar.bz2 |
ld: Allow EXCLUDE_FILE to be used outside of the section list
Currently the EXCLUDE_FILE linker script construct can only be used
within the input section list, and applied only to the section pattern
immediately following the EXCLUDE_FILE. For example:
*.o (EXCLUDE_FILE (a.o) .text .rodata)
In this case all sections matching '.text' are included from all files
matching '*.o' but not from the file 'a.o'. All sections matching
'.rodata' are also included from all files matching '*.o' (incluing from
'a.o').
If the user wants to restrict the inclusion of section '.rodata' so that
this too is not taken from the file 'a.o' then the above example must be
extended like this:
*.o (EXCLUDE_FILE (a.o) .text EXCLUDE_FILE (a.o) .rodata)
However, due to the internal grammar of the linker script language the
snippet 'EXCLUDE_FILE (a.o) .text' is parsed by a pattern called
'wildcard_spec'. The same 'wildcard_spec' pattern is also used to parse
the input file name snippet '*.o' in the above examples. As a result of
this pattern reuse within the linker script grammar then the following
is also a valid linker script construct:
EXCLUDE_FILE (a.o) *.o (.text .rodata)
However, though the linker accepts this without complaint the
EXCLUDE_FILE part is silently ignored and has no effect.
This commit takes this last example and makes it a useful, valid,
construct. The last example now means to include sections '.text' and
'.rodata' from all files matching '*.o' except for the file 'a.o'.
If the list of input sections is long, and the user knows that the file
exclusion applies across the list then the second form might be a
clearer alternative to replicating the EXCLUDE_FILE construct.
I've added a set of tests for EXCLUDE_FILE to the linker, including
tests for the new functionality.
ld/ChangeLog:
* ldlang.h (struct lang_wild_statement_struct): Add
exclude_name_list field.
* ldlang.c (walk_wild_file_in_exclude_list): New function.
(walk_wild_consider_section): Use new
walk_wild_file_in_exclude_list function.
(walk_wild_file): Add call to walk_wild_file_in_exclude_list.
(print_wild_statement): Print new exclude_name_list field.
(lang_add_wild): Initialise new exclude_name_list field.
* testsuite/ld-scripts/exclude-file-1.d: New file.
* testsuite/ld-scripts/exclude-file-1.map: New file.
* testsuite/ld-scripts/exclude-file-1.t: New file.
* testsuite/ld-scripts/exclude-file-2.d: New file.
* testsuite/ld-scripts/exclude-file-2.map: New file.
* testsuite/ld-scripts/exclude-file-2.t: New file.
* testsuite/ld-scripts/exclude-file-3.d: New file.
* testsuite/ld-scripts/exclude-file-3.map: New file.
* testsuite/ld-scripts/exclude-file-3.t: New file.
* testsuite/ld-scripts/exclude-file-4.d: New file.
* testsuite/ld-scripts/exclude-file-4.map: New file.
* testsuite/ld-scripts/exclude-file-4.t: New file.
* testsuite/ld-scripts/exclude-file-a.s: New file.
* testsuite/ld-scripts/exclude-file-b.s: New file.
* testsuite/ld-scripts/exclude-file.exp: New file.
* ld.texinfo (Input Section Basics): Update description of
EXCLUDE_FILE to cover the new features.
* NEWS: Mention new EXCLUDE_FILE usage.
Diffstat (limited to 'ld/testsuite/ld-scripts')
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-1.d | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-1.map | 8 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-1.t | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-2.d | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-2.map | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-2.t | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-3.d | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-3.map | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-3.t | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-4.d | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-4.map | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-4.t | 10 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-a.s | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file-b.s | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-scripts/exclude-file.exp | 32 |
15 files changed, 131 insertions, 0 deletions
diff --git a/ld/testsuite/ld-scripts/exclude-file-1.d b/ld/testsuite/ld-scripts/exclude-file-1.d new file mode 100644 index 0000000..068ecac --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-1.d @@ -0,0 +1,5 @@ +#source: exclude-file-a.s +#source: exclude-file-b.s +#ld: -T exclude-file-1.t +#map: exclude-file-1.map + diff --git a/ld/testsuite/ld-scripts/exclude-file-1.map b/ld/testsuite/ld-scripts/exclude-file-1.map new file mode 100644 index 0000000..0fbf601 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-1.map @@ -0,0 +1,8 @@ +#... +\.data +0x[0-9a-f]+ +0x[0-9a-f]+ + \*\(EXCLUDE_FILE\(\*-b\.o\) \.data \.data\.\*\) + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o + \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o + \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-b\.o + +#...
\ No newline at end of file diff --git a/ld/testsuite/ld-scripts/exclude-file-1.t b/ld/testsuite/ld-scripts/exclude-file-1.t new file mode 100644 index 0000000..f75e6c3 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-1.t @@ -0,0 +1,10 @@ +SECTIONS +{ + .data : { + * (EXCLUDE_FILE (*-b.o) .data .data.*) + } + + /DISCARD/ : { + * (*) + } +} diff --git a/ld/testsuite/ld-scripts/exclude-file-2.d b/ld/testsuite/ld-scripts/exclude-file-2.d new file mode 100644 index 0000000..7c62c2f --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-2.d @@ -0,0 +1,5 @@ +#source: exclude-file-a.s +#source: exclude-file-b.s +#ld: -T exclude-file-2.t +#map: exclude-file-2.map + diff --git a/ld/testsuite/ld-scripts/exclude-file-2.map b/ld/testsuite/ld-scripts/exclude-file-2.map new file mode 100644 index 0000000..67acfe7 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-2.map @@ -0,0 +1,7 @@ +#... +\.data +0x[0-9a-f]+ +0x[0-9a-f]+ + \*\(EXCLUDE_FILE\(\*-b\.o\) \.data EXCLUDE_FILE\(\*-b\.o\) \.data\.\*\) + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o + \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o + +#...
\ No newline at end of file diff --git a/ld/testsuite/ld-scripts/exclude-file-2.t b/ld/testsuite/ld-scripts/exclude-file-2.t new file mode 100644 index 0000000..efdb5c0 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-2.t @@ -0,0 +1,10 @@ +SECTIONS +{ + .data : { + * (EXCLUDE_FILE (*-b.o) .data EXCLUDE_FILE (*-b.o) .data.*) + } + + /DISCARD/ : { + * (*) + } +} diff --git a/ld/testsuite/ld-scripts/exclude-file-3.d b/ld/testsuite/ld-scripts/exclude-file-3.d new file mode 100644 index 0000000..19bfc4f --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-3.d @@ -0,0 +1,5 @@ +#source: exclude-file-a.s +#source: exclude-file-b.s +#ld: -T exclude-file-3.t +#map: exclude-file-3.map + diff --git a/ld/testsuite/ld-scripts/exclude-file-3.map b/ld/testsuite/ld-scripts/exclude-file-3.map new file mode 100644 index 0000000..389d170 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-3.map @@ -0,0 +1,7 @@ +#... +\.data +0x[0-9a-f]+ +0x[0-9a-f]+ + EXCLUDE_FILE\(\*-b\.o\) \*\(\.data \.data\.\*\) + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o + \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o + +#...
\ No newline at end of file diff --git a/ld/testsuite/ld-scripts/exclude-file-3.t b/ld/testsuite/ld-scripts/exclude-file-3.t new file mode 100644 index 0000000..4d4be58 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-3.t @@ -0,0 +1,10 @@ +SECTIONS +{ + .data : { + EXCLUDE_FILE (*-b.o) * (.data .data.*) + } + + /DISCARD/ : { + * (*) + } +} diff --git a/ld/testsuite/ld-scripts/exclude-file-4.d b/ld/testsuite/ld-scripts/exclude-file-4.d new file mode 100644 index 0000000..b087fee --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-4.d @@ -0,0 +1,5 @@ +#source: exclude-file-a.s +#source: exclude-file-b.s +#ld: -T exclude-file-4.t +#map: exclude-file-4.map + diff --git a/ld/testsuite/ld-scripts/exclude-file-4.map b/ld/testsuite/ld-scripts/exclude-file-4.map new file mode 100644 index 0000000..8549283 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-4.map @@ -0,0 +1,7 @@ +#... +\.data +0x[0-9a-f]+ +0x[0-9a-f]+ + \*\(EXCLUDE_FILE\(\*-b\.o\) \.data EXCLUDE_FILE\(\*-a\.o\) \.data\.\*\) + \.data +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-a\.o + \.data\.1 +0x[0-9a-f]+ +0x[0-9a-f]+ tmpdir/exclude-file-b\.o + +#...
\ No newline at end of file diff --git a/ld/testsuite/ld-scripts/exclude-file-4.t b/ld/testsuite/ld-scripts/exclude-file-4.t new file mode 100644 index 0000000..a9b03c4 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-4.t @@ -0,0 +1,10 @@ +SECTIONS +{ + .data : { + * (EXCLUDE_FILE (*-b.o) .data EXCLUDE_FILE (*-a.o) .data.*) + } + + /DISCARD/ : { + * (*) + } +} diff --git a/ld/testsuite/ld-scripts/exclude-file-a.s b/ld/testsuite/ld-scripts/exclude-file-a.s new file mode 100644 index 0000000..19f5def --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-a.s @@ -0,0 +1,5 @@ + .section ".data", "aw" + .word 0x0 + + .section ".data.1", "aw" + .word 0x0 diff --git a/ld/testsuite/ld-scripts/exclude-file-b.s b/ld/testsuite/ld-scripts/exclude-file-b.s new file mode 100644 index 0000000..19f5def --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file-b.s @@ -0,0 +1,5 @@ + .section ".data", "aw" + .word 0x0 + + .section ".data.1", "aw" + .word 0x0 diff --git a/ld/testsuite/ld-scripts/exclude-file.exp b/ld/testsuite/ld-scripts/exclude-file.exp new file mode 100644 index 0000000..79fba17 --- /dev/null +++ b/ld/testsuite/ld-scripts/exclude-file.exp @@ -0,0 +1,32 @@ +# Test EXCLUDE_FILE in a linker script. +# By Nathan Sidwell, CodeSourcery LLC +# Copyright (C) 2004-2016 Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. + +if { ![is_elf_format] } then { + unsupported exclude-file.exp + return +} + +set test_list [lsort [glob -nocomplain $srcdir/$subdir/exclude-file-*.d]] +foreach t $test_list { + # We need to strip the ".d", but can leave the dirname. + verbose [file rootname $t] + run_dump_test [file rootname $t] +} |