This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR ld/12851: --gc-sections doesn't work on note sections
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Wed, 8 Jun 2011 13:10:14 -0700
- Subject: PATCH: PR ld/12851: --gc-sections doesn't work on note sections
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
SHT_NOTE sections are special. We check it in elf_gc_sweep. But
we missed it in bfd_elf_gc_sections. This patch fixes it. OK for
trunk?
Thanks.
H.J.
---
bfd/
2011-06-08 H.J. Lu <hongjiu.lu@intel.com>
PR ld/12851
* elflink.c (bfd_elf_gc_sections): Also check SHT_NOTE sections.
ld/testsuite/
2011-06-08 H.J. Lu <hongjiu.lu@intel.com>
PR ld/12851
* ld-elf/pr12851.d: New.
* ld-elf/pr12851.s: Likewise.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 562217d..958b9fb 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -12013,8 +12013,12 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
continue;
+ /* Also keep SHT_NOTE sections. */
for (o = sub->sections; o != NULL; o = o->next)
- if ((o->flags & (SEC_EXCLUDE | SEC_KEEP)) == SEC_KEEP && !o->gc_mark)
+ if ((o->flags & SEC_EXCLUDE) == 0
+ && ((o->flags & SEC_KEEP) != 0
+ || elf_section_data (o)->this_hdr.sh_type == SHT_NOTE)
+ && !o->gc_mark)
if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
return FALSE;
}
diff --git a/ld/testsuite/ld-elf/pr12851.d b/ld/testsuite/ld-elf/pr12851.d
new file mode 100644
index 0000000..84aa59a
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr12851.d
@@ -0,0 +1,14 @@
+#source: pr12851.s
+#source: start.s
+#ld: --gc-sections
+#readelf: -s --wide
+#notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
+#notarget: alpha-*-* hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
+#xfail: cr16-*-* crx-*-*
+# generic linker targets don't support --gc-sections, nor do a bunch of others
+# cr16 and crx use non-standard scripts with memory regions, which don't play
+# well with unique group sections under ld -r.
+
+#...
+ +.* _.stapsdt.base
+#pass
diff --git a/ld/testsuite/ld-elf/pr12851.s b/ld/testsuite/ld-elf/pr12851.s
new file mode 100644
index 0000000..784b91f
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr12851.s
@@ -0,0 +1,5 @@
+ .section .note.stapsdt,"?","note"
+ .dc.a _.stapsdt.base
+ .section .stapsdt.base,"a","progbits"
+_.stapsdt.base: .space 1
+ .size _.stapsdt.base,1