Mark symbol in executables if it matches dynamic_list
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Feb 2014 17:44:25 +0000 (09:44 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 10 Feb 2014 16:05:54 +0000 (08:05 -0800)
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
bfd/elflink.c
ld/testsuite/ChangeLog
ld/testsuite/ld-elf/dynamic-1.c [new file with mode: 0644]
ld/testsuite/ld-elf/dynamic-1.rd [new file with mode: 0644]
ld/testsuite/ld-elf/dynamic-1.syms [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp

index 16ca958e8bceedf62e07af0fc14b3eed0ebe5e35..2117f417159a3cb0729275d6f099099821dbb1c3 100644 (file)
@@ -1,3 +1,9 @@
+2014-02-10  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-10  Alan Modra  <amodra@gmail.com>
 
        * po/SRC-POTFILES.in: Regenerate.
index af4f6bb190d0bf275559ed59dc4aa7f0efb8ef9d..b1962036d6f95bbaa7f73e78240af3a64b880b78 100644 (file)
@@ -12140,11 +12140,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
index e9eb2aadfcdb2d140a3c758f436a17445cc178e7..e28938393776bacdac2f2fbfe6d177665b09530e 100644 (file)
@@ -1,3 +1,12 @@
+2014-02-10  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 (file)
index 0000000..439ffd1
--- /dev/null
@@ -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 (file)
index 0000000..2c2f23b
--- /dev/null
@@ -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 (file)
index 0000000..c9517f8
--- /dev/null
@@ -0,0 +1,3 @@
+{
+  dynamic;
+};
index 981ce71f28bee5e495a39cd49c30a95a3179537d..949851f20d7a7b3272dc5d8dd9fe3705185fbb12 100644 (file)
@@ -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