This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR ld/11143: Static linking with gc-sections deletes note section
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Wed, 6 Jan 2010 09:19:43 -0800
- Subject: PATCH: PR ld/11143: Static linking with gc-sections deletes note section
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
-gc-sections deletes note section. This patch fixes it. OK to install?
Thanks.
H.J.
---
bfd/
2010-01-06 H.J. Lu <hongjiu.lu@intel.com>
PR ld/11143
* elflink.c (elf_gc_sweep): Keep SHT_NOTE section.
ld/testsuite/
2010-01-06 H.J. Lu <hongjiu.lu@intel.com>
PR ld/11143
* ld-gc/gc.exp: Run abi-note.
* ld-gc/abi-note.d: New.
* ld-gc/abi-note.s: Likewise.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index b529e16..0c685bc 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -11554,9 +11554,10 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
o->gc_mark = first->gc_mark;
}
else if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0
- || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)
+ || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0
+ || elf_section_data (o)->this_hdr.sh_type == SHT_NOTE)
{
- /* Keep debug and special sections. */
+ /* Keep debug, special and SHT_NOTE sections. */
o->gc_mark = 1;
}
diff --git a/ld/testsuite/ld-gc/abi-note.d b/ld/testsuite/ld-gc/abi-note.d
new file mode 100644
index 0000000..e802fe5
--- /dev/null
+++ b/ld/testsuite/ld-gc/abi-note.d
@@ -0,0 +1,8 @@
+#name: --gc-sections with note section
+#ld: --gc-sections -e _start
+#readelf: -S --wide
+#target: *-*-linux*
+
+#...
+.* .note.ABI-tag[ ]+NOTE.*
+#...
diff --git a/ld/testsuite/ld-gc/abi-note.s b/ld/testsuite/ld-gc/abi-note.s
new file mode 100644
index 0000000..22536c0
--- /dev/null
+++ b/ld/testsuite/ld-gc/abi-note.s
@@ -0,0 +1,15 @@
+ .text
+ .global _start
+_start:
+ .long 1
+
+ .section ".note.ABI-tag", "a"
+ .p2align 2
+ .long 1f - 0f /* name length */
+ .long 3f - 2f /* data length */
+ .long 1 /* note type */
+0: .asciz "GNU" /* vendor name */
+1: .p2align 2
+2: .long 1
+ .long 2
+3: .p2align 2 /* pad out section */
diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp
index c85b909..b557879 100644
--- a/ld/testsuite/ld-gc/gc.exp
+++ b/ld/testsuite/ld-gc/gc.exp
@@ -91,3 +91,4 @@ test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func"
run_dump_test "noent"
run_dump_test "start"
+run_dump_test "abi-note"