+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
 
     {
       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);
 
 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
              || 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;
 }
 
 
   [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.
 
--- /dev/null
+int
+main (void)
+{
+  return 0;
+}
+
+void 
+KeepMe (void)
+{
+}
 
--- /dev/null
+#...
+[0-9a-f]+ . _?KeepMe
+#pass