ld -r: Don't merge with member of output section group

Message ID CAMe9rOrTX=EQhF07pD=m2re3nW2d6KmG9TvVWfjYitDw7bvs-Q@mail.gmail.com
State New
Headers show
Series
  • ld -r: Don't merge with member of output section group
Related show

Commit Message

H.J. Lu July 17, 2019, 8:20 p.m.
When doing a relocatable link, members of input section group are
placed in their own output sections.  We need to make sure that no
input sections are merged with member of output section group.

OK for master and release branches?

PR ld/24819
* emultempl/elf32.em (elf_orphan_compatible): Return FALSE for
member of output section group when doing a relocatable link.
* testsuite/ld-elf/pr24819.d: New file.
* testsuite/ld-elf/pr24819.s: Likewise.

-- 
H.J.

Comments

Alan Modra July 18, 2019, 12:41 p.m. | #1
On Wed, Jul 17, 2019 at 01:20:04PM -0700, H.J. Lu wrote:
> 	PR ld/24819

> 	* emultempl/elf32.em (elf_orphan_compatible): Return FALSE for

> 	member of output section group when doing a relocatable link.

> 	* testsuite/ld-elf/pr24819.d: New file.

> 	* testsuite/ld-elf/pr24819.s: Likewise.


OK.

-- 
Alan Modra
Australia Development Lab, IBM
Alan Modra July 19, 2019, 7:42 a.m. | #2
On Thu, Jul 18, 2019 at 10:11:24PM +0930, Alan Modra wrote:
> On Wed, Jul 17, 2019 at 01:20:04PM -0700, H.J. Lu wrote:

> > 	PR ld/24819

> > 	* emultempl/elf32.em (elf_orphan_compatible): Return FALSE for

> > 	member of output section group when doing a relocatable link.

> > 	* testsuite/ld-elf/pr24819.d: New file.

> > 	* testsuite/ld-elf/pr24819.s: Likewise.

> 

> OK.


d30v-elf  +FAIL: ld-elf/pr24819
dlx-elf  +FAIL: ld-elf/pr24819
fr30-elf  +FAIL: ld-elf/pr24819
frv-elf  +FAIL: ld-elf/pr24819
ft32-elf  +FAIL: ld-elf/pr24819
iq2000-elf  +FAIL: ld-elf/pr24819
mn10200-elf  +FAIL: ld-elf/pr24819
moxie-elf  +FAIL: ld-elf/pr24819
msp430-elf  +FAIL: ld-elf/pr24819
mt-elf  +FAIL: ld-elf/pr24819
pj-elf  +FAIL: ld-elf/pr24819
s12z-elf  +FAIL: ld-elf/pr24819
xgate-elf  +FAIL: ld-elf/pr24819

I'm going to commit the following after another test run.

	PR 24819
	* testsuite/ld-elf/pr24819.d: xfail for genelf targets.

diff --git a/ld/testsuite/ld-elf/pr24819.d b/ld/testsuite/ld-elf/pr24819.d
index 0a82b63c39..c97ef5fbac 100644
--- a/ld/testsuite/ld-elf/pr24819.d
+++ b/ld/testsuite/ld-elf/pr24819.d
@@ -1,5 +1,6 @@
 #ld: -r
 #readelf: -S --wide
+#xfail: [uses_genelf]
 
 #...
   \[[ 0-9]+\] \.data\.foo[ \t]+PROGBITS[ \t0-9a-f]+WAG .*


-- 
Alan Modra
Australia Development Lab, IBM

Patch

From b1d60254febe7476dab9d4572b29dfa2619f4207 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 17 Jul 2019 12:47:04 -0700
Subject: [PATCH] ld -r: Don't merge with member of output section group

When doing a relocatable link, members of input section group are
placed in their own output sections.  We need to make sure that no
input sections are merged with member of output section group.

	PR ld/24819
	* emultempl/elf32.em (elf_orphan_compatible): Return FALSE for
	member of output section group when doing a relocatable link.
	* testsuite/ld-elf/pr24819.d: New file.
	* testsuite/ld-elf/pr24819.s: Likewise.
---
 ld/emultempl/elf32.em         | 9 ++++++---
 ld/testsuite/ld-elf/pr24819.d | 8 ++++++++
 ld/testsuite/ld-elf/pr24819.s | 4 ++++
 3 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/pr24819.d
 create mode 100644 ld/testsuite/ld-elf/pr24819.s

diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 3e8ee4693e..f3c6e3adee 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -2028,10 +2028,13 @@  elf_orphan_compatible (asection *in, asection *out)
   if (elf_section_data (out)->this_hdr.sh_info
       != elf_section_data (in)->this_hdr.sh_info)
     return FALSE;
-  /* We can't merge two sections with differing SHF_EXCLUDE when doing
-     a relocatable link.  */
+  /* We can't merge with member of output section group nor merge two
+     sections with differing SHF_EXCLUDE when doing a relocatable link.
+   */
   if (bfd_link_relocatable (&link_info)
-      && ((elf_section_flags (out) ^ elf_section_flags (in)) & SHF_EXCLUDE) != 0)
+      && (elf_next_in_group (out) != NULL
+	  || ((elf_section_flags (out) ^ elf_section_flags (in))
+	      & SHF_EXCLUDE) != 0))
     return FALSE;
   return _bfd_elf_match_sections_by_type (link_info.output_bfd, out,
 					  in->owner, in);
diff --git a/ld/testsuite/ld-elf/pr24819.d b/ld/testsuite/ld-elf/pr24819.d
new file mode 100644
index 0000000000..0a82b63c39
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr24819.d
@@ -0,0 +1,8 @@ 
+#ld: -r
+#readelf: -S --wide
+
+#...
+  \[[ 0-9]+\] \.data\.foo[ \t]+PROGBITS[ \t0-9a-f]+WAG .*
+#...
+  \[[ 0-9]+\] \.data\.foo[ \t]+PROGBITS[ \t0-9a-f]+WA .*
+#pass
diff --git a/ld/testsuite/ld-elf/pr24819.s b/ld/testsuite/ld-elf/pr24819.s
new file mode 100644
index 0000000000..08ba2b8437
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr24819.s
@@ -0,0 +1,4 @@ 
+	.section	.data.foo,"awG",%progbits,.group1,comdat
+	.byte 0
+	.section	.data.foo,"aw",%progbits
+	.byte 0
-- 
2.20.1