This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH 6/7] ld: Make SORT_BY_* and EXCLUDE_FILE separate rules in the grammar
Split the rules that handle the SORT_BY_* and EXCLUDE_FILE for
sections. This split means that EXCLUDE_FILE is now supported in more
places, making its handling much more consistent.
For example, this was valid:
*(SORT_BY_NAME ( EXCLUDE_FILE ( a.o ) .text.* ))
but this is not:
*(SORT_BY_NAME ( SORT_BY_NAME ( EXCLUDE_FILE ( a.o ) .text.* ) ))
despite this being legal:
*(SORT_BY_NAME ( SORT_BY_NAME ( .text.* ) ))
Or this is not legal:
*(SORT_BY_ALIGNMENT ( SORT_BY_NAME ( EXCLUDE_FILE (a.o) .text.* )))
despite this being legal:
*(SORT_BY_ALIGNMENT ( SORT_BY_NAME ( .text.* )))
After this commit all of these inconsistencies are resolved, anywhere
that we can give a section wildcard we can now prefix that with
EXCLUDE_FILE.
ld/ChangeLog:
* ldgram.y (section_name_spec): Simplifiy and use
wildcard_maybe_exclude.
* 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 change.
---
ld/ChangeLog | 15 +++++++
ld/NEWS | 3 ++
ld/ldgram.y | 70 ++++++++----------------------
ld/testsuite/ld-scripts/exclude-file-5.d | 5 +++
ld/testsuite/ld-scripts/exclude-file-5.map | 8 ++++
ld/testsuite/ld-scripts/exclude-file-5.t | 11 +++++
ld/testsuite/ld-scripts/exclude-file-6.d | 5 +++
ld/testsuite/ld-scripts/exclude-file-6.map | 8 ++++
ld/testsuite/ld-scripts/exclude-file-6.t | 11 +++++
ld/testsuite/ld-scripts/exclude-file-7.d | 5 +++
ld/testsuite/ld-scripts/exclude-file-7.map | 8 ++++
ld/testsuite/ld-scripts/exclude-file-7.t | 11 +++++
12 files changed, 107 insertions(+), 53 deletions(-)
create mode 100644 ld/testsuite/ld-scripts/exclude-file-5.d
create mode 100644 ld/testsuite/ld-scripts/exclude-file-5.map
create mode 100644 ld/testsuite/ld-scripts/exclude-file-5.t
create mode 100644 ld/testsuite/ld-scripts/exclude-file-6.d
create mode 100644 ld/testsuite/ld-scripts/exclude-file-6.map
create mode 100644 ld/testsuite/ld-scripts/exclude-file-6.t
create mode 100644 ld/testsuite/ld-scripts/exclude-file-7.d
create mode 100644 ld/testsuite/ld-scripts/exclude-file-7.map
create mode 100644 ld/testsuite/ld-scripts/exclude-file-7.t
diff --git a/ld/NEWS b/ld/NEWS
index 4486029ddb0..13932657dc6 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -4,6 +4,9 @@
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
diff --git a/ld/ldgram.y b/ld/ldgram.y
index 662c161521f..442cdec6dbe 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -479,82 +479,46 @@ filename_spec:
;
section_name_spec:
- wildcard_name
- {
- $$.name = $1;
- $$.sorted = none;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
- }
- | EXCLUDE_FILE '(' exclude_name_list ')' wildcard_name
- {
- $$.name = $5;
- $$.sorted = none;
- $$.exclude_name_list = $3;
- $$.section_flag_list = NULL;
- }
- | SORT_BY_NAME '(' wildcard_name ')'
+ 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_BY_ALIGNMENT '(' wildcard_maybe_exclude ')'
{
- $$.name = $3;
+ $$ = $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 ')'
- {
- $$.name = $7;
- $$.sorted = by_name;
- $$.exclude_name_list = $5;
- $$.section_flag_list = NULL;
}
- | SORT_BY_INIT_PRIORITY '(' wildcard_name ')'
+ | SORT_BY_INIT_PRIORITY '(' wildcard_maybe_exclude ')'
{
- $$.name = $3;
+ $$ = $3;
$$.sorted = by_init_priority;
- $$.exclude_name_list = NULL;
- $$.section_flag_list = NULL;
}
;
diff --git a/ld/testsuite/ld-scripts/exclude-file-5.d b/ld/testsuite/ld-scripts/exclude-file-5.d
new file mode 100644
index 00000000000..dc7040b0cc2
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-5.d
@@ -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
+
diff --git a/ld/testsuite/ld-scripts/exclude-file-5.map b/ld/testsuite/ld-scripts/exclude-file-5.map
new file mode 100644
index 00000000000..9148fd697c2
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-5.map
@@ -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
+
+#...
\ No newline at end of file
diff --git a/ld/testsuite/ld-scripts/exclude-file-5.t b/ld/testsuite/ld-scripts/exclude-file-5.t
new file mode 100644
index 00000000000..e20f5ae198a
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-5.t
@@ -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/ : {
+ * (*)
+ }
+}
diff --git a/ld/testsuite/ld-scripts/exclude-file-6.d b/ld/testsuite/ld-scripts/exclude-file-6.d
new file mode 100644
index 00000000000..7bc9d659b39
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-6.d
@@ -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
+
diff --git a/ld/testsuite/ld-scripts/exclude-file-6.map b/ld/testsuite/ld-scripts/exclude-file-6.map
new file mode 100644
index 00000000000..42e1b38157e
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-6.map
@@ -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
+
+#...
\ No newline at end of file
diff --git a/ld/testsuite/ld-scripts/exclude-file-6.t b/ld/testsuite/ld-scripts/exclude-file-6.t
new file mode 100644
index 00000000000..437e24043ce
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-6.t
@@ -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/ : {
+ * (*)
+ }
+}
diff --git a/ld/testsuite/ld-scripts/exclude-file-7.d b/ld/testsuite/ld-scripts/exclude-file-7.d
new file mode 100644
index 00000000000..89704153292
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-7.d
@@ -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
+
diff --git a/ld/testsuite/ld-scripts/exclude-file-7.map b/ld/testsuite/ld-scripts/exclude-file-7.map
new file mode 100644
index 00000000000..eb1d0a8ce20
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-7.map
@@ -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
+
+#...
\ No newline at end of file
diff --git a/ld/testsuite/ld-scripts/exclude-file-7.t b/ld/testsuite/ld-scripts/exclude-file-7.t
new file mode 100644
index 00000000000..200096e4ed9
--- /dev/null
+++ b/ld/testsuite/ld-scripts/exclude-file-7.t
@@ -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/ : {
+ * (*)
+ }
+}
--
2.13.3