This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Fix visibilities handling in write_symbol


Hi,
compiling:

void exit (int);
int main (void)
{
  exit (0);
}

With -fvisibility=hidden -flto -fuse-linker-plugin leads to unresolved symbol
on exit.  This is because we output exit into symbol table as hidden, while
when producing assembly we do not declare it this way.

This patch makes write_symbol to immitate what assemble_external do.
We need to output for external symbols non-default visibility only when
it is specified by attribute not defualted to by -fvisibility and this is
tested by !targetm.binds_local_p there, so I just copied it.

Bootstrapped/regtested x86_64-linux, OK?
	* lto-streamer-out.c (write_symbol): Fix visibilities of external
	references.
Index: lto-streamer-out.c
===================================================================
--- lto-streamer-out.c	(revision 162310)
+++ lto-streamer-out.c	(working copy)
@@ -2344,29 +2354,40 @@ write_symbol (struct lto_streamer_cache_
       else
 	kind = GCCPK_DEF;
 
       /* When something is defined, it should have a node attached.
 	 FIXME: For fortran this is still not the case since wrapup global
 	 decls is done after streaming.  */
       gcc_assert (alias || TREE_CODE (t) != FUNCTION_DECL
 		  || (cgraph_get_node (t)
 		      && cgraph_get_node (t)->analyzed));
     }
 
-  switch (DECL_VISIBILITY(t))
-    {
-    case VISIBILITY_DEFAULT:
-      visibility = GCCPV_DEFAULT;
-      break;
-    case VISIBILITY_PROTECTED:
-      visibility = GCCPV_PROTECTED;
-      break;
-    case VISIBILITY_HIDDEN:
-      visibility = GCCPV_HIDDEN;
-      break;
-    case VISIBILITY_INTERNAL:
-      visibility = GCCPV_INTERNAL;
-      break;
-    }
+  /* Immitate what default_elf_asm_output_external do.
+     When symbol is external, we need to output it with DEFAULT visibility
+     when compiling with -fvisibility=default, while with HIDDEN visiblity
+     when symbol has attribute (visibility("hidden")) specified.
+     targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
+     right. */
+     
+  if (DECL_EXTERNAL (t)
+      && !targetm.binds_local_p (t))
+    visibility = GCCPV_DEFAULT;
+  else
+    switch (DECL_VISIBILITY(t))
+      {
+      case VISIBILITY_DEFAULT:
+	visibility = GCCPV_DEFAULT;
+	break;
+      case VISIBILITY_PROTECTED:
+	visibility = GCCPV_PROTECTED;
+	break;
+      case VISIBILITY_HIDDEN:
+	visibility = GCCPV_HIDDEN;
+	break;
+      case VISIBILITY_INTERNAL:
+	visibility = GCCPV_INTERNAL;
+	break;
+      }
 
   if (kind == GCCPK_COMMON
       && DECL_SIZE (t)


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