This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] ld: Set non_ir_ref_regular for --undefined SYMBOL


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=94d401b8b88a76b1372ce44e805516756a4f737b

commit 94d401b8b88a76b1372ce44e805516756a4f737b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 4 06:27:58 2018 -0700

    ld: Set non_ir_ref_regular for --undefined SYMBOL
    
    Set non_ir_ref_regular to TRUE for symbols forced into the output file
    so that they won't be removed by garbage collection with LTO.
    
    	PR ld/23309
    	* ldlang.c (insert_undefined): Set non_ir_ref_regular to TRUE.
    	* plugin.c (is_visible_from_outside): Don't scan entry_symbol.
    	* testsuite/ld-plugin/pr23309.c: New file.
    	* testsuite/ld-plugin/pr23309.d: Likewise.

Diff:
---
 ld/ChangeLog                     |  8 ++++++++
 ld/ldlang.c                      |  1 +
 ld/plugin.c                      |  7 -------
 ld/testsuite/ld-plugin/lto.exp   |  4 ++++
 ld/testsuite/ld-plugin/pr23309.c | 10 ++++++++++
 ld/testsuite/ld-plugin/pr23309.d |  3 +++
 6 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 6696014..e28d55d 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,13 @@
 2018-07-04  H.J. Lu  <hongjiu.lu@intel.com>
 
+	PR ld/23309
+	* ldlang.c (insert_undefined): Set non_ir_ref_regular to TRUE.
+	* plugin.c (is_visible_from_outside): Don't scan entry_symbol.
+	* testsuite/ld-plugin/pr23309.c: New file.
+	* testsuite/ld-plugin/pr23309.d: Likewise.
+
+2018-07-04  H.J. Lu  <hongjiu.lu@intel.com>
+
 	PR ld/23358
 	* lexsup.c (elf_shlib_list_options): Properly display default
 	for -z separate-code.
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 21ef9be..350baf2 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -3413,6 +3413,7 @@ insert_undefined (const char *name)
     {
       h->type = bfd_link_hash_undefined;
       h->u.undef.abfd = NULL;
+      h->non_ir_ref_regular = TRUE;
       if (is_elf_hash_table (link_info.hash))
 	((struct elf_link_hash_entry *) h)->mark = 1;
       bfd_link_add_undef (link_info.hash, h);
diff --git a/ld/plugin.c b/ld/plugin.c
index 78f2e04..994eb6b 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -625,8 +625,6 @@ static inline bfd_boolean
 is_visible_from_outside (struct ld_plugin_symbol *lsym,
 			 struct bfd_link_hash_entry *blhe)
 {
-  struct bfd_sym_chain *sym;
-
   if (bfd_link_relocatable (&link_info))
     return TRUE;
   if (blhe->non_ir_ref_dynamic
@@ -658,11 +656,6 @@ is_visible_from_outside (struct ld_plugin_symbol *lsym,
 	      || lsym->visibility == LDPV_PROTECTED);
     }
 
-  for (sym = &entry_symbol; sym != NULL; sym = sym->next)
-    if (sym->name
-	&& strcmp (sym->name, blhe->root.string) == 0)
-      return TRUE;
-
   return FALSE;
 }
 
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 70274b3..7c50b0f 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -242,6 +242,10 @@ set lto_compile_elf_tests [list \
   [list "Compile 8b" \
    "" "-flto -O2" \
    {lto-8b.c} {} ""] \
+  [list "PR ld/23309" \
+   "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections -Wl,--gc-sections,-u,KeepMe" \
+   "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections" \
+   {pr23309.c} {{"nm" {} "pr23309.d"}} "pr23309.exe" "c"] \
 ]
 
 # Generate input files for complex LTO tests for ELF.
diff --git a/ld/testsuite/ld-plugin/pr23309.c b/ld/testsuite/ld-plugin/pr23309.c
new file mode 100644
index 0000000..da8bb3a
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr23309.c
@@ -0,0 +1,10 @@
+int
+main (void)
+{
+  return 0;
+}
+
+void 
+KeepMe (void)
+{
+}
diff --git a/ld/testsuite/ld-plugin/pr23309.d b/ld/testsuite/ld-plugin/pr23309.d
new file mode 100644
index 0000000..c353b66
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr23309.d
@@ -0,0 +1,3 @@
+#...
+[0-9a-f]+ . _?KeepMe
+#pass


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]