diff mbox

Fix visibilities handling in write_symbol

Message ID 20100721114437.GB10125@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka July 21, 2010, 11:44 a.m. UTC
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.

Comments

Diego Novillo July 21, 2010, 12:07 p.m. UTC | #1
On 10-07-21 07:44 , Jan Hubicka wrote:

> 	* lto-streamer-out.c (write_symbol): Fix visibilities of external
> 	references.

OK with

> +  /* Immitate what default_elf_asm_output_external do.

s/Immitate/Imitate/

> +     When symbol is external, we need to output it with DEFAULT visibility
> +     when compiling with -fvisibility=default, while with HIDDEN visiblity

s/visiblity/visibility/


Diego.
diff mbox

Patch

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)