This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] Don't merge 2 sections with different SHF_EXCLUDE
- From: H.J.Lu <hjl at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 29 Sep 2016 19:59:42 -0000
- Subject: [binutils-gdb] Don't merge 2 sections with different SHF_EXCLUDE
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=93dc595d7659a8cf224a9fc33aa9071f38328334
commit 93dc595d7659a8cf224a9fc33aa9071f38328334
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Thu Sep 29 12:58:29 2016 -0700
Don't merge 2 sections with different SHF_EXCLUDE
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.
Diff:
---
ld/ChangeLog | 10 ++++++++++
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 ++++++
6 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 988cb65..c5367a3 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,13 @@
+2016-09-29 H.J. Lu <hongjiu.lu@intel.com>
+
+ 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.
+
2016-09-28 Christophe Lyon <christophe.lyon@linaro.org>
PR ld/20608
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