This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Mark symbol in executables if it matches dynamic_list
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Octoploid <cryptooctoploid at gmail dot com>, Binutils <binutils at sourceware dot org>
- Date: Thu, 6 Feb 2014 09:49:41 -0800
- Subject: PATCH: Mark symbol in executables if it matches dynamic_list
- Authentication-results: sourceware.org; auth=none
On Wed, Jan 29, 2014 at 2:35 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Nov 7, 2011 at 9:35 PM, Alan Modra <amodra@gmail.com> wrote:
>> On Mon, Nov 07, 2011 at 09:50:26PM +0100, Octoploid wrote:
>>> On Mon, Nov 7, 2011 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
>>> > I'll note that this was recently fixed in gold. If --export-dynamic is
>>> > passed to the linker, I think we should not garbage collect globally
>>> > visible functions.
>>
>> Try this.
>>
>> * elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark syms in
>> executables when export_dynamic.
>>
>> Index: bfd/elflink.c
>> ===================================================================
>> RCS file: /cvs/src/src/bfd/elflink.c,v
>> retrieving revision 1.428
>> diff -u -p -r1.428 elflink.c
>> --- bfd/elflink.c 19 Oct 2011 07:17:19 -0000 1.428
>> +++ bfd/elflink.c 8 Nov 2011 05:31:11 -0000
>> @@ -11947,7 +11947,7 @@ bfd_elf_gc_mark_dynamic_ref_symbol (stru
>> if ((h->root.type == bfd_link_hash_defined
>> || h->root.type == bfd_link_hash_defweak)
>> && (h->ref_dynamic
>> - || (!info->executable
>> + || ((!info->executable || info->export_dynamic)
>> && h->def_regular
>> && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
>> && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
>>
>>
>
We failed to handle --dynamic-list here. This patch fixes it.
OK to install?
Thanks.
--
H.J.
----
bfd/
PR gold/16530
* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark symbol in
executables if it matches dynamic_list.
ld/testsuite/
PR gold/16530
* ld-elf/dynamic-1.c: New file.
* ld-elf/dynamic-1.rd: Likewise.
* ld-elf/dynamic-1.syms: Likewise.
* ld-elf/shared.exp (build_tests): Add dynamic-1.
From 2db37e5a32cde6cc08f393b7d41e5e7ce55513dd Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 6 Feb 2014 09:44:25 -0800
Subject: [PATCH] Mark symbol in executables if it matches dynamic_list
bfd/
PR gold/16530
* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark symbol in
executables if it matches dynamic_list.
ld/testsuite/
PR gold/16530
* ld-elf/dynamic-1.c: New file.
* ld-elf/dynamic-1.rd: Likewise.
* ld-elf/dynamic-1.syms: Likewise.
* ld-elf/shared.exp (build_tests): Add dynamic-1.
---
bfd/ChangeLog | 6 ++++++
bfd/elflink.c | 6 +++++-
ld/testsuite/ChangeLog | 9 +++++++++
ld/testsuite/ld-elf/dynamic-1.c | 10 ++++++++++
ld/testsuite/ld-elf/dynamic-1.rd | 5 +++++
ld/testsuite/ld-elf/dynamic-1.syms | 3 +++
ld/testsuite/ld-elf/shared.exp | 3 +++
7 files changed, 41 insertions(+), 1 deletion(-)
create mode 100644 ld/testsuite/ld-elf/dynamic-1.c
create mode 100644 ld/testsuite/ld-elf/dynamic-1.rd
create mode 100644 ld/testsuite/ld-elf/dynamic-1.syms
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index e7ed98f..b25934c 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2014-02-06 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR gold/16530
+ * elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark symbol in
+ executables if it matches dynamic_list.
+
2014-02-04 Jan Kratochvil <jan.kratochvil@redhat.com>
* coff-rs6000.c (xcoff_write_archive_contents_big): Free OFFSETS in
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 88967c8..a783dd3 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -12131,11 +12131,15 @@ bfd_boolean
bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry *h, void *inf)
{
struct bfd_link_info *info = (struct bfd_link_info *) inf;
+ struct bfd_elf_dynamic_list *d = info->dynamic_list;
if ((h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
&& (h->ref_dynamic
- || ((!info->executable || info->export_dynamic)
+ || ((!info->executable
+ || info->export_dynamic
+ || (d != NULL
+ && (*d->match) (&d->head, NULL, h->root.root.string)))
&& h->def_regular
&& ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
&& ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index e9eb2aa..1237780 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2014-02-06 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR gold/16530
+ * ld-elf/dynamic-1.c: New file.
+ * ld-elf/dynamic-1.rd: Likewise.
+ * ld-elf/dynamic-1.syms: Likewise.
+
+ * ld-elf/shared.exp (build_tests): Add dynamic-1.
+
2014-02-02 Sebastian Huber <sebastian.huber@embedded-brains.de>
* ld-scripts/rgn-at9.d: New file.
diff --git a/ld/testsuite/ld-elf/dynamic-1.c b/ld/testsuite/ld-elf/dynamic-1.c
new file mode 100644
index 0000000..439ffd1
--- /dev/null
+++ b/ld/testsuite/ld-elf/dynamic-1.c
@@ -0,0 +1,10 @@
+void
+dynamic ()
+{
+}
+
+int
+main ()
+{
+ return 0;
+}
diff --git a/ld/testsuite/ld-elf/dynamic-1.rd b/ld/testsuite/ld-elf/dynamic-1.rd
new file mode 100644
index 0000000..2c2f23b
--- /dev/null
+++ b/ld/testsuite/ld-elf/dynamic-1.rd
@@ -0,0 +1,5 @@
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +FUNC +GLOBAL +DEFAULT +[0-9]+ +_?dynamic
+#...
diff --git a/ld/testsuite/ld-elf/dynamic-1.syms b/ld/testsuite/ld-elf/dynamic-1.syms
new file mode 100644
index 0000000..c9517f8
--- /dev/null
+++ b/ld/testsuite/ld-elf/dynamic-1.syms
@@ -0,0 +1,3 @@
+{
+ dynamic;
+};
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 981ce71..949851f 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -227,6 +227,9 @@ set build_tests {
{"Build rdynamic-1"
"-rdynamic -Wl,--gc-sections" "-ffunction-sections"
{rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
+ {"Build dynamic-1"
+ "-Wl,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
+ {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
}
run_cc_link_tests $build_tests
--
1.8.5.3