public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix visibilities handling in write_symbol
@ 2010-07-21 11:44 Jan Hubicka
  2010-07-21 12:08 ` Diego Novillo
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Hubicka @ 2010-07-21 11:44 UTC (permalink / raw)
  To: gcc-patches

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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Fix visibilities handling in write_symbol
  2010-07-21 11:44 Fix visibilities handling in write_symbol Jan Hubicka
@ 2010-07-21 12:08 ` Diego Novillo
  0 siblings, 0 replies; 2+ messages in thread
From: Diego Novillo @ 2010-07-21 12:08 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-21 12:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-21 11:44 Fix visibilities handling in write_symbol Jan Hubicka
2010-07-21 12:08 ` Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).