public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, GCC/LTO] Fix PR69866: LTO with def for weak alias in regular object file
@ 2017-03-02 14:52 Thomas Preudhomme
  2017-03-09  9:43 ` Thomas Preudhomme
  0 siblings, 1 reply; 13+ messages in thread
From: Thomas Preudhomme @ 2017-03-02 14:52 UTC (permalink / raw)
  To: Richard Biener, gcc-patches; +Cc: Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]

Hi,

This patch fixes an assert failure when linking one LTOed object file
having a weak alias with a regular object file containing a strong
definition for that same symbol. The patch is twofold:

+ do not add an alias to a partition if it is external
+ do not declare (.globl) an alias if it is external

ChangeLog entries are as follow:

*** gcc/lto/ChangeLog ***

2017-03-01  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	PR lto/69866
	* lto/lto-partition.c (add_symbol_to_partition_1): Do not add external
	aliases to partition.

*** gcc/ChangeLog ***

2017-03-01  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	PR lto/69866
	* cgraphunit.c (cgraph_node::assemble_thunks_and_aliases): Do not
	declare external aliases.

*** gcc/testsuite/ChangeLog ***

2017-02-28  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.


Testing: Testsuite shows no regression when targeting Cortex-M3 with an
arm-none-eabi GCC cross-compiler, neither does it show any regression with 
native LTO-bootstrapped x86-64_linux-gnu and aarch64-linux-gnu compilers.

Is this ok for stage4?

Best regards,

Thomas

[-- Attachment #2: fix_pr69866.patch --]
[-- Type: text/x-patch, Size: 2370 bytes --]

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index c82a88a599ca61b068dd9783d2a6158163809b37..580500ff922b8546d33119261a2455235edbf16d 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1972,7 +1972,7 @@ cgraph_node::assemble_thunks_and_aliases (void)
   FOR_EACH_ALIAS (this, ref)
     {
       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
-      if (!alias->transparent_alias)
+      if (!alias->transparent_alias && !DECL_EXTERNAL (alias->decl))
 	{
 	  bool saved_written = TREE_ASM_WRITTEN (decl);
 
diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c
index e27d0d1690c1fcfb39e2fac03ce0f4154031fc7c..f44fd435ed075a27e373bdfdf0464eb06e1731ef 100644
--- a/gcc/lto/lto-partition.c
+++ b/gcc/lto/lto-partition.c
@@ -178,7 +178,8 @@ add_symbol_to_partition_1 (ltrans_partition part, symtab_node *node)
   /* Add all aliases associated with the symbol.  */
 
   FOR_EACH_ALIAS (node, ref)
-    if (!ref->referring->transparent_alias)
+    if (!ref->referring->transparent_alias
+	&& ref->referring->get_partitioning_class () != SYMBOL_EXTERNAL)
       add_symbol_to_partition_1 (part, ref->referring);
     else
       {
@@ -189,7 +190,8 @@ add_symbol_to_partition_1 (ltrans_partition part, symtab_node *node)
 	  {
 	    /* Nested transparent aliases are not permitted.  */
 	    gcc_checking_assert (!ref2->referring->transparent_alias);
-	    add_symbol_to_partition_1 (part, ref2->referring);
+	    if (ref2->referring->get_partitioning_class () != SYMBOL_EXTERNAL)
+	      add_symbol_to_partition_1 (part, ref2->referring);
 	  }
       }
 
diff --git a/gcc/testsuite/gcc.dg/lto/pr69866_0.c b/gcc/testsuite/gcc.dg/lto/pr69866_0.c
new file mode 100644
index 0000000000000000000000000000000000000000..f49ef8d4c1da7a21d1bfb5409d647bd18141595b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr69866_0.c
@@ -0,0 +1,13 @@
+/* { dg-lto-do link } */
+
+int _umh(int i)
+{
+  return i+1;
+}
+
+int weaks(int i) __attribute__((weak, alias("_umh")));
+
+int main()
+{
+  return weaks(10);
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr69866_1.c b/gcc/testsuite/gcc.dg/lto/pr69866_1.c
new file mode 100644
index 0000000000000000000000000000000000000000..3a14f850eefaffbf659ce4642adef7900330f4ed
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr69866_1.c
@@ -0,0 +1,6 @@
+/* { dg-options { -fno-lto } } */
+
+int weaks(int i)
+{
+  return i+1;
+}

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

end of thread, other threads:[~2017-06-15  9:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-02 14:52 [PATCH, GCC/LTO] Fix PR69866: LTO with def for weak alias in regular object file Thomas Preudhomme
2017-03-09  9:43 ` Thomas Preudhomme
2017-03-16 14:05   ` [PATCH, GCC/LTO, ping2] " Thomas Preudhomme
2017-03-23 16:08     ` [PATCH, GCC/LTO, stage4, ping3] " Thomas Preudhomme
2017-03-31 15:25     ` [PATCH, GCC/LTO, ping2] " Jeff Law
2017-03-31 18:11       ` Richard Biener
2017-05-02 16:56         ` [PATCH, GCC/LTO, ping3] " Thomas Preudhomme
2017-05-09 10:43           ` Thomas Preudhomme
2017-05-09 23:52             ` Jan Hubicka
2017-05-10 10:57               ` Thomas Preudhomme
2017-06-06 10:12               ` Thomas Preudhomme
2017-06-12  9:13                 ` [PATCH, GCC/LTO, ping] " Thomas Preudhomme
2017-06-15  9:26                   ` Jan Hubicka

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).