From patchwork Tue Jun 6 10:12:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Preudhomme X-Patchwork-Id: 771744 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3whnYs2HQSz9s0Z for ; Tue, 6 Jun 2017 20:12:49 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="EOlUbs7p"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=EI2224q9xwrIoiswx PEOuLooQta2Yu+/bI81r3m+wfDHdzb7uQtLEc2bEPemHnXveZK6z0hjxAm7lnb93 2aXszxv4usWiH8vV4smxZT2TqbjXY+J2bPCu6lYxOl8pUU8BIzL1YPtHbPRxZYOT WMZoS2YYcAf9nO9RPZWUnv5pKo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=ptnum7/Bq2YetfDZ0MsxtLt NECo=; b=EOlUbs7piuSpnlSL2rFw0Y8qp3rItOEMvUPr5FVjXlnXEvM+c/OhRVx 3yXW40lqs9Y5q3XP4JG1mmPhf/S0lhKZmPPVgCMivH7ThiOzSrO/7MxCLOLD1Bqo 47lz50T9Qi88IIq0jAqWTCq6XpbmUQ2KoTRKdAl3waHqhroq5fG0= Received: (qmail 86013 invoked by alias); 6 Jun 2017 10:12:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 85944 invoked by uid 89); 6 Jun 2017 10:12:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, KAM_STOCKGEN, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=habe, targeting, U*law, 1788 X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Jun 2017 10:12:33 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2C4902B; Tue, 6 Jun 2017 03:12:35 -0700 (PDT) Received: from [10.2.206.52] (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5E4053F578; Tue, 6 Jun 2017 03:12:34 -0700 (PDT) Subject: Re: [PATCH, GCC/LTO, ping3] Fix PR69866: LTO with def for weak alias in regular object file To: Jan Hubicka References: <654b4277-ced9-e778-bcda-3054e1983727@foss.arm.com> <1db1d20c-6f06-9bd3-2e7d-e862e31199cd@foss.arm.com> <2924a838-1869-9cd4-8b32-3c2c51a12bc5@redhat.com> <2485e103-8b05-2019-10e2-b75d8cc0f374@foss.arm.com> <7a758c6f-31d5-7133-0df3-3258d08b6b56@foss.arm.com> <20170509223658.GB82149@kam.mff.cuni.cz> Cc: "gcc-patches@gcc.gnu.org" , Richard Biener , Jeff Law From: Thomas Preudhomme Message-ID: <530b495f-e3e8-8223-cda0-1fe0525ba46b@foss.arm.com> Date: Tue, 6 Jun 2017 11:12:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170509223658.GB82149@kam.mff.cuni.cz> X-IsSubscribed: yes On 09/05/17 23:36, Jan Hubicka wrote: >> Ping? > Sorry for late reply My turn to apologize now. >>> 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 > > Adding external alises to partitions is important to keep the information > that two symbols are the same. So how about simply relaxing the assert then? Right now it trips for any external symbol, even external aliases. How about the following: ChangeLog entries are as follow: *** gcc/lto/ChangeLog *** 2017-06-02 Thomas Preud'homme * lto/lto-partition.c (add_symbol_to_partition_1): Change assert to allow external aliases to be added. *** gcc/ChangeLog *** 2017-03-01 Thomas Preud'homme * cgraphunit.c (cgraph_node::assemble_thunks_and_aliases): Do not declare external aliases. *** gcc/testsuite/ChangeLog *** 2017-02-28 Thomas Preud'homme * gcc.dg/lto/pr69866_0.c: New test. * gcc.dg/lto/pr69866_1.c: Likewise. Bootstrapped with LTO on Aarch64 and ARM and testsuite on both of these architectures do not show any regression. Is this ok for trunk? Best regards, Thomas > The second part makes sense to me. What breaks when you drop the first > change? > > Honza >>> >>> ChangeLog entries are as follow: >>> >>> *** gcc/lto/ChangeLog *** >>> >>> 2017-03-01 Thomas Preud'homme >>> >>> 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 >>> >>> 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 >>> >>> 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 >>> >>> On 31/03/17 18:07, Richard Biener wrote: >>>> On March 31, 2017 5:23:03 PM GMT+02:00, Jeff Law wrote: >>>>> On 03/16/2017 08:05 AM, Thomas Preudhomme wrote: >>>>>> Ping? >>>>>> >>>>>> Is this ok for stage4? >>>>> Given the lack of response from Richi, I'd suggest deferring to stage1. >>>> >>>> Honza needs to review this, i habe too little knowledge here. >>>> >>>> Richard. >>>> >>>>> jeff >>>> > >> 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 (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; >> +} > diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 7b4f47e6efb41e7c401e7347d86fffca6618c4e9..c2cc9df6419573bdc6223e1d2ee348f8af69ccca 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1984,7 +1984,7 @@ cgraph_node::assemble_thunks_and_aliases (void) FOR_EACH_ALIAS (this, ref) { cgraph_node *alias = dyn_cast (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 3600ab23bd9157aad76751912306abd498acae92..620deac090b7e718f05d3f37e6ef68e759de0008 100644 --- a/gcc/lto/lto-partition.c +++ b/gcc/lto/lto-partition.c @@ -132,7 +132,7 @@ add_symbol_to_partition_1 (ltrans_partition part, symtab_node *node) /* Be sure that we never try to duplicate partitioned symbol or add external symbol. */ - gcc_assert (c != SYMBOL_EXTERNAL + gcc_assert ((c != SYMBOL_EXTERNAL || node->alias) && (c == SYMBOL_DUPLICATE || !symbol_partitioned_p (node))); part->symbols++; 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; +}