This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Always keep sections marked with SEC_KEEP
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: binutils at sourceware dot org
- Date: Thu, 22 Oct 2015 12:24:53 -0700
- Subject: [PATCH] Always keep sections marked with SEC_KEEP
- Authentication-results: sourceware.org; auth=none
SEC_KEEP check in elf_gc_sweep was missing in commit:
commit bde6f3eb6dff94cea1d471e15c6154d55d49820f
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Fri Jan 8 01:43:23 2010 +0000
Set SEC_KEEP on section XXX for undefined __start_XXX/__stop_XXX
bfd/
2010-01-07 H.J. Lu <hongjiu.lu@intel.com>
PR ld/11133
* elflink.c (_bfd_elf_gc_mark_hook): Check section XXX for
undefined __start_XXX/__stop_XXX in all input files and set
SEC_KEEP.
This patch adds SEC_KEEP check to elf_gc_sweep.
bfd/
PR ld/19161
* elflink.c (elf_gc_sweep): Always keep sections marked with
SEC_KEEP.
ld/testsuite/
PR ld/19161
* ld-gc/gc.exp: Run pr19161 test.
* ld-gc/pr19161-1.c: New file.
* ld-gc/pr19161-2.c: Likewise.
* ld-gc/pr19161.d: Likewise.
---
bfd/ChangeLog | 6 ++++++
bfd/elflink.c | 3 ++-
ld/testsuite/ChangeLog | 8 ++++++++
ld/testsuite/ld-gc/gc.exp | 6 ++++++
ld/testsuite/ld-gc/pr19161-1.c | 7 +++++++
ld/testsuite/ld-gc/pr19161-2.c | 19 +++++++++++++++++++
ld/testsuite/ld-gc/pr19161.d | 9 +++++++++
7 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 ld/testsuite/ld-gc/pr19161-1.c
create mode 100644 ld/testsuite/ld-gc/pr19161-2.c
create mode 100644 ld/testsuite/ld-gc/pr19161.d
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index e647a2b..60b79ed 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2015-10-22 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/19161
+ * elflink.c (elf_gc_sweep): Always keep sections marked with
+ SEC_KEEP.
+
2015-10-22 Hans-Peter Nilsson <hp@bitrange.com>
* mmo.c (struct mmo_data_struct): New members
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 73fe469..06df821 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -12449,7 +12449,8 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
o->gc_mark = first->gc_mark;
}
- if (o->gc_mark)
+ /* Always keep sections marked with SEC_KEEP. */
+ if (o->gc_mark || (o->flags & SEC_KEEP))
continue;
/* Skip sweeping sections already excluded. */
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index a206247..12c4dce 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2015-10-22 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/19161
+ * ld-gc/gc.exp: Run pr19161 test.
+ * ld-gc/pr19161-1.c: New file.
+ * ld-gc/pr19161-2.c: Likewise.
+ * ld-gc/pr19161.d: Likewise.
+
2015-10-22 Hans-Peter Nilsson <hp@bitrange.com>
* ld-scripts/script.exp (extract_symbol_test): Allow nm output of
diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp
index b2a3450..f7438d4 100644
--- a/ld/testsuite/ld-gc/gc.exp
+++ b/ld/testsuite/ld-gc/gc.exp
@@ -139,3 +139,9 @@ if { [is_remote host] || [which $CC] != 0 } {
ld_compile "$CC $CFLAGS $cflags" $srcdir/$subdir/pr14265.c tmpdir/pr14265.o
run_dump_test "pr14265"
}
+
+if { [is_remote host] || [which $CC] != 0 } {
+ ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-1.c tmpdir/pr19161-1.o
+ ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-2.c tmpdir/pr19161-2.o
+ run_dump_test "pr19161"
+}
diff --git a/ld/testsuite/ld-gc/pr19161-1.c b/ld/testsuite/ld-gc/pr19161-1.c
new file mode 100644
index 0000000..519948e
--- /dev/null
+++ b/ld/testsuite/ld-gc/pr19161-1.c
@@ -0,0 +1,7 @@
+int (*p)(void);
+
+int
+main ()
+{
+ return p () != 0x1234;
+}
diff --git a/ld/testsuite/ld-gc/pr19161-2.c b/ld/testsuite/ld-gc/pr19161-2.c
new file mode 100644
index 0000000..b51f31a
--- /dev/null
+++ b/ld/testsuite/ld-gc/pr19161-2.c
@@ -0,0 +1,19 @@
+int __attribute__((section("my_section"))) a[2] = {0x1234, 0x5678};
+
+extern int __start_my_section;
+
+extern int (*p)(void);
+
+int
+dump()
+{
+ int* ap = &__start_my_section;
+ return ap[0];
+}
+
+void
+__attribute__((constructor))
+foo()
+{
+ p = dump;
+}
diff --git a/ld/testsuite/ld-gc/pr19161.d b/ld/testsuite/ld-gc/pr19161.d
new file mode 100644
index 0000000..64b17e0
--- /dev/null
+++ b/ld/testsuite/ld-gc/pr19161.d
@@ -0,0 +1,9 @@
+#name: --gc-sections with __start_SECTIONNAME
+#source: dummy.s
+#ld: --gc-sections -e main tmpdir/pr19161-1.o tmpdir/pr19161-2.o
+#nm: --format=bsd
+#xfail: sh64*-*-* iq2000-*-* lm32-*-* epiphany-*-* mips64vr-*-* frv-*-* m32c-*-* rl78-*-* rx-*-* sh-*-* powerpc*-*-eabivle msp430-*-*
+
+#...
+0*[1-9a-f]+[0-9a-f]*[ ](D)[ ]_*__start_my_section
+#...
--
2.4.3