Patchwork Fix visibilities handling in write_symbol

login
register
mail settings
Submitter Jan Hubicka
Date July 21, 2010, 11:44 a.m.
Message ID <20100721114437.GB10125@kam.mff.cuni.cz>
Download mbox | patch
Permalink /patch/59432/
State New
Headers show

Comments

Jan Hubicka - July 21, 2010, 11:44 a.m.
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.
Diego Novillo - July 21, 2010, 12:07 p.m.
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.

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)