ELF: Hide symbols defined in discarded input sections
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 25 Oct 2018 01:08:13 +0000 (18:08 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 25 Oct 2018 01:08:24 +0000 (18:08 -0700)
When assigning symbol version, we should hide debug symbols defined in
discarded sections from IR objects so that they can be removed later.

bfd/

PR ld/23818
* elflink.c (_bfd_elf_link_assign_sym_version): Hide symbols
defined in discarded input sections.

ld/

PR ld/23818
* testsuite/ld-plugin/lto.exp: Run PR ld/23818 test.
* testsuite/ld-plugin/pr23818.d: New file.
* testsuite/ld-plugin/pr23818.t: Likewise.
* testsuite/ld-plugin/pr23818a.c: Likewise.
* testsuite/ld-plugin/pr23818b.c: Likewise.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr23818.d [new file with mode: 0644]
ld/testsuite/ld-plugin/pr23818.t [new file with mode: 0644]
ld/testsuite/ld-plugin/pr23818a.c [new file with mode: 0644]
ld/testsuite/ld-plugin/pr23818b.c [new file with mode: 0644]

index 7e9fb6837c53d19915fc45206500b95d0ee70bac..0959688f616d7e285ace4ab9d1afe1293632444f 100644 (file)
@@ -1,3 +1,9 @@
+2018-10-24  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/23818
+       * elflink.c (_bfd_elf_link_assign_sym_version): Hide symbols
+       defined in discarded input sections.
+
 2018-10-24  Alan Modra  <amodra@gmail.com>
 
        * elf32-arm.c (elf32_arm_size_stubs): Ignore as-needed libs that
index 87440db9605551795b645561ce12693360274e0c..4eca389bd184a2e25dc0bef71bdcc2ef842134ef 100644 (file)
@@ -2359,13 +2359,21 @@ _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry *h, void *data)
       return FALSE;
     }
 
+  bed = get_elf_backend_data (info->output_bfd);
+
   /* We only need version numbers for symbols defined in regular
      objects.  */
   if (!h->def_regular)
-    return TRUE;
+    {
+      /* Hide symbols defined in discarded input sections.  */
+      if ((h->root.type == bfd_link_hash_defined
+          || h->root.type == bfd_link_hash_defweak)
+         && discarded_section (h->root.u.def.section))
+       (*bed->elf_backend_hide_symbol) (info, h, TRUE);
+      return TRUE;
+    }
 
   hide = FALSE;
-  bed = get_elf_backend_data (info->output_bfd);
   p = strchr (h->root.root.string, ELF_VER_CHR);
   if (p != NULL && h->verinfo.vertree == NULL)
     {
index f0a373d036b087c43f848d0c842d8dbb317e5527..60265758c7fe572f294838cf55881a0e8928b9f9 100644 (file)
@@ -1,3 +1,12 @@
+2018-10-24  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/23818
+       * testsuite/ld-plugin/lto.exp: Run PR ld/23818 test.
+       * testsuite/ld-plugin/pr23818.d: New file.
+       * testsuite/ld-plugin/pr23818.t: Likewise.
+       * testsuite/ld-plugin/pr23818a.c: Likewise.
+       * testsuite/ld-plugin/pr23818b.c: Likewise.
+
 2018-10-23  Alan Modra  <amodra@gmail.com>
 
        * testsuite/ld-elf/shared.exp: Don't build pr19073 test on alpha.
index 18829fdd64a5ea8f4cb4305488ca826dad5ad7b4..008bde79de7733825d43a300d5aa2074d47ba264 100644 (file)
@@ -219,6 +219,12 @@ set lto_link_tests [list \
   [list "Build pr22751.a" \
    "$plug_opt" "-flto $lto_no_fat $INT128_CFLAGS" \
    {pr22751.c} {} "pr22751.a"] \
+  [list "Build libpr23818.so" \
+   "-shared -flto -g -Wl,-version-script,pr23818.t" \
+   "-g -flto $lto_fat" \
+   {pr23818a.c pr23818b.c} \
+   {{"readelf" {-s --wide} "pr23818.d"}} \
+   "libpr23818.so"] \
 ]
 
 if { [at_least_gcc_version 4 7] } {
diff --git a/ld/testsuite/ld-plugin/pr23818.d b/ld/testsuite/ld-plugin/pr23818.d
new file mode 100644 (file)
index 0000000..5753cd6
--- /dev/null
@@ -0,0 +1,4 @@
+#failif
+#...
+.*0+ +[A-Z]+ +GLOBAL +DEFAULT +ABS foo
+#...
diff --git a/ld/testsuite/ld-plugin/pr23818.t b/ld/testsuite/ld-plugin/pr23818.t
new file mode 100644 (file)
index 0000000..45bca55
--- /dev/null
@@ -0,0 +1,4 @@
+{
+  global: bar;
+  local: *;
+};
diff --git a/ld/testsuite/ld-plugin/pr23818a.c b/ld/testsuite/ld-plugin/pr23818a.c
new file mode 100644 (file)
index 0000000..5b5ccbf
--- /dev/null
@@ -0,0 +1,4 @@
+void
+foo ()
+{
+}
diff --git a/ld/testsuite/ld-plugin/pr23818b.c b/ld/testsuite/ld-plugin/pr23818b.c
new file mode 100644 (file)
index 0000000..d4be333
--- /dev/null
@@ -0,0 +1,7 @@
+void foo (void);
+
+void
+bar (void)
+{
+  foo ();
+}
This page took 0.035021 seconds and 4 git commands to generate.