aboutsummaryrefslogtreecommitdiff
path: root/ld/ld.texinfo
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2016-09-20 14:21:05 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2016-11-04 12:04:11 +0000
commit8f1732fc2a11dc2dbece0800d4ed6f011590d3ad (patch)
treeacc377f4e67f75cfa0b0add266c83e79486aa4a3 /ld/ld.texinfo
parent88bd15396002102beedf49c87adee7b16c2bb409 (diff)
downloadgdb-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/ld.texinfo')
-rw-r--r--ld/ld.texinfo28
1 files changed, 23 insertions, 5 deletions
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 6528b6a..500fda6 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -4192,14 +4192,24 @@ include all input @samp{.text} sections, you would write:
@end smallexample
@noindent
Here the @samp{*} is a wildcard which matches any file name. To exclude a list
+@cindex EXCLUDE_FILE
of files from matching the file name wildcard, EXCLUDE_FILE may be used to
match all files except the ones specified in the EXCLUDE_FILE list. For
example:
@smallexample
+EXCLUDE_FILE (*crtend.o *otherfile.o) *(.ctors)
+@end smallexample
+@noindent
+will cause all .ctors sections from all files except @file{crtend.o}
+and @file{otherfile.o} to be included. The EXCLUDE_FILE can also be
+placed inside the section list, for example:
+@smallexample
*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
@end smallexample
-will cause all .ctors sections from all files except @file{crtend.o} and
-@file{otherfile.o} to be included.
+@noindent
+The result of this is identically to the previous example. Supporting
+two syntaxes for EXCLUDE_FILE is useful if the section list contains
+more than one section, as described below.
There are two ways to include more than one section:
@smallexample
@@ -4214,8 +4224,9 @@ they are found in the linker input. In the second example, all
@samp{.text} input sections will appear first, followed by all
@samp{.rdata} input sections.
-When using EXCLUDE_FILE with more than one section, the exclusion only
-applies to the section immediately following, for example:
+When using EXCLUDE_FILE with more than one section, if the exclusion
+is within the section list then the exclusion only applies to the
+immediately following section, for example:
@smallexample
*(EXCLUDE_FILE (*somefile.o) .text .rdata)
@end smallexample
@@ -4224,10 +4235,17 @@ will cause all @samp{.text} sections from all files except
@file{somefile.o} to be included, while all @samp{.rdata} sections
from all files, including @file{somefile.o}, will be included. To
exclude the @samp{.rdata} sections from @file{somefile.o} the example
-should be modified to:
+could be modified to:
@smallexample
*(EXCLUDE_FILE (*somefile.o) .text EXCLUDE_FILE (*somefile.o) .rdata)
@end smallexample
+@noindent
+Alternatively, placing the EXCLUDE_FILE outside of the section list,
+before the input file selection, will cause the exclusion to apply for
+all sections. Thus the previous example can be rewritten as:
+@smallexample
+EXCLUDE_FILE (*somefile.o) *(.text .rdata)
+@end smallexample
You can specify a file name to include sections from a particular file.
You would do this if one or more of your files contain special data that