This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] ld -r: Don't merge with member of output section group


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=54d7dae59a2239720c848985a7d50a0a8b3319eb

commit 54d7dae59a2239720c848985a7d50a0a8b3319eb
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jul 18 08:01:45 2019 -0700

    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.

Diff:
---
 ld/ChangeLog                  | 8 ++++++++
 ld/emultempl/elf32.em         | 9 ++++++---
 ld/testsuite/ld-elf/pr24819.d | 8 ++++++++
 ld/testsuite/ld-elf/pr24819.s | 4 ++++
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 4f15124..782d426 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,11 @@
+2019-07-18  H.J. Lu  <hongjiu.lu@intel.com>
+
+	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.
+
 2019-07-13  Alan Modra  <amodra@gmail.com>
 
 	* testsuite/ld-powerpc/tlsso.r: Update.
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 3e8ee46..f3c6e3a 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 0000000..0a82b63
--- /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 0000000..08ba2b8
--- /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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]