This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] ELF: Don't sort output note section by alignments in ascending order
On Thu, Oct 4, 2018 at 1:09 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Oct 4, 2018 at 11:30 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Thu, Oct 4, 2018 at 7:57 AM Nick Clifton <nickc@redhat.com> wrote:
> > >
> > > Hi H.J.
> > >
> > > We are getting some new linker testsuite failures:
> > >
> > > cr16-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > crx-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > d30v-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > dlx-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > fr30-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > frv-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > ft32-elf/ld/ld.sum:FAIL: ld-elf/pr23658-1
> > > iq2000-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > mips64el-openbsd/ld/ld.sum:FAIL: ld-elf/pr23658-1
> > > mips64-openbsd/ld/ld.sum:FAIL: ld-elf/pr23658-1
> > > mn10200-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > moxie-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > ms1-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > msp430-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > mt-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > or1k-elf/ld/ld.sum:FAIL: ld-elf/pr23658-1
> > > pj-elf/ld/ld.sum:XFAIL: ld-elf/pr23658-1
> > > pru-elf/ld/ld.sum:FAIL: ld-elf/pr23658-1
> > > visium-elf/ld/ld.sum:FAIL: ld-elf/pr23658-1
> > > xc16x-elf/ld/ld.sum:FAIL: ld-elf/pr23658-1
> > > xgate-elf/ld/ld.sum:FAIL: ld-elf/pr23658-1
> > >
> > > Would you mind taking a look please ?
> > >
> >
> > ft32-elf and xgate-elf fail since they use the generic linker. I am checking
> > in this:
> >
> > diff --git a/ld/testsuite/ld-elf/pr23658-1.d b/ld/testsuite/ld-elf/pr23658-1.d
> > index 252fb872ed..e21206b38a 100644
> > --- a/ld/testsuite/ld-elf/pr23658-1.d
> > +++ b/ld/testsuite/ld-elf/pr23658-1.d
> > @@ -7,8 +7,8 @@
> > #readelf: -l --wide
> > # Since generic linker targets don't place SHT_NOTE sections as orphan,
> > # SHT_NOTE sections aren't grouped nor sorted.
> > -#xfail: cr16-* crx-* d30v-* dlx-* fr30-* frv-* iq2000-*
> > -#xfail: m68hc12-* mn10200-* moxie-* mt-* msp430-* pj-*
> > +#xfail: cr16-* crx-* d30v-* dlx-* fr30-* frv-* ft32-* iq2000-*
> > +#xfail: m68hc12-* mn10200-* moxie-* mt-* msp430-* pj-* xgate-*
> >
> > #...
> > +[0-9]+ +\.note\.4 \.note\.1 +
> >
> > I am investigating others.
> >
>
> -shared isn't right:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=23658#c6
>
Since we can only insert a note section after another note section, the
alignment order is determined by the alignment of the first note section.
We should just group and sort output note section by alignments in the
order as they are being processed.
OK for trunk?
--
H.J.
From 71188a88da5c44acfae911e9914f1dae0af89a51 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 4 Oct 2018 15:23:26 -0700
Subject: [PATCH] ELF: Don't sort output note section by alignments in
ascending order
Since we can only insert a note section after another note section, the
alignment order is determined by the alignment of the first note section.
We should just group and sort output note section by alignments in the
order as they are being processed.
PR ld/23658
* ldlang.c (lang_insert_orphan): Don't sort output note section
by alignments in ascending order.
* testsuite/ld-elf/pr23658-1.d: Renamed to ...
* testsuite/ld-elf/pr23658-1a.d: This. Updated.
* testsuite/ld-elf/pr23658-1b.d: New test.
* testsuite/ld-elf/pr23658-1c.d: Likewise.
* testsuite/ld-elf/pr23658-1d.d: Likewise.
* testsuite/ld-elf/pr23658-1e.d: Likewise.
---
ld/ldlang.c | 61 ++++++++++++-------
.../ld-elf/{pr23658-1.d => pr23658-1a.d} | 7 ++-
ld/testsuite/ld-elf/pr23658-1b.d | 17 ++++++
ld/testsuite/ld-elf/pr23658-1c.d | 15 +++++
ld/testsuite/ld-elf/pr23658-1d.d | 15 +++++
ld/testsuite/ld-elf/pr23658-1e.d | 13 ++++
6 files changed, 105 insertions(+), 23 deletions(-)
rename ld/testsuite/ld-elf/{pr23658-1.d => pr23658-1a.d} (63%)
create mode 100644 ld/testsuite/ld-elf/pr23658-1b.d
create mode 100644 ld/testsuite/ld-elf/pr23658-1c.d
create mode 100644 ld/testsuite/ld-elf/pr23658-1d.d
create mode 100644 ld/testsuite/ld-elf/pr23658-1e.d
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 1a27787193..74eee85911 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -1933,15 +1933,18 @@ lang_insert_orphan (asection *s,
specific section to maintain output note section order. */
bfd_boolean after_sec_note;
- /* Group and sort output note section by alignments in
- ascending order. */
+ /* Group and sort output note section by alignments.
+ NB: Since we can only insert a note section after
+ another note section, the alignment order is determined
+ by the alignment of the first note section. */
after_sec = NULL;
if (elf_section_type (s) == SHT_NOTE
&& (s->flags & SEC_LOAD) != 0)
{
- /* Search forward for the last output note section
- with equal or larger alignments. */
- asection *first_note = NULL;
+ /* Search forward for the last output note section as
+ well as the last output note section with the same
+ alignment. */
+ asection *last_note = NULL;
for (sec = as;
(sec != NULL
@@ -1951,9 +1954,8 @@ lang_insert_orphan (asection *s,
&& elf_section_type (sec) == SHT_NOTE
&& (sec->flags & SEC_LOAD) != 0)
{
- if (!first_note)
- first_note = sec;
- if (sec->alignment_power >= s->alignment_power)
+ last_note = sec;
+ if (sec->alignment_power == s->alignment_power)
after_sec = sec;
}
@@ -1962,8 +1964,9 @@ lang_insert_orphan (asection *s,
else
{
/* Search backward for the first output note section
- as well as the last output note section with equal
- or larger alignments. */
+ with the same alignment. */
+ asection *prev_note = NULL;
+
after_sec = NULL;
for (sec = as;
(sec != NULL
@@ -1973,23 +1976,25 @@ lang_insert_orphan (asection *s,
&& elf_section_type (sec) == SHT_NOTE
&& (sec->flags & SEC_LOAD) != 0)
{
- first_note = sec;
- if (!after_sec
- && sec->alignment_power >= s->alignment_power)
- after_sec = sec;
+ if (!prev_note)
+ prev_note = sec;
+ if (sec->alignment_power == s->alignment_power)
+ {
+ after_sec = sec;
+ break;
+ }
}
/* If this will be the first note section, it can be
placed at the default location. */
- after_sec_note = first_note != NULL;
+ after_sec_note = (last_note != NULL
+ || prev_note != NULL);
if (after_sec == NULL && after_sec_note)
{
- /* If all output note sections have smaller
- alignments, place the section before all
- output note sections. AFTER_SEC will be
- NULL if FIRST_NOTE is the first output
- section. */
- after_sec = first_note->prev;
+ /* If no output note sections have the same
+ alignment, place the section after all
+ output note sections. */
+ after_sec = last_note ? last_note : prev_note;
}
}
}
@@ -2014,6 +2019,8 @@ lang_insert_orphan (asection *s,
{
/* Insert OS after AFTER_SEC output statement. */
lang_output_section_statement_type *stmt;
+
+ /* Search forward for AFTER_SEC output statement. */
for (stmt = after;
stmt != NULL;
stmt = stmt->next)
@@ -2023,6 +2030,18 @@ lang_insert_orphan (asection *s,
after = stmt;
break;
}
+
+ /* Search backward for AFTER_SEC output statement. */
+ if (after->bfd_section != after_sec)
+ for (stmt = after->prev;
+ stmt != NULL;
+ stmt = stmt->prev)
+ if (stmt->bfd_section == after_sec)
+ {
+ place_after = TRUE;
+ after = stmt;
+ break;
+ }
}
if (after_sec == NULL || after_sec->next != snew)
diff --git a/ld/testsuite/ld-elf/pr23658-1.d b/ld/testsuite/ld-elf/pr23658-1a.d
similarity index 63%
rename from ld/testsuite/ld-elf/pr23658-1.d
rename to ld/testsuite/ld-elf/pr23658-1a.d
index e21206b38a..0b4071393f 100644
--- a/ld/testsuite/ld-elf/pr23658-1.d
+++ b/ld/testsuite/ld-elf/pr23658-1a.d
@@ -7,10 +7,13 @@
#readelf: -l --wide
# Since generic linker targets don't place SHT_NOTE sections as orphan,
# SHT_NOTE sections aren't grouped nor sorted.
-#xfail: cr16-* crx-* d30v-* dlx-* fr30-* frv-* ft32-* iq2000-*
+#xfail: d30v-* dlx-* fr30-* frv-*-elf ft32-* iq2000-*
#xfail: m68hc12-* mn10200-* moxie-* mt-* msp430-* pj-* xgate-*
+# The following targets don't support --build-id.
+#xfail: cr16-* crx-* visium-* xc16x-*
+# The following targets place .note.gnu.build-id in unusual places.
+#xfail: pru-*
#...
- +[0-9]+ +\.note\.4 \.note\.1 +
+[0-9]+ +\.note.gnu.build-id \.note\.2 .note\.3 +
#pass
diff --git a/ld/testsuite/ld-elf/pr23658-1b.d b/ld/testsuite/ld-elf/pr23658-1b.d
new file mode 100644
index 0000000000..279f292343
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr23658-1b.d
@@ -0,0 +1,17 @@
+#source: pr23658-1a.s
+#source: pr23658-1b.s
+#source: pr23658-1c.s
+#source: pr23658-1d.s
+#source: start.s
+#ld: --build-id
+#readelf: -l --wide
+# Since generic linker targets don't place SHT_NOTE sections as orphan,
+# SHT_NOTE sections aren't grouped nor sorted.
+#xfail: d30v-* dlx-* fr30-* frv-*-elf ft32-* iq2000-*
+#xfail: mn10200-* moxie-* mt-* msp430-* pj-* xgate-*
+# The following targets don't support --build-id.
+#xfail: cr16-* crx-* visium-* xc16x-*
+
+#...
+ +[0-9]+ +\.note\.4 \.note\.1 +
+#pass
diff --git a/ld/testsuite/ld-elf/pr23658-1c.d b/ld/testsuite/ld-elf/pr23658-1c.d
new file mode 100644
index 0000000000..f3dbb3af94
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr23658-1c.d
@@ -0,0 +1,15 @@
+#source: pr23658-1a.s
+#source: pr23658-1b.s
+#source: pr23658-1c.s
+#source: pr23658-1d.s
+#source: start.s
+#ld:
+#readelf: -l --wide
+# Since generic linker targets don't place SHT_NOTE sections as orphan,
+# SHT_NOTE sections aren't grouped nor sorted.
+#xfail: d30v-* dlx-* fr30-* frv-*-elf ft32-* iq2000-*
+#xfail: mn10200-* moxie-* mt-* msp430-* pj-* xgate-*
+
+#...
+ +[0-9]+ +\.note\.4 \.note\.1( .note.gnu.property|) +
+#pass
diff --git a/ld/testsuite/ld-elf/pr23658-1d.d b/ld/testsuite/ld-elf/pr23658-1d.d
new file mode 100644
index 0000000000..07b4bd3696
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr23658-1d.d
@@ -0,0 +1,15 @@
+#source: pr23658-1a.s
+#source: pr23658-1b.s
+#source: pr23658-1c.s
+#source: pr23658-1d.s
+#source: start.s
+#ld:
+#readelf: -l --wide
+# Since generic linker targets don't place SHT_NOTE sections as orphan,
+# SHT_NOTE sections aren't grouped nor sorted.
+#xfail: d30v-* dlx-* fr30-* frv-*-elf ft32-* iq2000-*
+#xfail: mn10200-* moxie-* mt-* msp430-* pj-* xgate-*
+
+#...
+ +[0-9]+ +\.note\.2 .note\.3( .note.gnu.property|) +
+#pass
diff --git a/ld/testsuite/ld-elf/pr23658-1e.d b/ld/testsuite/ld-elf/pr23658-1e.d
new file mode 100644
index 0000000000..56ebdcbffe
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr23658-1e.d
@@ -0,0 +1,13 @@
+#source: pr23658-1a.s
+#source: pr23658-1b.s
+#source: pr23658-1c.s
+#source: pr23658-1d.s
+#source: start.s
+#ld: --build-id -shared
+#readelf: -l --wide
+#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
+
+#...
+ +[0-9]+ +\.note.gnu.build-id \.note\.2 .note\.3 +
+ +[0-9]+ +\.note\.4 \.note\.1 +
+#pass
--
2.17.1