diff mbox series

[arm-embedded,GCC/LTO,ping] Fix PR69866: LTO with def for weak alias in regular object file

Message ID e9051968-7e3d-fee6-c525-16c864dc5d03@foss.arm.com
State New
Headers show
Series [arm-embedded,GCC/LTO,ping] Fix PR69866: LTO with def for weak alias in regular object file | expand

Commit Message

Thomas Preudhomme Nov. 28, 2017, 3:25 p.m. UTC
Hi,

We have decided to apply the forwarded patch to the embedded-7-branch to fix an 
ICE when doing partial LTO with weak symbols.

ChangeLog entry is as follows:

2017-11-28  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	Backport from mainline
	2017-06-15  Jan Hubicka  <hubicka@ucw.cz>
		    Thomas Preud'homme  <thomas.preudhomme@arm.com>

	PR lto/69866
	* lto-symtab.c (lto_symtab_merge_symbols): Drop useless definitions
	that resolved externally.

	Backport from mainline
	2017-06-15  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	PR lto/69866
	* gcc.dg/lto/pr69866_0.c: New test.
	* gcc.dg/lto/pr69866_1.c: Likewise.


Best regards,

Thomas
Hi,
I am testing the following. Let me know if it works for you.

Honza
diff mbox series

Patch

Index: lto/lto-symtab.c
===================================================================
--- lto/lto-symtab.c	(revision 249213)
+++ lto/lto-symtab.c	(working copy)
@@ -952,6 +952,42 @@ 
 	      if (tgt)
 		node->resolve_alias (tgt, true);
 	    }
+	  /* If the symbol was preempted outside IR, see if we want to get rid
+	     of the definition.  */
+	  if (node->analyzed
+	      && !DECL_EXTERNAL (node->decl)
+	      && (node->resolution == LDPR_PREEMPTED_REG
+		  || node->resolution == LDPR_RESOLVED_IR
+		  || node->resolution == LDPR_RESOLVED_EXEC
+		  || node->resolution == LDPR_RESOLVED_DYN))
+	    {
+	      DECL_EXTERNAL (node->decl) = 1;
+	      /* If alias to local symbol was preempted by external definition,
+		 we know it is not pointing to the local symbol.  Remove it.  */
+	      if (node->alias
+		  && !node->weakref
+		  && !node->transparent_alias
+		  && node->get_alias_target ()->binds_to_current_def_p ())
+		{
+		  node->alias = false;
+		  node->remove_all_references ();
+		  node->definition = false;
+		  node->analyzed = false;
+		  node->cpp_implicit_alias = false;
+		}
+	      else if (!node->alias
+		       && node->definition
+		       && node->get_availability () <= AVAIL_INTERPOSABLE)
+		{
+		  if ((cnode = dyn_cast <cgraph_node *> (node)) != NULL)
+		    cnode->reset ();
+		  else
+		    {
+		      node->analyzed = node->definition = false;
+		      node->remove_all_references ();
+		    }
+		}
+	    }
 
 	  if (!(cnode = dyn_cast <cgraph_node *> (node))
 	      || !cnode->clone_of