public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: binutils@sourceware.org
Subject: [committted, PATCH] PR ld/20528: Don't merge 2 sections with different SHF_EXCLUDE
Date: Thu, 29 Sep 2016 20:00:00 -0000	[thread overview]
Message-ID: <20160929200029.GA28690@intel.com> (raw)

SEC_EXCLUDE is ignored when doing a relocatable link.  But we can't
merge 2 input sections with the same name when only one of them has
SHF_EXCLUDE.

	PR ld/20528
	* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Don't
	merge 2 sections with different SHF_EXCLUDE.
	* testsuite/ld-elf/pr20528a.d: New file.
	* testsuite/ld-elf/pr20528a.s: Likewise.
	* testsuite/ld-elf/pr20528b.d: Likewise.
	* testsuite/ld-elf/pr20528b.s: Likewise.
---
 ld/emultempl/elf32.em          | 9 ++++++++-
 ld/testsuite/ld-elf/pr20528a.d | 9 +++++++++
 ld/testsuite/ld-elf/pr20528a.s | 6 ++++++
 ld/testsuite/ld-elf/pr20528b.d | 9 +++++++++
 ld/testsuite/ld-elf/pr20528b.s | 6 ++++++
 5 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-elf/pr20528a.d
 create mode 100644 ld/testsuite/ld-elf/pr20528a.s
 create mode 100644 ld/testsuite/ld-elf/pr20528b.d
 create mode 100644 ld/testsuite/ld-elf/pr20528b.s

diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 8461b1d..2815a3e 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1907,9 +1907,16 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
 	   lang_insert_orphan to create a new output section.  */
 	constraint = SPECIAL;
 
+	/* SEC_EXCLUDE is cleared when doing a relocatable link.  But
+	   we can't merge 2 input sections with the same name when only
+	   one of them has SHF_EXCLUDE.  */
 	if (os->bfd_section != NULL
 	    && (os->bfd_section->flags == 0
-		|| (((s->flags ^ os->bfd_section->flags)
+		|| ((!bfd_link_relocatable (&link_info)
+		     || (((elf_section_flags (s)
+			  ^ elf_section_flags (os->bfd_section))
+			 & SHF_EXCLUDE) == 0))
+		    && ((s->flags ^ os->bfd_section->flags)
 		     & (SEC_LOAD | SEC_ALLOC)) == 0
 		    && _bfd_elf_match_sections_by_type (link_info.output_bfd,
 							os->bfd_section,
diff --git a/ld/testsuite/ld-elf/pr20528a.d b/ld/testsuite/ld-elf/pr20528a.d
new file mode 100644
index 0000000..00d0a7a
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr20528a.d
@@ -0,0 +1,9 @@
+#source: pr20528a.s
+#source: pr20528b.s
+#ld: -r
+#readelf: -S --wide
+
+#...
+[ 	]*\[.*\][ 	]+\.text.startup[ 	]+PROGBITS.*[ 	]+AX[   ]+.*
+[ 	]*\[.*\][ 	]+\.text.startup[ 	]+PROGBITS.*[ 	]+AXE[   ]+.*
+#pass
diff --git a/ld/testsuite/ld-elf/pr20528a.s b/ld/testsuite/ld-elf/pr20528a.s
new file mode 100644
index 0000000..523bc6f
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr20528a.s
@@ -0,0 +1,6 @@
+        .text
+        .section        .text.startup,"ax",%progbits
+        .globl  main
+        .type   main, %function
+main:
+	.byte 0
diff --git a/ld/testsuite/ld-elf/pr20528b.d b/ld/testsuite/ld-elf/pr20528b.d
new file mode 100644
index 0000000..3ae6153
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr20528b.d
@@ -0,0 +1,9 @@
+#source: pr20528b.s
+#source: pr20528a.s
+#ld: -r
+#readelf: -S --wide
+
+#...
+[ 	]*\[.*\][ 	]+\.text.startup[ 	]+PROGBITS.*[ 	]+AXE[   ]+.*
+[ 	]*\[.*\][ 	]+\.text.startup[ 	]+PROGBITS.*[ 	]+AX[   ]+.*
+#pass
diff --git a/ld/testsuite/ld-elf/pr20528b.s b/ld/testsuite/ld-elf/pr20528b.s
new file mode 100644
index 0000000..9c41e8b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr20528b.s
@@ -0,0 +1,6 @@
+        .text
+        .section        .text.startup,"axe",%progbits
+        .globl  main1
+        .type   main1, %function
+main1:
+	.byte 0
-- 
2.7.4

                 reply	other threads:[~2016-09-29 20:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160929200029.GA28690@intel.com \
    --to=hongjiu.lu@intel.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).